diff --git a/src/main/java/net/momirealms/customcrops/Placeholders.java b/src/main/java/net/momirealms/customcrops/Placeholders.java index 1ff0ec8..f65028b 100644 --- a/src/main/java/net/momirealms/customcrops/Placeholders.java +++ b/src/main/java/net/momirealms/customcrops/Placeholders.java @@ -14,7 +14,6 @@ public class Placeholders extends PlaceholderExpansion{ this.plugin = plugin; } - @Override public @NotNull String getIdentifier() { return "customcrops"; diff --git a/src/main/java/net/momirealms/customcrops/listener/BreakFurniture.java b/src/main/java/net/momirealms/customcrops/listener/BreakFurniture.java index 95d1be0..01f2deb 100644 --- a/src/main/java/net/momirealms/customcrops/listener/BreakFurniture.java +++ b/src/main/java/net/momirealms/customcrops/listener/BreakFurniture.java @@ -13,12 +13,10 @@ public class BreakFurniture implements Listener { @EventHandler public void breakFurniture(EntitySpawnEvent event){ - FileConfiguration config = CustomCrops.instance.getConfig(); Entity entity = event.getEntity(); - if(!(entity instanceof Item)){ - return; - } + if(!(entity instanceof Item)) return; if(CustomStack.byItemStack(((Item) entity).getItemStack()) != null){ + FileConfiguration config = CustomCrops.instance.getConfig(); if(CustomStack.byItemStack(((Item) entity).getItemStack()).getNamespacedID().equalsIgnoreCase(config.getString("config.sprinkler-1"))){ entity.remove(); entity.getWorld().dropItem(entity.getLocation() ,CustomStack.getInstance(config.getString("config.sprinkler-1-item")).getItemStack()); diff --git a/src/main/java/net/momirealms/customcrops/listener/RightClickBlock.java b/src/main/java/net/momirealms/customcrops/listener/RightClickBlock.java index 4e08ee7..cf45d02 100644 --- a/src/main/java/net/momirealms/customcrops/listener/RightClickBlock.java +++ b/src/main/java/net/momirealms/customcrops/listener/RightClickBlock.java @@ -1,9 +1,5 @@ package net.momirealms.customcrops.listener; -import com.bekvon.bukkit.residence.Residence; -import com.bekvon.bukkit.residence.protection.ClaimedResidence; -import com.bekvon.bukkit.residence.protection.FlagPermissions; -import com.bekvon.bukkit.residence.protection.ResidencePermissions; import dev.lone.itemsadder.api.CustomStack; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.DataManager.MaxSprinklersPerChunk; @@ -33,11 +29,11 @@ public class RightClickBlock implements Listener { @EventHandler public void rightClickBlock(PlayerInteractEvent event){ - FileConfiguration config = CustomCrops.instance.getConfig(); - if(!event.hasItem()){ - return; - } + + if(!event.hasItem()) return; if(event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) return; + if(CustomStack.byItemStack(event.getItem()) == null) return; + Player player = event.getPlayer(); ItemStack itemStack = event.getItem(); //水壶加水 @@ -54,10 +50,12 @@ public class RightClickBlock implements Listener { return; } } + if(event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if(event.getBlockFace() != BlockFace.UP) return; - if(CustomStack.byItemStack(event.getItem()) == null) return; + + FileConfiguration config = CustomCrops.instance.getConfig(); Location location = event.getClickedBlock().getLocation(); //res兼容 if(config.getBoolean("config.integration.residence")){ @@ -82,7 +80,6 @@ public class RightClickBlock implements Listener { MessageManager.playerMessage(config.getString("messages.prefix") + config.getString("messages.not-a-good-place"),player); return; } - if(CustomStack.byItemStack(event.getItem()).getNamespacedID().equalsIgnoreCase(config.getString("config.sprinkler-1-item"))){ if(MaxSprinklersPerChunk.maxSprinklersPerChunk(location)){ MessageManager.playerMessage(config.getString("messages.prefix")+config.getString("messages.reach-limit-sprinkler").replace("{Max}", config.getString("config.max-sprinklers")),player); @@ -107,18 +104,16 @@ public class RightClickBlock implements Listener { } private void addWater(ItemStack itemStack, Player player){ FileConfiguration config = CustomCrops.instance.getConfig(); - if(CustomStack.byItemStack(itemStack)!= null){ - CustomStack customStack = CustomStack.byItemStack(itemStack); - if(customStack.getNamespacedID().equalsIgnoreCase(config.getString("config.watering-can-1")) || - customStack.getNamespacedID().equalsIgnoreCase(config.getString("config.watering-can-2")) || - customStack.getNamespacedID().equalsIgnoreCase(config.getString("config.watering-can-3"))) - { - if(customStack.getMaxDurability() == customStack.getDurability()){ - MessageManager.playerMessage(config.getString("messages.prefix") + config.getString("messages.can-full"),player); - }else { - customStack.setDurability(customStack.getDurability() + 1); - player.playSound(player, Sound.ITEM_BUCKET_FILL,1,1); - } + CustomStack customStack = CustomStack.byItemStack(itemStack); + if(customStack.getNamespacedID().equalsIgnoreCase(config.getString("config.watering-can-1")) || + customStack.getNamespacedID().equalsIgnoreCase(config.getString("config.watering-can-2")) || + customStack.getNamespacedID().equalsIgnoreCase(config.getString("config.watering-can-3"))) + { + if(customStack.getMaxDurability() == customStack.getDurability()){ + MessageManager.playerMessage(config.getString("messages.prefix") + config.getString("messages.can-full"),player); + }else { + customStack.setDurability(customStack.getDurability() + 1); + player.playSound(player, Sound.ITEM_BUCKET_FILL,1,1); } } } diff --git a/src/main/java/net/momirealms/customcrops/listener/RightClickCustomBlock.java b/src/main/java/net/momirealms/customcrops/listener/RightClickCustomBlock.java index abc3942..d1594a9 100644 --- a/src/main/java/net/momirealms/customcrops/listener/RightClickCustomBlock.java +++ b/src/main/java/net/momirealms/customcrops/listener/RightClickCustomBlock.java @@ -40,6 +40,7 @@ public class RightClickCustomBlock implements Listener { return; } } + //空手收获农作物 if (event.getItem() == null) { if(config.getBoolean("config.integration.residence")){ if(ResidenceIntegrations.checkResHarvest(clickedBlockLocation,player)){ @@ -61,11 +62,13 @@ public class RightClickCustomBlock implements Listener { clickedBlockLocation.getWorld().dropItem(clickedBlockLocation.clone().add(0.5,0.2,0.5),itemStack); }); CustomBlock.remove(clickedBlockLocation); + //如果配置文件有配置则返回第几阶段 if(config.getConfigurationSection("crops." + cropNameList[0]).getKeys(false).contains("return")){ CustomBlock.place(config.getString("crops." + cropNameList[0] + ".return"), clickedBlockLocation); } } } + return; } //res兼容 if(config.getBoolean("config.integration.residence")){ @@ -73,17 +76,14 @@ public class RightClickCustomBlock implements Listener { return; } } - //wg兼容 if(config.getBoolean("config.integration.worldguard")){ if(WorldGuardIntegrations.checkWGBuild(clickedBlockLocation,player)){ return; } } - World world = player.getWorld(); ItemStack mainHandItem = player.getInventory().getItemInMainHand(); - //右键的作物下方是否为自定义方块 if (CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation.clone().subtract(0,1,0))) != null && clickedBlock.getType() == Material.TRIPWIRE) { //检测右键的方块下方是否为干燥的种植盆方块 @@ -152,14 +152,12 @@ public class RightClickCustomBlock implements Listener { } //检测右键的方块是否为湿润的种植盆方块 }else if(CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation)).getNamespacedID().equalsIgnoreCase(config.getString("config.watered-pot"))){ - tryPlantSeed(clickedBlockLocation, mainHandItem, player, config); } } } //尝试种植植物 private void tryPlantSeed(Location clickedBlockLocation, ItemStack mainHandItem, Player player, FileConfiguration config) { - if(CustomStack.byItemStack(mainHandItem) == null) return; if (CustomStack.byItemStack(mainHandItem).getNamespacedID().toLowerCase().endsWith("_seeds")){ String namespaced_id = CustomStack.byItemStack(mainHandItem).getNamespacedID().toLowerCase(); @@ -221,9 +219,7 @@ public class RightClickCustomBlock implements Listener { private void waterPot(ItemStack itemStack, Player player, Location location, FileConfiguration config){ if(CustomStack.byItemStack(itemStack) == null) return; - CustomStack customStack = CustomStack.byItemStack(itemStack); - if(customStack.getDurability() > 0){ CustomStack.byItemStack(itemStack).setDurability(CustomStack.byItemStack(itemStack).getDurability() - 1); }else return; diff --git a/src/main/resources/config-english.yml b/src/main/resources/config-english.yml index 6eb1773..247af7e 100644 --- a/src/main/resources/config-english.yml +++ b/src/main/resources/config-english.yml @@ -65,6 +65,10 @@ config: # should we only alow crops in loaded chunks to grow? # This is good for server performance only-grow-in-loaded-chunks: true + integration: + residence: false + worldguard: false + kingdomsX: false messages: prefix: '[CustomCrops] '