diff --git a/src/main/java/net/momirealms/customcrops/CustomCrops.java b/src/main/java/net/momirealms/customcrops/CustomCrops.java index b86cfcc..07935b9 100644 --- a/src/main/java/net/momirealms/customcrops/CustomCrops.java +++ b/src/main/java/net/momirealms/customcrops/CustomCrops.java @@ -26,15 +26,16 @@ import net.momirealms.customcrops.api.customplugin.PlatformInterface; import net.momirealms.customcrops.api.customplugin.PlatformManager; import net.momirealms.customcrops.api.customplugin.itemsadder.ItemsAdderPluginImpl; import net.momirealms.customcrops.api.customplugin.oraxen.OraxenPluginImpl; +import net.momirealms.customcrops.api.object.HologramManager; import net.momirealms.customcrops.api.object.basic.ConfigManager; import net.momirealms.customcrops.api.object.basic.MessageManager; import net.momirealms.customcrops.api.object.crop.CropManager; -import net.momirealms.customcrops.api.object.pot.PotManager; import net.momirealms.customcrops.api.object.fertilizer.FertilizerManager; +import net.momirealms.customcrops.api.object.pot.PotManager; +import net.momirealms.customcrops.api.object.schedule.Scheduler; import net.momirealms.customcrops.api.object.season.SeasonManager; import net.momirealms.customcrops.api.object.sprinkler.SprinklerManager; import net.momirealms.customcrops.api.object.wateringcan.WateringCanManager; -import net.momirealms.customcrops.api.object.world.CCWorld; import net.momirealms.customcrops.api.object.world.WorldDataManager; import net.momirealms.customcrops.api.util.AdventureUtils; import net.momirealms.customcrops.command.CustomCropsCommand; @@ -68,8 +69,10 @@ public final class CustomCrops extends JavaPlugin { private ConfigManager configManager; private MessageManager messageManager; private PlatformManager platformManager; + private HologramManager hologramManager; private VersionHelper versionHelper; private CustomCropsAPI customCropsAPI; + private Scheduler scheduler; @Override public void onLoad(){ @@ -85,6 +88,7 @@ public final class CustomCrops extends JavaPlugin { this.registerCommands(); this.loadPlatform(); + this.scheduler = new Scheduler(this); this.configManager = new ConfigManager(this); this.messageManager = new MessageManager(this); this.versionHelper = new VersionHelper(this); @@ -96,6 +100,7 @@ public final class CustomCrops extends JavaPlugin { this.wateringCanManager = new WateringCanManager(this); this.fertilizerManager = new FertilizerManager(this); this.potManager = new PotManager(this); + this.hologramManager = new HologramManager(this); this.platformManager = new PlatformManager(this); this.customCropsAPI = new CustomCropsAPI(this); @@ -122,6 +127,7 @@ public final class CustomCrops extends JavaPlugin { this.potManager.unload(); this.seasonManager.unload(); this.platformManager.unload(); + this.hologramManager.unload(); this.configManager.load(); this.messageManager.load(); @@ -134,6 +140,7 @@ public final class CustomCrops extends JavaPlugin { this.potManager.load(); this.seasonManager.load(); this.platformManager.load(); + this.hologramManager.load(); } @Override @@ -150,6 +157,8 @@ public final class CustomCrops extends JavaPlugin { if (this.messageManager != null) this.messageManager.unload(); if (this.configManager != null) this.configManager.unload(); if (this.integrationManager != null) this.integrationManager.unload(); + if (this.hologramManager != null) this.hologramManager.unload(); + if (this.scheduler != null) this.scheduler.disable(); } private void loadLibs() { @@ -256,7 +265,15 @@ public final class CustomCrops extends JavaPlugin { return platformManager; } + public HologramManager getHologramManager() { + return hologramManager; + } + public CustomCropsAPI getAPI() { return customCropsAPI; } + + public Scheduler getScheduler() { + return scheduler; + } } diff --git a/src/main/java/net/momirealms/customcrops/api/CustomCropsAPI.java b/src/main/java/net/momirealms/customcrops/api/CustomCropsAPI.java index d05e736..a767156 100644 --- a/src/main/java/net/momirealms/customcrops/api/CustomCropsAPI.java +++ b/src/main/java/net/momirealms/customcrops/api/CustomCropsAPI.java @@ -1,9 +1,26 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.customplugin.PlatformInterface; -import net.momirealms.customcrops.api.object.crop.CropConfig; import net.momirealms.customcrops.api.object.ItemMode; +import net.momirealms.customcrops.api.object.crop.CropConfig; import net.momirealms.customcrops.api.object.pot.Pot; import net.momirealms.customcrops.api.object.season.CCSeason; import net.momirealms.customcrops.api.object.world.SimpleLocation; diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/Handler.java b/src/main/java/net/momirealms/customcrops/api/customplugin/Handler.java index 83dbc76..05740bb 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/Handler.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/Handler.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.customplugin; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/Platform.java b/src/main/java/net/momirealms/customcrops/api/customplugin/Platform.java index 44b3fe9..9a45a4c 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/Platform.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/Platform.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.customplugin; public enum Platform { diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformInterface.java b/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformInterface.java index 4c4541a..200bffe 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformInterface.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformInterface.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.customplugin; import net.momirealms.customcrops.CustomCrops; @@ -40,14 +57,28 @@ public interface PlatformInterface { void dropBlockLoot(Block block); - boolean removeItemDisplay(Location location); - void placeChorus(Location location, String id); Location getItemFrameLocation(Location location); - @Nullable - String getCustomItemAt(Location location); + @NotNull + default String getAnyItemIDAt(Location location) { + String block = getBlockID(location.getBlock()); + if (!block.equals("AIR")) return block; + + String item_frame_id = getItemFrameIDAt(location); + if (item_frame_id != null) { + return item_frame_id; + } + + if (CustomCrops.getInstance().getVersionHelper().isVersionNewerThan1_19_R3()) { + String item_display_id = getItemDisplayIDAt(location); + if (item_display_id != null) { + return item_display_id; + } + } + return "AIR"; + } default void removeCustomItemAt(Location location) { removeCustomBlock(location); @@ -55,16 +86,35 @@ public interface PlatformInterface { } @NotNull - String getItemID(@NotNull ItemStack itemStack); + String getItemStackID(@NotNull ItemStack itemStack); + + @Nullable + default String getItemDisplayIDAt(Location location) { + ItemDisplay itemDisplay = getItemDisplayAt(location); + if (itemDisplay == null) return null; + return getItemDisplayID(itemDisplay); + } + + @Nullable + default String getItemFrameIDAt(Location location) { + ItemFrame itemFrame = getItemFrameAt(location); + if (itemFrame == null) return null; + return getItemFrameID(itemFrame); + } + + @Nullable + String getItemDisplayID(ItemDisplay itemDisplay); + + @Nullable + String getItemFrameID(ItemFrame itemFrame); @Nullable default ItemFrame getItemFrameAt(Location location) { - Collection itemFrames = getItemFrameLocation(location).getNearbyEntitiesByType(ItemFrame.class, 0, 0, 0); + Collection itemFrames = getItemFrameLocation(location).getNearbyEntitiesByType(ItemFrame.class, 0.5, 0.5, 0.5); int i = itemFrames.size(); int j = 1; for (ItemFrame itemFrame : itemFrames) { if (j != i) { - // To prevent item frames stack in one block itemFrame.remove(); j++; } @@ -73,6 +123,21 @@ public interface PlatformInterface { return null; } + @Nullable + default ItemDisplay getItemDisplayAt(Location location) { + Collection itemDisplays = getItemFrameLocation(location).getNearbyEntitiesByType(ItemDisplay.class, 0.5, 0.5, 0.5); + int i = itemDisplays.size(); + int j = 1; + for (ItemDisplay itemDisplay : itemDisplays) { + if (j != i) { + itemDisplay.remove(); + j++; + } + else return itemDisplay; + } + return null; + } + default boolean removeItemFrame(Location location) { ItemFrame itemFrame = getItemFrameAt(location); if (itemFrame != null) { @@ -82,6 +147,15 @@ public interface PlatformInterface { return false; } + default boolean removeItemDisplay(Location location) { + ItemDisplay itemDisplay = getItemDisplayAt(location); + if (itemDisplay != null) { + itemDisplay.remove(); + return true; + } + return false; + } + default boolean detectAnyThing(Location location) { Block block = location.getBlock(); if (block.getType() != Material.AIR) return true; diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformManager.java b/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformManager.java index d999933..54b53ec 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformManager.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformManager.java @@ -1,14 +1,31 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.customplugin; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.CustomCropsAPI; import net.momirealms.customcrops.api.customplugin.itemsadder.ItemsAdderHandler; import net.momirealms.customcrops.api.customplugin.oraxen.OraxenHandler; +import net.momirealms.customcrops.api.event.*; import net.momirealms.customcrops.api.object.BoneMeal; import net.momirealms.customcrops.api.object.Function; import net.momirealms.customcrops.api.object.InteractWithItem; import net.momirealms.customcrops.api.object.ItemType; -import net.momirealms.customcrops.api.object.fill.PassiveFillMethod; import net.momirealms.customcrops.api.object.action.Action; import net.momirealms.customcrops.api.object.basic.ConfigManager; import net.momirealms.customcrops.api.object.basic.MessageManager; @@ -17,6 +34,7 @@ import net.momirealms.customcrops.api.object.crop.GrowingCrop; import net.momirealms.customcrops.api.object.crop.StageConfig; import net.momirealms.customcrops.api.object.fertilizer.Fertilizer; import net.momirealms.customcrops.api.object.fertilizer.FertilizerConfig; +import net.momirealms.customcrops.api.object.fill.PassiveFillMethod; import net.momirealms.customcrops.api.object.fill.PositiveFillMethod; import net.momirealms.customcrops.api.object.pot.Pot; import net.momirealms.customcrops.api.object.pot.PotConfig; @@ -26,10 +44,10 @@ import net.momirealms.customcrops.api.object.sprinkler.SprinklerConfig; import net.momirealms.customcrops.api.object.wateringcan.WateringCanConfig; import net.momirealms.customcrops.api.object.world.SimpleLocation; import net.momirealms.customcrops.api.util.AdventureUtils; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Particle; -import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -115,10 +133,10 @@ public class PlatformManager extends Function { @NotNull public ItemType onInteractAir(Player player) { ItemStack item_in_hand = player.getInventory().getItemInMainHand(); - String id = plugin.getPlatformInterface().getItemID(item_in_hand); + String id = plugin.getPlatformInterface().getItemStackID(item_in_hand); if (onInteractWithWateringCan(player, id, item_in_hand)) { - return ItemType.WATERINGCAN; + return ItemType.WATERING_CAN; } return ItemType.UNKNOWN; @@ -171,7 +189,7 @@ public class PlatformManager extends Function { @NotNull ItemType onInteractSomething(Player player, Location location, String id, Cancellable event) { ItemStack item_in_hand = player.getInventory().getItemInMainHand(); - String item_in_hand_id = plugin.getPlatformInterface().getItemID(item_in_hand); + String item_in_hand_id = plugin.getPlatformInterface().getItemStackID(item_in_hand); if (onInteractWithSprinkler(player, location, item_in_hand, item_in_hand_id)) { return ItemType.SPRINKLER; @@ -190,7 +208,7 @@ public class PlatformManager extends Function { } if (onInteractWithWateringCan(player, item_in_hand_id, item_in_hand)) { - return ItemType.WATERINGCAN; + return ItemType.WATERING_CAN; } return ItemType.UNKNOWN; @@ -250,8 +268,15 @@ public class PlatformManager extends Function { PassiveFillMethod[] passiveFillMethods = sprinklerConfig.getPassiveFillMethods(); for (PassiveFillMethod passiveFillMethod : passiveFillMethods) { if (passiveFillMethod.isRightItem(item_in_hand_id)) { + + SprinklerFillEvent sprinklerFillEvent = new SprinklerFillEvent(player, item_in_hand, passiveFillMethod.getAmount(), location); + Bukkit.getPluginManager().callEvent(sprinklerFillEvent); + if (sprinklerFillEvent.isCancelled()) { + return true; + } + doPassiveFillAction(player, item_in_hand, passiveFillMethod, location.clone().add(0,0.2,0)); - plugin.getWorldDataManager().addWaterToSprinkler(SimpleLocation.getByBukkitLocation(location), passiveFillMethod.getAmount(), sprinklerConfig.getRange(), sprinklerConfig.getStorage()); + plugin.getWorldDataManager().addWaterToSprinkler(SimpleLocation.getByBukkitLocation(location), sprinklerFillEvent.getWater(), sprinklerConfig.getRange(), sprinklerConfig.getStorage()); return true; } } @@ -272,7 +297,11 @@ public class PlatformManager extends Function { int current_water = plugin.getWateringCanManager().getCurrentWater(item_in_hand); if (current_water <= 0) return true; - //TODO API Events + SprinklerFillEvent sprinklerFillEvent = new SprinklerFillEvent(player, item_in_hand, 1, location); + Bukkit.getPluginManager().callEvent(sprinklerFillEvent); + if (sprinklerFillEvent.isCancelled()) { + return true; + } current_water--; if (wateringCanConfig.hasActionBar()) { @@ -364,17 +393,16 @@ public class PlatformManager extends Function { int current_water = plugin.getWateringCanManager().getCurrentWater(item_in_hand); if (current_water <= 0) return true; - //TODO API Events + Location pot_loc = location.clone().subtract(0,1,0); + PotWaterEvent potWaterEvent = new PotWaterEvent(player, item_in_hand, 1, pot_loc); + Bukkit.getPluginManager().callEvent(potWaterEvent); + if (potWaterEvent.isCancelled()) { + return true; + } current_water--; - this.waterPot(wateringCanConfig.getWidth(), wateringCanConfig.getLength(), location.clone().subtract(0,1,0), player.getLocation().getYaw(), potData.getPotKey(), wateringCanConfig.getParticle()); - if (wateringCanConfig.hasActionBar()) { - AdventureUtils.playerActionbar(player, wateringCanConfig.getActionBarMsg(current_water)); - } - if (wateringCanConfig.getSound() != null) { - AdventureUtils.playerSound(player, wateringCanConfig.getSound()); - } - plugin.getWateringCanManager().setWater(item_in_hand, current_water, wateringCanConfig); + this.waterPot(wateringCanConfig.getWidth(), wateringCanConfig.getLength(), pot_loc, player.getLocation().getYaw(), potData.getPotKey(), wateringCanConfig.getParticle(), potWaterEvent.getWater()); + this.doWateringCanActions(player, item_in_hand, wateringCanConfig, current_water); return true; } @@ -437,125 +465,182 @@ public class PlatformManager extends Function { return false; } - // water - PassiveFillMethod[] passiveFillMethods = potConfig.getPassiveFillMethods(); - for (PassiveFillMethod passiveFillMethod : passiveFillMethods) { - if (passiveFillMethod.isRightItem(item_in_hand_id)) { - doPassiveFillAction(player, item_in_hand, passiveFillMethod, location); - plugin.getWorldDataManager().addWaterToPot(SimpleLocation.getByBukkitLocation(location), passiveFillMethod.getAmount(), pot_id); - return true; - } + PotInteractEvent potInteractEvent = new PotInteractEvent(player, item_in_hand, location, potConfig); + Bukkit.getPluginManager().callEvent(potInteractEvent); + if (potInteractEvent.isCancelled()) { + return true; } - CropConfig cropConfig = plugin.getCropManager().getCropConfigBySeed(item_in_hand_id); - if (cropConfig != null) { - String[] pot_whitelist = cropConfig.getBottom_blocks(); - outer: { - for (String bottom_block : pot_whitelist) { - if (bottom_block.equals(pot_id)) { - break outer; + outer: { + // plant + CropConfig cropConfig = plugin.getCropManager().getCropConfigBySeed(item_in_hand_id); + if (cropConfig != null) { + String[] pot_whitelist = cropConfig.getPotWhitelist(); + inner: { + for (String bottom_block : pot_whitelist) { + if (bottom_block.equals(pot_id)) { + break inner; + } + } + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.unsuitablePot); + return true; + } + + Location crop_loc = location.clone().add(0,1,0); + Requirement[] requirements = cropConfig.getPlantRequirements(); + if (requirements != null) { + CurrentState currentState = new CurrentState(crop_loc, player); + for (Requirement requirement : requirements) { + if (!requirement.isConditionMet(currentState)) { + return true; + } } } - AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.unsuitablePot); + + if (plugin.getPlatformInterface().detectAnyThing(crop_loc)) return true; + if (ConfigManager.enableLimitation && plugin.getWorldDataManager().getChunkCropAmount(SimpleLocation.getByBukkitLocation(crop_loc)) >= ConfigManager.maxCropPerChunk) { + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.reachChunkLimit); + return true; + } + + String crop_model = Objects.requireNonNull(cropConfig.getStageConfig(0)).getModel(); + CropPlantEvent cropPlantEvent = new CropPlantEvent(player, item_in_hand, location, cropConfig.getKey(), 0, crop_model); + Bukkit.getPluginManager().callEvent(cropPlantEvent); + if (cropPlantEvent.isCancelled()) { + return true; + } + + Action[] plantActions = cropConfig.getPlantActions(); + if (plantActions != null) { + for (Action action : plantActions) { + action.doOn(player, SimpleLocation.getByBukkitLocation(crop_loc), cropConfig.getCropMode()); + } + } + + if (player.getGameMode() != GameMode.CREATIVE) item_in_hand.setAmount(item_in_hand.getAmount() - 1); + player.swingMainHand(); + CustomCropsAPI.getInstance().placeCustomItem(crop_loc, cropPlantEvent.getCropModel(), cropConfig.getCropMode()); + plugin.getWorldDataManager().addCropData(SimpleLocation.getByBukkitLocation(crop_loc), new GrowingCrop(cropConfig.getKey(), cropPlantEvent.getPoint())); return true; } - Location crop_loc = location.clone().add(0,1,0); - Requirement[] requirements = cropConfig.getPlantRequirements(); - if (requirements != null) { - CurrentState currentState = new CurrentState(crop_loc, player); - for (Requirement requirement : requirements) { - if (!requirement.isConditionMet(currentState)) { + // water + PassiveFillMethod[] passiveFillMethods = potConfig.getPassiveFillMethods(); + for (PassiveFillMethod passiveFillMethod : passiveFillMethods) { + if (passiveFillMethod.isRightItem(item_in_hand_id)) { + + PotWaterEvent potWaterEvent = new PotWaterEvent(player, item_in_hand, passiveFillMethod.getAmount(), location); + Bukkit.getPluginManager().callEvent(potWaterEvent); + if (potWaterEvent.isCancelled()) { + return true; + } + + doPassiveFillAction(player, item_in_hand, passiveFillMethod, location); + plugin.getWorldDataManager().addWaterToPot(SimpleLocation.getByBukkitLocation(location), potWaterEvent.getWater(), pot_id); + break outer; + } + } + + // use watering can + WateringCanConfig wateringCanConfig = plugin.getWateringCanManager().getConfigByItemID(item_in_hand_id); + if (wateringCanConfig != null) { + String[] pot_whitelist = wateringCanConfig.getPotWhitelist(); + if (pot_whitelist != null) { + inner: { + for (String pot : pot_whitelist) { + if (pot.equals(pot_id)) { + break inner; + } + } return true; } } - } - if (plugin.getPlatformInterface().detectAnyThing(crop_loc)) return true; - if (ConfigManager.enableLimitation && plugin.getWorldDataManager().getChunkCropAmount(SimpleLocation.getByBukkitLocation(crop_loc)) >= ConfigManager.maxCropPerChunk) { - AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.reachChunkLimit); - return true; - } + int current_water = plugin.getWateringCanManager().getCurrentWater(item_in_hand); + if (current_water <= 0) return true; - if (player.getGameMode() != GameMode.CREATIVE) item_in_hand.setAmount(item_in_hand.getAmount() - 1); - player.swingMainHand(); - CustomCropsAPI.getInstance().placeCustomItem(crop_loc, Objects.requireNonNull(cropConfig.getStageConfig(0)).getModel(), cropConfig.getCropMode()); - plugin.getWorldDataManager().addCropData(SimpleLocation.getByBukkitLocation(crop_loc), new GrowingCrop(cropConfig.getKey(), 0)); - return true; - } - - // use fertilizer - FertilizerConfig fertilizerConfig = plugin.getFertilizerManager().getConfigByItemID(item_in_hand_id); - if (fertilizerConfig != null) { - if (fertilizerConfig.isBeforePlant() && plugin.getCropManager().containsStage(plugin.getPlatformInterface().getCustomItemAt(location.clone().add(0,1,0)))) { - AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.beforePlant); - return true; - } - if (player.getGameMode() != GameMode.CREATIVE) item_in_hand.setAmount(item_in_hand.getAmount() - 1); - player.swingMainHand(); - if (fertilizerConfig.getSound() != null) { - AdventureUtils.playerSound(player, fertilizerConfig.getSound()); - } - if (fertilizerConfig.getParticle() != null) { - location.getWorld().spawnParticle(fertilizerConfig.getParticle(), location.clone().add(0.5,1.1,0.5), 5,0.25,0.1,0.25, 0); - } - plugin.getWorldDataManager().addFertilizerToPot(SimpleLocation.getByBukkitLocation(location), new Fertilizer(fertilizerConfig), pot_id); - return true; - } - - // use watering can - WateringCanConfig wateringCanConfig = plugin.getWateringCanManager().getConfigByItemID(item_in_hand_id); - if (wateringCanConfig != null) { - String[] pot_whitelist = wateringCanConfig.getPotWhitelist(); - if (pot_whitelist != null) { - outer: { - for (String pot : pot_whitelist) { - if (pot.equals(pot_id)) { - break outer; - } - } + PotWaterEvent potWaterEvent = new PotWaterEvent(player, item_in_hand, 1, location); + Bukkit.getPluginManager().callEvent(potWaterEvent); + if (potWaterEvent.isCancelled()) { return true; } + + current_water--; + this.waterPot(wateringCanConfig.getWidth(), wateringCanConfig.getLength(), location, player.getLocation().getYaw(), pot_id, wateringCanConfig.getParticle(), potWaterEvent.getWater()); + this.doWateringCanActions(player, item_in_hand, wateringCanConfig, current_water); + break outer; } - int current_water = plugin.getWateringCanManager().getCurrentWater(item_in_hand); - if (current_water <= 0) return true; + // use fertilizer + FertilizerConfig fertilizerConfig = plugin.getFertilizerManager().getConfigByItemID(item_in_hand_id); + if (fertilizerConfig != null) { - //TODO API Events + FertilizerUseEvent fertilizerUseEvent = new FertilizerUseEvent(player, item_in_hand, fertilizerConfig, location); + Bukkit.getPluginManager().callEvent(fertilizerUseEvent); + if (fertilizerUseEvent.isCancelled()) { + return true; + } - current_water--; - this.waterPot(wateringCanConfig.getWidth(), wateringCanConfig.getLength(), location, player.getLocation().getYaw(), pot_id, wateringCanConfig.getParticle()); + if (fertilizerConfig.isBeforePlant() && plugin.getCropManager().containsStage(plugin.getPlatformInterface().getAnyItemIDAt(location.clone().add(0,1,0)))) { + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.beforePlant); + return true; + } - if (wateringCanConfig.hasActionBar()) { - AdventureUtils.playerActionbar(player, wateringCanConfig.getActionBarMsg(current_water)); - } - if (wateringCanConfig.getSound() != null) { - AdventureUtils.playerSound(player, wateringCanConfig.getSound()); + if (player.getGameMode() != GameMode.CREATIVE) item_in_hand.setAmount(item_in_hand.getAmount() - 1); + player.swingMainHand(); + + if (fertilizerConfig.getSound() != null) { + AdventureUtils.playerSound(player, fertilizerConfig.getSound()); + } + if (fertilizerConfig.getParticle() != null) { + location.getWorld().spawnParticle(fertilizerConfig.getParticle(), location.clone().add(0.5,1.1,0.5), 5,0.25,0.1,0.25, 0); + } + plugin.getWorldDataManager().addFertilizerToPot(SimpleLocation.getByBukkitLocation(location), new Fertilizer(fertilizerConfig), pot_id); + break outer; } + } - plugin.getWateringCanManager().setWater(item_in_hand, current_water, wateringCanConfig); - return true; + Pot potData = plugin.getWorldDataManager().getPotData(SimpleLocation.getByBukkitLocation(location)); + GrowingCrop growingCrop = plugin.getWorldDataManager().getCropData(SimpleLocation.getByBukkitLocation(location)); + PotInfoEvent potInfoEvent = new PotInfoEvent(player, location, item_in_hand, potConfig, potData == null ? null : potData.getFertilizer(), potData == null ? 0 : potData.getWater(), growingCrop); + Bukkit.getPluginManager().callEvent(potInfoEvent); + + if (potConfig.isHologramEnabled() && potData != null) { + double offset = 0; + StageConfig stageConfig = plugin.getCropManager().getStageConfig(plugin.getPlatformInterface().getAnyItemIDAt(location.clone().add(0,1,0))); + if (stageConfig != null) { + offset = stageConfig.getOffsetCorrection(); + } + potConfig.getPotHologram().show(player, potData, location.clone().add(0.5,0,0.5), offset); } return true; } + private void doWateringCanActions(Player player, ItemStack item_in_hand, WateringCanConfig wateringCanConfig, int current_water) { + if (wateringCanConfig.hasActionBar()) { + AdventureUtils.playerActionbar(player, wateringCanConfig.getActionBarMsg(current_water)); + } + if (wateringCanConfig.getSound() != null) { + AdventureUtils.playerSound(player, wateringCanConfig.getSound()); + } + plugin.getWateringCanManager().setWater(item_in_hand, current_water, wateringCanConfig); + } + public boolean onBreakPot(Player player, String id, Location location, Cancellable event) { if (!plugin.getPotManager().containsPotBlock(id)) { return false; } Location above_loc = location.clone().add(0,1,0); - String above_id = plugin.getPlatformInterface().getCustomItemAt(above_loc); + String above_id = plugin.getPlatformInterface().getAnyItemIDAt(above_loc); // has item above - if (above_id != null) { - // is a crop - if (onBreakCrop(player, above_id, above_loc, event)) { - // The event might be cancelled if the player doesn't meet the break requirements - if (event.isCancelled()) { - return true; - } - plugin.getPlatformInterface().removeCustomItemAt(above_loc); + // is a crop + if (onBreakCrop(player, above_id, above_loc, event)) { + // The event might be cancelled if the player doesn't meet the break requirements + if (event.isCancelled()) { + return true; } + plugin.getPlatformInterface().removeCustomItemAt(above_loc); } plugin.getWorldDataManager().removePotData(SimpleLocation.getByBukkitLocation(location)); @@ -612,7 +697,7 @@ public class PlatformManager extends Function { return true; } - private void waterPot(int width, int length, Location location, float yaw, String id, @Nullable Particle particle){ + private void waterPot(int width, int length, Location location, float yaw, String id, @Nullable Particle particle, int water){ int extend = width / 2; if (yaw < 45 && yaw > -135) { if (yaw > -45) { @@ -620,7 +705,7 @@ public class PlatformManager extends Function { Location tempLoc = location.clone().add(i, 0, -1); for (int j = 0; j < length; j++){ tempLoc.add(0,0,1); - tryToWaterPot(tempLoc, id, particle); + tryToWaterPot(tempLoc, id, particle, water); } } } @@ -629,7 +714,7 @@ public class PlatformManager extends Function { Location tempLoc = location.clone().add(-1, 0, i); for (int j = 0; j < length; j++){ tempLoc.add(1,0,0); - tryToWaterPot(tempLoc, id, particle); + tryToWaterPot(tempLoc, id, particle, water); } } } @@ -640,7 +725,7 @@ public class PlatformManager extends Function { Location tempLoc = location.clone().add(1, 0, i); for (int j = 0; j < length; j++){ tempLoc.subtract(1,0,0); - tryToWaterPot(tempLoc, id, particle); + tryToWaterPot(tempLoc, id, particle, water); } } } @@ -649,18 +734,18 @@ public class PlatformManager extends Function { Location tempLoc = location.clone().add(i, 0, 1); for (int j = 0; j < length; j++){ tempLoc.subtract(0,0,1); - tryToWaterPot(tempLoc, id, particle); + tryToWaterPot(tempLoc, id, particle, water); } } } } } - private void tryToWaterPot(Location location, String pot_id, @Nullable Particle particle) { + private void tryToWaterPot(Location location, String pot_id, @Nullable Particle particle, int water) { String blockID = plugin.getPlatformInterface().getBlockID(location.getBlock()); String current_id = plugin.getPotManager().getPotKeyByBlockID(blockID); if (current_id != null && current_id.equals(pot_id)) { - plugin.getWorldDataManager().addWaterToPot(SimpleLocation.getByBukkitLocation(location), 1, pot_id); + plugin.getWorldDataManager().addWaterToPot(SimpleLocation.getByBukkitLocation(location), water, pot_id); if (particle != null) location.getWorld().spawnParticle(particle, location.clone().add(0.5,1, 0.5),3,0.1,0.1,0.1); } diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderHandler.java b/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderHandler.java index 98f22ba..c5ed2a3 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderHandler.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderHandler.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.customplugin.itemsadder; import dev.lone.itemsadder.api.Events.*; diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderPluginImpl.java b/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderPluginImpl.java index 437e1b5..460bdce 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderPluginImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderPluginImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.customplugin.itemsadder; import de.tr7zw.changeme.nbtapi.NBTCompound; @@ -89,12 +106,6 @@ public class ItemsAdderPluginImpl implements PlatformInterface { } } - @Override - public boolean removeItemDisplay(Location location) { - //TODO Not implemented - return false; - } - @Override public void placeChorus(Location location, String id) { CustomBlock.place(id, location); @@ -105,25 +116,9 @@ public class ItemsAdderPluginImpl implements PlatformInterface { return location.clone().add(0.5, 0.5, 0.5); } - @Nullable - @Override - public String getCustomItemAt(Location location) { - String block = getBlockID(location.getBlock()); - if (!block.equals("AIR")) return block; - - ItemFrame itemFrame = getItemFrameAt(location); - if (itemFrame != null) { - CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(itemFrame); - if (customFurniture != null) { - return customFurniture.getNamespacedID(); - } - } - return null; - } - @NotNull @Override - public String getItemID(@NotNull ItemStack itemStack) { + public String getItemStackID(@NotNull ItemStack itemStack) { if (itemStack.getType() != Material.AIR) { NBTItem nbtItem = new NBTItem(itemStack); NBTCompound nbtCompound = nbtItem.getCompound("itemsadder"); @@ -131,4 +126,19 @@ public class ItemsAdderPluginImpl implements PlatformInterface { } return itemStack.getType().name(); } + + @Nullable + @Override + public String getItemDisplayID(ItemDisplay itemDisplay) { + //TODO Not implemented + return null; + } + + @Nullable + @Override + public String getItemFrameID(ItemFrame itemFrame) { + CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(itemFrame); + if (customFurniture == null) return null; + return customFurniture.getNamespacedID(); + } } diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenHandler.java b/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenHandler.java index 28b2490..484073e 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenHandler.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenHandler.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.customplugin.oraxen; import io.th0rgal.oraxen.api.events.*; diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenPluginImpl.java b/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenPluginImpl.java index f309743..113d756 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenPluginImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenPluginImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.customplugin.oraxen; import de.tr7zw.changeme.nbtapi.NBTCompound; @@ -15,6 +32,7 @@ import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanic import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanicFactory; import io.th0rgal.oraxen.utils.drops.Drop; import net.momirealms.customcrops.api.customplugin.PlatformInterface; +import net.momirealms.customcrops.api.util.AdventureUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Rotation; @@ -52,26 +70,36 @@ public class OraxenPluginImpl implements PlatformInterface { @Override public ItemFrame placeItemFrame(Location location, String id) { FurnitureMechanic mechanic = (FurnitureMechanic) FurnitureFactory.getInstance().getMechanic(id); + if (mechanic == null) { + AdventureUtils.consoleMessage("[CustomCrops] Item Frame not exists: " + id); + return null; + } Entity entity = mechanic.place(location, 0, Rotation.NONE, BlockFace.UP); if (entity instanceof ItemFrame itemFrame) return itemFrame; else { + AdventureUtils.consoleMessage("[CustomCrops] Item Frame not exists: " + id); entity.remove(); + return null; } - return null; } @Nullable @Override public ItemDisplay placeItemDisplay(Location location, String id) { FurnitureMechanic mechanic = (FurnitureMechanic) FurnitureFactory.getInstance().getMechanic(id); + if (mechanic == null) { + AdventureUtils.consoleMessage("[CustomCrops] Item Display not exists: " + id); + return null; + } Entity entity = mechanic.place(location); if (entity instanceof ItemDisplay itemDisplay) return itemDisplay; else { + AdventureUtils.consoleMessage("[CustomCrops] Item Display not exists: " + id); entity.remove(); + return null; } - return null; } @Override @@ -105,42 +133,40 @@ public class OraxenPluginImpl implements PlatformInterface { drop.spawns(block.getLocation(), new ItemStack(Material.AIR)); } - @Override - public boolean removeItemDisplay(Location location) { - //TODO Not implemented - return false; - } - @Override public void placeChorus(Location location, String id) { - //TODO Not implemented + //TODO Not implemented, so use tripwire instead + StringBlockMechanicFactory.setBlockModel(location.getBlock(), id); } @Override public Location getItemFrameLocation(Location location) { - return location.clone().add(0.5,0.03125,0.5); + return location.clone().add(0.5,0.5,0.5); } @Nullable @Override - public String getCustomItemAt(Location location) { - String block = getBlockID(location.getBlock()); - if (!block.equals("AIR")) return block; - - ItemFrame itemFrame = getItemFrameAt(location); - if (itemFrame != null) { - FurnitureMechanic furnitureMechanic = OraxenFurniture.getFurnitureMechanic(itemFrame); - if (furnitureMechanic != null) { - return furnitureMechanic.getItemID(); - } + public String getItemDisplayID(ItemDisplay itemDisplay) { + FurnitureMechanic furnitureMechanic = OraxenFurniture.getFurnitureMechanic(itemDisplay); + if (furnitureMechanic != null) { + return furnitureMechanic.getItemID(); } + return null; + } + @Nullable + @Override + public String getItemFrameID(ItemFrame itemFrame) { + FurnitureMechanic furnitureMechanic = OraxenFurniture.getFurnitureMechanic(itemFrame); + if (furnitureMechanic != null) { + return furnitureMechanic.getItemID(); + } return null; } @NotNull @Override - public String getItemID(@NotNull ItemStack itemStack) { + public String getItemStackID(@NotNull ItemStack itemStack) { if (itemStack.getType() != Material.AIR) { NBTItem nbtItem = new NBTItem(itemStack); NBTCompound bukkitPublic = nbtItem.getCompound("PublicBukkitValues"); diff --git a/src/main/java/net/momirealms/customcrops/api/event/CropPlantEvent.java b/src/main/java/net/momirealms/customcrops/api/event/CropPlantEvent.java new file mode 100644 index 0000000..52e8ddd --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/event/CropPlantEvent.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +public class CropPlantEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final ItemStack hand; + private final String crop; + private final Location location; + private int point; + private String crop_model; + + public CropPlantEvent(@NotNull Player who, ItemStack hand, Location location, String crop, int point, String crop_model) { + super(who); + this.hand = hand; + this.location = location; + this.crop = crop; + this.point = point; + this.crop_model = crop_model; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + public ItemStack getHand() { + return hand; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + + public String getCrop() { + return crop; + } + + public Location getLocation() { + return location; + } + + public int getPoint() { + return point; + } + + public void setPoint(int point) { + this.point = point; + } + + /** + * Get the crop stage model key + * @return crop model + */ + public String getCropModel() { + return crop_model; + } + + public void setCropModel(String crop_model) { + this.crop_model = crop_model; + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/event/FertilizerUseEvent.java b/src/main/java/net/momirealms/customcrops/api/event/FertilizerUseEvent.java new file mode 100644 index 0000000..0d040f5 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/event/FertilizerUseEvent.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.event; + +import net.momirealms.customcrops.api.object.fertilizer.FertilizerConfig; +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.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +public class FertilizerUseEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final ItemStack hand; + private final FertilizerConfig fertilizerConfig; + private final Location location; + + public FertilizerUseEvent(@NotNull Player who, ItemStack hand, FertilizerConfig fertilizerConfig, Location location) { + super(who); + this.hand = hand; + this.fertilizerConfig = fertilizerConfig; + this.location = location; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + public ItemStack getHand() { + return hand; + } + + public FertilizerConfig getFertilizerConfig() { + return fertilizerConfig; + } + + public Location getLocation() { + return location; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/event/PotInfoEvent.java b/src/main/java/net/momirealms/customcrops/api/event/PotInfoEvent.java new file mode 100644 index 0000000..0ee75cb --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/event/PotInfoEvent.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.event; + +import net.momirealms.customcrops.api.object.crop.GrowingCrop; +import net.momirealms.customcrops.api.object.fertilizer.Fertilizer; +import net.momirealms.customcrops.api.object.pot.PotConfig; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class PotInfoEvent extends PlayerEvent { + + private static final HandlerList handlers = new HandlerList(); + private final PotConfig potConfig; + private final Fertilizer fertilizer; + private final int water; + private final GrowingCrop growingCrop; + private final ItemStack hand; + private final Location location; + + public PotInfoEvent(@NotNull Player who, Location location, ItemStack hand, PotConfig potConfig, @Nullable Fertilizer fertilizer, int water, GrowingCrop growingCrop) { + super(who); + this.potConfig = potConfig; + this.fertilizer = fertilizer; + this.water = water; + this.growingCrop = growingCrop; + this.hand = hand; + this.location = location; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + + public PotConfig getPotConfig() { + return potConfig; + } + + @Nullable + public Fertilizer getFertilizer() { + return fertilizer; + } + + public int getWater() { + return water; + } + + @Nullable + public GrowingCrop getGrowingCrop() { + return growingCrop; + } + + public ItemStack getHand() { + return hand; + } + + public Location getLocation() { + return location; + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/event/PotInteractEvent.java b/src/main/java/net/momirealms/customcrops/api/event/PotInteractEvent.java new file mode 100644 index 0000000..ad4f61b --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/event/PotInteractEvent.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.event; + +import net.momirealms.customcrops.api.object.pot.PotConfig; +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.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +public class PotInteractEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final ItemStack hand; + private final Location location; + private final PotConfig potConfig; + + public PotInteractEvent(@NotNull Player who, ItemStack hand, Location location, PotConfig potConfig) { + super(who); + this.hand = hand; + this.location = location; + this.potConfig = potConfig; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + + public ItemStack getHand() { + return hand; + } + + public Location getLocation() { + return location; + } + + public PotConfig getPotConfig() { + return potConfig; + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/event/PotWaterEvent.java b/src/main/java/net/momirealms/customcrops/api/event/PotWaterEvent.java new file mode 100644 index 0000000..3a10828 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/event/PotWaterEvent.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +public class PotWaterEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final ItemStack hand; + private int water; + private final Location location; + + public PotWaterEvent(@NotNull Player who, ItemStack hand, int water, Location location) { + super(who); + this.hand = hand; + this.water = water; + this.location = location; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + + public Location getLocation() { + return location; + } + + public ItemStack getHand() { + return hand; + } + + /** + * Get the amount of water + * @return the amount of water that adds to the pot + */ + public int getWater() { + return water; + } + + public void setWater(int water) { + this.water = water; + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/event/SprinklerFillEvent.java b/src/main/java/net/momirealms/customcrops/api/event/SprinklerFillEvent.java new file mode 100644 index 0000000..ad1f5e9 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/event/SprinklerFillEvent.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +public class SprinklerFillEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final ItemStack hand; + private int water; + private final Location location; + + public SprinklerFillEvent(@NotNull Player who, ItemStack hand, int water, Location location) { + super(who); + this.hand = hand; + this.water = water; + this.location = location; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + + public ItemStack getHand() { + return hand; + } + + public Location getLocation() { + return location; + } + + /** + * Get the amount of water + * @return the amount of water that adds to the sprinkler + */ + public int getWater() { + return water; + } + + public void setWater(int water) { + this.water = water; + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/event/WaterPotEvent.java b/src/main/java/net/momirealms/customcrops/api/event/WaterPotEvent.java deleted file mode 100644 index 3046400..0000000 --- a/src/main/java/net/momirealms/customcrops/api/event/WaterPotEvent.java +++ /dev/null @@ -1,4 +0,0 @@ -package net.momirealms.customcrops.api.event; - -public class WaterPotEvent { -} diff --git a/src/main/java/net/momirealms/customcrops/api/object/BoneMeal.java b/src/main/java/net/momirealms/customcrops/api/object/BoneMeal.java index 4a6e9e1..9526995 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/BoneMeal.java +++ b/src/main/java/net/momirealms/customcrops/api/object/BoneMeal.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object; import net.kyori.adventure.sound.Sound; diff --git a/src/main/java/net/momirealms/customcrops/api/object/CrowTask.java b/src/main/java/net/momirealms/customcrops/api/object/CrowTask.java index 3b1e298..bc99018 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/CrowTask.java +++ b/src/main/java/net/momirealms/customcrops/api/object/CrowTask.java @@ -17,18 +17,18 @@ package net.momirealms.customcrops.api.object; -import com.willfp.eco.core.items.Items; import net.momirealms.customcrops.CustomCrops; -import net.momirealms.customcrops.api.util.ArmorStandUtils; +import net.momirealms.customcrops.api.util.FakeEntityUtils; import org.bukkit.Location; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import java.util.Random; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ThreadLocalRandom; -public class CrowTask extends BukkitRunnable { +public class CrowTask implements Runnable { private int timer; private final int entityID; @@ -39,38 +39,43 @@ public class CrowTask extends BukkitRunnable { private final float yaw; private final ItemStack fly; private final ItemStack stand; + private ScheduledFuture scheduledFuture; public CrowTask(Player player, Location crop, String fly_model, String stand_model) { this.timer = 0; this.fly = CustomCrops.getInstance().getIntegrationManager().build(fly_model); this.stand = CustomCrops.getInstance().getIntegrationManager().build(stand_model); this.player = player; - this.entityID = new Random().nextInt(10000000); - this.yaw = new Random().nextInt(361) - 180; + this.entityID = ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE); + this.yaw = ThreadLocalRandom.current().nextInt(361) - 180; this.from = crop.clone().add(10 * Math.sin((Math.PI * yaw)/180), 10, - 10 * Math.cos((Math.PI * yaw)/180)); Location relative = crop.clone().subtract(from); this.vectorDown = new Vector(relative.getX() / 100, -0.1, relative.getZ() / 100); this.vectorUp = new Vector(relative.getX() / 100, 0.1, relative.getZ() / 100); - CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getSpawnPacket(entityID, from)); - CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getMetaPacket(entityID)); - CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getEquipPacket(entityID, fly)); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getSpawnPacket(entityID, from, EntityType.ARMOR_STAND)); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getMetaPacket(entityID)); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getEquipPacket(entityID, fly)); } @Override public void run() { timer++; if (timer < 100) { - CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getTeleportPacket(entityID, from.add(vectorDown), yaw)); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getTeleportPacket(entityID, from.add(vectorDown), yaw)); } else if (timer == 100){ - CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getEquipPacket(entityID, stand)); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getEquipPacket(entityID, stand)); } else if (timer == 150) { - CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getEquipPacket(entityID, fly)); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getEquipPacket(entityID, fly)); } else if (timer > 150) { - CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getTeleportPacket(entityID, from.add(vectorUp), yaw)); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getTeleportPacket(entityID, from.add(vectorUp), yaw)); } if (timer > 300) { - CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getDestroyPacket(entityID)); - cancel(); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getDestroyPacket(entityID)); + if (scheduledFuture != null) scheduledFuture.cancel(false); } } + + public void setScheduledFuture(ScheduledFuture scheduledFuture) { + this.scheduledFuture = scheduledFuture; + } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/api/object/Function.java b/src/main/java/net/momirealms/customcrops/api/object/Function.java index c3657f6..7d66af8 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/Function.java +++ b/src/main/java/net/momirealms/customcrops/api/object/Function.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object; public class Function { diff --git a/src/main/java/net/momirealms/customcrops/api/object/HologramManager.java b/src/main/java/net/momirealms/customcrops/api/object/HologramManager.java new file mode 100644 index 0000000..18eddf6 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/object/HologramManager.java @@ -0,0 +1,157 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.object; + +import net.kyori.adventure.text.Component; +import net.momirealms.customcrops.CustomCrops; +import net.momirealms.customcrops.api.util.FakeEntityUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.ArrayList; +import java.util.Map; +import java.util.UUID; +import java.util.Vector; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ThreadLocalRandom; + +public class HologramManager extends Function implements Listener { + + private final ConcurrentHashMap hologramMap; + private final CustomCrops plugin; + private ScheduledFuture scheduledFuture; + + public HologramManager(CustomCrops plugin) { + this.plugin = plugin; + this.hologramMap = new ConcurrentHashMap<>(); + } + + @Override + public void load() { + Bukkit.getPluginManager().registerEvents(this, plugin); + scheduledFuture = plugin.getScheduler().runTaskTimerAsync(() -> { + ArrayList removed = new ArrayList<>(4); + long current = System.currentTimeMillis(); + for (Map.Entry entry : hologramMap.entrySet()) { + Player player = Bukkit.getPlayer(entry.getKey()); + if (player == null || !player.isOnline()) { + removed.add(entry.getKey()); + } else { + entry.getValue().removeOutDated(current, player); + } + } + for (UUID uuid : removed) { + hologramMap.remove(uuid); + } + }, 500, 500); + } + + @Override + public void unload() { + HandlerList.unregisterAll(this); + for (Map.Entry entry : hologramMap.entrySet()) { + Player player = Bukkit.getPlayer(entry.getKey()); + if (player != null && player.isOnline()) { + entry.getValue().removeAll(player); + } + } + if (scheduledFuture != null) scheduledFuture.cancel(false); + this.hologramMap.clear(); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + this.hologramMap.remove(event.getPlayer().getUniqueId()); + } + + public void showHologram(Player player, Location location, Component component, int millis, Mode mode) { + HologramCache hologramCache = hologramMap.get(player.getUniqueId()); + if (hologramCache != null) { + hologramCache.showHologram(player, location, component, millis, mode); + } else { + hologramCache = new HologramCache(); + hologramCache.showHologram(player, location, component, millis, mode); + hologramMap.put(player.getUniqueId(), hologramCache); + } + } + + public enum Mode { + ARMOR_STAND, + TEXT_DISPLAY + } + + @SuppressWarnings("unchecked") + public static class HologramCache { + + private final Vector> tupleList; + private Tuple[] tuples; + + public HologramCache() { + this.tupleList = new Vector<>(); + this.tuples = new Tuple[0]; + } + + public int push(Location new_loc, int time) { + for (Tuple tuple : tuples) { + if (new_loc.equals(tuple.getLeft())) { + tuple.setRight(System.currentTimeMillis() + time); + return tuple.getMid(); + } + } + return 0; + } + + public void removeOutDated(long current, Player player) { + for (Tuple tuple : tuples) { + if (tuple.getRight() < current) { + tupleList.remove(tuple); + this.tuples = tupleList.toArray(new Tuple[0]); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getDestroyPacket(tuple.getMid())); + } + } + } + + public void showHologram(Player player, Location location, Component component, int millis, Mode mode) { + int entity_id = push(location, millis); + if (entity_id == 0) { + int random = ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE); + tupleList.add(Tuple.of(location, random, System.currentTimeMillis() + millis)); + this.tuples = tupleList.toArray(new Tuple[0]); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getSpawnPacket(random, location, EntityType.ARMOR_STAND)); + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getMetaPacket(random, component)); + } else { + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getMetaPacket(entity_id, component)); + } + } + + public void removeAll(Player player) { + for (Tuple tuple : tuples) { + CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getDestroyPacket(tuple.getMid())); + } + this.tupleList.clear(); + this.tuples = null; + } + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/object/InteractWithItem.java b/src/main/java/net/momirealms/customcrops/api/object/InteractWithItem.java index ca1f6b1..f9d9f15 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/InteractWithItem.java +++ b/src/main/java/net/momirealms/customcrops/api/object/InteractWithItem.java @@ -1,9 +1,24 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object; -import net.kyori.adventure.sound.Sound; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.action.Action; -import org.bukkit.Particle; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/momirealms/customcrops/api/object/ItemMode.java b/src/main/java/net/momirealms/customcrops/api/object/ItemMode.java index 41d5564..b8d9b1c 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/ItemMode.java +++ b/src/main/java/net/momirealms/customcrops/api/object/ItemMode.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object; public enum ItemMode { diff --git a/src/main/java/net/momirealms/customcrops/api/object/ItemType.java b/src/main/java/net/momirealms/customcrops/api/object/ItemType.java index 0913761..a0e1d65 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/ItemType.java +++ b/src/main/java/net/momirealms/customcrops/api/object/ItemType.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object; public enum ItemType { @@ -7,5 +24,6 @@ public enum ItemType { CROP, SPRINKLER, SCARECROW, - WATERINGCAN, UNKNOWN + WATERING_CAN, + UNKNOWN } diff --git a/src/main/java/net/momirealms/customcrops/api/object/Pair.java b/src/main/java/net/momirealms/customcrops/api/object/Pair.java index 67f2e72..4616c5f 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/Pair.java +++ b/src/main/java/net/momirealms/customcrops/api/object/Pair.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object; public record Pair(L left, R right) { diff --git a/src/main/java/net/momirealms/customcrops/api/object/Tuple.java b/src/main/java/net/momirealms/customcrops/api/object/Tuple.java new file mode 100644 index 0000000..f2b12a0 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/object/Tuple.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.object; + +public class Tuple { + + private L left; + private M mid; + private R right; + + public Tuple(L left, M mid, R right) { + this.left = left; + this.mid = mid; + this.right = right; + } + + public static Tuple of(final L left, final M mid, final R right) { + return new Tuple<>(left, mid, right); + } + + public L getLeft() { + return left; + } + + public void setLeft(L left) { + this.left = left; + } + + public M getMid() { + return mid; + } + + public void setMid(M mid) { + this.mid = mid; + } + + public R getRight() { + return right; + } + + public void setRight(R right) { + this.right = right; + } +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/BreakImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/BreakImpl.java index 944abc1..71a4af4 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/BreakImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/BreakImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.action; import net.momirealms.customcrops.CustomCrops; @@ -5,7 +22,6 @@ import net.momirealms.customcrops.api.CustomCropsAPI; import net.momirealms.customcrops.api.object.ItemMode; import net.momirealms.customcrops.api.object.crop.StageConfig; import net.momirealms.customcrops.api.object.world.SimpleLocation; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; @@ -22,7 +38,7 @@ public class BreakImpl implements Action { @Override public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { if (crop_loc == null) return; - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { CustomCropsAPI.getInstance().removeCustomItem(crop_loc.getBukkitLocation(), itemMode); CustomCrops.getInstance().getWorldDataManager().removeCropData(crop_loc); return null; diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/ChainImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/ChainImpl.java index 8fddfcb..37cfd2b 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/ChainImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/ChainImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.action; import net.momirealms.customcrops.api.object.ItemMode; diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/DropItemImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/DropItemImpl.java index 2f5a545..ae1bd2c 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/DropItemImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/DropItemImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.action; import net.momirealms.customcrops.api.object.ItemMode; diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/JobXPImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/JobXPImpl.java index d574eb9..2fa7938 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/JobXPImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/JobXPImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.action; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/ParticleImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/ParticleImpl.java index f4d8dc9..72c812a 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/ParticleImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/ParticleImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.action; import net.momirealms.customcrops.api.object.ItemMode; diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/ReplantImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/ReplantImpl.java index a42c67a..2ae94f8 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/ReplantImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/ReplantImpl.java @@ -1,15 +1,31 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.action; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.CustomCropsAPI; +import net.momirealms.customcrops.api.object.ItemMode; import net.momirealms.customcrops.api.object.basic.ConfigManager; import net.momirealms.customcrops.api.object.basic.MessageManager; import net.momirealms.customcrops.api.object.crop.CropConfig; -import net.momirealms.customcrops.api.object.ItemMode; import net.momirealms.customcrops.api.object.crop.GrowingCrop; import net.momirealms.customcrops.api.object.world.SimpleLocation; import net.momirealms.customcrops.api.util.AdventureUtils; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; @@ -31,7 +47,7 @@ public class ReplantImpl implements Action { CropConfig cropConfig = CustomCrops.getInstance().getCropManager().getCropConfigByID(crop); if (crop_loc != null && cropConfig != null) { ItemMode newCMode = cropConfig.getCropMode(); - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { Location location = crop_loc.getBukkitLocation(); if (location == null) return null; if (ConfigManager.enableLimitation && CustomCrops.getInstance().getWorldDataManager().getChunkCropAmount(crop_loc) >= ConfigManager.maxCropPerChunk) { diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/VariationImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/VariationImpl.java index ff3f614..75d8ac0 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/VariationImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/VariationImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.action; import net.momirealms.customcrops.CustomCrops; @@ -7,7 +24,6 @@ import net.momirealms.customcrops.api.object.crop.VariationCrop; import net.momirealms.customcrops.api.object.fertilizer.Variation; import net.momirealms.customcrops.api.object.pot.Pot; import net.momirealms.customcrops.api.object.world.SimpleLocation; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -48,7 +64,7 @@ public record VariationImpl(VariationCrop[] variationCrops) implements Action { } private void doVariation(@NotNull SimpleLocation crop_loc, ItemMode itemMode, VariationCrop variationCrop) { - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { Location location = crop_loc.getBukkitLocation(); if (CustomCropsAPI.getInstance().removeCustomItem(location, itemMode)) { CustomCropsAPI.getInstance().placeCustomItem(location, variationCrop.getId(), variationCrop.getCropMode()); diff --git a/src/main/java/net/momirealms/customcrops/api/object/basic/ConfigManager.java b/src/main/java/net/momirealms/customcrops/api/object/basic/ConfigManager.java index 7a7bdca..7785613 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/basic/ConfigManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/basic/ConfigManager.java @@ -1,8 +1,24 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.basic; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.Function; -import net.momirealms.customcrops.api.util.AdventureUtils; import net.momirealms.customcrops.api.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/net/momirealms/customcrops/api/object/basic/MessageManager.java b/src/main/java/net/momirealms/customcrops/api/object/basic/MessageManager.java index ab205bf..df570e1 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/basic/MessageManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/basic/MessageManager.java @@ -1,6 +1,22 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.basic; -import com.gmail.nossr50.mcmmo.acf.ACFUtil; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.Function; import net.momirealms.customcrops.api.util.ConfigUtils; diff --git a/src/main/java/net/momirealms/customcrops/api/object/condition/AndCondition.java b/src/main/java/net/momirealms/customcrops/api/object/condition/AndCondition.java index 90e5ab3..9cbb49d 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/condition/AndCondition.java +++ b/src/main/java/net/momirealms/customcrops/api/object/condition/AndCondition.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.condition; import net.momirealms.customcrops.api.object.world.SimpleLocation; diff --git a/src/main/java/net/momirealms/customcrops/api/object/condition/Condition.java b/src/main/java/net/momirealms/customcrops/api/object/condition/Condition.java index b38ec0c..e9c21a1 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/condition/Condition.java +++ b/src/main/java/net/momirealms/customcrops/api/object/condition/Condition.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.condition; import net.momirealms.customcrops.api.object.world.SimpleLocation; @@ -5,4 +22,8 @@ import net.momirealms.customcrops.api.object.world.SimpleLocation; public interface Condition { boolean isMet(SimpleLocation simpleLocation); + + default int getDelay() { + return 0; + } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/condition/CrowAttack.java b/src/main/java/net/momirealms/customcrops/api/object/condition/CrowAttack.java index a090671..ba20ba4 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/condition/CrowAttack.java +++ b/src/main/java/net/momirealms/customcrops/api/object/condition/CrowAttack.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.condition; import net.momirealms.customcrops.CustomCrops; @@ -7,6 +24,8 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; +import java.util.concurrent.ScheduledFuture; + public class CrowAttack implements Condition { private final double chance; @@ -24,12 +43,19 @@ public class CrowAttack implements Condition { if (Math.random() > chance) return false; Location location = simpleLocation.getBukkitLocation(); if (location == null) return false; - Bukkit.getScheduler().runTask(CustomCrops.getInstance(), () -> { - for (Player player : location.getNearbyPlayers(48)) { + for (Player player : Bukkit.getOnlinePlayers()) { + SimpleLocation playerLoc = SimpleLocation.getByBukkitLocation(player.getLocation()); + if (playerLoc.isNear(simpleLocation, 48)) { CrowTask crowTask = new CrowTask(player, location.clone().add(0.4,0,0.4), fly_model, stand_model); - crowTask.runTaskTimerAsynchronously(CustomCrops.getInstance(), 1, 1); + ScheduledFuture scheduledFuture = CustomCrops.getInstance().getScheduler().runTaskTimerAsync(crowTask, 50, 50); + crowTask.setScheduledFuture(scheduledFuture); } - }); + } return true; } + + @Override + public int getDelay() { + return 7000; + } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/api/object/condition/DeathCondition.java b/src/main/java/net/momirealms/customcrops/api/object/condition/DeathCondition.java index 9a82488..a38ed0e 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/condition/DeathCondition.java +++ b/src/main/java/net/momirealms/customcrops/api/object/condition/DeathCondition.java @@ -1,10 +1,26 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.condition; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.CustomCropsAPI; import net.momirealms.customcrops.api.object.ItemMode; import net.momirealms.customcrops.api.object.world.SimpleLocation; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -19,19 +35,19 @@ public class DeathCondition { this.conditions = conditions; } - public boolean checkIfDead(SimpleLocation simpleLocation) { + public int checkIfDead(SimpleLocation simpleLocation) { for (Condition condition : conditions) { if (condition.isMet(simpleLocation)) { - return true; + return condition.getDelay(); } } - return false; + return -1; } public void applyDeadModel(SimpleLocation simpleLocation, ItemMode itemMode) { Location location = simpleLocation.getBukkitLocation(); if (location == null) return; - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { CustomCropsAPI.getInstance().removeCustomItem(location, itemMode); if (dead_model != null) { CustomCropsAPI.getInstance().placeCustomItem(location, dead_model, itemMode); diff --git a/src/main/java/net/momirealms/customcrops/api/object/condition/OrCondition.java b/src/main/java/net/momirealms/customcrops/api/object/condition/OrCondition.java index 3857820..6730454 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/condition/OrCondition.java +++ b/src/main/java/net/momirealms/customcrops/api/object/condition/OrCondition.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.condition; import net.momirealms.customcrops.api.object.world.SimpleLocation; diff --git a/src/main/java/net/momirealms/customcrops/api/object/condition/Random.java b/src/main/java/net/momirealms/customcrops/api/object/condition/Random.java index d9c5a90..81d05aa 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/condition/Random.java +++ b/src/main/java/net/momirealms/customcrops/api/object/condition/Random.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.condition; import net.momirealms.customcrops.api.object.world.SimpleLocation; diff --git a/src/main/java/net/momirealms/customcrops/api/object/condition/RightSeason.java b/src/main/java/net/momirealms/customcrops/api/object/condition/RightSeason.java index dcfb93f..61bee3a 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/condition/RightSeason.java +++ b/src/main/java/net/momirealms/customcrops/api/object/condition/RightSeason.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.condition; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/api/object/condition/WaterLessThan.java b/src/main/java/net/momirealms/customcrops/api/object/condition/WaterLessThan.java index 5b045d5..1154c8b 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/condition/WaterLessThan.java +++ b/src/main/java/net/momirealms/customcrops/api/object/condition/WaterLessThan.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.condition; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/api/object/condition/WaterMoreThan.java b/src/main/java/net/momirealms/customcrops/api/object/condition/WaterMoreThan.java index a57b5fc..67c6874 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/condition/WaterMoreThan.java +++ b/src/main/java/net/momirealms/customcrops/api/object/condition/WaterMoreThan.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.condition; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/api/object/condition/WrongSeason.java b/src/main/java/net/momirealms/customcrops/api/object/condition/WrongSeason.java index f27d9f8..10c62fc 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/condition/WrongSeason.java +++ b/src/main/java/net/momirealms/customcrops/api/object/condition/WrongSeason.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.condition; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/api/object/crop/CropConfig.java b/src/main/java/net/momirealms/customcrops/api/object/crop/CropConfig.java index ea00166..a2ef7b8 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/crop/CropConfig.java +++ b/src/main/java/net/momirealms/customcrops/api/object/crop/CropConfig.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.crop; import net.momirealms.customcrops.api.object.BoneMeal; @@ -13,7 +30,7 @@ import java.util.HashMap; public class CropConfig { - private String key; + private final String key; private final ItemMode itemMode; private final String[] bottom_blocks; private final int max_points; @@ -59,21 +76,17 @@ public class CropConfig { return itemMode; } - public int getMaxPoints() { - return max_points; - } - @Nullable public StageConfig getStageConfig(int stage) { return stageMap.get(stage); } @NotNull - public String[] getBottom_blocks() { + public String[] getPotWhitelist() { return bottom_blocks; } - public int getMax_points() { + public int getMaxPoints() { return max_points; } diff --git a/src/main/java/net/momirealms/customcrops/api/object/crop/CropManager.java b/src/main/java/net/momirealms/customcrops/api/object/crop/CropManager.java index d8e0d5a..733e656 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/crop/CropManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/crop/CropManager.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.crop; import net.momirealms.customcrops.CustomCrops; @@ -96,7 +113,8 @@ public class CropManager extends Function implements Listener { ConfigUtils.getActions(pointSec.getConfigurationSection(point + ".events.break"), stageModel), ConfigUtils.getActions(pointSec.getConfigurationSection(point + ".events.grow"), stageModel), ConfigUtils.getInteractActions(pointSec.getConfigurationSection(point + ".events.interact-with-item"), stageModel), - ConfigUtils.getActions(pointSec.getConfigurationSection(point + ".events.interact-by-hand"), stageModel) + ConfigUtils.getActions(pointSec.getConfigurationSection(point + ".events.interact-by-hand"), stageModel), + pointSec.getDouble(point + ".hologram-offset-correction", 0d) ); stageMap.put(parsed, stageConfig); if (stageModel != null) { @@ -165,7 +183,7 @@ public class CropManager extends Function implements Listener { public void onItemSpawn(ItemSpawnEvent event) { if (event.isCancelled()) return; Item item = event.getEntity(); - String id = plugin.getPlatformInterface().getItemID(item.getItemStack()); + String id = plugin.getPlatformInterface().getItemStackID(item.getItemStack()); if (containsStage(id)) { event.setCancelled(true); } diff --git a/src/main/java/net/momirealms/customcrops/api/object/crop/GrowingCrop.java b/src/main/java/net/momirealms/customcrops/api/object/crop/GrowingCrop.java index 0d8306a..f9a1396 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/crop/GrowingCrop.java +++ b/src/main/java/net/momirealms/customcrops/api/object/crop/GrowingCrop.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.crop; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/api/object/crop/StageConfig.java b/src/main/java/net/momirealms/customcrops/api/object/crop/StageConfig.java index 0456860..956103a 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/crop/StageConfig.java +++ b/src/main/java/net/momirealms/customcrops/api/object/crop/StageConfig.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.crop; import net.momirealms.customcrops.api.object.InteractWithItem; @@ -11,13 +28,15 @@ public class StageConfig { private final InteractWithItem[] interactActions; private final Action[] growActions; private final Action[] interactByHandActions; + private final double offsetCorrection; - public StageConfig(@Nullable String model, @Nullable Action[] breakActions, @Nullable Action[] growActions, @Nullable InteractWithItem[] interactActions, @Nullable Action[] interactByHandActions) { + public StageConfig(@Nullable String model, @Nullable Action[] breakActions, @Nullable Action[] growActions, @Nullable InteractWithItem[] interactActions, @Nullable Action[] interactByHandActions, double offsetCorrection) { this.breakActions = breakActions; this.interactActions = interactActions; this.growActions = growActions; this.interactByHandActions = interactByHandActions; this.model = model; + this.offsetCorrection = offsetCorrection; } @Nullable @@ -44,4 +63,8 @@ public class StageConfig { public String getModel() { return model; } + + public double getOffsetCorrection() { + return offsetCorrection; + } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/crop/VariationCrop.java b/src/main/java/net/momirealms/customcrops/api/object/crop/VariationCrop.java index b2e676e..039d99a 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/crop/VariationCrop.java +++ b/src/main/java/net/momirealms/customcrops/api/object/crop/VariationCrop.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.crop; import net.momirealms.customcrops.api.object.ItemMode; diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Fertilizer.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Fertilizer.java index e6ec858..5eb4a99 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Fertilizer.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Fertilizer.java @@ -1,7 +1,23 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fertilizer; import net.momirealms.customcrops.CustomCrops; -import org.jetbrains.annotations.Nullable; import java.io.Serializable; @@ -32,8 +48,11 @@ public class Fertilizer implements Serializable { return key; } - @Nullable public FertilizerConfig getConfig() { return CustomCrops.getInstance().getFertilizerManager().getConfigByFertilizer(this); } + + public int getLeftTimes() { + return times; + } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerConfig.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerConfig.java index 51bde95..1799ffe 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerConfig.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerConfig.java @@ -23,16 +23,17 @@ import org.jetbrains.annotations.Nullable; public abstract class FertilizerConfig { - protected int times; - protected double chance; - protected String key; - protected FertilizerType fertilizerType; - protected String[] pot_whitelist; - protected boolean beforePlant; - protected Particle particle; - protected Sound sound; + private final int times; + private final double chance; + private final String key; + private final FertilizerType fertilizerType; + private final String[] pot_whitelist; + private final boolean beforePlant; + private final Particle particle; + private final Sound sound; + private final String icon; - public FertilizerConfig(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) { + public FertilizerConfig(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, @Nullable String icon) { this.times = times; this.chance = chance; this.key = key; @@ -41,6 +42,7 @@ public abstract class FertilizerConfig { this.beforePlant = beforePlant; this.particle = particle; this.sound = sound; + this.icon = icon; } public int getTimes() { @@ -81,4 +83,8 @@ public abstract class FertilizerConfig { public Sound getSound() { return sound; } + + public String getIcon() { + return icon; + } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerManager.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerManager.java index 896cdb7..faa25bd 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerManager.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.key.Key; @@ -55,7 +72,7 @@ public class FertilizerManager extends Function { public FertilizerConfig getConfigByItemID(String id) { String key = itemToKey.get(id); if (key == null) return null; - return fertilizerConfigMap.get(id); + return getConfigByKey(key); } private void loadConfig() { @@ -83,16 +100,20 @@ public class FertilizerManager extends Function { Particle particle = fertilizerSec.contains("particle") ? Particle.valueOf(fertilizerSec.getString("particle")) : null; @Subst("namespace:key") String soundKey = fertilizerSec.getString("sound", "minecraft:item.hoe.till"); Sound sound = fertilizerSec.contains("sound") ? Sound.sound(Key.key(soundKey), Sound.Source.PLAYER, 1, 1) : null; + String icon = fertilizerSec.getString("icon"); switch (fertilizerType) { - case SPEED_GROW -> fertilizerConfig = new SpeedGrow(key, fertilizerType, times, getChancePair(fertilizerSec), pot_whitelist, beforePlant, particle, sound); - case YIELD_INCREASE -> fertilizerConfig = new YieldIncrease(key, fertilizerType, times, fertilizerSec.getDouble("chance"), getChancePair(fertilizerSec), pot_whitelist, beforePlant, particle, sound); - case VARIATION -> fertilizerConfig = new Variation(key, fertilizerType, times, fertilizerSec.getDouble("chance"), pot_whitelist, beforePlant, particle, sound); - case QUALITY -> fertilizerConfig = new Quality(key, fertilizerType, times, fertilizerSec.getDouble("chance"), ConfigUtils.getQualityRatio(fertilizerSec.getString("ratio", "2/2/1")), pot_whitelist, beforePlant, particle, sound); - case SOIL_RETAIN -> fertilizerConfig = new SoilRetain(key, fertilizerType, times, fertilizerSec.getDouble("chance"), pot_whitelist, beforePlant, particle, sound); + case SPEED_GROW -> fertilizerConfig = new SpeedGrow(key, fertilizerType, times, getChancePair(fertilizerSec), pot_whitelist, beforePlant, particle, sound, icon); + case YIELD_INCREASE -> fertilizerConfig = new YieldIncrease(key, fertilizerType, times, fertilizerSec.getDouble("chance"), getChancePair(fertilizerSec), pot_whitelist, beforePlant, particle, sound, icon); + case VARIATION -> fertilizerConfig = new Variation(key, fertilizerType, times, fertilizerSec.getDouble("chance"), pot_whitelist, beforePlant, particle, sound, icon); + case QUALITY -> fertilizerConfig = new Quality(key, fertilizerType, times, fertilizerSec.getDouble("chance"), ConfigUtils.getQualityRatio(fertilizerSec.getString("ratio", "2/2/1")), pot_whitelist, beforePlant, particle, sound, icon); + case SOIL_RETAIN -> fertilizerConfig = new SoilRetain(key, fertilizerType, times, fertilizerSec.getDouble("chance"), pot_whitelist, beforePlant, particle, sound, icon); default -> fertilizerConfig = null; } - if (fertilizerConfig != null) + String item = fertilizerSec.getString("item"); + if (fertilizerConfig != null && item != null) { fertilizerConfigMap.put(key, fertilizerConfig); + itemToKey.put(item, key); + } else AdventureUtils.consoleMessage("[CustomCrops] Invalid fertilizer: " + key); } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerType.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerType.java index c897439..f83d472 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerType.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerType.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fertilizer; public enum FertilizerType { diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Quality.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Quality.java index 51683da..4fb8369 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Quality.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Quality.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; @@ -8,8 +25,9 @@ public class Quality extends FertilizerConfig { private final double[] ratio; - public Quality(String key, FertilizerType fertilizerType, int times, double chance, double[] ratio, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) { - super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound); + public Quality(String key, FertilizerType fertilizerType, int times, double chance, double[] ratio, + @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, @Nullable String icon) { + super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon); this.ratio = ratio; } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SoilRetain.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SoilRetain.java index 2e89e09..9821530 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SoilRetain.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SoilRetain.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; @@ -6,7 +23,8 @@ import org.jetbrains.annotations.Nullable; public class SoilRetain extends FertilizerConfig { - public SoilRetain(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) { - super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound); + public SoilRetain(String key, FertilizerType fertilizerType, int times, double chance, + @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, String icon) { + super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon); } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SpeedGrow.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SpeedGrow.java index dd77d1c..4483154 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SpeedGrow.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SpeedGrow.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; @@ -11,15 +28,12 @@ public class SpeedGrow extends FertilizerConfig { private final List> pairs; - public SpeedGrow(String key, FertilizerType fertilizerType, int times, List> pairs, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) { - super(key, fertilizerType, times, 1, pot_whitelist, beforePlant, particle, sound); + public SpeedGrow(String key, FertilizerType fertilizerType, int times, List> pairs, + @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, String icon) { + super(key, fertilizerType, times, 1, pot_whitelist, beforePlant, particle, sound, icon); this.pairs = pairs; } - public List> getPairs() { - return pairs; - } - public int getPointBonus() { for (Pair pair : pairs) { if (Math.random() < pair.left()) { diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Variation.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Variation.java index 58cb966..1837efa 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Variation.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Variation.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; @@ -6,7 +23,9 @@ import org.jetbrains.annotations.Nullable; public class Variation extends FertilizerConfig { - public Variation(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) { - super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound); + public Variation(String key, FertilizerType fertilizerType, int times, double chance, + @Nullable String[] pot_whitelist, boolean beforePlant, + @Nullable Particle particle, @Nullable Sound sound, String icon) { + super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon); } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/YieldIncrease.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/YieldIncrease.java index 4f3d026..8a46b8d 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/YieldIncrease.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/YieldIncrease.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; @@ -11,15 +28,13 @@ public class YieldIncrease extends FertilizerConfig { private final List> pairs; - public YieldIncrease(String key, FertilizerType fertilizerType, int times, double chance, List> pairs, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) { - super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound); + public YieldIncrease(String key, FertilizerType fertilizerType, int times, double chance, + List> pairs, @Nullable String[] pot_whitelist, boolean beforePlant, + @Nullable Particle particle, @Nullable Sound sound, String icon) { + super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon); this.pairs = pairs; } - public List> getPairs() { - return pairs; - } - public int getAmountBonus() { for (Pair pair : pairs) { if (Math.random() < pair.left()) { diff --git a/src/main/java/net/momirealms/customcrops/api/object/fill/AbstractFillMethod.java b/src/main/java/net/momirealms/customcrops/api/object/fill/AbstractFillMethod.java index 3d3b4f4..f48b8ef 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fill/AbstractFillMethod.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fill/AbstractFillMethod.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fill; import net.kyori.adventure.sound.Sound; diff --git a/src/main/java/net/momirealms/customcrops/api/object/fill/PassiveFillMethod.java b/src/main/java/net/momirealms/customcrops/api/object/fill/PassiveFillMethod.java index f1b9e0b..5a636aa 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fill/PassiveFillMethod.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fill/PassiveFillMethod.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fill; import net.kyori.adventure.sound.Sound; diff --git a/src/main/java/net/momirealms/customcrops/api/object/fill/PositiveFillMethod.java b/src/main/java/net/momirealms/customcrops/api/object/fill/PositiveFillMethod.java index af6a1a5..673b2d2 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fill/PositiveFillMethod.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fill/PositiveFillMethod.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.fill; import net.kyori.adventure.sound.Sound; diff --git a/src/main/java/net/momirealms/customcrops/api/object/loot/Loot.java b/src/main/java/net/momirealms/customcrops/api/object/loot/Loot.java index 79160cc..f10d1b4 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/loot/Loot.java +++ b/src/main/java/net/momirealms/customcrops/api/object/loot/Loot.java @@ -1,10 +1,24 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.loot; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.basic.ConfigManager; -import net.momirealms.customcrops.api.object.pot.Pot; -import net.momirealms.customcrops.api.object.fertilizer.YieldIncrease; -import net.momirealms.customcrops.api.object.world.SimpleLocation; import net.momirealms.customcrops.integration.SkillInterface; import net.objecthunter.exp4j.Expression; import net.objecthunter.exp4j.ExpressionBuilder; diff --git a/src/main/java/net/momirealms/customcrops/api/object/loot/QualityLoot.java b/src/main/java/net/momirealms/customcrops/api/object/loot/QualityLoot.java index 429329d..d0ae215 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/loot/QualityLoot.java +++ b/src/main/java/net/momirealms/customcrops/api/object/loot/QualityLoot.java @@ -1,11 +1,28 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.loot; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.basic.ConfigManager; import net.momirealms.customcrops.api.object.fertilizer.FertilizerConfig; +import net.momirealms.customcrops.api.object.fertilizer.Quality; import net.momirealms.customcrops.api.object.fertilizer.YieldIncrease; import net.momirealms.customcrops.api.object.pot.Pot; -import net.momirealms.customcrops.api.object.fertilizer.Quality; import net.momirealms.customcrops.api.object.world.SimpleLocation; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/main/java/net/momirealms/customcrops/api/object/pot/Pot.java b/src/main/java/net/momirealms/customcrops/api/object/pot/Pot.java index 4deb801..5dda063 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/pot/Pot.java +++ b/src/main/java/net/momirealms/customcrops/api/object/pot/Pot.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.pot; import net.momirealms.customcrops.CustomCrops; @@ -35,11 +52,11 @@ public class Pot implements Serializable { */ public boolean addWater(int amount) { if (water == 0) { - this.water = Math.min(getConfig().getMax_storage(), amount); + this.water = Math.min(getConfig().getMaxStorage(), amount); return true; } else { - this.water = Math.min(getConfig().getMax_storage(), water + amount); + this.water = Math.min(getConfig().getMaxStorage(), water + amount); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/pot/PotConfig.java b/src/main/java/net/momirealms/customcrops/api/object/pot/PotConfig.java index 7b0f916..f21f017 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/pot/PotConfig.java +++ b/src/main/java/net/momirealms/customcrops/api/object/pot/PotConfig.java @@ -1,10 +1,27 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.pot; import net.momirealms.customcrops.api.object.Pair; -import net.momirealms.customcrops.api.object.fill.PassiveFillMethod; import net.momirealms.customcrops.api.object.fertilizer.Fertilizer; import net.momirealms.customcrops.api.object.fertilizer.FertilizerConfig; import net.momirealms.customcrops.api.object.fertilizer.FertilizerType; +import net.momirealms.customcrops.api.object.fill.PassiveFillMethod; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,13 +34,18 @@ public class PotConfig { private final Pair pot; private final boolean enableFertilized; private final PassiveFillMethod[] passiveFillMethods; + private final boolean enableHologram; + private final PotHologram potHologram; - public PotConfig(int max_storage, String dry_pot, String wet_pot, boolean enableFertilized, @NotNull PassiveFillMethod[] passiveFillMethods) { + public PotConfig(int max_storage, String dry_pot, String wet_pot, boolean enableFertilized, + @NotNull PassiveFillMethod[] passiveFillMethods, boolean enableHologram, @Nullable PotHologram potHologram) { this.max_storage = max_storage; this.pot = Pair.of(dry_pot, wet_pot); this.enableFertilized = enableFertilized; this.fertilizerConvertMap = new HashMap<>(); this.passiveFillMethods = passiveFillMethods; + this.enableHologram = enableHologram; + this.potHologram = potHologram; } public void registerFertilizedPot(FertilizerType fertilizerType, String dry_pot, String wet_pot) { @@ -50,7 +72,7 @@ public class PotConfig { else return pair.left(); } - public int getMax_storage() { + public int getMaxStorage() { return max_storage; } @@ -58,4 +80,12 @@ public class PotConfig { public PassiveFillMethod[] getPassiveFillMethods() { return passiveFillMethods; } + + public boolean isHologramEnabled() { + return enableHologram; + } + + public PotHologram getPotHologram() { + return potHologram; + } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/pot/PotHologram.java b/src/main/java/net/momirealms/customcrops/api/object/pot/PotHologram.java new file mode 100644 index 0000000..50dfb4c --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/object/pot/PotHologram.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.object.pot; + +import net.momirealms.customcrops.CustomCrops; +import net.momirealms.customcrops.api.object.HologramManager; +import net.momirealms.customcrops.api.object.fertilizer.Fertilizer; +import net.momirealms.customcrops.api.util.AdventureUtils; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class PotHologram { + + private final String fertilizerText; + private final double fertilizerOffset; + private final String waterText; + private final double waterOffset; + private final HologramManager.Mode mode; + private final int duration; + private final String bar_left; + private final String bar_full; + private final String bar_empty; + private final String bar_right; + private final Pattern betterPattern = Pattern.compile("\\{(.+?)\\}"); + + public PotHologram(String fertilizerText, double fertilizerOffset, String waterText, double waterOffset, HologramManager.Mode mode, int duration, + String bar_left, String bar_full, String bar_empty, String bar_right) { + this.mode = mode; + this.duration = duration; + this.fertilizerText = fertilizerText; + this.waterText = waterText; + this.fertilizerOffset = fertilizerOffset; + this.waterOffset = waterOffset; + this.bar_left = bar_left; + this.bar_full = bar_full; + this.bar_empty = bar_empty; + this.bar_right = bar_right; + } + + private List detectBetterPlaceholders(String text) { + List placeholders = new ArrayList<>(); + Matcher matcher = betterPattern.matcher(text); + while (matcher.find()) placeholders.add(matcher.group()); + return placeholders; + } + + public void show(Player player, Pot pot, Location location, double offset) { + if (fertilizerText != null && pot.getFertilizer() != null) { + String parsed = CustomCrops.getInstance().getIntegrationManager().getPlaceholderManager().parse(player, fertilizerText); + parseAndSend(parsed, player, pot, location, offset + fertilizerOffset); + } + if (waterText != null) { + String parsed = CustomCrops.getInstance().getIntegrationManager().getPlaceholderManager().parse(player, waterText); + parseAndSend(parsed, player, pot, location, offset + waterOffset); + } + } + + public void parseAndSend(String parsed, Player player, Pot pot, Location location, double offset) { + for (String detected : detectBetterPlaceholders(parsed)) { + String replacer = getReplacer(detected, pot); + parsed = parsed.replace(detected, replacer); + } + CustomCrops.getInstance().getHologramManager().showHologram(player, location.clone().add(0, offset, 0), AdventureUtils.getComponentFromMiniMessage(parsed), duration * 1000, mode); + } + + public String getReplacer(String text, Pot pot) { + switch (text) { + case "{icon}" -> { + Fertilizer fertilizer = pot.getFertilizer(); + if (fertilizer == null) return ""; + return fertilizer.getConfig().getIcon(); + } + case "{left_times}" -> { + Fertilizer fertilizer = pot.getFertilizer(); + if (fertilizer == null) return ""; + return String.valueOf(fertilizer.getLeftTimes()); + } + case "{max_times}" -> { + Fertilizer fertilizer = pot.getFertilizer(); + if (fertilizer == null) return ""; + return String.valueOf(fertilizer.getConfig().getTimes()); + } + case "{current}" -> { + return String.valueOf(pot.getWater()); + } + case "{storage}" -> { + return String.valueOf(pot.getConfig().getMaxStorage()); + } + case "{water_bar}" -> { + return getWaterBar(pot.getWater(), pot.getConfig().getMaxStorage()); + } + } + return ""; + } + + public String getWaterBar(int current, int storage) { + return bar_left + + String.valueOf(bar_full).repeat(current) + + String.valueOf(bar_empty).repeat(storage - current) + + bar_right; + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/object/pot/PotManager.java b/src/main/java/net/momirealms/customcrops/api/object/pot/PotManager.java index a3aea8f..5123fe1 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/pot/PotManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/pot/PotManager.java @@ -1,7 +1,25 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.pot; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.Function; +import net.momirealms.customcrops.api.object.HologramManager; import net.momirealms.customcrops.api.object.fertilizer.FertilizerType; import net.momirealms.customcrops.api.object.fill.PassiveFillMethod; import net.momirealms.customcrops.api.util.AdventureUtils; @@ -63,12 +81,26 @@ public class PotManager extends Function { } blockToPotKey.put(base_wet, key); blockToPotKey.put(base_dry, key); + boolean enableHolo = section.getBoolean("hologram.enable", false); PotConfig potConfig = new PotConfig( section.getInt("max-water-storage"), base_dry, base_wet, enableFertilized, - methods + methods, + enableHolo, + enableHolo ? new PotHologram( + section.getString("hologram.fertilizer.text"), + section.getDouble("hologram.fertilizer.vertical-offset"), + section.getString("hologram.water.text"), + section.getDouble("hologram.water.vertical-offset"), + HologramManager.Mode.valueOf(section.getString("hologram.type", "ARMOR_STAND").toUpperCase()), + section.getInt("hologram.duration"), + section.getString("hologram.water.water-bar.left"), + section.getString("hologram.water.water-bar.full"), + section.getString("hologram.water.water-bar.empty"), + section.getString("hologram.water.water-bar.right") + ) : null ); if (enableFertilized) { ConfigurationSection fertilizedSec = section.getConfigurationSection("fertilized-pots"); diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/DateImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/DateImpl.java index 2dbaf6e..a65e339 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/DateImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/DateImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.requirement; import java.util.Calendar; diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/JobLevelImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/JobLevelImpl.java index 379cd02..8ddb31b 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/JobLevelImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/JobLevelImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.requirement; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/SkillLevelImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/SkillLevelImpl.java index 823678f..068fde2 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/SkillLevelImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/SkillLevelImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.requirement; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/api/object/schedule/BukkitSchedulerImpl.java b/src/main/java/net/momirealms/customcrops/api/object/schedule/BukkitSchedulerImpl.java new file mode 100644 index 0000000..5b16a74 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/object/schedule/BukkitSchedulerImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.object.schedule; + +import net.momirealms.customcrops.CustomCrops; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.Callable; +import java.util.concurrent.Future; + +public class BukkitSchedulerImpl implements SchedulerPlatform { + + private final CustomCrops plugin; + + public BukkitSchedulerImpl(CustomCrops plugin) { + this.plugin = plugin; + } + + @Override + public Future callSyncMethod(@NotNull Callable task) { + return Bukkit.getScheduler().callSyncMethod(plugin, task); + } + + @Override + public void runTask(Runnable runnable) { + Bukkit.getScheduler().runTask(plugin, runnable); + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/object/schedule/Scheduler.java b/src/main/java/net/momirealms/customcrops/api/object/schedule/Scheduler.java new file mode 100644 index 0000000..e329c70 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/object/schedule/Scheduler.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.object.schedule; + +import net.momirealms.customcrops.CustomCrops; +import net.momirealms.customcrops.api.object.Function; +import net.momirealms.customcrops.api.object.basic.ConfigManager; +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.*; + +public class Scheduler extends Function { + + private final ScheduledThreadPoolExecutor schedule; + private final SchedulerPlatform schedulerPlatform; + + public Scheduler(CustomCrops plugin) { + this.schedulerPlatform = new BukkitSchedulerImpl(plugin); + this.schedule = new ScheduledThreadPoolExecutor(1); + this.schedule.setMaximumPoolSize(2); + this.schedule.setKeepAliveTime(ConfigManager.keepAliveTime, TimeUnit.SECONDS); + this.schedule.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy()); + } + + @Override + public void disable() { + this.schedule.shutdown(); + } + + public ScheduledFuture runTaskAsyncLater(Runnable runnable, long delay) { + return this.schedule.schedule(runnable, delay, TimeUnit.MILLISECONDS); + } + + public void runTaskAsync(Runnable runnable) { + this.schedule.execute(runnable); + } + + public void runTask(Runnable runnable) { + this.schedulerPlatform.runTask(runnable); + } + + public Future callSyncMethod(@NotNull Callable task) { + return this.schedulerPlatform.callSyncMethod(task); + } + + public ScheduledFuture runTaskTimerAsync(Runnable runnable, long delay, long interval) { + return this.schedule.scheduleAtFixedRate(runnable, delay, interval, TimeUnit.MILLISECONDS); + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/object/schedule/SchedulerPlatform.java b/src/main/java/net/momirealms/customcrops/api/object/schedule/SchedulerPlatform.java new file mode 100644 index 0000000..dd936b4 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/object/schedule/SchedulerPlatform.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.object.schedule; + +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.Callable; +import java.util.concurrent.Future; + +public interface SchedulerPlatform { + + Future callSyncMethod(@NotNull Callable task); + + void runTask(Runnable runnable); +} diff --git a/src/main/java/net/momirealms/customcrops/api/object/season/SeasonData.java b/src/main/java/net/momirealms/customcrops/api/object/season/SeasonData.java index 53876b0..a1fbaed 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/season/SeasonData.java +++ b/src/main/java/net/momirealms/customcrops/api/object/season/SeasonData.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.season; import net.momirealms.customcrops.api.object.basic.ConfigManager; diff --git a/src/main/java/net/momirealms/customcrops/api/object/season/SeasonManager.java b/src/main/java/net/momirealms/customcrops/api/object/season/SeasonManager.java index e2197dd..dc2040c 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/season/SeasonManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/season/SeasonManager.java @@ -1,9 +1,24 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.season; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.Function; -import net.momirealms.customcrops.api.object.basic.ConfigManager; -import net.momirealms.customcrops.integration.SeasonInterface; import org.jetbrains.annotations.Nullable; import java.util.concurrent.ConcurrentHashMap; diff --git a/src/main/java/net/momirealms/customcrops/api/object/sprinkler/Sprinkler.java b/src/main/java/net/momirealms/customcrops/api/object/sprinkler/Sprinkler.java index e73303a..416e823 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/sprinkler/Sprinkler.java +++ b/src/main/java/net/momirealms/customcrops/api/object/sprinkler/Sprinkler.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.sprinkler; import java.io.Serializable; diff --git a/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerConfig.java b/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerConfig.java index 05b0132..60a1247 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerConfig.java +++ b/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerConfig.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.sprinkler; import net.kyori.adventure.sound.Sound; diff --git a/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerManager.java b/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerManager.java index 094ec2e..6659833 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerManager.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.sprinkler; import net.kyori.adventure.key.Key; @@ -113,7 +130,7 @@ public class SprinklerManager extends Function implements Listener { public void onItemSpawn(ItemSpawnEvent event) { if (event.isCancelled()) return; Item item = event.getEntity(); - String id = plugin.getPlatformInterface().getItemID(item.getItemStack()); + String id = plugin.getPlatformInterface().getItemStackID(item.getItemStack()); String key = itemToKey.get(id); if (key == null) return; String twoD = sprinklerConfigMap.get(key).getTwoD(); diff --git a/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanConfig.java b/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanConfig.java index 717e956..eaa00a1 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanConfig.java +++ b/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanConfig.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.wateringcan; import net.kyori.adventure.sound.Sound; diff --git a/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanManager.java b/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanManager.java index b3f8fe7..9928c64 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanManager.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.wateringcan; import de.tr7zw.changeme.nbtapi.NBTCompound; diff --git a/src/main/java/net/momirealms/customcrops/api/object/world/CCChunk.java b/src/main/java/net/momirealms/customcrops/api/object/world/CCChunk.java index 83982d4..ff714ec 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/world/CCChunk.java +++ b/src/main/java/net/momirealms/customcrops/api/object/world/CCChunk.java @@ -1,19 +1,37 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.world; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.CustomCropsAPI; import net.momirealms.customcrops.api.object.basic.ConfigManager; import net.momirealms.customcrops.api.object.crop.GrowingCrop; -import net.momirealms.customcrops.api.object.pot.Pot; import net.momirealms.customcrops.api.object.fertilizer.Fertilizer; +import net.momirealms.customcrops.api.object.pot.Pot; import net.momirealms.customcrops.api.object.sprinkler.Sprinkler; -import org.bukkit.Bukkit; -import org.bukkit.Sound; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.Serializable; -import java.util.*; +import java.util.Collections; +import java.util.HashSet; +import java.util.Random; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; @@ -108,7 +126,7 @@ public class CCChunk implements Serializable { Pot pot = potMap.get(simpleLocation); if (pot != null) { if (pot.addWater(amount)) { - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { CustomCropsAPI.getInstance().changePotModel(simpleLocation, pot); return null; }); @@ -117,7 +135,7 @@ public class CCChunk implements Serializable { else if (pot_id != null) { Pot newPot = new Pot(pot_id, null, amount); potMap.put(simpleLocation, newPot); - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { CustomCropsAPI.getInstance().changePotModel(simpleLocation, newPot); return null; }); @@ -128,7 +146,7 @@ public class CCChunk implements Serializable { Pot pot = potMap.get(simpleLocation); if (pot != null) { pot.setFertilizer(fertilizer); - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { CustomCropsAPI.getInstance().changePotModel(simpleLocation, pot); return null; }); @@ -136,7 +154,7 @@ public class CCChunk implements Serializable { else { Pot newPot = new Pot(pot_id, fertilizer, 0); potMap.put(simpleLocation, newPot); - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { CustomCropsAPI.getInstance().changePotModel(simpleLocation, newPot); return null; }); diff --git a/src/main/java/net/momirealms/customcrops/api/object/world/CCWorld.java b/src/main/java/net/momirealms/customcrops/api/object/world/CCWorld.java index 37857a9..6853917 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/world/CCWorld.java +++ b/src/main/java/net/momirealms/customcrops/api/object/world/CCWorld.java @@ -1,19 +1,38 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.world; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.CustomCropsAPI; import net.momirealms.customcrops.api.object.Function; +import net.momirealms.customcrops.api.object.ItemMode; import net.momirealms.customcrops.api.object.action.Action; import net.momirealms.customcrops.api.object.action.VariationImpl; import net.momirealms.customcrops.api.object.basic.ConfigManager; import net.momirealms.customcrops.api.object.condition.Condition; import net.momirealms.customcrops.api.object.condition.DeathCondition; import net.momirealms.customcrops.api.object.crop.CropConfig; -import net.momirealms.customcrops.api.object.ItemMode; import net.momirealms.customcrops.api.object.crop.GrowingCrop; import net.momirealms.customcrops.api.object.crop.StageConfig; -import net.momirealms.customcrops.api.object.crop.VariationCrop; -import net.momirealms.customcrops.api.object.fertilizer.*; +import net.momirealms.customcrops.api.object.fertilizer.Fertilizer; +import net.momirealms.customcrops.api.object.fertilizer.FertilizerConfig; +import net.momirealms.customcrops.api.object.fertilizer.SoilRetain; +import net.momirealms.customcrops.api.object.fertilizer.SpeedGrow; import net.momirealms.customcrops.api.object.pot.Pot; import net.momirealms.customcrops.api.object.season.CCSeason; import net.momirealms.customcrops.api.object.season.SeasonData; @@ -26,7 +45,6 @@ import org.apache.commons.pool2.PooledObject; import org.apache.commons.pool2.impl.DefaultPooledObject; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; @@ -194,6 +212,9 @@ public class CCWorld extends Function { private void closePool() { this.schedule.shutdown(); + //this.cropTaskPool.close(); + //this.sprinklerTaskPool.close(); + //this.consumeTaskPool.close(); } public void pushCropTask(SimpleLocation simpleLocation, int delay) { @@ -299,7 +320,7 @@ public class CCWorld extends Function { pot.setWater(pot.getWater() + 1); } if (pot.reduceWater() | pot.reduceFertilizer()) { - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { CustomCropsAPI.getInstance().changePotModel(simpleLocation, pot); return null; }); @@ -370,9 +391,18 @@ public class CCWorld extends Function { DeathCondition[] deathConditions = cropConfig.getDeathConditions(); if (deathConditions != null) { for (DeathCondition deathCondition : deathConditions) { - if (deathCondition.checkIfDead(simpleLocation)) { - removeCropData(simpleLocation); - deathCondition.applyDeadModel(simpleLocation, itemMode); + int delay = deathCondition.checkIfDead(simpleLocation); + if (delay != -1) { + if (delay == 0) { + removeCropData(simpleLocation); + deathCondition.applyDeadModel(simpleLocation, itemMode); + } else { + SimpleLocation copied = simpleLocation.copy(); + schedule.schedule(() -> { + removeCropData(copied); + deathCondition.applyDeadModel(copied, itemMode); + }, delay, TimeUnit.MILLISECONDS); + } return; } } @@ -440,7 +470,7 @@ public class CCWorld extends Function { growingCrop.setPoints(current + points); if (ConfigManager.debug) Log.info(simpleLocation.toString() + ":" + growingCrop.getPoints()); - if (growingCrop.getPoints() >= cropConfig.getMax_points()) { + if (growingCrop.getPoints() >= cropConfig.getMaxPoints()) { removeCropData(simpleLocation); } @@ -454,7 +484,7 @@ public class CCWorld extends Function { return chunk.isEntitiesLoaded(); }); loadEntities.whenComplete((result, throwable) -> - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { if (CustomCropsAPI.getInstance().removeCustomItem(location, itemMode)) { CustomCropsAPI.getInstance().placeCustomItem(location, finalNextModel, itemMode); } else { @@ -465,7 +495,7 @@ public class CCWorld extends Function { } else { asyncGetChunk.whenComplete((result, throwable) -> - Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { if (CustomCropsAPI.getInstance().removeCustomItem(location, itemMode)) { CustomCropsAPI.getInstance().placeCustomItem(location, finalNextModel, itemMode); } else { diff --git a/src/main/java/net/momirealms/customcrops/api/object/world/ChunkCoordinate.java b/src/main/java/net/momirealms/customcrops/api/object/world/ChunkCoordinate.java index ad45240..c6295a5 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/world/ChunkCoordinate.java +++ b/src/main/java/net/momirealms/customcrops/api/object/world/ChunkCoordinate.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.world; import org.bukkit.Chunk; diff --git a/src/main/java/net/momirealms/customcrops/api/object/world/SimpleLocation.java b/src/main/java/net/momirealms/customcrops/api/object/world/SimpleLocation.java index ac9021d..4972886 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/world/SimpleLocation.java +++ b/src/main/java/net/momirealms/customcrops/api/object/world/SimpleLocation.java @@ -123,4 +123,21 @@ public class SimpleLocation implements Serializable { public String toString() { return "[" + worldName + "," + x + "," + y + "," + z + "]"; } + + public boolean isNear(SimpleLocation simpleLocation, int distance) { + if (Math.abs(simpleLocation.x - this.x) > distance) { + return false; + } + if (Math.abs(simpleLocation.z - this.z) > distance) { + return false; + } + if (Math.abs(simpleLocation.y - this.y) > distance) { + return false; + } + return true; + } + + public SimpleLocation copy() { + return new SimpleLocation(worldName, x, y, z); + } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/api/object/world/WorldDataManager.java b/src/main/java/net/momirealms/customcrops/api/object/world/WorldDataManager.java index 2331473..f9b5886 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/world/WorldDataManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/world/WorldDataManager.java @@ -1,14 +1,29 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.world; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.Function; import net.momirealms.customcrops.api.object.basic.ConfigManager; -import net.momirealms.customcrops.api.object.crop.CropConfig; import net.momirealms.customcrops.api.object.crop.GrowingCrop; -import net.momirealms.customcrops.api.object.pot.Pot; import net.momirealms.customcrops.api.object.fertilizer.Fertilizer; +import net.momirealms.customcrops.api.object.pot.Pot; import net.momirealms.customcrops.api.object.sprinkler.Sprinkler; -import net.momirealms.customcrops.api.object.sprinkler.SprinklerConfig; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.event.HandlerList; @@ -40,6 +55,7 @@ public class WorldDataManager extends Function { @Override public void disable() { + this.unload(); for (CCWorld ccWorld : worldMap.values()) { ccWorld.unload(); } @@ -174,6 +190,7 @@ public class WorldDataManager extends Function { } } + @Nullable public Pot getPotData(SimpleLocation simpleLocation) { CCWorld ccWorld = worldMap.get(simpleLocation.getWorldName()); if (ccWorld != null) { @@ -208,4 +225,13 @@ public class WorldDataManager extends Function { } return false; } + + @Nullable + public GrowingCrop getCropData(SimpleLocation simpleLocation) { + CCWorld ccWorld = worldMap.get(simpleLocation.getWorldName()); + if (ccWorld != null) { + return ccWorld.getCropData(simpleLocation); + } + return null; + } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/world/WorldListener.java b/src/main/java/net/momirealms/customcrops/api/object/world/WorldListener.java index 09c72ff..aea2602 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/world/WorldListener.java +++ b/src/main/java/net/momirealms/customcrops/api/object/world/WorldListener.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.object.world; import org.bukkit.event.EventHandler; diff --git a/src/main/java/net/momirealms/customcrops/api/util/ConfigUtils.java b/src/main/java/net/momirealms/customcrops/api/util/ConfigUtils.java index f2d14da..0a44993 100644 --- a/src/main/java/net/momirealms/customcrops/api/util/ConfigUtils.java +++ b/src/main/java/net/momirealms/customcrops/api/util/ConfigUtils.java @@ -28,13 +28,13 @@ import net.kyori.adventure.sound.Sound; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.BoneMeal; import net.momirealms.customcrops.api.object.InteractWithItem; +import net.momirealms.customcrops.api.object.ItemMode; import net.momirealms.customcrops.api.object.Pair; -import net.momirealms.customcrops.api.object.fill.PassiveFillMethod; import net.momirealms.customcrops.api.object.action.*; import net.momirealms.customcrops.api.object.condition.Random; import net.momirealms.customcrops.api.object.condition.*; -import net.momirealms.customcrops.api.object.ItemMode; import net.momirealms.customcrops.api.object.crop.VariationCrop; +import net.momirealms.customcrops.api.object.fill.PassiveFillMethod; import net.momirealms.customcrops.api.object.fill.PositiveFillMethod; import net.momirealms.customcrops.api.object.loot.Loot; import net.momirealms.customcrops.api.object.loot.OtherLoot; diff --git a/src/main/java/net/momirealms/customcrops/api/util/ArmorStandUtils.java b/src/main/java/net/momirealms/customcrops/api/util/FakeEntityUtils.java similarity index 53% rename from src/main/java/net/momirealms/customcrops/api/util/ArmorStandUtils.java rename to src/main/java/net/momirealms/customcrops/api/util/FakeEntityUtils.java index 10f840e..b9e2862 100644 --- a/src/main/java/net/momirealms/customcrops/api/util/ArmorStandUtils.java +++ b/src/main/java/net/momirealms/customcrops/api/util/FakeEntityUtils.java @@ -1,14 +1,29 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.util; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.wrappers.EnumWrappers; -import com.comphenix.protocol.wrappers.Pair; -import com.comphenix.protocol.wrappers.WrappedDataValue; -import com.comphenix.protocol.wrappers.WrappedDataWatcher; +import com.comphenix.protocol.wrappers.*; import com.google.common.collect.Lists; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.momirealms.customcrops.CustomCrops; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -16,17 +31,16 @@ import org.bukkit.inventory.ItemStack; import java.util.*; -public class ArmorStandUtils { +public class FakeEntityUtils { public static void playWaterAnimation(Player player, Location location, String animation_id) { int id = new Random().nextInt(Integer.MAX_VALUE); - CustomCrops.getProtocolManager().sendServerPacket(player, getSpawnPacket(id, location)); + CustomCrops.getProtocolManager().sendServerPacket(player, getSpawnPacket(id, location, EntityType.ARMOR_STAND)); CustomCrops.getProtocolManager().sendServerPacket(player, getMetaPacket(id)); CustomCrops.getProtocolManager().sendServerPacket(player, getEquipPacket(id, CustomCrops.getInstance().getIntegrationManager().build(animation_id))); - - Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.getInstance(), () -> { + CustomCrops.getInstance().getScheduler().runTaskAsyncLater(() -> { CustomCrops.getProtocolManager().sendServerPacket(player, getDestroyPacket(id)); - }, 200); + }, 10000); } public static WrappedDataWatcher createInvisibleDataWatcher() { @@ -45,11 +59,11 @@ public class ArmorStandUtils { return destroyPacket; } - public static PacketContainer getSpawnPacket(int id, Location location) { + public static PacketContainer getSpawnPacket(int id, Location location, EntityType entityType) { PacketContainer entityPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY); entityPacket.getModifier().write(0, id); entityPacket.getModifier().write(1, UUID.randomUUID()); - entityPacket.getEntityTypeModifier().write(0, EntityType.ARMOR_STAND); + entityPacket.getEntityTypeModifier().write(0, entityType); entityPacket.getDoubles().write(0, location.getX()); entityPacket.getDoubles().write(1, location.getY()); entityPacket.getDoubles().write(2, location.getZ()); @@ -61,12 +75,7 @@ public class ArmorStandUtils { metaPacket.getIntegers().write(0, id); if (CustomCrops.getInstance().getVersionHelper().isVersionNewerThan1_19_R2()) { WrappedDataWatcher wrappedDataWatcher = createInvisibleDataWatcher(); - List wrappedDataValueList = Lists.newArrayList(); - wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> { - final WrappedDataWatcher.WrappedDataWatcherObject dataWatcherObject = entry.getWatcherObject(); - wrappedDataValueList.add(new WrappedDataValue(dataWatcherObject.getIndex(), dataWatcherObject.getSerializer(), entry.getRawValue())); - }); - metaPacket.getDataValueCollectionModifier().write(0, wrappedDataValueList); + setWrappedDataValue(metaPacket, wrappedDataWatcher); } else { metaPacket.getWatchableCollectionModifier().write(0, createInvisibleDataWatcher().getWatchableObjects()); } @@ -92,9 +101,33 @@ public class ArmorStandUtils { return packet; } - public static PacketContainer getRotationPacket(int id, float yaw) { - PacketContainer rotationPacket = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION); - rotationPacket.getIntegers().write(0, id); - return rotationPacket; + public static PacketContainer getMetaPacket(int id, Component component) { + PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); + WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher(); + WrappedDataWatcher.Serializer serializer1 = WrappedDataWatcher.Registry.get(Boolean.class); + WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.getChatComponentSerializer(true)), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(component)).getHandle())); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer1), true); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(5, serializer1), true); + byte mask1 = 0x20; + byte mask2 = 0x01; + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer2), mask1); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), mask2); + metaPacket.getModifier().write(0, id); + if (CustomCrops.getInstance().getVersionHelper().isVersionNewerThan1_19_R2()) { + setWrappedDataValue(metaPacket, wrappedDataWatcher); + } else { + metaPacket.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects()); + } + return metaPacket; + } + + private static void setWrappedDataValue(PacketContainer metaPacket, WrappedDataWatcher wrappedDataWatcher) { + List wrappedDataValueList = Lists.newArrayList(); + wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> { + final WrappedDataWatcher.WrappedDataWatcherObject dataWatcherObject = entry.getWatcherObject(); + wrappedDataValueList.add(new WrappedDataValue(dataWatcherObject.getIndex(), dataWatcherObject.getSerializer(), entry.getRawValue())); + }); + metaPacket.getDataValueCollectionModifier().write(0, wrappedDataValueList); } } diff --git a/src/main/java/net/momirealms/customcrops/api/util/PaperUtils.java b/src/main/java/net/momirealms/customcrops/api/util/PaperUtils.java deleted file mode 100644 index 2abcfd5..0000000 --- a/src/main/java/net/momirealms/customcrops/api/util/PaperUtils.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.momirealms.customcrops.api.util; - -import org.bukkit.Chunk; -import org.bukkit.World; - -import java.util.concurrent.CompletableFuture; - -public class PaperUtils { - - public static CompletableFuture getChunkAtAsync(final World world, final int x, final int z) { - if (world == null) return CompletableFuture.completedFuture(null); - return world.getChunkAtAsync(x, z, false); - } -} diff --git a/src/main/java/net/momirealms/customcrops/api/util/RotationUtils.java b/src/main/java/net/momirealms/customcrops/api/util/RotationUtils.java index f138eb2..dde2bdd 100644 --- a/src/main/java/net/momirealms/customcrops/api/util/RotationUtils.java +++ b/src/main/java/net/momirealms/customcrops/api/util/RotationUtils.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.api.util; import org.bukkit.Rotation; diff --git a/src/main/java/net/momirealms/customcrops/command/subcmd/SetDateCommand.java b/src/main/java/net/momirealms/customcrops/command/subcmd/SetDateCommand.java index e2d692c..e5a3208 100644 --- a/src/main/java/net/momirealms/customcrops/command/subcmd/SetDateCommand.java +++ b/src/main/java/net/momirealms/customcrops/command/subcmd/SetDateCommand.java @@ -1,9 +1,25 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.command.subcmd; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.basic.ConfigManager; import net.momirealms.customcrops.api.object.basic.MessageManager; -import net.momirealms.customcrops.api.object.season.CCSeason; import net.momirealms.customcrops.api.object.season.SeasonData; import net.momirealms.customcrops.api.util.AdventureUtils; import net.momirealms.customcrops.command.AbstractSubCommand; diff --git a/src/main/java/net/momirealms/customcrops/command/subcmd/SetSeasonCommand.java b/src/main/java/net/momirealms/customcrops/command/subcmd/SetSeasonCommand.java index c8606cf..a0dc95e 100644 --- a/src/main/java/net/momirealms/customcrops/command/subcmd/SetSeasonCommand.java +++ b/src/main/java/net/momirealms/customcrops/command/subcmd/SetSeasonCommand.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.command.subcmd; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/helper/VersionHelper.java b/src/main/java/net/momirealms/customcrops/helper/VersionHelper.java index e2410f9..0330f3c 100644 --- a/src/main/java/net/momirealms/customcrops/helper/VersionHelper.java +++ b/src/main/java/net/momirealms/customcrops/helper/VersionHelper.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.helper; import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; @@ -5,7 +22,6 @@ import de.tr7zw.changeme.nbtapi.utils.VersionChecker; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.basic.ConfigManager; import net.momirealms.customcrops.api.util.AdventureUtils; -import org.bukkit.Bukkit; import java.io.BufferedReader; import java.io.InputStream; @@ -89,7 +105,7 @@ public class VersionHelper { } public void checkUpdate() { - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + plugin.getScheduler().runTaskAsync(() -> { try { URL url = new URL("https://api.polymart.org/v1/getResourceInfoSimple/?resource_id=2625&key=version"); URLConnection conn = url.openConnection(); diff --git a/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java b/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java index 6c430c7..ed06209 100644 --- a/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java +++ b/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.integration; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/integration/JobInterface.java b/src/main/java/net/momirealms/customcrops/integration/JobInterface.java index f47a268..a5a7d7b 100644 --- a/src/main/java/net/momirealms/customcrops/integration/JobInterface.java +++ b/src/main/java/net/momirealms/customcrops/integration/JobInterface.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.integration; import org.bukkit.entity.Player; diff --git a/src/main/java/net/momirealms/customcrops/integration/ProtectionInterface.java b/src/main/java/net/momirealms/customcrops/integration/ProtectionInterface.java index b52dd49..5b6ba37 100644 --- a/src/main/java/net/momirealms/customcrops/integration/ProtectionInterface.java +++ b/src/main/java/net/momirealms/customcrops/integration/ProtectionInterface.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.integration; public interface ProtectionInterface { diff --git a/src/main/java/net/momirealms/customcrops/integration/SkillInterface.java b/src/main/java/net/momirealms/customcrops/integration/SkillInterface.java index 75424ce..d69466b 100644 --- a/src/main/java/net/momirealms/customcrops/integration/SkillInterface.java +++ b/src/main/java/net/momirealms/customcrops/integration/SkillInterface.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.integration; import org.bukkit.entity.Player; diff --git a/src/main/java/net/momirealms/customcrops/integration/item/DefaultImpl.java b/src/main/java/net/momirealms/customcrops/integration/item/DefaultImpl.java index 148325b..3373f68 100644 --- a/src/main/java/net/momirealms/customcrops/integration/item/DefaultImpl.java +++ b/src/main/java/net/momirealms/customcrops/integration/item/DefaultImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.integration.item; import net.momirealms.customcrops.CustomCrops; @@ -14,8 +31,7 @@ public class DefaultImpl implements ItemInterface { public ItemStack build(String id) { if (ConfigUtils.isVanillaItem(id)) { return new ItemStack(Material.valueOf(id)); - } - else { + } else { return CustomCrops.getInstance().getPlatformInterface().getItemStack(id); } } diff --git a/src/main/java/net/momirealms/customcrops/integration/papi/PlaceholderManager.java b/src/main/java/net/momirealms/customcrops/integration/papi/PlaceholderManager.java index 0abce6c..3840b48 100644 --- a/src/main/java/net/momirealms/customcrops/integration/papi/PlaceholderManager.java +++ b/src/main/java/net/momirealms/customcrops/integration/papi/PlaceholderManager.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.integration.papi; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/java/net/momirealms/customcrops/integration/papi/SeasonPapi.java b/src/main/java/net/momirealms/customcrops/integration/papi/SeasonPapi.java index 7725242..66a133f 100644 --- a/src/main/java/net/momirealms/customcrops/integration/papi/SeasonPapi.java +++ b/src/main/java/net/momirealms/customcrops/integration/papi/SeasonPapi.java @@ -1,9 +1,24 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.integration.papi; -import com.comphenix.protocol.PacketType; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import net.momirealms.customcrops.CustomCrops; -import net.momirealms.customcrops.api.customplugin.PlatformManager; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/momirealms/customcrops/integration/season/CustomCropsSeasonImpl.java b/src/main/java/net/momirealms/customcrops/integration/season/CustomCropsSeasonImpl.java index ae87f68..2cd15bd 100644 --- a/src/main/java/net/momirealms/customcrops/integration/season/CustomCropsSeasonImpl.java +++ b/src/main/java/net/momirealms/customcrops/integration/season/CustomCropsSeasonImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.momirealms.customcrops.integration.season; import net.momirealms.customcrops.CustomCrops; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c5e7fbc..0c637d5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -43,7 +43,7 @@ schedule-system: # 线程池设置 thread-pool-settings: # 核心线程池大小 - corePoolSize: 2 + corePoolSize: 1 # 最大线程池大小 maximumPoolSize: 4 # seconds (秒) diff --git a/src/main/resources/contents/crops/tomato.yml b/src/main/resources/contents/crops/tomato.yml index 4b63daf..2487c96 100644 --- a/src/main/resources/contents/crops/tomato.yml +++ b/src/main/resources/contents/crops/tomato.yml @@ -1,6 +1,6 @@ tomato: - # TripWire / Item_Frame / Item_Display - crop-mode: TripWire + # TripWire / Item_Frame / Item_Display (1.19.4+) + crop-mode: Item_Frame # The crop can only be planted on certain pots pot-whitelist: @@ -43,6 +43,7 @@ tomato: points: 0: model: customcrops:tomato_stage_1 + hologram-offset-correction: 0.2 events: break: action_1: @@ -63,6 +64,7 @@ tomato: pitch: 1 1: model: customcrops:tomato_stage_2 + hologram-offset-correction: 0.2 events: break: action_1: @@ -83,6 +85,7 @@ tomato: pitch: 1 3: model: customcrops:tomato_stage_3 + hologram-offset-correction: 0.2 events: break: action_1: @@ -103,6 +106,7 @@ tomato: pitch: 1 5: model: customcrops:tomato_stage_4 + hologram-offset-correction: 0.2 events: break: action_1: @@ -155,18 +159,6 @@ tomato: model: customcrops:tomato_stage_1 interact-with-item: interact_1: - item: customcrops:hoe - reduce-amount: false - actions: - action_1: - type: break - action_2: - type: replant - value: - point: 0 - crop: tomato # Replant the crop - model: customcrops:tomato_stage_1 - interact_2: item: customcrops:i_want_overgrown_tomato_right_now reduce-amount: true return: customcrops:returned_item @@ -222,6 +214,19 @@ tomato: point: 0 crop: tomato # Replant the crop model: customcrops:tomato_stage_1 + interact-with-item: + interact_1: + item: GOLDEN_HOE + reduce-amount: false + actions: + action_1: + type: break + action_2: + type: replant + value: + point: 0 + crop: tomato + model: customcrops:tomato_stage_1 # grow conditions grow-conditions: diff --git a/src/main/resources/contents/fertilizers/quality.yml b/src/main/resources/contents/fertilizers/quality.yml index e380f85..2fd1a03 100644 --- a/src/main/resources/contents/fertilizers/quality.yml +++ b/src/main/resources/contents/fertilizers/quality.yml @@ -1,6 +1,6 @@ quality_1: type: QUALITY - name: '뀆' + icon: '뀆' chance: 1 times: 28 ratio: 7/2/1 @@ -12,7 +12,7 @@ quality_1: - default quality_2: type: QUALITY - name: '뀇' + icon: '뀇' chance: 1 times: 28 ratio: 11/6/3 @@ -24,7 +24,7 @@ quality_2: - default quality_3: type: QUALITY - name: '뀈' + icon: '뀈' chance: 1 times: 28 ratio: 2/2/1 diff --git a/src/main/resources/contents/fertilizers/soil-retain.yml b/src/main/resources/contents/fertilizers/soil-retain.yml index fb62127..990659e 100644 --- a/src/main/resources/contents/fertilizers/soil-retain.yml +++ b/src/main/resources/contents/fertilizers/soil-retain.yml @@ -1,6 +1,6 @@ soil_retain_1: type: SOIL_RETAIN - name: '뀉' + icon: '뀉' chance: 0.1 times: 28 item: customcrops:soil_retain_1 @@ -11,7 +11,7 @@ soil_retain_1: - default soil_retain_2: type: SOIL_RETAIN - name: '뀊' + icon: '뀊' chance: 0.2 times: 28 item: customcrops:soil_retain_2 @@ -22,7 +22,7 @@ soil_retain_2: - default soil_retain_3: type: SOIL_RETAIN - name: '뀋' + icon: '뀋' chance: 0.3 times: 28 item: customcrops:soil_retain_3 diff --git a/src/main/resources/contents/fertilizers/speed-grow.yml b/src/main/resources/contents/fertilizers/speed-grow.yml index 641c8db..fabe12c 100644 --- a/src/main/resources/contents/fertilizers/speed-grow.yml +++ b/src/main/resources/contents/fertilizers/speed-grow.yml @@ -1,7 +1,7 @@ speed_grow_1: type: SPEED_GROW # Fertilizer Hologram display name - name: '뀌' + icon: '뀌' # How many days can this fertilizer stay in pot times: 14 # ItemsAdder item namespacedID @@ -18,7 +18,7 @@ speed_grow_1: 1: 0.5 speed_grow_2: type: SPEED_GROW - name: '뀍' + icon: '뀍' times: 14 item: customcrops:speed_grow_2 before-plant: true @@ -30,7 +30,7 @@ speed_grow_2: 1: 0.9 speed_grow_3: type: SPEED_GROW - name: '뀎' + icon: '뀎' times: 14 item: customcrops:speed_grow_3 before-plant: true diff --git a/src/main/resources/contents/fertilizers/variation.yml b/src/main/resources/contents/fertilizers/variation.yml index 50c37ea..fa97abd 100644 --- a/src/main/resources/contents/fertilizers/variation.yml +++ b/src/main/resources/contents/fertilizers/variation.yml @@ -1,6 +1,6 @@ variation_1: type: VARIATION - name: '뀒' + icon: '뀒' times: 14 # If a crop's default variation chance is 0.01, now it's 0.03 chance: 0.02 @@ -12,7 +12,7 @@ variation_1: - default variation_2: type: VARIATION - name: '뀓' + icon: '뀓' times: 14 chance: 0.04 item: customcrops:variation_2 @@ -23,7 +23,7 @@ variation_2: - default variation_3: type: VARIATION - name: '뀔' + icon: '뀔' times: 14 chance: 0.08 item: customcrops:variation_3 diff --git a/src/main/resources/contents/fertilizers/yield-increase.yml b/src/main/resources/contents/fertilizers/yield-increase.yml index 2d8e22a..ed0ed59 100644 --- a/src/main/resources/contents/fertilizers/yield-increase.yml +++ b/src/main/resources/contents/fertilizers/yield-increase.yml @@ -1,6 +1,6 @@ yield_increase_1: type: YIELD_INCREASE - name: '뀏' + icon: '뀏' times: 14 item: customcrops:yield_increase_1 before-plant: true @@ -14,7 +14,7 @@ yield_increase_1: 1: 0.8 yield_increase_2: type: YIELD_INCREASE - name: '뀐' + icon: '뀐' times: 14 item: customcrops:yield_increase_2 before-plant: true @@ -28,7 +28,7 @@ yield_increase_2: 1: 1 yield_increase_3: type: YIELD_INCREASE - name: '뀑' + icon: '뀑' times: 14 item: customcrops:yield_increase_3 before-plant: true diff --git a/src/main/resources/contents/pots/default.yml b/src/main/resources/contents/pots/default.yml index 43bd698..4260e7a 100644 --- a/src/main/resources/contents/pots/default.yml +++ b/src/main/resources/contents/pots/default.yml @@ -1,5 +1,5 @@ default: - max-water-storage: 10 + max-water-storage: 4 base: # basic models dry: customcrops:dry_pot @@ -45,4 +45,21 @@ default: item: customcrops:magic_water amount: 10 particle: WATER_SPLASH - sound: minecraft:block.water.ambient \ No newline at end of file + sound: minecraft:block.water.ambient + hologram: + enable: true + # ARMOR_STAND / TEXT_DISPLAY (1.19.4+) + type: ARMOR_STAND + duration: 2 + fertilizer: + vertical-offset: 0.8 + text: '{icon} {left_times}/{max_times}' + water: + vertical-offset: 1.05 + text: '{water_bar}' + #text: '{current}/{storage}' + water-bar: + left: '뀂' + full: '뀁뀃' + empty: '뀁뀄' + right: '뀁뀅' \ No newline at end of file diff --git a/src/main/resources/contents/sprinklers/default.yml b/src/main/resources/contents/sprinklers/default.yml index 0b967e9..044759e 100644 --- a/src/main/resources/contents/sprinklers/default.yml +++ b/src/main/resources/contents/sprinklers/default.yml @@ -5,26 +5,31 @@ sprinkler_1: storage: 5 3D-item: customcrops:sprinkler_1 2D-item: customcrops:sprinkler_1_item - # Item_Frame / Item_Display / Tripwire + # Item_Frame / Tripwire / Item_Display (1.19.4+) type: Item_Frame place-sound: minecraft:block.bone_block.place hologram: enable: true + # ARMOR_STAND / TEXT_DISPLAY (1.19.4+) + type: ARMOR_STAND y-offset: 0.8 duration: 1 # Available variables: + # {water_bar} water bar image # {current} current water # {storage} max storage - left: '뀂' - full: '뀁뀃' - empty: '뀁뀄' - right: '뀁뀅' + content: '{water_bar}' + water-bar: + left: '뀂' + full: '뀁뀃' + empty: '뀁뀄' + right: '뀁뀅' # Water splash animation when sprinkler works sprinkler-animation: enable: true y-offset: 0.4 item: customcrops:water_animation - # ARMOR_STAND / ITEM_DISPLAY + # ARMOR_STAND / ITEM_DISPLAY (1.19.4+) type: ARMOR_STAND pot-whitelist: - default @@ -52,12 +57,15 @@ sprinkler_2: place-sound: minecraft:block.bone_block.place hologram: enable: true + type: ARMOR_STAND y-offset: 0.8 duration: 1 - left: '뀂' - full: '뀁뀃' - empty: '뀁뀄' - right: '뀁뀅' + content: '{water_bar}' + water-bar: + left: '뀂' + full: '뀁뀃' + empty: '뀁뀄' + right: '뀁뀅' sprinkler-animation: enable: true y-offset: 0.4 @@ -88,12 +96,15 @@ sprinkler_3: place-sound: minecraft:block.bone_block.place hologram: enable: true + type: ARMOR_STAND y-offset: 0.8 duration: 1 - left: '뀂' - full: '뀁뀃' - empty: '뀁뀄' - right: '뀁뀅' + content: '{water_bar}' + water-bar: + left: '뀂' + full: '뀁뀃' + empty: '뀁뀄' + right: '뀁뀅' sprinkler-animation: enable: true y-offset: 0.4 diff --git a/src/main/resources/messages/messages_english.yml b/src/main/resources/messages/messages_english.yml index 518f036..8751de7 100644 --- a/src/main/resources/messages/messages_english.yml +++ b/src/main/resources/messages/messages_english.yml @@ -1,20 +1,21 @@ -prefix: '[CustomCrops] ' -reload: 'Reloaded! Took {time}ms.' -invalid-args: 'Invalid arguments.' -no-console: 'This command can only be executed by a player.' -not-online: 'Player {player} is not online.' -lack-args: 'Arguments are insufficient.' -not-none-args: 'Not a none argument command.' -before-plant: 'This fertilizer must be used before planting!' -unsuitable-pot: "You can't plant the seed in this pot." -reach-crop-limit: 'The number of crops has reached the limitation.' -no-perm: "You don't have permission to do that." -spring: 'Spring' -summer: 'Summer' -autumn: 'Autumn' -winter: 'Winter' -no-season: 'SEASON DISABLED IN THIS WORLD' -set-season: "Successfully set {world}'s season to {season}." -set-date: "Successfully set {world}'s date to {date}." -world-not-exist: 'World {world} does not exist.' -season-not-exist: 'Season {season} does not exist.' \ No newline at end of file +messages: + prefix: '[CustomCrops] ' + reload: 'Reloaded! Took {time}ms.' + invalid-args: 'Invalid arguments.' + no-console: 'This command can only be executed by a player.' + not-online: 'Player {player} is not online.' + lack-args: 'Arguments are insufficient.' + not-none-args: 'Not a none argument command.' + before-plant: 'This fertilizer must be used before planting!' + unsuitable-pot: "You can't plant the seed in this pot." + reach-crop-limit: 'The number of crops has reached the limitation.' + no-perm: "You don't have permission to do that." + spring: 'Spring' + summer: 'Summer' + autumn: 'Autumn' + winter: 'Winter' + no-season: 'SEASON DISABLED IN THIS WORLD' + set-season: "Successfully set {world}'s season to {season}." + set-date: "Successfully set {world}'s date to {date}." + world-not-exist: 'World {world} does not exist.' + season-not-exist: 'Season {season} does not exist.' \ No newline at end of file