add getShopBySignLocation(Location signLocation) to api

This commit is contained in:
Len 2022-07-09 16:34:38 +02:00
parent 226aaa2ba2
commit 016b24987a
7 changed files with 80 additions and 52 deletions

View File

@ -19,6 +19,14 @@ public interface ShopHandler { // TODO finish docs
*/
Shop getShop(Location location);
/**
* Get the shop at a given location
*
* @param signLocation Location of the shopSign
* @return Shop at the given location or <b>null</b> if no shop is found there
*/
Shop getShopBySignLocation(Location signLocation);
/**
* Checks whether there is a shop at a given location
* @param location Location to check

View File

@ -2,15 +2,12 @@ package com.alttd.playershops.api.events;
import com.alttd.playershops.api.Shop;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerCreateShopEvent extends ShopEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private boolean cancelled;
public PlayerCreateShopEvent(Player player, Shop shop) {
super(shop);
@ -21,16 +18,6 @@ public class PlayerCreateShopEvent extends ShopEvent {
return player;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean set) {
cancelled = set;
}
@NotNull
@Override
public HandlerList getHandlers() {

View File

@ -2,8 +2,6 @@ package com.alttd.playershops.api.events;
import com.alttd.playershops.api.Shop;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@ -11,7 +9,6 @@ public class PlayerDestroyShopEvent extends ShopEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private boolean cancelled;
public PlayerDestroyShopEvent(Player player, Shop shop) {
super(shop);
@ -22,16 +19,6 @@ public class PlayerDestroyShopEvent extends ShopEvent {
return player;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean set) {
cancelled = set;
}
@NotNull
@Override
public HandlerList getHandlers() {

View File

@ -2,8 +2,6 @@ package com.alttd.playershops.api.events;
import com.alttd.playershops.api.Shop;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@ -11,7 +9,6 @@ public class PlayerExchangeShopEvent extends ShopEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private boolean cancelled;
public PlayerExchangeShopEvent(Player player, Shop shop) {
super(shop);
@ -22,16 +19,6 @@ public class PlayerExchangeShopEvent extends ShopEvent {
return player;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean set) {
cancelled = set;
}
@NotNull
@Override
public HandlerList getHandlers() {

View File

@ -2,8 +2,6 @@ package com.alttd.playershops.api.events;
import com.alttd.playershops.api.Shop;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@ -11,7 +9,6 @@ public class PlayerInitializeShopEvent extends ShopEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private boolean cancelled;
public PlayerInitializeShopEvent(Player player, Shop shop) {
super(shop);
@ -22,16 +19,6 @@ public class PlayerInitializeShopEvent extends ShopEvent {
return player;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean set) {
cancelled = set;
}
@NotNull
@Override
public HandlerList getHandlers() {

View File

@ -0,0 +1,41 @@
package com.alttd.playershops.api.events;
import com.alttd.playershops.api.Shop;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class ShopBalanceChangeEvent extends ShopEvent {
private static final HandlerList handlers = new HandlerList();
private final ChangeReason changeReason;
public ShopBalanceChangeEvent(Shop shop, ChangeReason reason) {
super(shop);
this.changeReason = reason;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
public ChangeReason getChangeReason() {
return changeReason;
}
public enum ChangeReason {
DEPOSIT,
WIDRAW,
SELL,
BUY,
UPKEEP
}
}

View File

@ -1,6 +1,15 @@
package com.alttd.playershops.listener;
import com.alttd.playershops.PlayerShops;
import com.alttd.playershops.api.Shop;
import com.alttd.playershops.config.Config;
import org.bukkit.Location;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.Iterator;
public class ShopListener extends EventListener {
@ -10,4 +19,26 @@ public class ShopListener extends EventListener {
this.plugin = plugin;
this.register(this.plugin);
}
@EventHandler(ignoreCancelled = true)
public void onEntityExplosion(EntityExplodeEvent event) {
if(!this.isRegistered) return;
Iterator<Block> blockIterator = event.blockList().iterator();
Shop shop = null;
while (blockIterator.hasNext()) {
Block block = blockIterator.next();
Location location = block.getLocation();
if (Tag.WALL_SIGNS.isTagged(block.getType())) {
shop = plugin.getShopHandler().getShopBySignLocation(location);
} else if (plugin.getShopHandler().isShopMaterial(block)) {
shop = plugin.getShopHandler().getShop(location);
}
if (shop != null) {
blockIterator.remove();
}
}
}
}