more listeners

Former-commit-id: 13bc7dae2f21267d0ac72010593399278772e89a [formerly 4def64065d3177ff94e93b1b7916f6c8da1c93d9]
Former-commit-id: 7fdb10019a50e166cba657f00e36dda969d0c2fa
This commit is contained in:
portlek committed 2019-11-24 03:54:20 +03:00
1 parent b6e1c9cf4d
commit a3bdbb0435
2 files changed
+77 -51

No files matched your search

@@ -39,9 +39,11 @@ public class ShopProtectionListener implements Listener {
if (ListenerHelper.isDisabled(e.getClass())) {
return;
}
for (int i = 0; i < e.blockList().size(); i++) {
Block b = e.blockList().get(i);
Shop shop = plugin.getShopManager().getShopIncludeAttached(b.getLocation());
final Block b = e.blockList().get(i);
final Shop shop = plugin.getShopManager().getShopIncludeAttached(b.getLocation());
if (shop != null) {
if (plugin.getConfig().getBoolean("protect.explode")) {
e.setCancelled(true);
@@ -54,32 +56,34 @@ public class ShopProtectionListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent e) {
if (ListenerHelper.isDisabled(e.getClass())) {
if (ListenerHelper.isDisabled(e.getClass()) ||
!useEnhanceProtection) {
return;
}
if (!useEnhanceProtection) {
return;
}
Shop shop = plugin.getShopManager().getShopIncludeAttached(e.getToBlock().getLocation());
final Shop shop = plugin.getShopManager().getShopIncludeAttached(e.getToBlock().getLocation());
if (shop == null) {
return;
}
e.setCancelled(true);
}
//Protect Redstone active shop
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockRedstoneChange(BlockRedstoneEvent event) {
if (ListenerHelper.isDisabled(event.getClass())) {
if (ListenerHelper.isDisabled(event.getClass()) ||
!useEnhanceProtection) {
return;
}
if (!useEnhanceProtection) {
return;
}
Shop shop = plugin.getShopManager().getShopIncludeAttached(event.getBlock().getLocation());
final Shop shop = plugin.getShopManager().getShopIncludeAttached(event.getBlock().getLocation());
if (shop == null) {
return;
}
event.setNewCurrent(event.getOldCurrent());
//plugin.getLogger().warning("[Exploit Alert] a Redstone tried to active of " + shop);
//Util.debugLog(ChatColor.RED + "[QuickShop][Exploit alert] Redstone was activated on the following shop " + shop);
@@ -87,15 +91,15 @@ public class ShopProtectionListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockSpread(BlockSpreadEvent e) {
if (ListenerHelper.isDisabled(e.getClass())) {
if (ListenerHelper.isDisabled(e.getClass()) ||
!useEnhanceProtection) {
return;
}
if (!useEnhanceProtection) {
return;
}
Block newBlock = e.getNewState().getBlock();
Shop thisBlockShop = plugin.getShopManager().getShopIncludeAttached(newBlock.getLocation());
Shop underBlockShop = plugin.getShopManager().getShopIncludeAttached(newBlock.getRelative(BlockFace.DOWN).getLocation());
final Block newBlock = e.getNewState().getBlock();
final Shop thisBlockShop = plugin.getShopManager().getShopIncludeAttached(newBlock.getLocation());
final Shop underBlockShop = plugin.getShopManager().getShopIncludeAttached(newBlock.getRelative(BlockFace.DOWN).getLocation());
if (thisBlockShop == null && underBlockShop == null) {
return;
}
@@ -110,9 +114,11 @@ public class ShopProtectionListener implements Listener {
if (ListenerHelper.isDisabled(e.getClass())) {
return;
}
for (int i = 0; i < e.blockList().size(); i++) {
Block b = e.blockList().get(i);
Shop shop = plugin.getShopManager().getShopIncludeAttached(b.getLocation());
final Block b = e.blockList().get(i);
final Shop shop = plugin.getShopManager().getShopIncludeAttached(b.getLocation());
if (shop != null) {
if (plugin.getConfig().getBoolean("protect.explode")) {
e.setCancelled(true);
@@ -129,58 +135,67 @@ public class ShopProtectionListener implements Listener {
if (ListenerHelper.isDisabled(event.getClass())) {
return;
}
Location loc = event.getSource().getLocation();
final Location loc = event.getSource().getLocation();
if (loc == null) {
return;
}
HashMap<Location, Shop> shopsInChunk = plugin.getShopManager().getShops(loc.getChunk());
if (shopsInChunk == null || shopsInChunk.isEmpty()) {
return;
}
if (shopsInChunk.get(loc) == null) {
final HashMap<Location, Shop> shopsInChunk = plugin.getShopManager().getShops(loc.getChunk());
if (shopsInChunk == null || shopsInChunk.isEmpty() || shopsInChunk.get(loc) == null) {
return;
}
event.setCancelled(true);
Location location = event.getInitiator().getLocation();
if (location != null) {
location.getBlock().breakNaturally();
MsgUtil.sendGlobalAlert("[DisplayGuard] Breaked the block at " + location + " try steal the items for shop " + loc);
final Location location = event.getInitiator().getLocation();
if (location == null) {
return;
}
location.getBlock().breakNaturally();
MsgUtil.sendGlobalAlert("[DisplayGuard] Breaked the block at " + location + " try steal the items for shop " + loc);
}
//Protect Entity pickup shop
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onMobChangeBlock(EntityChangeBlockEvent event) {
if (ListenerHelper.isDisabled(event.getClass())) {
if (ListenerHelper.isDisabled(event.getClass()) ||
!useEnhanceProtection) {
return;
}
if (!useEnhanceProtection) {
return;
}
Shop shop = plugin.getShopManager().getShopIncludeAttached(event.getBlock().getLocation());
final Shop shop = plugin.getShopManager().getShopIncludeAttached(event.getBlock().getLocation());
if (shop == null) {
return;
}
if (plugin.getConfig().getBoolean("protect.entity")) {
event.setCancelled(true);
} else {
shop.delete();
return;
}
shop.delete();
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent event) {
if (ListenerHelper.isDisabled(event.getClass())) {
return;
}
if (!useEnhanceProtection) {
if (ListenerHelper.isDisabled(event.getClass()) ||
!useEnhanceProtection) {
return;
}
for (BlockState blockstate : event.getBlocks()) {
Shop shop = plugin.getShopManager().getShopIncludeAttached(blockstate.getLocation());
final Shop shop = plugin.getShopManager().getShopIncludeAttached(blockstate.getLocation());
if (shop == null) {
continue;
}
event.setCancelled(true);
return;
//plugin.getLogger().warning("[Exploit Alert] a StructureGrowing tried to break the shop of " + shop);
@@ -9,6 +9,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.jetbrains.annotations.NotNull;
import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.Shop.Shop;
import org.maxgamer.quickshop.Shop.ShopChunk;
@@ -18,7 +19,9 @@ import java.util.Map.Entry;
@AllArgsConstructor
public class WorldListener implements Listener {
private QuickShop plugin;
@NotNull
private final QuickShop plugin;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldLoad(WorldLoadEvent e) {
@@ -28,24 +31,27 @@ public class WorldListener implements Listener {
* world value is the same.
* ************************************
*/
final World world = e.getWorld();
World world = e.getWorld();
plugin.getShopLoader().loadShops(world.getName());
// New world data
HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = new HashMap<>(1);
final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = new HashMap<>(1);
// Old world data
HashMap<ShopChunk, HashMap<Location, Shop>> oldInWorld = plugin.getShopManager().getShops(world.getName());
final HashMap<ShopChunk, HashMap<Location, Shop>> oldInWorld = plugin.getShopManager().getShops(world.getName());
// Nothing in the old world, therefore we don't care. No locations to
// update.
if (oldInWorld == null) {
return;
}
for (Entry<ShopChunk, HashMap<Location, Shop>> oldInChunk : oldInWorld.entrySet()) {
HashMap<Location, Shop> inChunk = new HashMap<>(1);
final HashMap<Location, Shop> inChunk = new HashMap<>(1);
// Put the new chunk were the old chunk was
inWorld.put(oldInChunk.getKey(), inChunk);
for (Entry<Location, Shop> entry : oldInChunk.getValue().entrySet()) {
Shop shop = entry.getValue();
final Shop shop = entry.getValue();
shop.getLocation().setWorld(world);
inChunk.put(shop.getLocation(), shop);
}
@@ -56,10 +62,12 @@ public class WorldListener implements Listener {
// world first loads....
// So manually tell all of these shops they're loaded.
for (Chunk chunk : world.getLoadedChunks()) {
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
if (inChunk == null || inChunk.isEmpty()) {
continue;
}
for (Shop shop : inChunk.values()) {
shop.onLoad();
}
@@ -68,6 +76,7 @@ public class WorldListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldUnload(WorldUnloadEvent e) {
// FIXME: 24/11/2019 It's not necessary but ok.
if (e.isCancelled()) {
return;
}
@@ -75,10 +84,12 @@ public class WorldListener implements Listener {
// world unloads, I think...
// So manually tell all of these shops they're unloaded.
for (Chunk chunk : e.getWorld().getLoadedChunks()) {
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
if (inChunk == null || inChunk.isEmpty()) {
continue;
}
for (Shop shop : inChunk.values()) {
shop.onUnload();
}