mirror of
https://github.com/songoda/EpicFarming.git
synced 2024-09-30 07:37:32 +02:00
Cleaned up listeners.
This commit is contained in:
parent
1a346e8d1c
commit
5aa19e2f3d
@ -29,22 +29,22 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
|||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public class BlockListeners implements Listener {
|
public class BlockListeners implements Listener {
|
||||||
|
|
||||||
private final EpicFarming instance;
|
private final EpicFarming plugin;
|
||||||
|
|
||||||
public BlockListeners(EpicFarming instance) {
|
public BlockListeners(EpicFarming plugin) {
|
||||||
this.instance = instance;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBlockFade(BlockFadeEvent e) {
|
public void onBlockFade(BlockFadeEvent e) {
|
||||||
Farm farm = instance.getFarmManager().checkForFarm(e.getBlock().getLocation());
|
Farm farm = plugin.getFarmManager().checkForFarm(e.getBlock().getLocation());
|
||||||
if (farm != null && farm.getFarmType() != FarmType.LIVESTOCK)
|
if (farm != null && farm.getFarmType() != FarmType.LIVESTOCK)
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onGrow(BlockGrowEvent e) {
|
public void onGrow(BlockGrowEvent e) {
|
||||||
Farm farm = instance.getFarmManager().checkForFarm(e.getBlock().getLocation());
|
Farm farm = plugin.getFarmManager().checkForFarm(e.getBlock().getLocation());
|
||||||
if (farm != null && farm.getFarmType() != FarmType.LIVESTOCK)
|
if (farm != null && farm.getFarmType() != FarmType.LIVESTOCK)
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -65,13 +65,13 @@ public class BlockListeners implements Listener {
|
|||||||
Material farmBlock = Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getBlockMaterial();
|
Material farmBlock = Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getBlockMaterial();
|
||||||
|
|
||||||
if (e.getPlayer().getItemInHand().getType() != farmBlock
|
if (e.getPlayer().getItemInHand().getType() != farmBlock
|
||||||
|| instance.getLevelFromItem(e.getItemInHand()) == 0 && !Settings.NON_COMMAND_FARMS.getBoolean())
|
|| plugin.getLevelFromItem(e.getItemInHand()) == 0 && !Settings.NON_COMMAND_FARMS.getBoolean())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (e.getBlockAgainst().getType() == farmBlock) e.setCancelled(true);
|
if (e.getBlockAgainst().getType() == farmBlock) e.setCancelled(true);
|
||||||
|
|
||||||
int amt = 0;
|
int amt = 0;
|
||||||
for (Farm farmm : instance.getFarmManager().getFarms().values()) {
|
for (Farm farmm : plugin.getFarmManager().getFarms().values()) {
|
||||||
if (farmm.getPlacedBy() == null || !farmm.getPlacedBy().equals(e.getPlayer().getUniqueId())) continue;
|
if (farmm.getPlacedBy() == null || !farmm.getPlacedBy().equals(e.getPlayer().getUniqueId())) continue;
|
||||||
amt++;
|
amt++;
|
||||||
}
|
}
|
||||||
@ -79,23 +79,23 @@ public class BlockListeners implements Listener {
|
|||||||
|
|
||||||
if (limit != -1 && amt >= limit) {
|
if (limit != -1 && amt >= limit) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
instance.getLocale().getMessage("event.limit.hit")
|
plugin.getLocale().getMessage("event.limit.hit")
|
||||||
.processPlaceholder("limit", limit).sendPrefixedMessage(e.getPlayer());
|
.processPlaceholder("limit", limit).sendPrefixedMessage(e.getPlayer());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Location location = e.getBlock().getLocation();
|
Location location = e.getBlock().getLocation();
|
||||||
if (e.getBlockPlaced().getType().equals(Material.MELON_SEEDS) || e.getBlockPlaced().getType().equals(Material.PUMPKIN_SEEDS)) {
|
if (e.getBlockPlaced().getType().equals(Material.MELON_SEEDS) || e.getBlockPlaced().getType().equals(Material.PUMPKIN_SEEDS)) {
|
||||||
if (instance.getFarmManager().checkForFarm(location) != null) {
|
if (plugin.getFarmManager().checkForFarm(location) != null) {
|
||||||
instance.getLocale().getMessage("event.warning.noauto").sendPrefixedMessage(e.getPlayer());
|
plugin.getLocale().getMessage("event.warning.noauto").sendPrefixedMessage(e.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int level = instance.getLevelFromItem(e.getItemInHand());
|
int level = plugin.getLevelFromItem(e.getItemInHand());
|
||||||
Bukkit.getScheduler().runTaskLater(instance, () -> {
|
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||||
if (location.getBlock().getType() != farmBlock) return;
|
if (location.getBlock().getType() != farmBlock) return;
|
||||||
|
|
||||||
Farm farm = new Farm(location, instance.getLevelManager().getLevel(level == 0 ? 1 : level), e.getPlayer().getUniqueId());
|
Farm farm = new Farm(location, plugin.getLevelManager().getLevel(level == 0 ? 1 : level), e.getPlayer().getUniqueId());
|
||||||
instance.getFarmManager().addFarm(location, farm);
|
plugin.getFarmManager().addFarm(location, farm);
|
||||||
|
|
||||||
farm.tillLand();
|
farm.tillLand();
|
||||||
}, 1);
|
}, 1);
|
||||||
@ -106,7 +106,7 @@ public class BlockListeners implements Listener {
|
|||||||
if (event.getBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getMaterial())
|
if (event.getBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getMaterial())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Farm farm = instance.getFarmManager().removeFarm(event.getBlock().getLocation());
|
Farm farm = plugin.getFarmManager().removeFarm(event.getBlock().getLocation());
|
||||||
|
|
||||||
if (farm == null) return;
|
if (farm == null) return;
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ public class BlockListeners implements Listener {
|
|||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
ItemStack item = instance.makeFarmItem(farm.getLevel());
|
ItemStack item = plugin.makeFarmItem(farm.getLevel());
|
||||||
|
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
|
|
||||||
@ -131,14 +131,14 @@ public class BlockListeners implements Listener {
|
|||||||
if (event.getBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getMaterial())
|
if (event.getBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getMaterial())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Farm farm = instance.getFarmManager().removeFarm(event.getBlock().getLocation());
|
Farm farm = plugin.getFarmManager().removeFarm(event.getBlock().getLocation());
|
||||||
|
|
||||||
if (farm == null) return;
|
if (farm == null) return;
|
||||||
FarmTask.getCrops(farm, false);
|
FarmTask.getCrops(farm, false);
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
ItemStack item = instance.makeFarmItem(farm.getLevel());
|
ItemStack item = plugin.makeFarmItem(farm.getLevel());
|
||||||
|
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ public class BlockListeners implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onBlockFromToEventMonitor(BlockFromToEvent event) {
|
public void onBlockFromToEventMonitor(BlockFromToEvent event) {
|
||||||
// prevent water/lava/egg griefs
|
// prevent water/lava/egg griefs
|
||||||
if (instance.getFarmManager().getFarm(event.getToBlock()) != null) {
|
if (plugin.getFarmManager().getFarm(event.getToBlock()) != null) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,10 @@ import java.util.List;
|
|||||||
|
|
||||||
public class EntityListeners implements Listener {
|
public class EntityListeners implements Listener {
|
||||||
|
|
||||||
private final EpicFarming instance;
|
private final EpicFarming plugin;
|
||||||
|
|
||||||
public EntityListeners(EpicFarming instance) {
|
public EntityListeners(EpicFarming plugin) {
|
||||||
this.instance = instance;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
@ -43,7 +43,7 @@ public class EntityListeners implements Listener {
|
|||||||
LivingEntity entity = event.getEntity();
|
LivingEntity entity = event.getEntity();
|
||||||
if (!entity.hasMetadata("EFA-TAGGED")) return;
|
if (!entity.hasMetadata("EFA-TAGGED")) return;
|
||||||
Location location = (Location) entity.getMetadata("EFA-TAGGED").get(0).value();
|
Location location = (Location) entity.getMetadata("EFA-TAGGED").get(0).value();
|
||||||
Farm farm = instance.getFarmManager().getFarm(location);
|
Farm farm = plugin.getFarmManager().getFarm(location);
|
||||||
|
|
||||||
boolean autoCollect = false;
|
boolean autoCollect = false;
|
||||||
for (Module module : farm.getLevel().getRegisteredModules()) {
|
for (Module module : farm.getLevel().getRegisteredModules()) {
|
||||||
@ -99,7 +99,7 @@ public class EntityListeners implements Listener {
|
|||||||
if (block.getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getMaterial())
|
if (block.getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial(CompatibleMaterial.END_ROD).getMaterial())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Farm farm = instance.getFarmManager().getFarm(block.getLocation());
|
Farm farm = plugin.getFarmManager().getFarm(block.getLocation());
|
||||||
if (farm == null) continue;
|
if (farm == null) continue;
|
||||||
|
|
||||||
toCancel.add(block);
|
toCancel.add(block);
|
||||||
@ -108,11 +108,11 @@ public class EntityListeners implements Listener {
|
|||||||
for (Block block : toCancel) {
|
for (Block block : toCancel) {
|
||||||
event.blockList().remove(block);
|
event.blockList().remove(block);
|
||||||
|
|
||||||
Farm farm = instance.getFarmManager().removeFarm(block.getLocation());
|
Farm farm = plugin.getFarmManager().removeFarm(block.getLocation());
|
||||||
|
|
||||||
FarmTask.getCrops(farm, false);
|
FarmTask.getCrops(farm, false);
|
||||||
|
|
||||||
ItemStack item = instance.makeFarmItem(farm.getLevel());
|
ItemStack item = plugin.makeFarmItem(farm.getLevel());
|
||||||
|
|
||||||
block.setType(Material.AIR);
|
block.setType(Material.AIR);
|
||||||
block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5, .5, .5), item);
|
block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5, .5, .5), item);
|
||||||
|
@ -17,10 +17,10 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
*/
|
*/
|
||||||
public class InteractListeners implements Listener {
|
public class InteractListeners implements Listener {
|
||||||
|
|
||||||
private final EpicFarming instance;
|
private final EpicFarming plugin;
|
||||||
|
|
||||||
public InteractListeners(EpicFarming instance) {
|
public InteractListeners(EpicFarming plugin) {
|
||||||
this.instance = instance;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
@ -29,7 +29,7 @@ public class InteractListeners implements Listener {
|
|||||||
Location location = e.getClickedBlock().getLocation();
|
Location location = e.getClickedBlock().getLocation();
|
||||||
|
|
||||||
if (e.getItem() != null && CompatibleMaterial.getMaterial(e.getItem()) == CompatibleMaterial.BONE_MEAL
|
if (e.getItem() != null && CompatibleMaterial.getMaterial(e.getItem()) == CompatibleMaterial.BONE_MEAL
|
||||||
&& instance.getFarmManager().checkForFarm(location) != null)
|
&& plugin.getFarmManager().checkForFarm(location) != null)
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
|
||||||
if (e.getClickedBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial().getMaterial())
|
if (e.getClickedBlock().getType() != Settings.FARM_BLOCK_MATERIAL.getMaterial().getMaterial())
|
||||||
@ -47,9 +47,9 @@ public class InteractListeners implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance.getFarmManager().getFarms().containsKey(location)) {
|
if (plugin.getFarmManager().getFarms().containsKey(location)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
instance.getFarmManager().getFarm(location).view(e.getPlayer(), false);
|
plugin.getFarmManager().getFarm(location).view(e.getPlayer(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,6 @@ public class InventoryListeners implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
Player player = (Player) event.getWhoClicked();
|
|
||||||
if (event.getCurrentItem() == null) return;
|
if (event.getCurrentItem() == null) return;
|
||||||
|
|
||||||
if (event.getRawSlot() > event.getView().getTopInventory().getSize() - 1) return;
|
if (event.getRawSlot() > event.getView().getTopInventory().getSize() - 1) return;
|
||||||
|
@ -13,21 +13,21 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class UnloadListeners implements Listener {
|
public class UnloadListeners implements Listener {
|
||||||
|
|
||||||
private final EpicFarming instance;
|
private final EpicFarming plugin;
|
||||||
|
|
||||||
public UnloadListeners(EpicFarming instance) {
|
public UnloadListeners(EpicFarming plugin) {
|
||||||
this.instance = instance;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onUnload(ChunkUnloadEvent event) {
|
public void onUnload(ChunkUnloadEvent event) {
|
||||||
Material type = Settings.FARM_BLOCK_MATERIAL.getMaterial().getMaterial();
|
Material type = Settings.FARM_BLOCK_MATERIAL.getMaterial().getMaterial();
|
||||||
for (Farm farm : new ArrayList<>(instance.getFarmManager().getFarms().values())) {
|
for (Farm farm : new ArrayList<>(plugin.getFarmManager().getFarms().values())) {
|
||||||
int x = farm.getLocation().getBlockX() >> 4;
|
int x = farm.getLocation().getBlockX() >> 4;
|
||||||
int z = farm.getLocation().getBlockZ() >> 4;
|
int z = farm.getLocation().getBlockZ() >> 4;
|
||||||
if (event.getChunk().getX() == x && event.getChunk().getZ() == z) {
|
if (event.getChunk().getX() == x && event.getChunk().getZ() == z) {
|
||||||
if (farm.getLocation().getBlock().getType() != type)
|
if (farm.getLocation().getBlock().getType() != type)
|
||||||
instance.getFarmManager().removeFarm(farm.getLocation());
|
plugin.getFarmManager().removeFarm(farm.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user