diff --git a/api/src/main/java/net/momirealms/customcrops/api/common/item/EventItem.java b/api/src/main/java/net/momirealms/customcrops/api/common/item/EventItem.java index 8ef98ab..c6a3ad0 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/common/item/EventItem.java +++ b/api/src/main/java/net/momirealms/customcrops/api/common/item/EventItem.java @@ -29,5 +29,4 @@ public interface EventItem { * @param state state */ void trigger(ActionTrigger actionTrigger, State state); - } diff --git a/api/src/main/java/net/momirealms/customcrops/api/manager/ItemManager.java b/api/src/main/java/net/momirealms/customcrops/api/manager/ItemManager.java index 4aa5db6..d0e7d16 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/manager/ItemManager.java +++ b/api/src/main/java/net/momirealms/customcrops/api/manager/ItemManager.java @@ -101,6 +101,14 @@ public interface ItemManager extends Reloadable { */ CRotation removeAnythingAt(Location location); + /** + * Get the rotation of the removed entity + * + * @param location location + * @return rotation + */ + CRotation getRotation(Location location); + /** * Get watering can config by ID * diff --git a/api/src/main/java/net/momirealms/customcrops/api/manager/WorldManager.java b/api/src/main/java/net/momirealms/customcrops/api/manager/WorldManager.java index 73133e6..edff0c5 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/manager/WorldManager.java +++ b/api/src/main/java/net/momirealms/customcrops/api/manager/WorldManager.java @@ -323,35 +323,40 @@ public interface WorldManager extends Reloadable { * * @param location location */ - void removeSprinklerAt(@NotNull SimpleLocation location); + @Nullable + WorldSprinkler removeSprinklerAt(@NotNull SimpleLocation location); /** * Remove pot data from a certain location * * @param location location */ - void removePotAt(@NotNull SimpleLocation location); + @Nullable + WorldPot removePotAt(@NotNull SimpleLocation location); /** * Remove crop data from a certain location * * @param location location */ - void removeCropAt(@NotNull SimpleLocation location); + @Nullable + WorldCrop removeCropAt(@NotNull SimpleLocation location); /** * Remove greenhouse glass data from a certain location * * @param location location */ - void removeGlassAt(@NotNull SimpleLocation location); + @Nullable + WorldGlass removeGlassAt(@NotNull SimpleLocation location); /** * Remove scarecrow data from a certain location * * @param location location */ - void removeScarecrowAt(@NotNull SimpleLocation location); + @Nullable + WorldScarecrow removeScarecrowAt(@NotNull SimpleLocation location); /** * If a certain type of item reached the limitation @@ -391,6 +396,12 @@ public interface WorldManager extends Reloadable { */ void saveRegionToFile(CustomCropsRegion region); + /** + * Remove any block data from a certain location + * + * @param location location + * @return block data + */ CustomCropsBlock removeAnythingAt(SimpleLocation location); /** diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/Action.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/Action.java index 860b7b5..fde774e 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/Action.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/Action.java @@ -21,5 +21,10 @@ import net.momirealms.customcrops.api.mechanic.requirement.State; public interface Action { - void trigger(State condition); + /** + * Trigger the action + * + * @param state the state of the player + */ + void trigger(State state); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/ActionExpansion.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/ActionExpansion.java index e349c7c..9f9f9a3 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/ActionExpansion.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/ActionExpansion.java @@ -19,11 +19,31 @@ package net.momirealms.customcrops.api.mechanic.action; public abstract class ActionExpansion { + /** + * Get the version number + * + * @return version + */ public abstract String getVersion(); + /** + * Get the author + * + * @return author + */ public abstract String getAuthor(); + /** + * Get the type of the action + * + * @return the type of the action + */ public abstract String getActionType(); + /** + * Get the action factory + * + * @return the action factory + */ public abstract ActionFactory getActionFactory(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/ActionFactory.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/ActionFactory.java index 61fa136..47389e4 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/ActionFactory.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/action/ActionFactory.java @@ -19,5 +19,12 @@ package net.momirealms.customcrops.api.mechanic.action; public interface ActionFactory { + /** + * Build an action by args and chance + * + * @param args args + * @param chance chance (0-1) + * @return action + */ Action build(Object args, double chance); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/Condition.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/Condition.java index fc9a96f..1f38f85 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/Condition.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/Condition.java @@ -21,5 +21,12 @@ import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock; public interface Condition { + /** + * If the block meets the conditions + * + * @param block block + * @param offline offline tick + * @return met or not + */ boolean isConditionMet(CustomCropsBlock block, boolean offline); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/ConditionExpansion.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/ConditionExpansion.java index 1f8691c..0ecde8a 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/ConditionExpansion.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/ConditionExpansion.java @@ -19,11 +19,31 @@ package net.momirealms.customcrops.api.mechanic.condition; public abstract class ConditionExpansion { + /** + * Get the version number + * + * @return version + */ public abstract String getVersion(); + /** + * Get the author + * + * @return author + */ public abstract String getAuthor(); + /** + * Get the type of the condition + * + * @return the type of the condition + */ public abstract String getConditionType(); + /** + * Get the condition factory + * + * @return the condition factory + */ public abstract ConditionFactory getConditionFactory(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/ConditionFactory.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/ConditionFactory.java index bde4c2a..97beece 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/ConditionFactory.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/ConditionFactory.java @@ -19,5 +19,11 @@ package net.momirealms.customcrops.api.mechanic.condition; public interface ConditionFactory { + /** + * Build a condition with the args + * + * @param args args + * @return condition + */ Condition build(Object args); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/Conditions.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/Conditions.java index e0f7c9a..aa38313 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/Conditions.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/Conditions.java @@ -8,6 +8,11 @@ public class Conditions { this.conditions = conditions; } + /** + * Get a list of conditions + * + * @return conditions + */ public Condition[] getConditions() { return conditions; } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/DeathConditions.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/DeathConditions.java index 501d2c0..7dcc29e 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/DeathConditions.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/condition/DeathConditions.java @@ -1,6 +1,7 @@ package net.momirealms.customcrops.api.mechanic.condition; import net.momirealms.customcrops.api.mechanic.item.ItemCarrier; +import org.jetbrains.annotations.Nullable; public class DeathConditions extends Conditions { @@ -15,14 +16,30 @@ public class DeathConditions extends Conditions { this.deathDelay = deathDelay; } + /** + * Get the item to replace, null if the crop would be removed + * + * @return the item to replace + */ + @Nullable public String getDeathItem() { return deathItem; } + /** + * Get the item carrier of the item to replace + * + * @return item carrier + */ public ItemCarrier getItemCarrier() { return itemCarrier; } + /** + * Get the delay in ticks + * + * @return delay + */ public int getDeathDelay() { return deathDelay; } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/BoneMeal.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/BoneMeal.java index 6839679..7883c7f 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/BoneMeal.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/BoneMeal.java @@ -52,14 +52,29 @@ public class BoneMeal { this.dispenserAllowed = dispenserAllowed; } + /** + * Get the ID of the bone meal item + * + * @return bonemeal item id + */ public String getItem() { return item; } + /** + * Get the returned item's ID + * + * @return returned item ID + */ public String getReturned() { return returned; } + /** + * Get the points to gain in one try + * + * @return points + */ public int getPoint() { for (Pair pair : pointGainList) { if (Math.random() < pair.left()) { @@ -69,18 +84,38 @@ public class BoneMeal { return 0; } + /** + * Trigger the actions of using the bone meal + * + * @param state player state + */ public void trigger(State state) { ActionManager.triggerActions(state, actions); } + /** + * Get the amount to consume + * + * @return amount to consume + */ public int getUsedAmount() { return usedAmount; } + /** + * Get the amount of the returned items + * + * @return amount of the returned items + */ public int getReturnedAmount() { return returnedAmount; } + /** + * If the bone meal can be used with a dispenser + * + * @return can be used or not + */ public boolean isDispenserAllowed() { return dispenserAllowed; } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Crop.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Crop.java index 29defa0..e378a98 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Crop.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Crop.java @@ -23,6 +23,7 @@ import net.momirealms.customcrops.api.mechanic.condition.Conditions; import net.momirealms.customcrops.api.mechanic.condition.DeathConditions; import net.momirealms.customcrops.api.mechanic.requirement.Requirement; import net.momirealms.customcrops.api.mechanic.requirement.State; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -30,50 +31,169 @@ import java.util.HashSet; public interface Crop extends KeyItem { + /** + * Get the id of the seed + * + * @return seed ID + */ String getSeedItemID(); + /** + * Get the max points to grow + * + * @return max points + */ int getMaxPoints(); + /** + * Get the requirements for planting + * + * @return requirements for planting + */ Requirement[] getPlantRequirements(); + /** + * Get the requirements for breaking + * + * @return requirements for breaking + */ Requirement[] getBreakRequirements(); + /** + * Get the requirements for interactions + * + * @return requirements for interactions + */ Requirement[] getInteractRequirements(); + /** + * Get the conditions to grow + * + * @return conditions to grow + */ Conditions getGrowConditions(); + /** + * Get the conditions of death + * + * @return conditions of death + */ DeathConditions[] getDeathConditions(); + /** + * Get the available bone meals + * + * @return bone meals + */ BoneMeal[] getBoneMeals(); + /** + * If the crop has rotations + */ boolean hasRotation(); + /** + * Trigger actions + * + * @param trigger action trigger + * @param state player state + */ void trigger(ActionTrigger trigger, State state); + /** + * Get the stage config by point + * + * @param point point + * @return stage config + */ + @Nullable Stage getStageByPoint(int point); + /** + * Get the stage item ID by point + * This is always NotNull if the point is no lower than 0 + * + * @param point point + * @return the stage item ID + */ + @NotNull String getStageItemByPoint(int point); - Stage getStageByItemID(String itemID); + /** + * Get stage config by stage item ID + * + * @param id item id + * @return stage config + */ + @Nullable + Stage getStageByItemID(String id); + /** + * Get all the stages + * + * @return stages + */ Collection getStages(); + /** + * Get the pots to plant + * + * @return whitelisted pots + */ HashSet getPotWhitelist(); + /** + * Get the carrier of this crop + * + * @return carrier of this crop + */ ItemCarrier getItemCarrier(); interface Stage { + /** + * Get the offset of the hologram + * + * @return offset + */ double getHologramOffset(); - @Nullable String getStageID(); + /** + * Get the stage item ID + * This can be null if this point doesn't have any state change + * + * @return stage item ID + */ + @Nullable + String getStageID(); + /** + * Get the point of this stage + * + * @return point + */ int getPoint(); + /** + * Trigger actions + * + * @param trigger action trigger + * @param state player state + */ void trigger(ActionTrigger trigger, State state); + /** + * Get the requirements for interactions + * + * @return requirements for interactions + */ Requirement[] getInteractRequirements(); + /** + * Get the requirements for breaking + * + * @return requirements for breaking + */ Requirement[] getBreakRequirements(); } } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Fertilizer.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Fertilizer.java index 3e44779..17d50c7 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Fertilizer.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Fertilizer.java @@ -23,19 +23,58 @@ import net.momirealms.customcrops.api.mechanic.requirement.Requirement; import java.util.HashSet; public interface Fertilizer extends EventItem { + + /** + * Get the key + * + * @return key + */ String getKey(); + /** + * Get the item ID + * + * @return item ID + */ String getItemID(); + /** + * Get the max times of usage + * + * @return the max times of usage + */ int getTimes(); + /** + * Get the type of the fertilizer + * + * @return the type of the fertilizer + */ FertilizerType getFertilizerType(); + /** + * Get the pot whitelist + * + * @return pot whitelist + */ HashSet getPotWhitelist(); + /** + * If the fertilizer can only be used before planting + */ boolean isBeforePlant(); + /** + * Get the image of the fertilizer + * + * @return icon + */ String getIcon(); + /** + * Get the requirements for this fertilizer + * + * @return requirements + */ Requirement[] getRequirements(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Pot.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Pot.java index df0513c..973c5e0 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Pot.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Pot.java @@ -28,34 +28,110 @@ import java.util.HashSet; public interface Pot extends KeyItem { + /** + * Get max water storage + * + * @return water storage + */ int getStorage(); + /** + * Get the key + * + * @return key + */ String getKey(); + /** + * Get the blocks that belong to this pot + * + * @return blocks + */ HashSet getPotBlocks(); + /** + * Get the methods to fill this pot + * + * @return methods + */ PassiveFillMethod[] getPassiveFillMethods(); + /** + * Get the dry state + * + * @return dry state item ID + */ String getDryItem(); + /** + * Get the wet state + * + * @return wet state item ID + */ String getWetItem(); + /** + * Get the requirements for placement + * + * @return requirements for placement + */ Requirement[] getPlaceRequirements(); + /** + * Get the requirements for breaking + * + * @return requirements for breaking + */ Requirement[] getBreakRequirements(); + /** + * Get the requirements for using + * + * @return requirements for using + */ Requirement[] getUseRequirements(); + /** + * Trigger actions + * + * @param trigger action trigger + * @param state player state + */ void trigger(ActionTrigger trigger, State state); + /** + * Get the water bar images + * + * @return water bar images + */ WaterBar getWaterBar(); + /** + * Does the pot absorb raindrop + */ boolean isRainDropAccepted(); + + /** + * Does nearby water make the pot wet + */ boolean isNearbyWaterAccepted(); + /** + * Get the block ID by water and fertilizers + * + * @param water water + * @param type the type of the fertilizer + * @return block item ID + */ String getBlockState(boolean water, FertilizerType type); + /** + * Is the pot a vanilla blocks + */ boolean isVanillaBlock(); + /** + * Is the id a wet pot + */ boolean isWetPot(String id); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Scarecrow.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Scarecrow.java index cc4d33f..e9667aa 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Scarecrow.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Scarecrow.java @@ -21,5 +21,10 @@ import net.momirealms.customcrops.api.common.item.KeyItem; public interface Scarecrow extends KeyItem { + /** + * Get the item ID + * + * @return item ID + */ String getItemID(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Sprinkler.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Sprinkler.java index addf6d5..f34148a 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Sprinkler.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/Sprinkler.java @@ -28,33 +28,107 @@ import java.util.HashSet; public interface Sprinkler extends KeyItem { + /** + * Get the 2D item ID + * + * @return 2D item ID + */ String get2DItemID(); + /** + * Get the 3D item ID + * + * @return 3D item ID + */ String get3DItemID(); + /** + * Get the 3D item ID (With water inside) + * + * @return 3D item ID (With water inside) + */ String get3DItemWithWater(); + /** + * Get the max storage of water + * + * @return max storage of water + */ int getStorage(); + /** + * Get the working range + * + * @return working range + */ int getRange(); + /** + * Is water infinite + */ boolean isInfinite(); + /** + * Get the amount of water to add to the pot during sprinkling + * + * @return amount of water to add to the pot during sprinkling + */ int getWater(); + /** + * Get the pots that receive the water + * + * @return whitelisted pots + */ HashSet getPotWhitelist(); + /** + * Get the carrier of the pot + * + * @return carrier of the pot + */ ItemCarrier getItemCarrier(); + /** + * Get methods to fill the sprinkler + * + * @return methods to fill the sprinkler + */ PassiveFillMethod[] getPassiveFillMethods(); + /** + * Get the requirements for placement + * + * @return requirements for placement + */ Requirement[] getPlaceRequirements(); + /** + * Get the requirements for breaking + * + * @return requirements for breaking + */ Requirement[] getBreakRequirements(); + /** + * Get the requirements for using + * + * @return requirements for using + */ Requirement[] getUseRequirements(); + /** + * Trigger actions + * + * @param trigger action trigger + * @param state player state + */ void trigger(ActionTrigger trigger, State state); + /** + * Get the water bar images + * + * @return water bar images + */ WaterBar getWaterBar(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/WateringCan.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/WateringCan.java index 645eda5..fccad50 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/WateringCan.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/WateringCan.java @@ -32,33 +32,107 @@ import java.util.Map; public interface WateringCan extends KeyItem { + /** + * Get the ID of the item + * + * @return item ID + */ String getItemID(); + /** + * Get the width of the effective range + * + * @return width + */ int getWidth(); + /** + * Get the length of the effective range + * + * @return length + */ int getLength(); + /** + * Get the storage of water + * + * @return storage of water + */ int getStorage(); + /** + * Get the amount of water to add in one try + */ int getWater(); + /** + * If the watering can has dynamic lore + */ boolean hasDynamicLore(); + /** + * Update a watering can's data + * + * @param player player + * @param itemStack watering can item + * @param water the amount of water + * @param args the placeholders + */ void updateItem(Player player, ItemStack itemStack, int water, Map args); + /** + * Get the current water + * + * @param itemStack watering can item + * @return current water + */ int getCurrentWater(ItemStack itemStack); + /** + * Get the pots that receive water from this watering can + * + * @return whitelisted pots + */ HashSet getPotWhitelist(); + /** + * Get the sprinklers that receive water from this watering can + * + * @return whitelisted sprinklers + */ HashSet getSprinklerWhitelist(); + /** + * Get the dynamic lores + * + * @return dynamic lores + */ List getLore(); + /** + * Get the water bar images + * + * @return water bar images + */ @Nullable WaterBar getWaterBar(); + /** + * Get the requirements for using this watering can + * + * @return requirements + */ Requirement[] getRequirements(); + /** + * If the water is infinite + */ boolean isInfinite(); + /** + * Trigger actions + * + * @param trigger action trigger + * @param state player state + */ void trigger(ActionTrigger trigger, State state); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/QualityCrop.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/QualityCrop.java index d50b9b0..53004bf 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/QualityCrop.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/QualityCrop.java @@ -20,7 +20,18 @@ package net.momirealms.customcrops.api.mechanic.item.fertilizer; import net.momirealms.customcrops.api.mechanic.item.Fertilizer; public interface QualityCrop extends Fertilizer { + + /** + * Get the chance of taking effect + * + * @return chance + */ double getChance(); + /** + * Get the modified quality ratio + * + * @return the modified quality ratio + */ double[] getRatio(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/SoilRetain.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/SoilRetain.java index aa01a20..0071623 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/SoilRetain.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/SoilRetain.java @@ -21,5 +21,10 @@ import net.momirealms.customcrops.api.mechanic.item.Fertilizer; public interface SoilRetain extends Fertilizer { + /** + * Get the chance of taking effect + * + * @return chance + */ double getChance(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/SpeedGrow.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/SpeedGrow.java index 23c0ec2..28a20b1 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/SpeedGrow.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/SpeedGrow.java @@ -21,5 +21,10 @@ import net.momirealms.customcrops.api.mechanic.item.Fertilizer; public interface SpeedGrow extends Fertilizer { + /** + * Get the extra points to gain + * + * @return points + */ int getPointBonus(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/Variation.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/Variation.java index 727c62d..b11e32b 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/Variation.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/Variation.java @@ -21,5 +21,10 @@ import net.momirealms.customcrops.api.mechanic.item.Fertilizer; public interface Variation extends Fertilizer { + /** + * Get the bonus of variation chance + * + * @return chance bonus + */ double getChanceBonus(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/YieldIncrease.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/YieldIncrease.java index cae5804..fbdfc51 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/YieldIncrease.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/fertilizer/YieldIncrease.java @@ -21,5 +21,10 @@ import net.momirealms.customcrops.api.mechanic.item.Fertilizer; public interface YieldIncrease extends Fertilizer { + /** + * Get the extra amount to drop + * + * @return amount bonus + */ int getAmountBonus(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/water/PassiveFillMethod.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/water/PassiveFillMethod.java index 54f4c44..adbef45 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/water/PassiveFillMethod.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/water/PassiveFillMethod.java @@ -36,18 +36,38 @@ public class PassiveFillMethod extends AbstractFillMethod { this.returnedAmount = returnedAmount; } + /** + * Get the consumed item ID + * + * @return consumed item ID + */ public String getUsed() { return used; } + /** + * Get the returned item ID + * + * @return returned item ID + */ public String getReturned() { return returned; } + /** + * Get the amount to consume + * + * @return amount to consume + */ public int getUsedAmount() { return usedAmount; } + /** + * Get the amount of the returned items + * + * @return amount of the returned items + */ public int getReturnedAmount() { return returnedAmount; } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/water/PositiveFillMethod.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/water/PositiveFillMethod.java index 8d91b8f..df621f4 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/water/PositiveFillMethod.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/water/PositiveFillMethod.java @@ -29,7 +29,12 @@ public class PositiveFillMethod extends AbstractFillMethod { this.id = id; } - public String getId() { + /** + * Get the block/furniture ID + * + * @return id + */ + public String getID() { return id; } } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/CRotation.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/CRotation.java index 69f25e6..1e1fc4c 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/CRotation.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/CRotation.java @@ -1,5 +1,7 @@ package net.momirealms.customcrops.api.mechanic.misc; +import org.bukkit.Rotation; + public enum CRotation { NONE(0f), @@ -18,4 +20,39 @@ public enum CRotation { public float getYaw() { return yaw; } + + public static CRotation getByRotation(Rotation rotation) { + switch (rotation) { + default -> { + return CRotation.NONE; + } + case CLOCKWISE -> { + return CRotation.WEST; + } + case COUNTER_CLOCKWISE -> { + return CRotation.EAST; + } + case FLIPPED -> { + return CRotation.NORTH; + } + } + } + + public static CRotation getByYaw(float yaw) { + yaw = (Math.abs(yaw + 180) % 360); + switch ((int) (yaw/90)) { + case 1 -> { + return CRotation.WEST; + } + case 2 -> { + return CRotation.NORTH; + } + case 3 -> { + return CRotation.EAST; + } + default -> { + return CRotation.SOUTH; + } + } + } } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/Value.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/Value.java index 503ba16..48e1802 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/Value.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/Value.java @@ -21,5 +21,11 @@ import org.bukkit.entity.Player; public interface Value { + /** + * Get double value + * + * @param player player + * @return the value + */ double get(Player player); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/Requirement.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/Requirement.java index e708478..e92876c 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/Requirement.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/Requirement.java @@ -19,5 +19,11 @@ package net.momirealms.customcrops.api.mechanic.requirement; public interface Requirement { + /** + * Does player meet the requirement + * + * @param state state of player + * @return met or not + */ boolean isStateMet(State state); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/RequirementExpansion.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/RequirementExpansion.java index 9f9972f..0b70b6a 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/RequirementExpansion.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/RequirementExpansion.java @@ -19,11 +19,31 @@ package net.momirealms.customcrops.api.mechanic.requirement; public abstract class RequirementExpansion { + /** + * Get the version number + * + * @return version + */ public abstract String getVersion(); + /** + * Get the author + * + * @return author + */ public abstract String getAuthor(); + /** + * Get the type of the requirement + * + * @return the type of the requirement + */ public abstract String getRequirementType(); + /** + * Get the requirement factory + * + * @return the requirement factory + */ public abstract RequirementFactory getRequirementFactory(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/RequirementFactory.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/RequirementFactory.java index cf429ec..4fa5eec 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/RequirementFactory.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/requirement/RequirementFactory.java @@ -23,8 +23,22 @@ import java.util.List; public interface RequirementFactory { + /** + * Build a requirement + * + * @param args args + * @param notMetActions actions to perform if the requirement is not met + * @param advanced whether to trigger the notMetActions or not + * @return requirement + */ Requirement build(Object args, List notMetActions, boolean advanced); + /** + * Build a requirement + * + * @param args args + * @return requirement + */ default Requirement build(Object args) { return build(args, null, false); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/CustomCropsBlock.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/CustomCropsBlock.java index 2f2fa6f..1aae7f8 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/CustomCropsBlock.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/CustomCropsBlock.java @@ -22,5 +22,10 @@ import net.momirealms.customcrops.api.mechanic.world.level.DataBlock; public interface CustomCropsBlock extends DataBlock, Tickable { + /** + * Get the type of the item + * + * @return type of the item + */ ItemType getType(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/Tickable.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/Tickable.java index db95766..031d045 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/Tickable.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/Tickable.java @@ -2,5 +2,11 @@ package net.momirealms.customcrops.api.mechanic.world; public interface Tickable { + /** + * Tick + * + * @param interval interval + * @param offline offline tick + */ void tick(int interval, boolean offline); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/AbstractCustomCropsBlock.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/AbstractCustomCropsBlock.java index 23ad475..56b0b7a 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/AbstractCustomCropsBlock.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/AbstractCustomCropsBlock.java @@ -33,26 +33,55 @@ public class AbstractCustomCropsBlock implements DataBlock { this.location = location; } + /** + * Set data by key + * + * @param key key + * @param tag data tag + */ @Override public void setData(String key, Tag tag) { compoundMap.put(key, tag); } + /** + * Get data tag by key + * + * @param key key + * @return data tag + */ @Override - public Tag getData(String name) { - return compoundMap.get(name); + public Tag getData(String key) { + return compoundMap.get(key); } + /** + * Get the data map + * + * @return data map + */ @Override public SynchronizedCompoundMap getCompoundMap() { return compoundMap; } + /** + * Get the location of the block + * + * @return location + */ @Override public SimpleLocation getLocation() { return location; } + /** + * interval is customized + * You can perform tick logics if the block is ticked for some times + * + * @param interval interval + * @return can be ticked or not + */ public boolean canTick(int interval) { if (interval == 1) { return true; diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsChunk.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsChunk.java index 1ac3812..93b7457 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsChunk.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsChunk.java @@ -24,84 +24,310 @@ import net.momirealms.customcrops.api.mechanic.item.Sprinkler; import net.momirealms.customcrops.api.mechanic.world.ChunkPos; import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock; import net.momirealms.customcrops.api.mechanic.world.SimpleLocation; +import org.jetbrains.annotations.Nullable; import java.util.Optional; public interface CustomCropsChunk { + /** + * Calculate the unload time and perform compensation + * This method can only be called in a loaded chunk + */ void notifyOfflineUpdates(); + /** + * Get the world associated with the chunk + * + * @return CustomCrops world + */ CustomCropsWorld getCustomCropsWorld(); + /** + * Get the region associated with the chunk + * + * @return CustomCrops region + */ CustomCropsRegion getCustomCropsRegion(); + /** + * Get the position of the chunk + * + * @return chunk position + */ ChunkPos getChunkPos(); + /** + * Do second timer + */ void secondTimer(); - long getLastLoadedTime(); - - int getLoadedSeconds(); - - Optional getCropAt(SimpleLocation location); - - Optional getSprinklerAt(SimpleLocation location); - - Optional getPotAt(SimpleLocation location); - - Optional getGlassAt(SimpleLocation location); - - Optional getScarecrowAt(SimpleLocation location); - - Optional getBlockAt(SimpleLocation location); - - void addWaterToSprinkler(Sprinkler sprinkler, SimpleLocation location, int amount); - - void addFertilizerToPot(Pot pot, Fertilizer fertilizer, SimpleLocation location); - - void addWaterToPot(Pot pot, SimpleLocation location, int amount); - - void removeSprinklerAt(SimpleLocation location); - - void removePotAt(SimpleLocation location); - - void removeCropAt(SimpleLocation location); - - void removeGlassAt(SimpleLocation location); - - void removeScarecrowAt(SimpleLocation location); - - CustomCropsBlock removeBlockAt(SimpleLocation location); - - CustomCropsBlock addBlockAt(CustomCropsBlock block, SimpleLocation location); - - int getCropAmount(); - - int getPotAmount(); - - int getSprinklerAmount(); - - void addPotAt(WorldPot pot, SimpleLocation location); - - void addSprinklerAt(WorldSprinkler sprinkler, SimpleLocation location); - - void addCropAt(WorldCrop crop, SimpleLocation location); - - void addPointToCrop(Crop crop, SimpleLocation location, int points); - - void addGlassAt(WorldGlass glass, SimpleLocation location); - - void addScarecrowAt(WorldScarecrow scarecrow, SimpleLocation location); - - void updateLastLoadedTime(); - - CustomCropsSection[] getSections(); - - CustomCropsSection getSection(int sectionID); - + /** + * Get the unloaded time in seconds + * This value would increase if the chunk is lazy + * + * @return the unloaded time + */ int getUnloadedSeconds(); + /** + * Set the unloaded seconds + * + * @param unloadedSeconds unloadedSeconds + */ void setUnloadedSeconds(int unloadedSeconds); + /** + * Get the last loaded time + * + * @return last loaded time + */ + long getLastLoadedTime(); + + /** + * Set the last loaded time to latest + */ + void updateLastLoadedTime(); + + /** + * Get the loaded time in seconds + * + * @return loaded time + */ + int getLoadedSeconds(); + + /** + * Get crop at a certain location + * + * @param location location + * @return crop data + */ + Optional getCropAt(SimpleLocation location); + + /** + * Get sprinkler at a certain location + * + * @param location location + * @return sprinkler data + */ + Optional getSprinklerAt(SimpleLocation location); + + /** + * Get pot at a certain location + * + * @param location location + * @return pot data + */ + Optional getPotAt(SimpleLocation location); + + /** + * Get greenhouse glass at a certain location + * + * @param location location + * @return greenhouse glass data + */ + Optional getGlassAt(SimpleLocation location); + + /** + * Get scarecrow at a certain location + * + * @param location location + * @return scarecrow data + */ + Optional getScarecrowAt(SimpleLocation location); + + /** + * Get block data at a certain location + * + * @param location location + * @return block data + */ + Optional getBlockAt(SimpleLocation location); + + /** + * Add water to the sprinkler + * This method would create new sprinkler data if the sprinkler data not exists in that place + * This method would also update the sprinkler's model if it has models according to the water amount + * + * @param sprinkler sprinkler config + * @param amount amount of water + * @param location location + */ + void addWaterToSprinkler(Sprinkler sprinkler, int amount, SimpleLocation location); + + /** + * Add fertilizer to the pot + * This method would create new pot data if the pot data not exists in that place + * This method would update the pot's block state if it has appearance variations for different fertilizers + * + * @param pot pot config + * @param fertilizer fertilizer config + * @param location location + */ + void addFertilizerToPot(Pot pot, Fertilizer fertilizer, SimpleLocation location); + + /** + * Add water to the pot + * This method would create new pot data if the pot data not exists in that place + * This method would update the pot's block state if it's dry + * + * @param pot pot config + * @param amount amount of water + * @param location location + */ + void addWaterToPot(Pot pot, int amount, SimpleLocation location); + + /** + * Add points to a crop + * This method would do nothing if the crop data not exists in that place + * This method would change the stage of the crop and trigger the actions + * + * @param crop crop config + * @param points points to add + * @param location location + */ + void addPointToCrop(Crop crop, int points, SimpleLocation location); + + /** + * Remove sprinkler data from a certain location + * + * @param location location + */ + @Nullable + WorldSprinkler removeSprinklerAt(SimpleLocation location); + + /** + * Remove pot data from a certain location + * + * @param location location + */ + @Nullable + WorldPot removePotAt(SimpleLocation location); + + /** + * Remove crop data from a certain location + * + * @param location location + */ + @Nullable + WorldCrop removeCropAt(SimpleLocation location); + + /** + * Remove greenhouse glass data from a certain location + * + * @param location location + */ + @Nullable + WorldGlass removeGlassAt(SimpleLocation location); + + /** + * Remove scarecrow data from a certain location + * + * @param location location + */ + @Nullable + WorldScarecrow removeScarecrowAt(SimpleLocation location); + + /** + * Remove any block data from a certain location + * + * @param location location + * @return block data + */ + @Nullable + CustomCropsBlock removeBlockAt(SimpleLocation location); + + /** + * Add a custom block data at a certain location + * + * @param block block data + * @param location location + * @return the previous block data + */ + @Nullable + CustomCropsBlock addBlockAt(CustomCropsBlock block, SimpleLocation location); + + /** + * Get the amount of crops in this chunk + * + * @return the amount of crops + */ + int getCropAmount(); + + /** + * Get the amount of pots in this chunk + * + * @return the amount of pots + */ + int getPotAmount(); + + /** + * Get the amount of sprinklers in this chunk + * + * @return the amount of sprinklers + */ + int getSprinklerAmount(); + + /** + * Add pot data + * + * @param pot pot data + * @param location location + */ + void addPotAt(WorldPot pot, SimpleLocation location); + + /** + * Add sprinkler data + * + * @param sprinkler sprinkler data + * @param location location + */ + void addSprinklerAt(WorldSprinkler sprinkler, SimpleLocation location); + + /** + * Add crop data + * + * @param crop crop data + * @param location location + */ + void addCropAt(WorldCrop crop, SimpleLocation location); + + /** + * Add greenhouse glass data + * + * @param glass glass data + * @param location location + */ + void addGlassAt(WorldGlass glass, SimpleLocation location); + + /** + * Add scarecrow data + * + * @param scarecrow scarecrow data + * @param location location + */ + void addScarecrowAt(WorldScarecrow scarecrow, SimpleLocation location); + + /** + * Get CustomCrops sections + * + * @return sections + */ + CustomCropsSection[] getSections(); + + /** + * Get section by ID + * + * @param sectionID id + * @return section + */ + @Nullable + CustomCropsSection getSection(int sectionID); + + /** + * If the chunk can be pruned + * + * @return can be pruned or not + */ boolean canPrune(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsRegion.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsRegion.java index 2825419..9852347 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsRegion.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsRegion.java @@ -25,17 +25,52 @@ import java.util.Map; public interface CustomCropsRegion { + /** + * Get the CustomCrops world associated with the region + * + * @return CustomCrops world + */ CustomCropsWorld getCustomCropsWorld(); + /** + * Get the cached chunk + * + * @param pos chunk position + * @return cached chunk in bytes + */ byte @Nullable [] getChunkBytes(ChunkPos pos); + /** + * Get the position of the region + * + * @return the position of the region + */ RegionPos getRegionPos(); + /** + * Remove a chunk by the position + * + * @param pos the position of the chunk + */ void removeChunk(ChunkPos pos); + /** + * Put a chunk's data to cache + * + * @param pos the position of the chunk + * @param data the serialized data + */ void saveChunk(ChunkPos pos, byte[] data); + /** + * Get the data to save + * + * @return the data to save + */ Map getRegionDataToSave(); + /** + * If the region can be pruned or not + */ boolean canPrune(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsSection.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsSection.java index 848440a..d2fff01 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsSection.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsSection.java @@ -19,22 +19,63 @@ package net.momirealms.customcrops.api.mechanic.world.level; import net.momirealms.customcrops.api.mechanic.world.BlockPos; import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock; +import org.jetbrains.annotations.Nullable; import java.util.Map; public interface CustomCropsSection { + /** + * Get the section ID + * + * @return section ID + */ int getSectionID(); + /** + * Get block at a certain position + * + * @param pos block position + * @return the block + */ + @Nullable CustomCropsBlock getBlockAt(BlockPos pos); + /** + * Remove a block by a certain position + * + * @param pos block position + * @return the removed block + */ + @Nullable CustomCropsBlock removeBlockAt(BlockPos pos); + /** + * Add block at a certain position + * + * @param pos block position + * @param block the new block + * @return the previous block + */ + @Nullable CustomCropsBlock addBlockAt(BlockPos pos, CustomCropsBlock block); + /** + * If the section can be pruned or not + */ boolean canPrune(); + /** + * Get the blocks in this section + * + * @return blocks + */ CustomCropsBlock[] getBlocks(); + /** + * Get the block map + * + * @return block map + */ Map getBlockMap(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsWorld.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsWorld.java index 523908f..b22bce5 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsWorld.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsWorld.java @@ -27,6 +27,7 @@ import net.momirealms.customcrops.api.mechanic.world.RegionPos; import net.momirealms.customcrops.api.mechanic.world.SimpleLocation; import net.momirealms.customcrops.api.mechanic.world.season.Season; import org.bukkit.World; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -34,96 +35,376 @@ import java.util.Optional; public interface CustomCropsWorld { + /** + * Save all the data + */ void save(); + /** + * Start the tick system + */ void startTick(); + /** + * Stop the tick system + */ void cancelTick(); + /** + * Check if a region is loaded + * + * @param regionPos region position + * @return loaded or not + */ boolean isRegionLoaded(RegionPos regionPos); + /** + * Removed lazy chunks (Delayed unloading chunks) + * + * @param chunkPos chunk position + * @return the removed lazy chunk + */ CustomCropsChunk removeLazyChunkAt(ChunkPos chunkPos); + /** + * Get the world's settings + * + * @return world settings + */ WorldSetting getWorldSetting(); + /** + * Set the world's settings + * + * @param setting settings + */ void setWorldSetting(WorldSetting setting); + /** + * Get all the chunks + * + * @return chunks + */ Collection getChunkStorage(); + /** + * Get bukkit world + * This would be null if the world is unloaded + * + * @return bukkit world + */ + @Nullable World getWorld(); + /** + * Get the world's name + * + * @return world's name + */ + @NotNull String getWorldName(); + /** + * Check if the chunk is loaded + * The chunk would only be loaded when it has CustomCrops data and being loaded by minecraft chunk system + * + * @param chunkPos chunk position + * @return loaded or not + */ boolean isChunkLoaded(ChunkPos chunkPos); + /** + * Create CustomCrops chunk at a certain chunk position + * This method can only be called if that chunk is loaded + * Otherwise it would fail + * + * @param chunkPos chunk position + * @return the generated CustomCrops chunk + */ Optional getOrCreateLoadedChunkAt(ChunkPos chunkPos); + /** + * Get the loaded CustomCrops chunk at a certain chunk position + * + * @param chunkPos chunk position + * @return CustomCrops chunk + */ Optional getLoadedChunkAt(ChunkPos chunkPos); + /** + * Get the loaded CustomCrops region at a certain region position + * + * @param regionPos region position + * @return CustomCrops region + */ Optional getLoadedRegionAt(RegionPos regionPos); + /** + * Load a CustomCrops region + * You don't need to worry about the unloading since CustomCrops would unload the region + * if it's unused + * + * @param region region + */ void loadRegion(CustomCropsRegion region); + /** + * Load a CustomCrops chunk + * It's unsafe to call this method. Please use world.getChunkAt instead + * + * @param chunk chunk + */ void loadChunk(CustomCropsChunk chunk); + /** + * Unload a CustomCrops chunk + * It's unsafe to call this method + * + * @param chunkPos chunk position + */ void unloadChunk(ChunkPos chunkPos); + /** + * Delete a chunk's data + * + * @param chunkPos chunk position + */ void deleteChunk(ChunkPos chunkPos); + /** + * Set the season and date of the world + * + * @param infoData info data + */ void setInfoData(WorldInfoData infoData); + /** + * Get the season and date + * This might return the wrong value if sync-seasons is enabled + * + * @return info data + */ WorldInfoData getInfoData(); + /** + * Get the date of the world + * This would return the reference world's date if sync-seasons is enabled + * + * @return date + */ int getDate(); + /** + * Get the season of the world + * This would return the reference world's season if sync-seasons is enabled + * + * @return date + */ @Nullable Season getSeason(); + /** + * Get sprinkler at a certain location + * + * @param location location + * @return sprinkler data + */ Optional getSprinklerAt(SimpleLocation location); + /** + * Get pot at a certain location + * + * @param location location + * @return pot data + */ Optional getPotAt(SimpleLocation location); + /** + * Get crop at a certain location + * + * @param location location + * @return crop data + */ Optional getCropAt(SimpleLocation location); + /** + * Get greenhouse glass at a certain location + * + * @param location location + * @return greenhouse glass data + */ Optional getGlassAt(SimpleLocation location); + /** + * Get scarecrow at a certain location + * + * @param location location + * @return scarecrow data + */ Optional getScarecrowAt(SimpleLocation location); + /** + * Get block data at a certain location + * + * @param location location + * @return block data + */ Optional getBlockAt(SimpleLocation location); - void addWaterToSprinkler(Sprinkler sprinkler, SimpleLocation location, int amount); + /** + * Add water to the sprinkler + * This method would create new sprinkler data if the sprinkler data not exists in that place + * This method would also update the sprinkler's model if it has models according to the water amount + * + * @param sprinkler sprinkler config + * @param amount amount of water + * @param location location + */ + void addWaterToSprinkler(Sprinkler sprinkler, int amount, SimpleLocation location); + /** + * Add fertilizer to the pot + * This method would create new pot data if the pot data not exists in that place + * This method would update the pot's block state if it has appearance variations for different fertilizers + * + * @param pot pot config + * @param fertilizer fertilizer config + * @param location location + */ void addFertilizerToPot(Pot pot, Fertilizer fertilizer, SimpleLocation location); - void addWaterToPot(Pot pot, SimpleLocation location, int amount); + /** + * Add water to the pot + * This method would create new pot data if the pot data not exists in that place + * This method would update the pot's block state if it's dry + * + * @param pot pot config + * @param amount amount of water + * @param location location + */ + void addWaterToPot(Pot pot, int amount, SimpleLocation location); - void removeSprinklerAt(SimpleLocation location); + /** + * Add points to a crop + * This method would do nothing if the crop data not exists in that place + * This method would change the stage of the crop and trigger the actions + * + * @param crop crop config + * @param points points to add + * @param location location + */ + void addPointToCrop(Crop crop, int points, SimpleLocation location); - void removePotAt(SimpleLocation location); + /** + * Remove sprinkler data from a certain location + * + * @param location location + */ + @Nullable + WorldSprinkler removeSprinklerAt(SimpleLocation location); - void removeCropAt(SimpleLocation location); + /** + * Remove pot data from a certain location + * + * @param location location + */ + @Nullable + WorldPot removePotAt(SimpleLocation location); - void removeGlassAt(SimpleLocation location); + /** + * Remove crop data from a certain location + * + * @param location location + */ + @Nullable + WorldCrop removeCropAt(SimpleLocation location); - void removeScarecrowAt(SimpleLocation location); + /** + * Remove greenhouse glass data from a certain location + * + * @param location location + */ + @Nullable + WorldGlass removeGlassAt(SimpleLocation location); + /** + * Remove scarecrow data from a certain location + * + * @param location location + */ + @Nullable + WorldScarecrow removeScarecrowAt(SimpleLocation location); + + /** + * Remove any block data from a certain location + * + * @param location location + * @return block data + */ + @Nullable CustomCropsBlock removeAnythingAt(SimpleLocation location); + /** + * If the amount of pot reaches the limitation + * + * @param location location + * @return reach or not + */ boolean isPotReachLimit(SimpleLocation location); + /** + * If the amount of crop reaches the limitation + * + * @param location location + * @return reach or not + */ boolean isCropReachLimit(SimpleLocation location); + /** + * If the amount of sprinkler reaches the limitation + * + * @param location location + * @return reach or not + */ boolean isSprinklerReachLimit(SimpleLocation location); + /** + * Add pot data + * + * @param pot pot data + * @param location location + */ void addPotAt(WorldPot pot, SimpleLocation location); + /** + * Add sprinkler data + * + * @param sprinkler sprinkler data + * @param location location + */ void addSprinklerAt(WorldSprinkler sprinkler, SimpleLocation location); + /** + * Add crop data + * + * @param crop crop data + * @param location location + */ void addCropAt(WorldCrop crop, SimpleLocation location); - void addPointToCrop(Crop crop, SimpleLocation location, int points); - + /** + * Add greenhouse glass data + * + * @param glass glass data + * @param location location + */ void addGlassAt(WorldGlass glass, SimpleLocation location); + /** + * Add scarecrow data + * + * @param scarecrow scarecrow data + * @param location location + */ void addScarecrowAt(WorldScarecrow scarecrow, SimpleLocation location); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/DataBlock.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/DataBlock.java index 6f13675..0236184 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/DataBlock.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/DataBlock.java @@ -23,11 +23,33 @@ import net.momirealms.customcrops.api.mechanic.world.SynchronizedCompoundMap; public interface DataBlock { + /** + * Set data by key + * + * @param key key + * @param tag data tag + */ void setData(String key, Tag tag); + /** + * Get data tag by key + * + * @param key key + * @return data tag + */ Tag getData(String key); + /** + * Get the data map + * + * @return data map + */ SynchronizedCompoundMap getCompoundMap(); + /** + * Get the location of the block + * + * @return location + */ SimpleLocation getLocation(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldCrop.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldCrop.java index 2667aa7..e56daee 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldCrop.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldCrop.java @@ -22,11 +22,31 @@ import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock; public interface WorldCrop extends CustomCropsBlock { + /** + * Get the key of the crop + * + * @return key + */ String getKey(); + /** + * Get the point + * + * @return point + */ int getPoint(); + /** + * Set the point + * + * @param point point + */ void setPoint(int point); + /** + * Get the config + * + * @return crop config + */ Crop getConfig(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldInfoData.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldInfoData.java index 42cd793..15a828c 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldInfoData.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldInfoData.java @@ -18,6 +18,7 @@ package net.momirealms.customcrops.api.mechanic.world.level; import com.google.gson.annotations.SerializedName; +import net.momirealms.customcrops.api.manager.ConfigManager; import net.momirealms.customcrops.api.mechanic.world.season.Season; public class WorldInfoData { @@ -36,19 +37,39 @@ public class WorldInfoData { return new WorldInfoData(Season.SPRING, 1); } + /** + * Get season + * + * @return season + */ public Season getSeason() { if (season == null) season = Season.SPRING; return season; } + /** + * Set season + * + * @param season the new season + */ public void setSeason(Season season) { this.season = season; } + /** + * Get date + * + * @return date + */ public int getDate() { return date; } + /** + * Set date + * + * @param date the new date + */ public void setDate(int date) { this.date = date; } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldPot.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldPot.java index 2d35b6e..7cd7a80 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldPot.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldPot.java @@ -20,26 +20,75 @@ package net.momirealms.customcrops.api.mechanic.world.level; import net.momirealms.customcrops.api.mechanic.item.Fertilizer; import net.momirealms.customcrops.api.mechanic.item.Pot; import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public interface WorldPot extends CustomCropsBlock { + /** + * Get the key of the pot + * + * @return key + */ String getKey(); + /** + * Get the amount of water + * + * @return amount of water + */ int getWater(); + /** + * Set the amount of water + * + * @param water water + */ void setWater(int water); + /** + * Get the fertilizer config + * + * @return fertilizer config + */ + @Nullable Fertilizer getFertilizer(); - void setFertilizer(Fertilizer fertilizer); + /** + * Set the fertilizer + * + * @param fertilizer fertilizer + */ + void setFertilizer(@NotNull Fertilizer fertilizer); + /** + * Remove the fertilizer + */ void removeFertilizer(); + /** + * Get the remaining usages of the fertilizer + * + * @return remaining usages of the fertilizer + */ int getFertilizerTimes(); + /** + * Set the remaining usages of the fertilizer + * + * @param times the remaining usages of the fertilizer + */ void setFertilizerTimes(int times); + /** + * Get the pot config + * + * @return pot config + */ Pot getConfig(); - void tickWater(CustomCropsChunk chunk); + /** + * Tick the rainwater and nearby water + */ + void tickWater(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldSprinkler.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldSprinkler.java index b26f2ec..9cab54d 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldSprinkler.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/WorldSprinkler.java @@ -22,11 +22,31 @@ import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock; public interface WorldSprinkler extends CustomCropsBlock { + /** + * Get the amount of water + * + * @return amount of water + */ int getWater(); + /** + * Set the amount of water + * + * @param water amount of water + */ void setWater(int water); + /** + * Get the key of the sprinkler + * + * @return key + */ String getKey(); + /** + * Get the sprinkler config + * + * @return sprinkler config + */ Sprinkler getConfig(); } diff --git a/build.gradle.kts b/build.gradle.kts index 5e62fbf..7909f6a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { allprojects { project.group = "net.momirealms" - project.version = "3.4.4.4" + project.version = "3.4.5" apply() apply(plugin = "java") diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 28e6696..01d08dd 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -51,7 +51,7 @@ dependencies { implementation(project(":legacy-api")) implementation("net.kyori:adventure-api:4.15.0") implementation("net.kyori:adventure-platform-bukkit:4.3.2") - implementation("com.github.Xiao-MoMi:AntiGriefLib:0.10") + implementation("com.github.Xiao-MoMi:AntiGriefLib:0.11") implementation("com.github.Xiao-MoMi:BiomeAPI:0.3") compileOnly("net.kyori:adventure-text-minimessage:4.15.0") diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/CustomProvider.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/CustomProvider.java index 2b9a341..ce1f80a 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/CustomProvider.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/CustomProvider.java @@ -81,7 +81,7 @@ public interface CustomProvider { CRotation previousCRotation; Entity first = entities.stream().findFirst().get(); if (first instanceof ItemFrame itemFrame) { - previousCRotation = RotationUtils.getCRotation(itemFrame.getRotation()); + previousCRotation = CRotation.getByRotation(itemFrame.getRotation()); } else if (VersionManager.isHigherThan1_19_R3()) { previousCRotation = DisplayEntityUtils.getRotation(first); } else { @@ -109,4 +109,27 @@ public interface CustomProvider { } return "AIR"; } + + default CRotation getRotation(Location location) { + if (location.getBlock().getType() == Material.AIR) { + Collection entities = location.getWorld().getNearbyEntities(LocationUtils.toCenterLocation(location), 0.5,0.51,0.5); + entities.removeIf(entity -> { + EntityType type = entity.getType(); + return type != EntityType.ITEM_FRAME + && (!VersionManager.isHigherThan1_19_R3() || type != EntityType.ITEM_DISPLAY); + }); + if (entities.size() == 0) return CRotation.NONE; + CRotation rotation; + Entity first = entities.stream().findFirst().get(); + if (first instanceof ItemFrame itemFrame) { + rotation = CRotation.getByRotation(itemFrame.getRotation()); + } else if (VersionManager.isHigherThan1_19_R3()) { + rotation = DisplayEntityUtils.getRotation(first); + } else { + rotation = CRotation.NONE; + } + return rotation; + } + return CRotation.NONE; + } } \ No newline at end of file diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java index f17ab16..ef108f1 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java @@ -372,6 +372,11 @@ public class ItemManagerImpl implements ItemManager { return customProvider.removeAnythingAt(location); } + @Override + public CRotation getRotation(Location location) { + return customProvider.getRotation(location); + } + @Override public WateringCan getWateringCanByID(@NotNull String id) { return id2WateringCanMap.get(id); @@ -1117,7 +1122,7 @@ public class ItemManagerImpl implements ItemManager { if (!wateringCan.isInfinite()) { PositiveFillMethod[] methods = wateringCan.getPositiveFillMethods(); for (PositiveFillMethod method : methods) { - if (method.getId().equals(clickedFurnitureID)) { + if (method.getID().equals(clickedFurnitureID)) { if (method.canFill(state)) { // fire the event WateringCanFillEvent fillEvent = new WateringCanFillEvent(player, itemInHand, location, wateringCan, method); @@ -1176,7 +1181,7 @@ public class ItemManagerImpl implements ItemManager { int water = wateringCan.getCurrentWater(itemInHand); PositiveFillMethod[] methods = wateringCan.getPositiveFillMethods(); for (PositiveFillMethod method : methods) { - if (method.getId().equals(blockID)) { + if (method.getID().equals(blockID)) { if (method.canFill(state)) { if (water < wateringCan.getStorage()) { // fire the event @@ -1230,7 +1235,7 @@ public class ItemManagerImpl implements ItemManager { int water = wateringCan.getCurrentWater(itemInHand); PositiveFillMethod[] methods = wateringCan.getPositiveFillMethods(); for (PositiveFillMethod method : methods) { - if (method.getId().equals(blockID)) { + if (method.getID().equals(blockID)) { if (method.canFill(state)) { if (water < wateringCan.getStorage()) { // fire the event diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/impl/CropConfig.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/impl/CropConfig.java index 5251d4f..2b746fe 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/impl/CropConfig.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/impl/CropConfig.java @@ -26,6 +26,7 @@ import net.momirealms.customcrops.api.mechanic.item.Crop; import net.momirealms.customcrops.api.mechanic.item.ItemCarrier; import net.momirealms.customcrops.api.mechanic.requirement.Requirement; import net.momirealms.customcrops.mechanic.item.AbstractEventItem; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -143,6 +144,7 @@ public class CropConfig extends AbstractEventItem implements Crop { return point2StageConfigMap.get(point); } + @NotNull @Override public String getStageItemByPoint(int point) { if (point >= 0) { diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CChunk.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CChunk.java index d8470ef..b74f1c3 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CChunk.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CChunk.java @@ -206,7 +206,7 @@ public class CChunk implements CustomCropsChunk { } } case POT -> { - ((WorldPot) block).tickWater(this); + ((WorldPot) block).tickWater(); if (setting.randomTickPot()) { block.tick(setting.getTickPotInterval(), offline); } @@ -277,7 +277,7 @@ public class CChunk implements CustomCropsChunk { } @Override - public void addWaterToSprinkler(Sprinkler sprinkler, SimpleLocation location, int amount) { + public void addWaterToSprinkler(Sprinkler sprinkler, int amount, SimpleLocation location) { Optional optionalSprinkler = getSprinklerAt(location); if (optionalSprinkler.isEmpty()) { addBlockAt(new MemorySprinkler(location, sprinkler.getKey(), amount), location); @@ -314,7 +314,7 @@ public class CChunk implements CustomCropsChunk { } @Override - public void addWaterToPot(Pot pot, SimpleLocation location, int amount) { + public void addWaterToPot(Pot pot, int amount, SimpleLocation location) { Optional optionalWorldPot = getPotAt(location); if (optionalWorldPot.isEmpty()) { MemoryPot memoryPot = new MemoryPot(location, pot.getKey()); @@ -365,7 +365,7 @@ public class CChunk implements CustomCropsChunk { } @Override - public void addPointToCrop(Crop crop, SimpleLocation location, int points) { + public void addPointToCrop(Crop crop, int points, SimpleLocation location) { if (points <= 0) return; Optional cropData = getCropAt(location); if (cropData.isEmpty()) { @@ -415,52 +415,72 @@ public class CChunk implements CustomCropsChunk { } @Override - public void removeSprinklerAt(SimpleLocation location) { + public WorldSprinkler removeSprinklerAt(SimpleLocation location) { CustomCropsBlock removed = removeBlockAt(location); if (removed == null) { CustomCropsPlugin.get().debug("Failed to remove sprinkler from " + location + " because sprinkler doesn't exist."); - } else if (!(removed instanceof WorldSprinkler)) { + return null; + } else if (!(removed instanceof WorldSprinkler worldSprinkler)) { CustomCropsPlugin.get().debug("Removed sprinkler from " + location + " but the previous block type is " + removed.getType().name()); + return null; + } else { + return worldSprinkler; } } @Override - public void removePotAt(SimpleLocation location) { + public WorldPot removePotAt(SimpleLocation location) { CustomCropsBlock removed = removeBlockAt(location); if (removed == null) { CustomCropsPlugin.get().debug("Failed to remove pot from " + location + " because pot doesn't exist."); - } else if (!(removed instanceof WorldPot)) { + return null; + } else if (!(removed instanceof WorldPot worldPot)) { CustomCropsPlugin.get().debug("Removed pot from " + location + " but the previous block type is " + removed.getType().name()); + return null; + } else { + return worldPot; } } @Override - public void removeCropAt(SimpleLocation location) { + public WorldCrop removeCropAt(SimpleLocation location) { CustomCropsBlock removed = removeBlockAt(location); if (removed == null) { CustomCropsPlugin.get().debug("Failed to remove crop from " + location + " because crop doesn't exist."); - } else if (!(removed instanceof WorldCrop)) { + return null; + } else if (!(removed instanceof WorldCrop worldCrop)) { CustomCropsPlugin.get().debug("Removed crop from " + location + " but the previous block type is " + removed.getType().name()); + return null; + } else { + return worldCrop; } } @Override - public void removeGlassAt(SimpleLocation location) { + public WorldGlass removeGlassAt(SimpleLocation location) { CustomCropsBlock removed = removeBlockAt(location); if (removed == null) { CustomCropsPlugin.get().debug("Failed to remove glass from " + location + " because glass doesn't exist."); - } else if (!(removed instanceof WorldGlass)) { + return null; + } else if (!(removed instanceof WorldGlass worldGlass)) { CustomCropsPlugin.get().debug("Removed glass from " + location + " but the previous block type is " + removed.getType().name()); + return null; + } else { + return worldGlass; } } @Override - public void removeScarecrowAt(SimpleLocation location) { + public WorldScarecrow removeScarecrowAt(SimpleLocation location) { CustomCropsBlock removed = removeBlockAt(location); if (removed == null) { CustomCropsPlugin.get().debug("Failed to remove scarecrow from " + location + " because scarecrow doesn't exist."); - } else if (!(removed instanceof WorldScarecrow)) { + return null; + } else if (!(removed instanceof WorldScarecrow worldScarecrow)) { CustomCropsPlugin.get().debug("Removed scarecrow from " + location + " but the previous block type is " + removed.getType().name()); + return null; + } else { + return worldScarecrow; } } diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java index a944ca9..b6898bf 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java @@ -39,6 +39,7 @@ import net.momirealms.customcrops.api.util.LogUtils; import net.momirealms.customcrops.util.EventUtils; import org.bukkit.Bukkit; import org.bukkit.World; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.ref.WeakReference; @@ -217,6 +218,7 @@ public class CWorld implements CustomCropsWorld { }); } + @NotNull @Override public String getWorldName() { return worldName; @@ -359,10 +361,10 @@ public class CWorld implements CustomCropsWorld { } @Override - public void addWaterToSprinkler(Sprinkler sprinkler, SimpleLocation location, int amount) { + public void addWaterToSprinkler(Sprinkler sprinkler, int amount, SimpleLocation location) { Optional chunk = getOrCreateLoadedChunkAt(location.getChunkPos()); if (chunk.isPresent()) { - chunk.get().addWaterToSprinkler(sprinkler, location, amount); + chunk.get().addWaterToSprinkler(sprinkler, amount, location); } else { LogUtils.warn("Invalid operation: Adding water to sprinkler in a not generated chunk"); } @@ -379,10 +381,10 @@ public class CWorld implements CustomCropsWorld { } @Override - public void addWaterToPot(Pot pot, SimpleLocation location, int amount) { + public void addWaterToPot(Pot pot, int amount, SimpleLocation location) { Optional chunk = getOrCreateLoadedChunkAt(location.getChunkPos()); if (chunk.isPresent()) { - chunk.get().addWaterToPot(pot, location, amount); + chunk.get().addWaterToPot(pot, amount, location); } else { LogUtils.warn("Invalid operation: Adding water to pot in a not generated chunk"); } @@ -419,10 +421,10 @@ public class CWorld implements CustomCropsWorld { } @Override - public void addPointToCrop(Crop crop, SimpleLocation location, int points) { + public void addPointToCrop(Crop crop, int points, SimpleLocation location) { Optional chunk = getOrCreateLoadedChunkAt(location.getChunkPos()); if (chunk.isPresent()) { - chunk.get().addPointToCrop(crop, location, points); + chunk.get().addPointToCrop(crop, points, location); } else { LogUtils.warn("Invalid operation: Adding point to crop in a not generated chunk"); } @@ -449,52 +451,57 @@ public class CWorld implements CustomCropsWorld { } @Override - public void removeSprinklerAt(SimpleLocation location) { + public WorldSprinkler removeSprinklerAt(SimpleLocation location) { Optional chunk = getLoadedChunkAt(location.getChunkPos()); if (chunk.isPresent()) { - chunk.get().removeSprinklerAt(location); + return chunk.get().removeSprinklerAt(location); } else { - LogUtils.warn("Invalid operation: Removing sprinkler from an unloaded chunk"); + LogUtils.warn("Invalid operation: Removing sprinkler from an unloaded/empty chunk"); + return null; } } @Override - public void removePotAt(SimpleLocation location) { + public WorldPot removePotAt(SimpleLocation location) { Optional chunk = getLoadedChunkAt(location.getChunkPos()); if (chunk.isPresent()) { - chunk.get().removePotAt(location); + return chunk.get().removePotAt(location); } else { - LogUtils.warn("Invalid operation: Removing pot from an unloaded chunk"); + LogUtils.warn("Invalid operation: Removing pot from an unloaded/empty chunk"); + return null; } } @Override - public void removeCropAt(SimpleLocation location) { + public WorldCrop removeCropAt(SimpleLocation location) { Optional chunk = getLoadedChunkAt(location.getChunkPos()); if (chunk.isPresent()) { - chunk.get().removeCropAt(location); + return chunk.get().removeCropAt(location); } else { - LogUtils.warn("Invalid operation: Removing crop from an unloaded chunk"); + LogUtils.warn("Invalid operation: Removing crop from an unloaded/empty chunk"); + return null; } } @Override - public void removeGlassAt(SimpleLocation location) { + public WorldGlass removeGlassAt(SimpleLocation location) { Optional chunk = getLoadedChunkAt(location.getChunkPos()); if (chunk.isPresent()) { - chunk.get().removeGlassAt(location); + return chunk.get().removeGlassAt(location); } else { - LogUtils.warn("Invalid operation: Removing glass from an unloaded chunk"); + LogUtils.warn("Invalid operation: Removing glass from an unloaded/empty chunk"); + return null; } } @Override - public void removeScarecrowAt(SimpleLocation location) { + public WorldScarecrow removeScarecrowAt(SimpleLocation location) { Optional chunk = getLoadedChunkAt(location.getChunkPos()); if (chunk.isPresent()) { - chunk.get().removeScarecrowAt(location); + return chunk.get().removeScarecrowAt(location); } else { - LogUtils.warn("Invalid operation: Removing scarecrow from an unloaded chunk"); + LogUtils.warn("Invalid operation: Removing scarecrow from an unloaded/empty chunk"); + return null; } } @@ -504,7 +511,7 @@ public class CWorld implements CustomCropsWorld { if (chunk.isPresent()) { return chunk.get().removeBlockAt(location); } else { - LogUtils.warn("Invalid operation: Removing anything from an unloaded chunk"); + LogUtils.warn("Invalid operation: Removing anything from an unloaded/empty chunk"); return null; } } diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java index 32952db..9de5ae4 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java @@ -321,7 +321,7 @@ public class WorldManagerImpl implements WorldManager, Listener { LogUtils.warn("Unsupported operation: Adding water to sprinkler in unloaded world " + location); return; } - cWorld.addWaterToSprinkler(sprinkler, location, amount); + cWorld.addWaterToSprinkler(sprinkler, amount, location); } @Override @@ -342,7 +342,7 @@ public class WorldManagerImpl implements WorldManager, Listener { LogUtils.warn("Unsupported operation: Adding water to pot in unloaded world " + location); return; } - cWorld.addWaterToPot(pot, location, amount); + cWorld.addWaterToPot(pot, amount, location); } @Override @@ -382,7 +382,7 @@ public class WorldManagerImpl implements WorldManager, Listener { LogUtils.warn("Unsupported operation: Adding point to crop in unloaded world " + location); return; } - cWorld.addPointToCrop(crop, location, points); + cWorld.addPointToCrop(crop, points, location); } @Override @@ -406,53 +406,53 @@ public class WorldManagerImpl implements WorldManager, Listener { } @Override - public void removeSprinklerAt(@NotNull SimpleLocation location) { + public WorldSprinkler removeSprinklerAt(@NotNull SimpleLocation location) { CWorld cWorld = loadedWorlds.get(location.getWorldName()); if (cWorld == null) { LogUtils.warn("Unsupported operation: Removing sprinkler from unloaded world " + location); - return; + return null; } - cWorld.removeSprinklerAt(location); + return cWorld.removeSprinklerAt(location); } @Override - public void removePotAt(@NotNull SimpleLocation location) { + public WorldPot removePotAt(@NotNull SimpleLocation location) { CWorld cWorld = loadedWorlds.get(location.getWorldName()); if (cWorld == null) { LogUtils.warn("Unsupported operation: Removing pot from unloaded world " + location); - return; + return null; } - cWorld.removePotAt(location); + return cWorld.removePotAt(location); } @Override - public void removeCropAt(@NotNull SimpleLocation location) { + public WorldCrop removeCropAt(@NotNull SimpleLocation location) { CWorld cWorld = loadedWorlds.get(location.getWorldName()); if (cWorld == null) { LogUtils.warn("Unsupported operation: Removing crop from unloaded world " + location); - return; + return null; } - cWorld.removeCropAt(location); + return cWorld.removeCropAt(location); } @Override - public void removeGlassAt(@NotNull SimpleLocation location) { + public WorldGlass removeGlassAt(@NotNull SimpleLocation location) { CWorld cWorld = loadedWorlds.get(location.getWorldName()); if (cWorld == null) { LogUtils.warn("Unsupported operation: Removing glass from unloaded world " + location); - return; + return null; } - cWorld.removeGlassAt(location); + return cWorld.removeGlassAt(location); } @Override - public void removeScarecrowAt(@NotNull SimpleLocation location) { + public WorldScarecrow removeScarecrowAt(@NotNull SimpleLocation location) { CWorld cWorld = loadedWorlds.get(location.getWorldName()); if (cWorld == null) { LogUtils.warn("Unsupported operation: Removing scarecrow from unloaded world " + location); - return; + return null; } - cWorld.removeScarecrowAt(location); + return cWorld.removeScarecrowAt(location); } @Override diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/block/MemoryPot.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/block/MemoryPot.java index 9f61ea6..f7e35c7 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/block/MemoryPot.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/block/MemoryPot.java @@ -35,6 +35,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.data.Waterlogged; +import org.jetbrains.annotations.NotNull; import java.util.Objects; @@ -95,7 +96,7 @@ public class MemoryPot extends AbstractCustomCropsBlock implements WorldPot { } @Override - public void setFertilizer(Fertilizer fertilizer) { + public void setFertilizer(@NotNull Fertilizer fertilizer) { setData("fertilizer", new StringTag("fertilizer", fertilizer.getKey())); setData("fertilizer-times", new IntTag("fertilizer-times", fertilizer.getTimes())); } @@ -122,7 +123,7 @@ public class MemoryPot extends AbstractCustomCropsBlock implements WorldPot { } @Override - public void tickWater(CustomCropsChunk chunk) { + public void tickWater() { Pot pot = getConfig(); if (pot == null) { LogUtils.warn("Found a pot without config at " + getLocation() + ". Try removing the data."); diff --git a/plugin/src/main/java/net/momirealms/customcrops/util/DisplayEntityUtils.java b/plugin/src/main/java/net/momirealms/customcrops/util/DisplayEntityUtils.java index d1f0825..856ef7d 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/util/DisplayEntityUtils.java +++ b/plugin/src/main/java/net/momirealms/customcrops/util/DisplayEntityUtils.java @@ -8,7 +8,7 @@ public class DisplayEntityUtils { public static CRotation getRotation(Entity entity) { if (entity instanceof ItemDisplay itemDisplay) { - return RotationUtils.getCRotation(itemDisplay.getLocation().getYaw()); + return CRotation.getByYaw(itemDisplay.getLocation().getYaw()); } return CRotation.NONE; } diff --git a/plugin/src/main/java/net/momirealms/customcrops/util/RotationUtils.java b/plugin/src/main/java/net/momirealms/customcrops/util/RotationUtils.java index abf1eb5..630876c 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/util/RotationUtils.java +++ b/plugin/src/main/java/net/momirealms/customcrops/util/RotationUtils.java @@ -61,39 +61,4 @@ public class RotationUtils { } } } - - public static CRotation getCRotation(Rotation rotation) { - switch (rotation) { - default -> { - return CRotation.NONE; - } - case CLOCKWISE -> { - return CRotation.WEST; - } - case COUNTER_CLOCKWISE -> { - return CRotation.EAST; - } - case FLIPPED -> { - return CRotation.NORTH; - } - } - } - - public static CRotation getCRotation(float yaw) { - yaw = Math.abs(yaw); - switch ((int) (yaw/90)) { - case 1 -> { - return CRotation.WEST; - } - case 2 -> { - return CRotation.NORTH; - } - case 3 -> { - return CRotation.EAST; - } - default -> { - return CRotation.SOUTH; - } - } - } }