diff --git a/build.gradle b/build.gradle index cedfdbb..8e9f960 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '2.2.2-hotfix' +version = '2.2.3' repositories { mavenCentral() diff --git a/src/main/java/net/momirealms/customcrops/CustomCrops.java b/src/main/java/net/momirealms/customcrops/CustomCrops.java index 74da901..fc01e3f 100644 --- a/src/main/java/net/momirealms/customcrops/CustomCrops.java +++ b/src/main/java/net/momirealms/customcrops/CustomCrops.java @@ -26,6 +26,7 @@ import net.momirealms.customcrops.commands.PluginCommand; import net.momirealms.customcrops.config.ConfigUtil; import net.momirealms.customcrops.config.MainConfig; import net.momirealms.customcrops.helper.LibraryLoader; +import net.momirealms.customcrops.helper.VersionHelper; import net.momirealms.customcrops.integrations.papi.PlaceholderManager; import net.momirealms.customcrops.integrations.protection.WorldGuardHook; import net.momirealms.customcrops.managers.CropManager; @@ -33,7 +34,6 @@ import net.momirealms.customcrops.utils.AdventureUtil; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; -import org.kingdoms.main.ConfigManager; import java.util.Objects; @@ -41,11 +41,11 @@ public final class CustomCrops extends JavaPlugin { public static BukkitAudiences adventure; public static CustomCrops plugin; - public static String version; public static ProtocolManager protocolManager; private PlaceholderManager placeholderManager; private CropManager cropManager; + private VersionHelper versionHelper; // _ooOoo_ // o8888888o @@ -79,10 +79,8 @@ public final class CustomCrops extends JavaPlugin { @Override public void onEnable() { - adventure = BukkitAudiences.create(plugin); protocolManager = ProtocolLibrary.getProtocolManager(); - version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; AdventureUtil.consoleMessage("[CustomCrops] Running on " + Bukkit.getVersion()); MinecraftVersion.disableBStats(); @@ -112,6 +110,7 @@ public final class CustomCrops extends JavaPlugin { Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setTabCompleter(pluginCommand); this.cropManager = new CropManager(); + this.versionHelper = new VersionHelper(); if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { this.placeholderManager = new PlaceholderManager(); @@ -148,4 +147,8 @@ public final class CustomCrops extends JavaPlugin { public CropManager getCropManager() { return cropManager; } + + public VersionHelper getVersionHelper() { + return versionHelper; + } } diff --git a/src/main/java/net/momirealms/customcrops/api/crop/Crop.java b/src/main/java/net/momirealms/customcrops/api/crop/Crop.java index 54c1df9..7a70737 100644 --- a/src/main/java/net/momirealms/customcrops/api/crop/Crop.java +++ b/src/main/java/net/momirealms/customcrops/api/crop/Crop.java @@ -28,7 +28,9 @@ public interface Crop { CCSeason[] getSeasons(); - RequirementInterface[] getRequirements(); + RequirementInterface[] getPlantRequirements(); + + RequirementInterface[] getHarvestRequirements(); String getReturnStage(); diff --git a/src/main/java/net/momirealms/customcrops/api/event/PreActionEvent.java b/src/main/java/net/momirealms/customcrops/api/event/PreActionEvent.java deleted file mode 100644 index cafe060..0000000 --- a/src/main/java/net/momirealms/customcrops/api/event/PreActionEvent.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.momirealms.customcrops.api.event; - -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; -import org.jetbrains.annotations.NotNull; - -public class PreActionEvent extends PlayerEvent implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - private boolean cancelled; - private final Location location; - - public PreActionEvent(@NotNull Player who, Location location) { - super(who); - this.location = location; - } - - @Override - public boolean isCancelled() { - return cancelled; - } - - @Override - public void setCancelled(boolean cancel) { - cancelled = cancel; - } - - @NotNull - public static HandlerList getHandlerList() { - return handlers; - } - - @NotNull - @Override - public HandlerList getHandlers() { - return getHandlerList(); - } - - public Location getLocation() { - return location; - } -} diff --git a/src/main/java/net/momirealms/customcrops/api/utils/AntiGriefUtils.java b/src/main/java/net/momirealms/customcrops/api/utils/AntiGriefUtils.java new file mode 100644 index 0000000..d7164c5 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/utils/AntiGriefUtils.java @@ -0,0 +1,15 @@ +package net.momirealms.customcrops.api.utils; + +import net.momirealms.customcrops.config.MainConfig; +import net.momirealms.customcrops.integrations.CCAntiGrief; + +public class AntiGriefUtils { + + public static void register(CCAntiGrief CCAntiGrief) { + MainConfig.registerAntiGrief(CCAntiGrief); + } + + public static void unregister(CCAntiGrief CCAntiGrief) { + MainConfig.unregisterAntiGrief(CCAntiGrief); + } +} diff --git a/src/main/java/net/momirealms/customcrops/commands/subcmd/BackUpCommand.java b/src/main/java/net/momirealms/customcrops/commands/subcmd/BackUpCommand.java index d59c5f0..2e713b5 100644 --- a/src/main/java/net/momirealms/customcrops/commands/subcmd/BackUpCommand.java +++ b/src/main/java/net/momirealms/customcrops/commands/subcmd/BackUpCommand.java @@ -29,7 +29,7 @@ public class BackUpCommand extends AbstractSubCommand { String worldName = args.get(0); World world = Bukkit.getWorld(worldName); if (world == null) { - AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists); + AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists.replace("{world}", worldName)); return true; } CustomWorld customWorld = CustomCrops.plugin.getCropManager().getCustomWorld(world); diff --git a/src/main/java/net/momirealms/customcrops/commands/subcmd/GrowCommand.java b/src/main/java/net/momirealms/customcrops/commands/subcmd/GrowCommand.java index b38768d..b679dc9 100644 --- a/src/main/java/net/momirealms/customcrops/commands/subcmd/GrowCommand.java +++ b/src/main/java/net/momirealms/customcrops/commands/subcmd/GrowCommand.java @@ -44,7 +44,7 @@ public class GrowCommand extends AbstractSubCommand { else { World world = Bukkit.getWorld(args.get(0)); if (world == null) { - AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists); + AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists.replace("{world}", args.get(0))); return true; } int growTime; diff --git a/src/main/java/net/momirealms/customcrops/commands/subcmd/SaveCacheCommand.java b/src/main/java/net/momirealms/customcrops/commands/subcmd/SaveCacheCommand.java index a0c8206..709fa6e 100644 --- a/src/main/java/net/momirealms/customcrops/commands/subcmd/SaveCacheCommand.java +++ b/src/main/java/net/momirealms/customcrops/commands/subcmd/SaveCacheCommand.java @@ -29,7 +29,7 @@ public class SaveCacheCommand extends AbstractSubCommand { String worldName = args.get(0); World world = Bukkit.getWorld(worldName); if (world == null) { - AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists); + AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists.replace("{world}", worldName)); return true; } CustomWorld customWorld = CustomCrops.plugin.getCropManager().getCustomWorld(world); diff --git a/src/main/java/net/momirealms/customcrops/commands/subcmd/SetSeasonCommand.java b/src/main/java/net/momirealms/customcrops/commands/subcmd/SetSeasonCommand.java index f6c6a33..1c669cd 100644 --- a/src/main/java/net/momirealms/customcrops/commands/subcmd/SetSeasonCommand.java +++ b/src/main/java/net/momirealms/customcrops/commands/subcmd/SetSeasonCommand.java @@ -52,7 +52,7 @@ public class SetSeasonCommand extends AbstractSubCommand { else { World world = Bukkit.getWorld(args.get(0)); if (world == null) { - AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists); + AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists.replace("{world}", args.get(0))); return true; } CCSeason ccSeason; diff --git a/src/main/java/net/momirealms/customcrops/commands/subcmd/SimulateCommand.java b/src/main/java/net/momirealms/customcrops/commands/subcmd/SimulateCommand.java index 1224e94..e9652ce 100644 --- a/src/main/java/net/momirealms/customcrops/commands/subcmd/SimulateCommand.java +++ b/src/main/java/net/momirealms/customcrops/commands/subcmd/SimulateCommand.java @@ -44,7 +44,7 @@ public class SimulateCommand extends AbstractSubCommand { else { World world = Bukkit.getWorld(args.get(0)); if (world == null) { - AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists); + AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists.replace("{world}", args.get(0))); return true; } int sprinklerTime; diff --git a/src/main/java/net/momirealms/customcrops/config/CropConfig.java b/src/main/java/net/momirealms/customcrops/config/CropConfig.java index 5adbee3..03d6fc7 100644 --- a/src/main/java/net/momirealms/customcrops/config/CropConfig.java +++ b/src/main/java/net/momirealms/customcrops/config/CropConfig.java @@ -155,49 +155,50 @@ public class CropConfig { case "return" -> { crop.setReturnStage(config.getString(key + ".return")); } - case "requirements" -> { + case "requirements", "plant-requirements", "harvest-requirements" -> { List requirementList = new ArrayList<>(); - for (String requirement : Objects.requireNonNull(config.getConfigurationSection(key + ".requirements")).getKeys(false)) { - String type = config.getString(key + ".requirements." + requirement + ".type"); + for (String requirement : Objects.requireNonNull(config.getConfigurationSection(key + "." + option)).getKeys(false)) { + String type = config.getString(key + "." + option + "." + requirement + ".type"); if (type == null) continue; switch (type) { case "time" -> requirementList.add(new RequirementTime( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") + config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"), + config.getString(key + "." + option + "." + requirement + ".message") )); case "weather" -> requirementList.add(new RequirementWeather( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") + config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"), + config.getString(key + "." + option + "." + requirement + ".message") )); case "yPos" -> requirementList.add(new RequirementYPos( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") + config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"), + config.getString(key + "." + option + "." + requirement + ".message") )); case "biome" -> requirementList.add(new RequirementBiome( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") + config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"), + config.getString(key + "." + option + "." + requirement + ".message") )); case "world" -> requirementList.add(new RequirementWorld( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") + config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"), + config.getString(key + "." + option + "." + requirement + ".message") )); case "permission" -> requirementList.add(new RequirementPermission( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") + config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"), + config.getString(key + "." + option + "." + requirement + ".message") )); case "papi-condition" -> requirementList.add(new CustomPapi( - Objects.requireNonNull(config.getConfigurationSection(key + ".requirements." + requirement + ".value")).getValues(false), - config.getString(key + ".requirements." + requirement + ".message") + Objects.requireNonNull(config.getConfigurationSection(key + "." + option + "." + requirement + ".value")).getValues(false), + config.getString(key + "." + option + "." + requirement + ".message") )); } } - crop.setRequirements(requirementList.toArray(new RequirementInterface[0])); + if (option.equals("harvest-requirements")) crop.setHarvestRequirements(requirementList.toArray(new RequirementInterface[0])); + else crop.setPlantRequirements(requirementList.toArray(new RequirementInterface[0])); } } } diff --git a/src/main/java/net/momirealms/customcrops/config/MainConfig.java b/src/main/java/net/momirealms/customcrops/config/MainConfig.java index 38e70ed..87efd07 100644 --- a/src/main/java/net/momirealms/customcrops/config/MainConfig.java +++ b/src/main/java/net/momirealms/customcrops/config/MainConfig.java @@ -18,7 +18,7 @@ package net.momirealms.customcrops.config; import net.momirealms.customcrops.helper.Log; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import net.momirealms.customcrops.integrations.SkillXP; import net.momirealms.customcrops.integrations.protection.*; import net.momirealms.customcrops.integrations.skill.*; @@ -48,7 +48,8 @@ public class MainConfig { public static boolean OraxenHook; public static boolean realisticSeasonHook; public static boolean cropMode; - public static List antiGriefs; + public static List internalAntiGriefs = new ArrayList<>(); + public static List externalAntiGriefs = new ArrayList<>(); public static SkillXP skillXP; public static double dryGrowChance; public static boolean limitation; @@ -89,6 +90,7 @@ public class MainConfig { public static String fertilizerInfo; public static boolean enableParticles; public static boolean enableAnimations; + public static double animationYOffset; public static boolean autoGrow; public static boolean enableCompensation; public static boolean syncSeason; @@ -122,7 +124,6 @@ public class MainConfig { public static boolean enableSkillBonus; public static double bonusPerLevel; public static HashMap vanilla2Crops; - public static boolean enableEvents; public static int saveInterval; public static boolean dryMakesCropDead; public static double dryDeadChance; @@ -191,7 +192,8 @@ public class MainConfig { autoBackUp = config.getBoolean("optimization.auto-back-up", true); enableParticles = !config.getBoolean("optimization.disable-water-particles", false); - enableAnimations = !config.getBoolean("optimization.disable-sprinkler-animation", false); + enableAnimations = config.getBoolean("mechanics.sprinkler-animation.enable", true); + animationYOffset = config.getDouble("mechanics.sprinkler-animation.y-offset", 1); enableSeasonBroadcast = config.getBoolean("season-broadcast.enable", true); springMsg = config.getStringList("season-broadcast.spring").toArray(new String[0]); @@ -216,7 +218,6 @@ public class MainConfig { skyLightLevel = config.getInt("mechanics.dead-if-no-sky-light.level", 10); needSkyLight = config.getBoolean("mechanics.dead-if-no-sky-light.enable", true); - enableEvents = config.getBoolean("other-settings.enable-additional-events", false); String[] split = StringUtils.split(config.getString("mechanics.default-quality-ratio", "17/2/1"), "/"); double[] weight = new double[3]; @@ -290,81 +291,81 @@ public class MainConfig { saveInterval = config.getInt("other-settings.data-save-interval", 3); - antiGriefs = new ArrayList<>(); + internalAntiGriefs.clear(); if (config.getBoolean("integration.Residence",false)){ if (Bukkit.getPluginManager().getPlugin("Residence") == null) Log.warn("Failed to initialize Residence!"); else { - antiGriefs.add(new ResidenceHook()); + internalAntiGriefs.add(new ResidenceHook()); hookMessage("Residence"); } } if (config.getBoolean("integration.Kingdoms",false)){ if (Bukkit.getPluginManager().getPlugin("Kingdoms") == null) Log.warn("Failed to initialize Kingdoms!"); else { - antiGriefs.add(new KingdomsXHook()); + internalAntiGriefs.add(new KingdomsXHook()); hookMessage("Kingdoms"); } } if (config.getBoolean("integration.WorldGuard",false)){ if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) Log.warn("Failed to initialize WorldGuard!"); else { - antiGriefs.add(new WorldGuardHook()); + internalAntiGriefs.add(new WorldGuardHook()); hookMessage("WorldGuard"); } } if (config.getBoolean("integration.GriefDefender",false)){ if(Bukkit.getPluginManager().getPlugin("GriefDefender") == null) Log.warn("Failed to initialize GriefDefender!"); else { - antiGriefs.add(new GriefDefenderHook()); + internalAntiGriefs.add(new GriefDefenderHook()); hookMessage("GriefDefender"); } } if (config.getBoolean("integration.PlotSquared",false)){ if(Bukkit.getPluginManager().getPlugin("PlotSquared") == null) Log.warn("Failed to initialize PlotSquared!"); else { - antiGriefs.add(new PlotSquaredHook()); + internalAntiGriefs.add(new PlotSquaredHook()); hookMessage("PlotSquared"); } } if (config.getBoolean("integration.Towny",false)){ if (Bukkit.getPluginManager().getPlugin("Towny") == null) Log.warn("Failed to initialize Towny!"); else { - antiGriefs.add(new TownyHook()); + internalAntiGriefs.add(new TownyHook()); hookMessage("Towny"); } } if (config.getBoolean("integration.Lands",false)){ if (Bukkit.getPluginManager().getPlugin("Lands") == null) Log.warn("Failed to initialize Lands!"); else { - antiGriefs.add(new LandsHook()); + internalAntiGriefs.add(new LandsHook()); hookMessage("Lands"); } } if (config.getBoolean("integration.GriefPrevention",false)){ if (Bukkit.getPluginManager().getPlugin("GriefPrevention") == null) Log.warn("Failed to initialize GriefPrevention!"); else { - antiGriefs.add(new GriefPreventionHook()); + internalAntiGriefs.add(new GriefPreventionHook()); hookMessage("GriefPrevention"); } } if (config.getBoolean("integration.CrashClaim",false)){ if (Bukkit.getPluginManager().getPlugin("CrashClaim") == null) Log.warn("Failed to initialize CrashClaim!"); else { - antiGriefs.add(new CrashClaimHook()); + internalAntiGriefs.add(new CrashClaimHook()); hookMessage("CrashClaim"); } } if (config.getBoolean("integration.BentoBox",false)){ if (Bukkit.getPluginManager().getPlugin("BentoBox") == null) Log.warn("Failed to initialize BentoBox!"); else { - antiGriefs.add(new BentoBoxHook()); + internalAntiGriefs.add(new BentoBoxHook()); hookMessage("BentoBox"); } } if (config.getBoolean("integration.IridiumSkyblock",false)){ if (Bukkit.getPluginManager().getPlugin("IridiumSkyblock") == null) Log.warn("Failed to initialize IridiumSkyblock!"); else { - antiGriefs.add(new IridiumSkyblockHook()); + internalAntiGriefs.add(new IridiumSkyblockHook()); hookMessage("IridiumSkyblock"); } } @@ -435,4 +436,13 @@ public class MainConfig { private static void hookMessage(String plugin){ AdventureUtil.consoleMessage("[CustomCrops] " + plugin + " Hooked!"); } + + public static void registerAntiGrief(CCAntiGrief ccAntiGrief) { + externalAntiGriefs.add(ccAntiGrief); + hookMessage(ccAntiGrief.getName()); + } + + public static void unregisterAntiGrief(CCAntiGrief ccAntiGrief) { + externalAntiGriefs.remove(ccAntiGrief); + } } diff --git a/src/main/java/net/momirealms/customcrops/helper/VersionHelper.java b/src/main/java/net/momirealms/customcrops/helper/VersionHelper.java new file mode 100644 index 0000000..8f49527 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/helper/VersionHelper.java @@ -0,0 +1,22 @@ +package net.momirealms.customcrops.helper; + +import org.bukkit.Bukkit; +import org.bukkit.Location; + +public class VersionHelper { + + private boolean isNewerThan1_19_R2; + private String version; + + public boolean isVersionNewerThan1_19_R2() { + if (version == null) { + version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + String[] split = version.split("_"); + int main_ver = Integer.parseInt(split[1]); + if (main_ver >= 20) isNewerThan1_19_R2 = true; + else if (main_ver == 19) isNewerThan1_19_R2 = Integer.parseInt(split[2].substring(1)) >= 2; + else isNewerThan1_19_R2 = false; + } + return isNewerThan1_19_R2; + } +} diff --git a/src/main/java/net/momirealms/customcrops/integrations/AntiGrief.java b/src/main/java/net/momirealms/customcrops/integrations/CCAntiGrief.java similarity index 66% rename from src/main/java/net/momirealms/customcrops/integrations/AntiGrief.java rename to src/main/java/net/momirealms/customcrops/integrations/CCAntiGrief.java index b7e7fc9..2fe7539 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/AntiGrief.java +++ b/src/main/java/net/momirealms/customcrops/integrations/CCAntiGrief.java @@ -21,7 +21,9 @@ import net.momirealms.customcrops.config.MainConfig; import org.bukkit.Location; import org.bukkit.entity.Player; -public interface AntiGrief { +public interface CCAntiGrief { + + String getName(); boolean canBreak(Location location, Player player); @@ -29,8 +31,13 @@ public interface AntiGrief { static boolean testBreak(Player player, Location location) { if (player.isOp()) return true; - for (AntiGrief antiGrief : MainConfig.antiGriefs) { - if(!antiGrief.canBreak(location, player)) { + for (CCAntiGrief CCAntiGrief : MainConfig.internalAntiGriefs) { + if(!CCAntiGrief.canBreak(location, player)) { + return false; + } + } + for (CCAntiGrief CCAntiGrief : MainConfig.externalAntiGriefs) { + if(!CCAntiGrief.canBreak(location, player)) { return false; } } @@ -39,8 +46,13 @@ public interface AntiGrief { static boolean testPlace(Player player, Location location) { if (player.isOp()) return true; - for (AntiGrief antiGrief : MainConfig.antiGriefs) { - if(!antiGrief.canPlace(location, player)) { + for (CCAntiGrief CCAntiGrief : MainConfig.internalAntiGriefs) { + if(!CCAntiGrief.canPlace(location, player)) { + return false; + } + } + for (CCAntiGrief CCAntiGrief : MainConfig.externalAntiGriefs) { + if(!CCAntiGrief.canPlace(location, player)) { return false; } } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java index 13b3484..31ba350 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java @@ -17,7 +17,6 @@ package net.momirealms.customcrops.integrations.customplugin; -import com.willfp.eco.core.items.Items; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -35,13 +34,12 @@ import net.momirealms.customcrops.objects.Function; import net.momirealms.customcrops.objects.Sprinkler; import net.momirealms.customcrops.objects.WaterCan; import net.momirealms.customcrops.objects.fertilizer.Fertilizer; -import net.momirealms.customcrops.objects.requirements.PlantingCondition; +import net.momirealms.customcrops.objects.requirements.PlayerCondition; import net.momirealms.customcrops.objects.requirements.RequirementInterface; import net.momirealms.customcrops.utils.AdventureUtil; import net.momirealms.customcrops.utils.FurnitureUtil; import net.momirealms.customcrops.utils.HologramUtil; import net.momirealms.customcrops.utils.LimitationUtil; -import org.apache.commons.lang.StringUtils; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.ItemFrame; @@ -228,29 +226,20 @@ public abstract class HandlerP extends Function { return true; } - private void removeCropCache(Location location) { + public void onBreakUnripeCrop(Location location) { CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld()); if (customWorld == null) return; customWorld.removeCropCache(location); } - public void onBreakUnripeCrop(Location location) { - removeCropCache(location); - } - - public void onBreakRipeCrop(Location location, String id, Player player, boolean instant) { - removeCropCache(location); - String[] ns = StringUtils.split(id, ":"); - String cropNameWithoutNS = ns[ns.length-1]; - String cropName = cropNameWithoutNS.substring(0, cropNameWithoutNS.indexOf("_stage_")); - - Crop crop = CropConfig.CROPS.get(cropName); - if (crop == null) return; - + public void onBreakRipeCrop(Location location, Crop crop, Player player, boolean instant) { + if (isInCoolDown(player, 50)) return; CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld()); if (customWorld != null) { + customWorld.removeCropCache(location); Fertilizer fertilizer = customWorld.getFertilizerCache(location.clone().subtract(0,1,0)); if (instant) { + //To prevent some unhooked region plugin duplication Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, ()-> { if (location.getBlock().getType() != Material.AIR) return; cropManager.proceedHarvest(crop, player, location, fertilizer, false); @@ -273,7 +262,7 @@ public abstract class HandlerP extends Function { } } - public void removeScarecrow(Location location) { + public void removeScarecrowCache(Location location) { CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld()); if (customWorld == null) return; customWorld.removeScarecrowCache(location); @@ -534,36 +523,20 @@ public abstract class HandlerP extends Function { } } - protected boolean canProceedAction(Player player, Location location) { - if (MainConfig.enableEvents) return true; - PreActionEvent preActionEvent = new PreActionEvent(player, location); - Bukkit.getPluginManager().callEvent(preActionEvent); - return !preActionEvent.isCancelled(); - } - - protected boolean onInteractRipeCrop(Location location, Crop crop, Player player) { + protected void onInteractRipeCrop(Location location, Crop crop, Player player) { CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld()); if (customWorld != null) { Fertilizer fertilizer = customWorld.getFertilizerCache(location.clone().subtract(0,1,0)); cropManager.proceedHarvest(crop, player, location, fertilizer, true); - String returnStage = crop.getReturnStage(); - if (returnStage == null) { - customWorld.removeCropCache(location); - return true; - } - else { - customWorld.addCropCache(location, crop.getKey(), Integer.parseInt(returnStage.substring(returnStage.indexOf("_stage_") + 7))); - return false; - } + if (returnStage == null) customWorld.removeCropCache(location); + else customWorld.addCropCache(location, crop.getKey(), Integer.parseInt(returnStage.substring(returnStage.indexOf("_stage_") + 7))); } else if (MainConfig.dropLootsInAllWorlds) { cropManager.proceedHarvest(crop, player, location, null, true); } - return true; } - public boolean plantSeed(Location seedLoc, String cropName, @Nullable Player player, @Nullable ItemStack itemInHand) { Crop crop = CropConfig.CROPS.get(cropName); if (crop == null) return false; @@ -574,10 +547,10 @@ public abstract class HandlerP extends Function { if (FurnitureUtil.hasFurniture(customInterface.getFrameCropLocation(seedLoc)) || seedLoc.getBlock().getType() != Material.AIR) return false; if (player != null) { - PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player); - if (crop.getRequirements() != null) { - for (RequirementInterface requirement : crop.getRequirements()) { - if (!requirement.isConditionMet(plantingCondition)) { + PlayerCondition playerCondition = new PlayerCondition(seedLoc, player); + if (crop.getPlantRequirements() != null) { + for (RequirementInterface requirement : crop.getPlantRequirements()) { + if (!requirement.isConditionMet(playerCondition)) { return false; } } @@ -666,4 +639,16 @@ public abstract class HandlerP extends Function { int stage = Integer.parseInt(id.substring(id.indexOf("_stage_") + 7)); return stage == crop.getMax_stage(); } + + protected boolean checkHarvestRequirements(Player player, Location location, Crop crop) { + PlayerCondition playerCondition = new PlayerCondition(location, player); + if (crop.getHarvestRequirements() != null) { + for (RequirementInterface requirement : crop.getHarvestRequirements()) { + if (!requirement.isConditionMet(playerCondition)) { + return false; + } + } + } + return true; + } } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameHandler.java index ccca6c7..d4241d0 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameHandler.java @@ -28,7 +28,7 @@ import net.momirealms.customcrops.config.BasicItemConfig; import net.momirealms.customcrops.config.MainConfig; import net.momirealms.customcrops.config.SoundConfig; import net.momirealms.customcrops.config.SprinklerConfig; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import net.momirealms.customcrops.managers.CropManager; import net.momirealms.customcrops.objects.Sprinkler; import net.momirealms.customcrops.utils.AdventureUtil; @@ -44,6 +44,7 @@ import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; public class ItemsAdderFrameHandler extends ItemsAdderHandler { @@ -55,40 +56,47 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler { public void onInteractFurniture(FurnitureInteractEvent event) { if (event.isCancelled()) return; - final String namespacedID = event.getNamespacedID(); - if (namespacedID == null) return; + final String entityNamespacedID = event.getNamespacedID(); + if (entityNamespacedID == null) return; final Player player = event.getPlayer(); final Entity entity = event.getBukkitEntity(); - final Location location = entity.getLocation();; + final Location entityLocation = entity.getLocation();; - if (!canProceedAction(player, location)) return; - - Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(namespacedID); + Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(entityNamespacedID); if (sprinkler != null) { - if (!AntiGrief.testPlace(player, entity.getLocation())) return; + if (!CCAntiGrief.testPlace(player, entity.getLocation())) return; super.onInteractSprinkler(entity.getLocation(), player, player.getInventory().getItemInMainHand(), sprinkler); return; } - if (!namespacedID.contains("_stage_")) return; - if (!namespacedID.equals(BasicItemConfig.deadCrop)) { + if (!entityNamespacedID.contains("_stage_")) return; + if (!entityNamespacedID.equals(BasicItemConfig.deadCrop)) { ItemStack itemInHand = player.getInventory().getItemInMainHand(); - if (isRipe(namespacedID)) { + if (isRipe(entityNamespacedID)) { if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) { - if (!AntiGrief.testBreak(player, entity.getLocation())) return; - if (!canProceedAction(player, entity.getLocation())) return; + if (!CCAntiGrief.testBreak(player, entity.getLocation())) return; + Crop crop = customInterface.getCropFromID(entityNamespacedID); + if (crop == null) return; + if (!checkHarvestRequirements(player, entityLocation, crop)) { + event.setCancelled(true); + return; + } customInterface.removeFurniture(entity); if (entity.isValid()) entity.remove(); - this.onInteractRipeCrop(location, namespacedID, player); + super.onInteractRipeCrop(entityLocation, crop, player); + if (crop.getReturnStage() != null) { + CustomFurniture customFurniture = CustomFurniture.spawn(crop.getReturnStage(), entityLocation.getBlock()); + if (crop.canRotate() && customFurniture instanceof ItemFrame itemFrame) itemFrame.setRotation(FurnitureUtil.getRandomRotation()); + } return; } } else if (MainConfig.enableBoneMeal && itemInHand.getType() == Material.BONE_MEAL) { - if (!AntiGrief.testPlace(player, location)) return; + if (!CCAntiGrief.testPlace(player, entityLocation)) return; if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); if (Math.random() < MainConfig.boneMealChance) { - entity.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0,0.5, 0),3,0.2,0.2,0.2); + entity.getWorld().spawnParticle(MainConfig.boneMealSuccess, entityLocation.clone().add(0,0.5, 0),3,0.2,0.2,0.2); if (SoundConfig.boneMeal.isEnable()) { AdventureUtil.playerSound( player, @@ -98,48 +106,54 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler { ); } customInterface.removeFurniture(entity); - customInterface.placeFurniture(location, customInterface.getNextStage(namespacedID)); + customInterface.placeFurniture(entityLocation, customInterface.getNextStage(entityNamespacedID)); } return; } } - super.tryMisc(player, player.getInventory().getItemInMainHand(), MiscUtils.getItemFrameBlockLocation(location.clone().subtract(0,1,0))); + super.tryMisc(player, player.getInventory().getItemInMainHand(), MiscUtils.getItemFrameBlockLocation(entityLocation.clone().subtract(0,1,0))); } public void onBreakFurniture(FurnitureBreakEvent event) { if (event.isCancelled()) return; - final String namespacedId = event.getNamespacedID(); - if (namespacedId == null) return; + final String entityNamespacedId = event.getNamespacedID(); + if (entityNamespacedId == null) return; - final Location location = event.getBukkitEntity().getLocation(); + final Location entityLocation = event.getBukkitEntity().getLocation(); final Player player = event.getPlayer(); - Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(namespacedId); + Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(entityNamespacedId); if (sprinkler != null) { - super.onBreakSprinkler(location); + super.onBreakSprinkler(entityLocation); return; } - if (MainConfig.enableCrow && namespacedId.equals(BasicItemConfig.scarecrow)) { - super.removeScarecrow(event.getBukkitEntity().getLocation()); + if (MainConfig.enableCrow && entityNamespacedId.equals(BasicItemConfig.scarecrow)) { + super.removeScarecrowCache(event.getBukkitEntity().getLocation()); return; } - if (namespacedId.contains("_stage_")) { - if (namespacedId.equals(BasicItemConfig.deadCrop)) return; - if (!isRipe(namespacedId)) super.onBreakUnripeCrop(location); - else super.onBreakRipeCrop(location, namespacedId, player, false); + if (entityNamespacedId.contains("_stage_") && !entityNamespacedId.equals(BasicItemConfig.deadCrop)) { + if (!isRipe(entityNamespacedId)) { + super.onBreakUnripeCrop(entityLocation); + } else { + Crop crop = customInterface.getCropFromID(entityNamespacedId); + if (crop == null) return; + if (!checkHarvestRequirements(player, entityLocation, crop)) { + event.setCancelled(true); + return; + } + super.onBreakRipeCrop(entityLocation, crop, player, false); + } } } @Override public void onPlayerInteract(PlayerInteractEvent event) { - final Player player = event.getPlayer(); - + if (event.getHand() != EquipmentSlot.HAND) return; super.onPlayerInteract(event); - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; Block block = event.getClickedBlock(); if (block == null) return; @@ -150,7 +164,6 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler { if (!blockID.equals(BasicItemConfig.wetPot) && !blockID.equals(BasicItemConfig.dryPot)) return; Location seedLoc = block.getLocation().clone().add(0,1,0); - if (!canProceedAction(player, seedLoc)) return; ItemStack itemInHand = event.getItem(); Location potLoc = block.getLocation(); @@ -180,33 +193,41 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler { final Player player = event.getPlayer(); final Location location = event.getBlock().getLocation(); - if (!AntiGrief.testBreak(player, location)) return; - if (!canProceedAction(player, location)) return; + if (!CCAntiGrief.testBreak(player, location)) return; if (namespacedId.equals(BasicItemConfig.dryPot) || namespacedId.equals(BasicItemConfig.wetPot)) { - super.onBreakPot(location); - ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(location.clone().add(0,1,0))); - if (itemFrame == null) return; - CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(itemFrame); - if (customFurniture == null) return; - String seedID = customFurniture.getNamespacedID(); - if (seedID.contains("_stage_")) { - CustomFurniture.remove(itemFrame, false); - if (itemFrame.isValid()) itemFrame.remove(); - if (seedID.equals(BasicItemConfig.deadCrop)) return; - if (!isRipe(seedID)) super.onBreakUnripeCrop(location.clone().add(0,1,0)); - else super.onBreakRipeCrop(location.clone().add(0,1,0), seedID, player, true); + label_out: { + Location seedLoc = location.clone().add(0,1,0); + ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(seedLoc)); + if (itemFrame == null) break label_out; + CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(itemFrame); + if (customFurniture == null) break label_out; + String seedID = customFurniture.getNamespacedID(); + if (seedID.contains("_stage_")) { + if (seedID.equals(BasicItemConfig.deadCrop)) { + CustomFurniture.remove(itemFrame, false); + if (itemFrame.isValid()) itemFrame.remove(); + break label_out; + } + if (!isRipe(seedID)) { + CustomFurniture.remove(itemFrame, false); + if (itemFrame.isValid()) itemFrame.remove(); + super.onBreakUnripeCrop(location.clone().add(0,1,0)); + } + else { + Crop crop = customInterface.getCropFromID(seedID); + if (crop == null) break label_out; + if (!checkHarvestRequirements(player, seedLoc, crop)) { + event.setCancelled(true); + return; + } + CustomFurniture.remove(itemFrame, false); + if (itemFrame.isValid()) itemFrame.remove(); + super.onBreakRipeCrop(seedLoc, crop, player, true); + } + } } - } - } - - private void onInteractRipeCrop(Location location, String id, Player player) { - Crop crop = customInterface.getCropFromID(id); - if (crop == null) return; - if (super.onInteractRipeCrop(location, crop, player)) return; - if (crop.getReturnStage() != null) { - CustomFurniture customFurniture = CustomFurniture.spawn(crop.getReturnStage(), location.getBlock()); - if (crop.canRotate() && customFurniture instanceof ItemFrame itemFrame) itemFrame.setRotation(FurnitureUtil.getRandomRotation()); + super.onBreakPot(location); } } } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHandler.java index abadcfe..cfc7c0e 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHandler.java @@ -31,7 +31,7 @@ import net.momirealms.customcrops.config.BasicItemConfig; import net.momirealms.customcrops.config.MainConfig; import net.momirealms.customcrops.config.SoundConfig; import net.momirealms.customcrops.config.WaterCanConfig; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import net.momirealms.customcrops.integrations.customplugin.HandlerP; import net.momirealms.customcrops.integrations.customplugin.itemsadder.listeners.ItemsAdderBlockListener; import net.momirealms.customcrops.integrations.customplugin.itemsadder.listeners.ItemsAdderFurnitureListener; @@ -114,8 +114,7 @@ public abstract class ItemsAdderHandler extends HandlerP { if (block == null) return; Location location = block.getLocation(); - if (!AntiGrief.testPlace(player, location)) return; - if (!canProceedAction(player, location)) return; + if (!CCAntiGrief.testPlace(player, location)) return; if (event.getBlockFace() == BlockFace.UP) { placeSprinkler(namespacedID, event.getClickedBlock().getLocation(), player, item); } @@ -123,7 +122,7 @@ public abstract class ItemsAdderHandler extends HandlerP { } public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) { - if (!AntiGrief.testPlace(player, potLoc)) return true; + if (!CCAntiGrief.testPlace(player, potLoc)) return true; if (itemInHand == null || itemInHand.getType() == Material.AIR) return true; if (useBucket(potLoc, player, itemInHand)) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireHandler.java index f84b2e6..7d86547 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireHandler.java @@ -27,7 +27,7 @@ import net.momirealms.customcrops.config.BasicItemConfig; import net.momirealms.customcrops.config.MainConfig; import net.momirealms.customcrops.config.SoundConfig; import net.momirealms.customcrops.config.SprinklerConfig; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import net.momirealms.customcrops.managers.CropManager; import net.momirealms.customcrops.objects.Sprinkler; import net.momirealms.customcrops.utils.AdventureUtil; @@ -41,6 +41,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; public class ItemsAdderWireHandler extends ItemsAdderHandler { @@ -52,16 +53,9 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler { //interact sprinkler public void onInteractFurniture(FurnitureInteractEvent event) { if (event.isCancelled()) return; - final Player player = event.getPlayer(); - - if (isInCoolDown(player, 100)) return; - Entity entity = event.getBukkitEntity(); - - if (!AntiGrief.testPlace(player, entity.getLocation())) return; - if (!canProceedAction(player, entity.getLocation())) return; - + if (!CCAntiGrief.testPlace(player, entity.getLocation())) return; String namespacedID = event.getNamespacedID(); if (namespacedID == null) return; Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(namespacedID); @@ -73,7 +67,6 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler { //break sprinkler public void onBreakFurniture(FurnitureBreakEvent event) { if (event.isCancelled()) return; - String namespacedID = event.getNamespacedID(); if (namespacedID == null) return; Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(namespacedID); @@ -81,30 +74,23 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler { super.onBreakSprinkler(event.getBukkitEntity().getLocation()); return; } - if (MainConfig.enableCrow && namespacedID.equals(BasicItemConfig.scarecrow)) { - super.removeScarecrow(event.getBukkitEntity().getLocation()); + super.removeScarecrowCache(event.getBukkitEntity().getLocation()); } } - @Override public void onPlayerInteract(PlayerInteractEvent event) { - final Player player = event.getPlayer(); - + if (event.getHand() != EquipmentSlot.HAND) return; super.onPlayerInteract(event); - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; Block block = event.getClickedBlock(); if (block == null) return; CustomBlock cb = CustomBlock.byAlreadyPlaced(block); if (cb == null) return; Location location = block.getLocation(); - final String blockID = cb.getNamespacedID(); - - if (!canProceedAction(player, location)) return; if (blockID.contains("_stage_")) { ItemStack itemInHand = event.getItem(); if (!blockID.equals(BasicItemConfig.deadCrop)) { @@ -112,15 +98,22 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler { ItemStack mainHand = player.getInventory().getItemInMainHand(); ItemStack offHand = player.getInventory().getItemInOffHand(); if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && (mainHand.getType() != Material.AIR || offHand.getType() != Material.AIR))) { - if (!AntiGrief.testBreak(player, location)) return; + if (!CCAntiGrief.testBreak(player, location)) return; + Crop crop = customInterface.getCropFromID(blockID); + if (crop == null) return; + if (!checkHarvestRequirements(player, location, crop)) { + event.setCancelled(true); + return; + } CustomBlock.remove(location); - this.onInteractRipeCrop(location, blockID, player); + super.onInteractRipeCrop(location, crop, player); + if (crop.getReturnStage() != null) CustomBlock.place(crop.getReturnStage(), location); return; } } //has next stage else if (MainConfig.enableBoneMeal && itemInHand != null && itemInHand.getType() == Material.BONE_MEAL) { - if (!AntiGrief.testPlace(player, location)) return; + if (!CCAntiGrief.testPlace(player, location)) return; if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); if (Math.random() < MainConfig.boneMealChance) { location.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0.5,0.5, 0.5),3,0.2,0.2,0.2); @@ -164,68 +157,63 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler { } } - private void onInteractRipeCrop(Location location, String id, Player player) { - Crop crop = customInterface.getCropFromID(id); - if (crop == null) return; - if (super.onInteractRipeCrop(location, crop, player)) return; - if (crop.getReturnStage() != null) CustomBlock.place(crop.getReturnStage(), location); - } - @Override public void onBreakBlock(CustomBlockBreakEvent event) { if (event.isCancelled()) return; - final Player player = event.getPlayer(); - if (isInCoolDown(player, 50)) return; - final String namespacedId = event.getNamespacedID(); final Location location = event.getBlock().getLocation(); - if (!canProceedAction(player, location)) return; + if (!CCAntiGrief.testBreak(player, location)) return; if (namespacedId.contains("_stage_")) { - if (!AntiGrief.testBreak(player, location)) { - event.setCancelled(true); - return; - } - if (player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH) || player.getInventory().getItemInMainHand().getType() == Material.SHEARS){ event.setCancelled(true); CustomBlock.place(namespacedId, location); if (player.getGameMode() != GameMode.CREATIVE) CustomBlock.byAlreadyPlaced(location.getBlock()).getLoot().forEach(itemStack -> location.getWorld().dropItemNaturally(location, itemStack)); CustomBlock.remove(location); } - if (namespacedId.equals(BasicItemConfig.deadCrop)) return; if (!isRipe(namespacedId)) super.onBreakUnripeCrop(location); - else super.onBreakRipeCrop(location, namespacedId, player, true); + else { + Crop crop = customInterface.getCropFromID(namespacedId); + if (crop == null) return; + if (!checkHarvestRequirements(player, location, crop)) { + event.setCancelled(true); + return; + } + super.onBreakRipeCrop(location, crop, player, true); + } } - else if (namespacedId.equals(BasicItemConfig.dryPot) || namespacedId.equals(BasicItemConfig.wetPot)) { - - if (!AntiGrief.testBreak(player, location)) { - event.setCancelled(true); - return; + label_out: { + Location seedLocation = location.clone().add(0,1,0); + CustomBlock customBlock = CustomBlock.byAlreadyPlaced(seedLocation.getBlock()); + if (customBlock == null) break label_out; + String seedID = customBlock.getNamespacedID(); + if (seedID.contains("_stage_")) { + if (seedID.equals(BasicItemConfig.deadCrop)) { + CustomBlock.remove(seedLocation); + break label_out; + } + if (!isRipe(seedID)) { + if (player.getGameMode() == GameMode.CREATIVE) break label_out; + CustomBlock.remove(seedLocation); + customBlock.getLoot().forEach(loot -> location.getWorld().dropItemNaturally(seedLocation.getBlock().getLocation(), loot)); + } + else { + Crop crop = customInterface.getCropFromID(seedID); + if (crop == null) break label_out; + if (!checkHarvestRequirements(player, seedLocation, crop)) { + event.setCancelled(true); + return; + } + CustomBlock.remove(seedLocation); + super.onBreakRipeCrop(seedLocation, crop, player, false); + } + } } - super.onBreakPot(location); - - Location seedLocation = location.clone().add(0,1,0); - CustomBlock customBlock = CustomBlock.byAlreadyPlaced(seedLocation.getBlock()); - if (customBlock == null) return; - String seedID = customBlock.getNamespacedID(); - - if (seedID.contains("_stage_")) { - CustomBlock.remove(seedLocation); - if (seedID.equals(BasicItemConfig.deadCrop)) return; - if (!isRipe(seedID)) { - if (player.getGameMode() == GameMode.CREATIVE) return; - customBlock.getLoot().forEach(loot -> location.getWorld().dropItemNaturally(seedLocation.getBlock().getLocation(), loot)); - } - else { - super.onBreakRipeCrop(seedLocation, seedID, player, false); - } - } } } } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java index 6c17e82..dcd6667 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java @@ -30,7 +30,7 @@ import net.momirealms.customcrops.config.BasicItemConfig; import net.momirealms.customcrops.config.MainConfig; import net.momirealms.customcrops.config.SoundConfig; import net.momirealms.customcrops.config.SprinklerConfig; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import net.momirealms.customcrops.managers.CropManager; import net.momirealms.customcrops.objects.Sprinkler; import net.momirealms.customcrops.utils.AdventureUtil; @@ -61,35 +61,45 @@ public class OraxenFrameHandler extends OraxenHandler { final Location location = event.getBlock().getLocation(); if (!id.equals(BasicItemConfig.dryPot) && !id.equals(BasicItemConfig.wetPot)) return; - if (!canProceedAction(player, location)) return; - - if (!AntiGrief.testBreak(player, location)) { + if (!CCAntiGrief.testBreak(player, location)) { event.setCancelled(true); return; } - super.onBreakPot(location); - Location seedLocation = location.clone().add(0,1,0); - ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(seedLocation)); - if (itemFrame == null) return; - String furnitureID = itemFrame.getPersistentDataContainer().get(OraxenHook.FURNITURE, PersistentDataType.STRING); - if (furnitureID == null) return; - if (furnitureID.contains("_stage_")) { - itemFrame.remove(); - if (furnitureID.equals(BasicItemConfig.deadCrop)) return; - if (!isRipe(furnitureID)) { - FurnitureMechanic mechanic = (FurnitureMechanic) FurnitureFactory.instance.getMechanic(furnitureID); - if (mechanic == null) return; - Drop drop = mechanic.getDrop(); - if (drop != null && player.getGameMode() != GameMode.CREATIVE) { - drop.spawns(seedLocation, new ItemStack(Material.AIR)); + label_out: { + Location seedLocation = location.clone().add(0,1,0); + ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(seedLocation)); + if (itemFrame == null) break label_out; + String furnitureID = itemFrame.getPersistentDataContainer().get(OraxenHook.FURNITURE, PersistentDataType.STRING); + if (furnitureID == null) break label_out; + if (furnitureID.contains("_stage_")) { + if (furnitureID.equals(BasicItemConfig.deadCrop)) { + itemFrame.remove(); + break label_out; + } + if (!isRipe(furnitureID)) { + itemFrame.remove(); + FurnitureMechanic mechanic = (FurnitureMechanic) FurnitureFactory.instance.getMechanic(furnitureID); + if (mechanic == null) break label_out; + Drop drop = mechanic.getDrop(); + if (drop != null && player.getGameMode() != GameMode.CREATIVE) { + drop.spawns(seedLocation, new ItemStack(Material.AIR)); + } + super.onBreakUnripeCrop(seedLocation); + } + else { + Crop crop = customInterface.getCropFromID(furnitureID); + if (crop == null) break label_out; + if (!checkHarvestRequirements(player, seedLocation, crop)) { + event.setCancelled(true); + return; + } + itemFrame.remove(); + super.onBreakRipeCrop(seedLocation, crop, player, false); } - super.onBreakUnripeCrop(seedLocation); - } - else { - super.onBreakRipeCrop(seedLocation, furnitureID, player, false); } } + super.onBreakPot(location); } @Override @@ -106,20 +116,28 @@ public class OraxenFrameHandler extends OraxenHandler { } if (MainConfig.enableCrow && id.equals(BasicItemConfig.scarecrow)) { - super.removeScarecrow(event.getBlock().getLocation()); + super.removeScarecrowCache(event.getBlock().getLocation()); return; } if (id.contains("_stage_")) { if (id.equals(BasicItemConfig.deadCrop)) return; - if (!isRipe(id)) super.onBreakUnripeCrop(event.getBlock().getLocation()); - else super.onBreakRipeCrop(event.getBlock().getLocation(), id, event.getPlayer(), false); + Location seedLoc = event.getBlock().getLocation(); + if (!isRipe(id)) super.onBreakUnripeCrop(seedLoc); + else { + Crop crop = customInterface.getCropFromID(id); + if (crop == null) return; + if (!checkHarvestRequirements(event.getPlayer(), seedLoc, crop)) { + event.setCancelled(true); + return; + } + super.onBreakRipeCrop(seedLoc, crop, event.getPlayer(), false); + } } } @Override public void onInteractNoteBlock(OraxenNoteBlockInteractEvent event) { - final Player player = event.getPlayer(); final ItemStack itemInHand = event.getItemInHand(); final Block block = event.getBlock(); @@ -130,10 +148,8 @@ public class OraxenFrameHandler extends OraxenHandler { Location potLoc = block.getLocation(); Location seedLoc = potLoc.clone().add(0,1,0); - if (!canProceedAction(player, potLoc)) return; if (super.tryMisc(player, itemInHand, potLoc)) return; if (event.getBlockFace() != BlockFace.UP) return; - if (isInCoolDown(player, 50)) return; String id = OraxenItems.getIdByItem(itemInHand); if (id != null) { @@ -159,11 +175,10 @@ public class OraxenFrameHandler extends OraxenHandler { final Player player = event.getPlayer(); final ItemFrame itemFrame = event.getItemFrame(); final Location location = itemFrame.getLocation(); - if (!canProceedAction(player, location)) return; Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(id); if (sprinkler != null) { - if (!AntiGrief.testPlace(player, itemFrame.getLocation())) return; + if (!CCAntiGrief.testPlace(player, itemFrame.getLocation())) return; super.onInteractSprinkler(location, player, player.getInventory().getItemInMainHand(), sprinkler); return; } @@ -173,14 +188,24 @@ public class OraxenFrameHandler extends OraxenHandler { ItemStack itemInHand = player.getInventory().getItemInMainHand(); if (isRipe(id)) { if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) { - if (!AntiGrief.testBreak(player, location)) return; + if (!CCAntiGrief.testBreak(player, location)) return; + Crop crop = customInterface.getCropFromID(id); + if (crop == null) return; + if (!checkHarvestRequirements(player, location, crop)) { + event.setCancelled(true); + return; + } itemFrame.remove(); - this.onInteractRipeCrop(location, id, player); + super.onInteractRipeCrop(location, crop, player); + if (crop.getReturnStage() != null) { + ItemFrame placedFurniture = cropManager.getCustomInterface().placeFurniture(location, crop.getReturnStage()); + if (crop.canRotate() && placedFurniture != null) itemFrame.setRotation(FurnitureUtil.getRandomRotation()); + } return; } } else if (MainConfig.enableBoneMeal && itemInHand.getType() == Material.BONE_MEAL) { - if (!AntiGrief.testPlace(player, location)) return; + if (!CCAntiGrief.testPlace(player, location)) return; if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); if (Math.random() < MainConfig.boneMealChance) { itemFrame.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0,0.5, 0),3,0.2,0.2,0.2); @@ -201,14 +226,4 @@ public class OraxenFrameHandler extends OraxenHandler { } super.tryMisc(player, player.getInventory().getItemInMainHand(), MiscUtils.getItemFrameBlockLocation(location.clone().subtract(0,1,0))); } - - private void onInteractRipeCrop(Location location, String id, Player player) { - Crop crop = customInterface.getCropFromID(id); - if (crop == null) return; - if (super.onInteractRipeCrop(location, crop, player)) return; - if (crop.getReturnStage() != null) { - ItemFrame itemFrame = cropManager.getCustomInterface().placeFurniture(location, crop.getReturnStage()); - if (crop.canRotate() && itemFrame != null) itemFrame.setRotation(FurnitureUtil.getRandomRotation()); - } - } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHandler.java index 6b7a1a6..164fa25 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHandler.java @@ -28,7 +28,7 @@ import net.momirealms.customcrops.config.BasicItemConfig; import net.momirealms.customcrops.config.MainConfig; import net.momirealms.customcrops.config.SoundConfig; import net.momirealms.customcrops.config.WaterCanConfig; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import net.momirealms.customcrops.integrations.customplugin.HandlerP; import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenBlockListener; import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenFurnitureListener; @@ -86,7 +86,7 @@ public abstract class OraxenHandler extends HandlerP { } public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) { - if (!AntiGrief.testPlace(player, potLoc)) return true; + if (!CCAntiGrief.testPlace(player, potLoc)) return true; if (itemInHand == null || itemInHand.getType() == Material.AIR) return true; if (useBucket(potLoc, player, itemInHand)) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java index cc0192e..037eeef 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java @@ -29,7 +29,7 @@ import net.momirealms.customcrops.config.BasicItemConfig; import net.momirealms.customcrops.config.MainConfig; import net.momirealms.customcrops.config.SoundConfig; import net.momirealms.customcrops.config.SprinklerConfig; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import net.momirealms.customcrops.managers.CropManager; import net.momirealms.customcrops.objects.Sprinkler; import net.momirealms.customcrops.utils.AdventureUtil; @@ -61,13 +61,11 @@ public class OraxenWireHandler extends OraxenHandler{ final Block block = event.getBlock(); Location location = block.getLocation(); - if (!AntiGrief.testBreak(player, location)) { + if (!CCAntiGrief.testBreak(player, location)) { event.setCancelled(true); return; } - if (!canProceedAction(player, location)) return; - if (player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH) || player.getInventory().getItemInMainHand().getType() == Material.SHEARS){ event.setCancelled(true); Drop drop = mechanic.getDrop(); @@ -78,7 +76,15 @@ public class OraxenWireHandler extends OraxenHandler{ if (id.equals(BasicItemConfig.deadCrop)) return; if (!isRipe(id)) super.onBreakUnripeCrop(location); - else super.onBreakRipeCrop(location, id, player, true); + else { + Crop crop = customInterface.getCropFromID(id); + if (crop == null) return; + if (!checkHarvestRequirements(player, location, crop)) { + event.setCancelled(true); + return; + } + super.onBreakRipeCrop(location, crop, player, true); + } } @Override @@ -94,7 +100,7 @@ public class OraxenWireHandler extends OraxenHandler{ return; } if (MainConfig.enableCrow && id.equals(BasicItemConfig.scarecrow)) { - super.removeScarecrow(event.getBlock().getLocation()); + super.removeScarecrowCache(event.getBlock().getLocation()); } } @@ -105,8 +111,7 @@ public class OraxenWireHandler extends OraxenHandler{ final Player player = event.getPlayer(); final Location blockLoc = event.getItemFrame().getLocation(); - if (!AntiGrief.testPlace(player, blockLoc)) return; - if (!canProceedAction(player, blockLoc)) return; + if (!CCAntiGrief.testPlace(player, blockLoc)) return; FurnitureMechanic mechanic = event.getMechanic(); if (mechanic == null) return; @@ -125,8 +130,6 @@ public class OraxenWireHandler extends OraxenHandler{ final Location potLoc = event.getBlock().getLocation(); final Player player = event.getPlayer(); - if (isInCoolDown(player, 50)) return; - if (!canProceedAction(player, potLoc)) return; if (super.tryMisc(event.getPlayer(), itemInHand, potLoc)) return; if (event.getBlockFace() != BlockFace.UP) return; @@ -151,29 +154,32 @@ public class OraxenWireHandler extends OraxenHandler{ if (event.isCancelled()) return; final Player player = event.getPlayer(); - - if (isInCoolDown(player, 50)) return; - final Block block = event.getBlock(); final String id = event.getMechanic().getItemID(); if (!id.contains("_stage_")) return; Location seedLoc = block.getLocation(); - if (!canProceedAction(player, seedLoc)) return; ItemStack itemInHand = event.getItemInHand(); if (!id.equals(BasicItemConfig.deadCrop)) { if (isRipe(id)) { if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand != null && itemInHand.getType() != Material.AIR)) { - if (!AntiGrief.testBreak(player, seedLoc)) return; + if (!CCAntiGrief.testBreak(player, seedLoc)) return; + Crop crop = customInterface.getCropFromID(id); + if (crop == null) return; + if (!checkHarvestRequirements(player, seedLoc, crop)) { + event.setCancelled(true); + return; + } block.setType(Material.AIR); - this.onInteractRipeCrop(seedLoc, id, player); + super.onInteractRipeCrop(seedLoc, crop, player); + if (crop.getReturnStage() != null) StringBlockMechanicFactory.setBlockModel(seedLoc.getBlock(), crop.getReturnStage()); return; } } //has next stage else if (MainConfig.enableBoneMeal && itemInHand != null && itemInHand.getType() == Material.BONE_MEAL) { - if (!AntiGrief.testPlace(player, seedLoc)) return; + if (!CCAntiGrief.testPlace(player, seedLoc)) return; if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); if (Math.random() < MainConfig.boneMealChance) { seedLoc.getWorld().spawnParticle(MainConfig.boneMealSuccess, seedLoc.clone().add(0.5,0.5, 0.5),3,0.2,0.2,0.2); @@ -202,39 +208,39 @@ public class OraxenWireHandler extends OraxenHandler{ final Location location = event.getBlock().getLocation(); if (!id.equals(BasicItemConfig.dryPot) && !id.equals(BasicItemConfig.wetPot)) return; - if (!canProceedAction(player, location)) return; + if (!CCAntiGrief.testBreak(player, location)) return; - if (!AntiGrief.testBreak(player, location)) { - event.setCancelled(true); - return; - } - - super.onBreakPot(location); - Location seedLocation = location.clone().add(0,1,0); - String blockID = customInterface.getBlockID(seedLocation); - if (blockID == null) return; - if (blockID.contains("_stage_")) { - customInterface.removeBlock(seedLocation); - if (blockID.equals(BasicItemConfig.deadCrop)) return; - if (!isRipe(blockID)) { - StringBlockMechanic mechanic = (StringBlockMechanic) FurnitureFactory.instance.getMechanic(blockID); - if (mechanic == null) return; - Drop drop = mechanic.getDrop(); - if (drop != null && player.getGameMode() != GameMode.CREATIVE) { - drop.spawns(seedLocation, new ItemStack(Material.AIR)); + label_out: { + Location seedLocation = location.clone().add(0,1,0); + String blockID = customInterface.getBlockID(seedLocation); + if (blockID == null) break label_out; + if (blockID.contains("_stage_")) { + if (blockID.equals(BasicItemConfig.deadCrop)) { + customInterface.removeBlock(seedLocation); + break label_out; + } + if (!isRipe(blockID)) { + StringBlockMechanic mechanic = (StringBlockMechanic) FurnitureFactory.instance.getMechanic(blockID); + if (mechanic == null) break label_out; + Drop drop = mechanic.getDrop(); + if (drop != null && player.getGameMode() != GameMode.CREATIVE) { + drop.spawns(seedLocation, new ItemStack(Material.AIR)); + } + customInterface.removeBlock(seedLocation); + super.onBreakUnripeCrop(seedLocation); + } + else { + Crop crop = customInterface.getCropFromID(id); + if (crop == null) break label_out; + if (!checkHarvestRequirements(player, seedLocation, crop)) { + event.setCancelled(true); + return; + } + customInterface.removeBlock(seedLocation); + super.onBreakRipeCrop(seedLocation, crop, player, false); } - super.onBreakUnripeCrop(seedLocation); - } - else { - super.onBreakRipeCrop(seedLocation, blockID, player, false); } } - } - - private void onInteractRipeCrop(Location location, String id, Player player) { - Crop crop = customInterface.getCropFromID(id); - if (crop == null) return; - if (super.onInteractRipeCrop(location, crop, player)) return; - if (crop.getReturnStage() != null) StringBlockMechanicFactory.setBlockModel(location.getBlock(), crop.getReturnStage()); + super.onBreakPot(location); } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/BentoBoxHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/BentoBoxHook.java index 48795a2..5fc842a 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/BentoBoxHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/BentoBoxHook.java @@ -17,7 +17,7 @@ package net.momirealms.customcrops.integrations.protection; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.Location; import org.bukkit.entity.Player; import world.bentobox.bentobox.BentoBox; @@ -27,7 +27,12 @@ import world.bentobox.bentobox.lists.Flags; import java.util.Optional; -public class BentoBoxHook implements AntiGrief { +public class BentoBoxHook implements CCAntiGrief { + + @Override + public String getName() { + return "BentoBox"; + } @Override public boolean canBreak(Location location, Player player) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/CrashClaimHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/CrashClaimHook.java index 4f5d1ac..5e41144 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/CrashClaimHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/CrashClaimHook.java @@ -19,11 +19,16 @@ package net.momirealms.customcrops.integrations.protection; import net.crashcraft.crashclaim.api.CrashClaimAPI; import net.crashcraft.crashclaim.permissions.PermissionRoute; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.Location; import org.bukkit.entity.Player; -public class CrashClaimHook implements AntiGrief { +public class CrashClaimHook implements CCAntiGrief { + + @Override + public String getName() { + return "CrashClaim"; + } @Override public boolean canBreak(Location location, Player player) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/GriefDefenderHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/GriefDefenderHook.java index 8ea5a5e..0886e6f 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/GriefDefenderHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/GriefDefenderHook.java @@ -17,11 +17,16 @@ package net.momirealms.customcrops.integrations.protection; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.Location; import org.bukkit.entity.Player; -public class GriefDefenderHook implements AntiGrief { +public class GriefDefenderHook implements CCAntiGrief { + + @Override + public String getName() { + return "GriefDefender"; + } @Override public boolean canBreak(Location location, Player player) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/GriefPreventionHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/GriefPreventionHook.java index 3ad8b33..2977432 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/GriefPreventionHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/GriefPreventionHook.java @@ -17,11 +17,16 @@ package net.momirealms.customcrops.integrations.protection; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.Location; import org.bukkit.entity.Player; -public class GriefPreventionHook implements AntiGrief { +public class GriefPreventionHook implements CCAntiGrief { + + @Override + public String getName() { + return "GriefPrevention"; + } @Override public boolean canBreak(Location location, Player player) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/IridiumSkyblockHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/IridiumSkyblockHook.java index 5f378ae..f69d8b7 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/IridiumSkyblockHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/IridiumSkyblockHook.java @@ -21,13 +21,18 @@ import com.iridium.iridiumskyblock.PermissionType; import com.iridium.iridiumskyblock.api.IridiumSkyblockAPI; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.Location; import org.bukkit.entity.Player; import java.util.Optional; -public class IridiumSkyblockHook implements AntiGrief { +public class IridiumSkyblockHook implements CCAntiGrief { + + @Override + public String getName() { + return "IridiumSkyblock"; + } private final IridiumSkyblockAPI api; diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/KingdomsXHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/KingdomsXHook.java index f4a7d62..0ad1c27 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/KingdomsXHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/KingdomsXHook.java @@ -17,14 +17,19 @@ package net.momirealms.customcrops.integrations.protection; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.Location; import org.bukkit.entity.Player; import org.kingdoms.constants.group.Kingdom; import org.kingdoms.constants.land.Land; import org.kingdoms.constants.player.KingdomPlayer; -public class KingdomsXHook implements AntiGrief { +public class KingdomsXHook implements CCAntiGrief { + + @Override + public String getName() { + return "KingdomsX"; + } @Override public boolean canBreak(Location location, Player player) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/LandsHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/LandsHook.java index 3403d08..9a8b48d 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/LandsHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/LandsHook.java @@ -18,19 +18,19 @@ package net.momirealms.customcrops.integrations.protection; import me.angeschossen.lands.api.LandsIntegration; -import me.angeschossen.lands.api.flags.Flags; -import me.angeschossen.lands.api.flags.enums.FlagTarget; -import me.angeschossen.lands.api.flags.enums.RoleFlagCategory; import me.angeschossen.lands.api.flags.types.RoleFlag; -import me.angeschossen.lands.api.land.Area; import me.angeschossen.lands.api.land.LandWorld; import net.momirealms.customcrops.CustomCrops; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.entity.Player; -public class LandsHook implements AntiGrief { +public class LandsHook implements CCAntiGrief { + + @Override + public String getName() { + return "Lands"; + } private final LandsIntegration api; diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/PlotSquaredHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/PlotSquaredHook.java index 85ed525..398e873 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/PlotSquaredHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/PlotSquaredHook.java @@ -18,10 +18,15 @@ package net.momirealms.customcrops.integrations.protection; import com.plotsquared.core.location.Location; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.entity.Player; -public class PlotSquaredHook implements AntiGrief { +public class PlotSquaredHook implements CCAntiGrief { + + @Override + public String getName() { + return "PlotSquared"; + } @Override public boolean canBreak(org.bukkit.Location location, Player player) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/ResidenceHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/ResidenceHook.java index 8f28520..556665e 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/ResidenceHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/ResidenceHook.java @@ -20,11 +20,16 @@ package net.momirealms.customcrops.integrations.protection; import com.bekvon.bukkit.residence.containers.Flags; import com.bekvon.bukkit.residence.protection.ClaimedResidence; import com.bekvon.bukkit.residence.protection.ResidencePermissions; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.Location; import org.bukkit.entity.Player; -public class ResidenceHook implements AntiGrief { +public class ResidenceHook implements CCAntiGrief { + + @Override + public String getName() { + return "Residence"; + } @Override public boolean canBreak(Location location, Player player) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/TownyHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/TownyHook.java index c82d0b1..22b1845 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/TownyHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/TownyHook.java @@ -19,11 +19,16 @@ package net.momirealms.customcrops.integrations.protection; import com.palmergames.bukkit.towny.object.TownyPermission; import com.palmergames.bukkit.towny.utils.PlayerCacheUtil; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.Location; import org.bukkit.entity.Player; -public class TownyHook implements AntiGrief { +public class TownyHook implements CCAntiGrief { + + @Override + public String getName() { + return "Towny"; + } @Override public boolean canBreak(Location location, Player player) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/WorldGuardHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/WorldGuardHook.java index f869b74..260836f 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/WorldGuardHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/WorldGuardHook.java @@ -29,11 +29,16 @@ import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.RegionQuery; -import net.momirealms.customcrops.integrations.AntiGrief; +import net.momirealms.customcrops.integrations.CCAntiGrief; import org.bukkit.Location; import org.bukkit.entity.Player; -public class WorldGuardHook implements AntiGrief { +public class WorldGuardHook implements CCAntiGrief { + + @Override + public String getName() { + return "WorldGuard"; + } public static StateFlag HARVEST_FLAG; public static StateFlag PLACE_FLAG; diff --git a/src/main/java/net/momirealms/customcrops/integrations/season/InternalSeason.java b/src/main/java/net/momirealms/customcrops/integrations/season/InternalSeason.java index 117850f..306baab 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/season/InternalSeason.java +++ b/src/main/java/net/momirealms/customcrops/integrations/season/InternalSeason.java @@ -61,7 +61,7 @@ public class InternalSeason extends Function implements SeasonInterface { public boolean isWrongSeason(World world, @Nullable CCSeason[] seasonList) { if (seasonList == null) return false; for (CCSeason season : seasonList) { - if (season == seasonHashMap.get(world)) { + if (season == getSeason(world)) { return false; } } diff --git a/src/main/java/net/momirealms/customcrops/managers/CustomWorld.java b/src/main/java/net/momirealms/customcrops/managers/CustomWorld.java index 6c526c9..04e805a 100644 --- a/src/main/java/net/momirealms/customcrops/managers/CustomWorld.java +++ b/src/main/java/net/momirealms/customcrops/managers/CustomWorld.java @@ -484,7 +484,7 @@ public class CustomWorld { @Override public void run() { for (Player player : sprinklerLoc.getNearbyPlayers(48)) { - cropManager.getArmorStandUtil().playWaterAnimation(player, sprinklerLoc.clone().add(0.5, 0.3, 0.5)); + cropManager.getArmorStandUtil().playWaterAnimation(player, sprinklerLoc.clone().add(0.5, MainConfig.animationYOffset, 0.5)); } } }.runTask(CustomCrops.plugin); diff --git a/src/main/java/net/momirealms/customcrops/managers/timer/CrowTask.java b/src/main/java/net/momirealms/customcrops/managers/timer/CrowTask.java index 2d01686..f75c104 100644 --- a/src/main/java/net/momirealms/customcrops/managers/timer/CrowTask.java +++ b/src/main/java/net/momirealms/customcrops/managers/timer/CrowTask.java @@ -25,7 +25,6 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import java.lang.reflect.InvocationTargetException; import java.util.Random; public class CrowTask extends BukkitRunnable { diff --git a/src/main/java/net/momirealms/customcrops/objects/CCCrop.java b/src/main/java/net/momirealms/customcrops/objects/CCCrop.java index d03ea14..15f85f2 100644 --- a/src/main/java/net/momirealms/customcrops/objects/CCCrop.java +++ b/src/main/java/net/momirealms/customcrops/objects/CCCrop.java @@ -25,7 +25,8 @@ import net.momirealms.customcrops.objects.requirements.RequirementInterface; public class CCCrop implements Crop { private CCSeason[] seasons; - private RequirementInterface[] requirementInterfaces; + private RequirementInterface[] plantRequirements; + private RequirementInterface[] harvestRequirements; private String returnStage; private QualityLoot qualityLoot; private GiganticCrop giganticCrop; @@ -56,8 +57,8 @@ public class CCCrop implements Crop { return seasons; } - public RequirementInterface[] getRequirements() { - return requirementInterfaces; + public RequirementInterface[] getPlantRequirements() { + return plantRequirements; } public String getReturnStage() { @@ -80,8 +81,8 @@ public class CCCrop implements Crop { this.seasons = seasons; } - public void setRequirements(RequirementInterface[] requirementInterfaces) { - this.requirementInterfaces = requirementInterfaces; + public void setPlantRequirements(RequirementInterface[] requirementInterfaces) { + this.plantRequirements = requirementInterfaces; } public void setReturnStage(String returnStage) { @@ -111,4 +112,12 @@ public class CCCrop implements Crop { public int getMax_stage() { return max_stage; } + + public RequirementInterface[] getHarvestRequirements() { + return harvestRequirements; + } + + public void setHarvestRequirements(RequirementInterface[] harvestRequirements) { + this.harvestRequirements = harvestRequirements; + } } diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/CustomPapi.java b/src/main/java/net/momirealms/customcrops/objects/requirements/CustomPapi.java index 9b42ac2..4386ddc 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/CustomPapi.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/CustomPapi.java @@ -73,9 +73,9 @@ public class CustomPapi implements RequirementInterface { } @Override - public boolean isConditionMet(PlantingCondition plantingCondition) { - if (!papiRequirement.isMet(plantingCondition.getPapiMap(), plantingCondition.getPlayer())) { - if (msg != null) AdventureUtil.playerMessage(plantingCondition.getPlayer(), msg); + public boolean isConditionMet(PlayerCondition playerCondition) { + if (!papiRequirement.isMet(playerCondition.getPapiMap(), playerCondition.getPlayer())) { + if (msg != null) AdventureUtil.playerMessage(playerCondition.getPlayer(), msg); return false; } return true; diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/PlantingCondition.java b/src/main/java/net/momirealms/customcrops/objects/requirements/PlayerCondition.java similarity index 94% rename from src/main/java/net/momirealms/customcrops/objects/requirements/PlantingCondition.java rename to src/main/java/net/momirealms/customcrops/objects/requirements/PlayerCondition.java index ce0f299..74ed6a4 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/PlantingCondition.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/PlayerCondition.java @@ -25,13 +25,13 @@ import org.jetbrains.annotations.Nullable; import java.util.HashMap; -public class PlantingCondition { +public class PlayerCondition { private final Location location; private final Player player; private HashMap papiMap; - public PlantingCondition(Location location, Player player) { + public PlayerCondition(Location location, Player player) { this.location = location; this.player = player; if (CustomCrops.plugin.hasPapi()){ diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementBiome.java b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementBiome.java index 550e480..98a49cc 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementBiome.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementBiome.java @@ -24,12 +24,12 @@ public class RequirementBiome extends Requirement implements RequirementInterfac } @Override - public boolean isConditionMet(PlantingCondition plantingCondition) { - String currentBiome = plantingCondition.getLocation().getBlock().getBiome().getKey().toString(); + public boolean isConditionMet(PlayerCondition playerCondition) { + String currentBiome = playerCondition.getLocation().getBlock().getBiome().getKey().toString(); if (mode) { for (String value : values) { if (!(currentBiome.equalsIgnoreCase(value))) { - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } @@ -41,7 +41,7 @@ public class RequirementBiome extends Requirement implements RequirementInterfac return true; } } - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementInterface.java b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementInterface.java index 4156d0c..4783f8d 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementInterface.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementInterface.java @@ -18,5 +18,5 @@ package net.momirealms.customcrops.objects.requirements; public interface RequirementInterface { - boolean isConditionMet(PlantingCondition plantingCondition); + boolean isConditionMet(PlayerCondition playerCondition); } diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementPermission.java b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementPermission.java index 51eb1ac..e8df939 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementPermission.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementPermission.java @@ -24,11 +24,11 @@ public class RequirementPermission extends Requirement implements RequirementInt } @Override - public boolean isConditionMet(PlantingCondition plantingCondition) { + public boolean isConditionMet(PlayerCondition playerCondition) { if (mode) { for (String value : values) { - if (!(plantingCondition.getPlayer().hasPermission(value))) { - notMetMessage(plantingCondition.getPlayer()); + if (!(playerCondition.getPlayer().hasPermission(value))) { + notMetMessage(playerCondition.getPlayer()); return false; } } @@ -36,11 +36,11 @@ public class RequirementPermission extends Requirement implements RequirementInt } else { for (String value : values) { - if (plantingCondition.getPlayer().hasPermission(value)) { + if (playerCondition.getPlayer().hasPermission(value)) { return true; } } - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementTime.java b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementTime.java index 84af59b..050c87e 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementTime.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementTime.java @@ -28,13 +28,13 @@ public class RequirementTime extends Requirement implements RequirementInterface } @Override - public boolean isConditionMet(PlantingCondition plantingCondition) { - long time = plantingCondition.getLocation().getWorld().getTime(); + public boolean isConditionMet(PlayerCondition playerCondition) { + long time = playerCondition.getLocation().getWorld().getTime(); if (mode) { for (String value : values) { String[] timeMinMax = StringUtils.split(value, "~"); if (!(time > Long.parseLong(timeMinMax[0]) && time < Long.parseLong(timeMinMax[1]))) { - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } @@ -47,7 +47,7 @@ public class RequirementTime extends Requirement implements RequirementInterface return true; } } - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementWeather.java b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementWeather.java index 952bf95..434a2d9 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementWeather.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementWeather.java @@ -28,8 +28,8 @@ public class RequirementWeather extends Requirement implements RequirementInterf } @Override - public boolean isConditionMet(PlantingCondition plantingCondition) { - World world = plantingCondition.getLocation().getWorld(); + public boolean isConditionMet(PlayerCondition playerCondition) { + World world = playerCondition.getLocation().getWorld(); String weather; if (world.isThundering()) weather = "thunder"; else if (world.isClearWeather()) weather = "clear"; @@ -37,7 +37,7 @@ public class RequirementWeather extends Requirement implements RequirementInterf if (mode) { for (String value : values) { if (!value.equalsIgnoreCase(weather)) { - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } @@ -49,7 +49,7 @@ public class RequirementWeather extends Requirement implements RequirementInterf return true; } } - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementWorld.java b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementWorld.java index 65bac3a..7d02047 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementWorld.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementWorld.java @@ -27,12 +27,12 @@ public class RequirementWorld extends Requirement implements RequirementInterfac } @Override - public boolean isConditionMet(PlantingCondition plantingCondition) { - String worldName = plantingCondition.getLocation().getWorld().getName(); + public boolean isConditionMet(PlayerCondition playerCondition) { + String worldName = playerCondition.getLocation().getWorld().getName(); if (mode) { for (String value : values) { if (!value.equals(worldName)) { - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } @@ -44,7 +44,7 @@ public class RequirementWorld extends Requirement implements RequirementInterfac return true; } } - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementYPos.java b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementYPos.java index 78cb3a2..09417df 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementYPos.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/RequirementYPos.java @@ -28,13 +28,13 @@ public class RequirementYPos extends Requirement implements RequirementInterface } @Override - public boolean isConditionMet(PlantingCondition plantingCondition) { - int y = plantingCondition.getLocation().getBlockY(); + public boolean isConditionMet(PlayerCondition playerCondition) { + int y = playerCondition.getLocation().getBlockY(); if (mode) { for (String value : values) { String[] yMinMax = StringUtils.split(value, "~"); if (!(y > Long.parseLong(yMinMax[0]) && y < Long.parseLong(yMinMax[1]))) { - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } @@ -47,7 +47,7 @@ public class RequirementYPos extends Requirement implements RequirementInterface return true; } } - notMetMessage(plantingCondition.getPlayer()); + notMetMessage(playerCondition.getPlayer()); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/utils/ArmorStandUtil.java b/src/main/java/net/momirealms/customcrops/utils/ArmorStandUtil.java index 138bdeb..f8f8df6 100644 --- a/src/main/java/net/momirealms/customcrops/utils/ArmorStandUtil.java +++ b/src/main/java/net/momirealms/customcrops/utils/ArmorStandUtil.java @@ -34,7 +34,6 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.lang.reflect.InvocationTargetException; import java.util.*; public class ArmorStandUtil { @@ -90,7 +89,7 @@ public class ArmorStandUtil { public PacketContainer getMetaPacket(int id) { PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); metaPacket.getIntegers().write(0, id); - if (CustomCrops.version.equals("v1_19_R2")) { + if (CustomCrops.plugin.getVersionHelper().isVersionNewerThan1_19_R2()) { WrappedDataWatcher wrappedDataWatcher = createDataWatcher(); List wrappedDataValueList = Lists.newArrayList(); wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> { diff --git a/src/main/java/net/momirealms/customcrops/utils/HologramUtil.java b/src/main/java/net/momirealms/customcrops/utils/HologramUtil.java index 63544a5..643104d 100644 --- a/src/main/java/net/momirealms/customcrops/utils/HologramUtil.java +++ b/src/main/java/net/momirealms/customcrops/utils/HologramUtil.java @@ -68,7 +68,7 @@ public class HologramUtil { wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), mask2); metaPacket.getModifier().write(0,id); - if (CustomCrops.version.equals("v1_19_R2")) { + if (CustomCrops.plugin.getVersionHelper().isVersionNewerThan1_19_R2()) { List wrappedDataValueList = Lists.newArrayList(); wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> { final WrappedDataWatcher.WrappedDataWatcherObject dataWatcherObject = entry.getWatcherObject(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4de9413..a6049da 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,6 +1,6 @@ # Don't change # 请不要修改 -config-version: '21' +config-version: '22' metrics: true # lang: english / spanish / chinese lang: english @@ -58,9 +58,6 @@ optimization: # Disable the water particles when using watering-cans # 关闭水粒子效果 disable-water-particles: false - # Disable the animation when sprinkler works - # 关闭洒水器动画 - disable-sprinkler-animation: false # Auto back up the data when a world is unloaded # 自动备份 auto-back-up: true @@ -119,6 +116,11 @@ mechanics: # 农作物是否只在白名单世界掉落农产品 drop-loots-in-all-worlds: false + # Water splash animation when sprinkler works + sprinkler-animation: + enable: true + y-offset: 0.4 + fill: watering-can-to-sprinkler: 1 water-bucket-to-sprinkler: 3 @@ -262,8 +264,6 @@ hologram: empty: '뀁뀄' right: '뀁뀅' - - actionbar: # Should actionbar be sent when using watering-can enable: true @@ -322,8 +322,4 @@ watering-can-lore: other-settings: # 3 days = 1 hour # Save the cache to file - data-save-interval: 3 - # PreAction events. - # It's useful if your anti grief plugin is not supported - # You can listen to PreActionEvent and cancel all the CustomCrops related events - enable-additional-events: false \ No newline at end of file + data-save-interval: 3 \ No newline at end of file diff --git a/src/main/resources/crops_itemsadder.yml b/src/main/resources/crops_itemsadder.yml index 00dbce8..7f9b35b 100644 --- a/src/main/resources/crops_itemsadder.yml +++ b/src/main/resources/crops_itemsadder.yml @@ -45,7 +45,7 @@ tomato: season: - Spring - requirements: + plant-requirements: condition_1: # Condition System: type: permission @@ -55,6 +55,14 @@ tomato: - crops.plant.tomato # The message to be shown when player doesn't fit the requirement message: 'You don''t have permission to plant this seed!' + harvest-requirements: + condition_1: + type: permission + mode: '&&' + value: + - crops.harvest.tomato + message: 'You don''t have permission to harvest tomato!' + grape: max-stage: 6 diff --git a/src/main/resources/crops_oraxen.yml b/src/main/resources/crops_oraxen.yml index 7d3c577..b5f82f0 100644 --- a/src/main/resources/crops_oraxen.yml +++ b/src/main/resources/crops_oraxen.yml @@ -43,7 +43,7 @@ tomato: season: - Spring - requirements: + plant-requirements: condition_1: # Condition System: type: permission @@ -53,6 +53,13 @@ tomato: - crops.plant.tomato # The message to be shown when player doesn't fit the requirement message: 'You don''t have permission to plant this seed!' + harvest-requirements: + condition_1: + type: permission + mode: '&&' + value: + - crops.harvest.tomato + message: 'You don''t have permission to harvest tomato!' grape: max-stage: 6