9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-31 12:56:27 +00:00

[API] Improved API

This commit is contained in:
XiaoMoMi
2024-04-22 04:49:48 +08:00
parent 6de266a1e5
commit 6dd75c6c40
53 changed files with 1626 additions and 181 deletions

View File

@@ -29,5 +29,4 @@ public interface EventItem {
* @param state state
*/
void trigger(ActionTrigger actionTrigger, State state);
}

View File

@@ -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
*

View File

@@ -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);
/**

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -8,6 +8,11 @@ public class Conditions {
this.conditions = conditions;
}
/**
* Get a list of conditions
*
* @return conditions
*/
public Condition[] getConditions() {
return conditions;
}

View File

@@ -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;
}

View File

@@ -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<Double, Integer> 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;
}

View File

@@ -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<? extends Stage> getStages();
/**
* Get the pots to plant
*
* @return whitelisted pots
*/
HashSet<String> 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();
}
}

View File

@@ -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<String> 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();
}

View File

@@ -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<String> 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);
}

View File

@@ -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();
}

View File

@@ -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<String> 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();
}

View File

@@ -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<String, String> 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<String> getPotWhitelist();
/**
* Get the sprinklers that receive water from this watering can
*
* @return whitelisted sprinklers
*/
HashSet<String> getSprinklerWhitelist();
/**
* Get the dynamic lores
*
* @return dynamic lores
*/
List<String> 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);
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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<Action> notMetActions, boolean advanced);
/**
* Build a requirement
*
* @param args args
* @return requirement
*/
default Requirement build(Object args) {
return build(args, null, false);
}

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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<WorldCrop> getCropAt(SimpleLocation location);
Optional<WorldSprinkler> getSprinklerAt(SimpleLocation location);
Optional<WorldPot> getPotAt(SimpleLocation location);
Optional<WorldGlass> getGlassAt(SimpleLocation location);
Optional<WorldScarecrow> getScarecrowAt(SimpleLocation location);
Optional<CustomCropsBlock> 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<WorldCrop> getCropAt(SimpleLocation location);
/**
* Get sprinkler at a certain location
*
* @param location location
* @return sprinkler data
*/
Optional<WorldSprinkler> getSprinklerAt(SimpleLocation location);
/**
* Get pot at a certain location
*
* @param location location
* @return pot data
*/
Optional<WorldPot> getPotAt(SimpleLocation location);
/**
* Get greenhouse glass at a certain location
*
* @param location location
* @return greenhouse glass data
*/
Optional<WorldGlass> getGlassAt(SimpleLocation location);
/**
* Get scarecrow at a certain location
*
* @param location location
* @return scarecrow data
*/
Optional<WorldScarecrow> getScarecrowAt(SimpleLocation location);
/**
* Get block data at a certain location
*
* @param location location
* @return block data
*/
Optional<CustomCropsBlock> 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();
}

View File

@@ -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<ChunkPos, byte[]> getRegionDataToSave();
/**
* If the region can be pruned or not
*/
boolean canPrune();
}

View File

@@ -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<BlockPos, CustomCropsBlock> getBlockMap();
}

View File

@@ -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<? extends CustomCropsChunk> 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<CustomCropsChunk> getOrCreateLoadedChunkAt(ChunkPos chunkPos);
/**
* Get the loaded CustomCrops chunk at a certain chunk position
*
* @param chunkPos chunk position
* @return CustomCrops chunk
*/
Optional<CustomCropsChunk> getLoadedChunkAt(ChunkPos chunkPos);
/**
* Get the loaded CustomCrops region at a certain region position
*
* @param regionPos region position
* @return CustomCrops region
*/
Optional<CustomCropsRegion> 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<WorldSprinkler> getSprinklerAt(SimpleLocation location);
/**
* Get pot at a certain location
*
* @param location location
* @return pot data
*/
Optional<WorldPot> getPotAt(SimpleLocation location);
/**
* Get crop at a certain location
*
* @param location location
* @return crop data
*/
Optional<WorldCrop> getCropAt(SimpleLocation location);
/**
* Get greenhouse glass at a certain location
*
* @param location location
* @return greenhouse glass data
*/
Optional<WorldGlass> getGlassAt(SimpleLocation location);
/**
* Get scarecrow at a certain location
*
* @param location location
* @return scarecrow data
*/
Optional<WorldScarecrow> getScarecrowAt(SimpleLocation location);
/**
* Get block data at a certain location
*
* @param location location
* @return block data
*/
Optional<CustomCropsBlock> 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);
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -8,7 +8,7 @@ plugins {
allprojects {
project.group = "net.momirealms"
project.version = "3.4.4.4"
project.version = "3.4.5"
apply<JavaPlugin>()
apply(plugin = "java")

View File

@@ -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")

View File

@@ -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<Entity> 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;
}
}

View File

@@ -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

View File

@@ -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) {

View File

@@ -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<WorldSprinkler> 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<WorldPot> 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<WorldCrop> 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;
}
}

View File

@@ -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<CustomCropsChunk> 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<CustomCropsChunk> 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<CustomCropsChunk> 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<CustomCropsChunk> 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<CustomCropsChunk> 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<CustomCropsChunk> 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<CustomCropsChunk> 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<CustomCropsChunk> 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;
}
}

View File

@@ -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

View File

@@ -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.");

View File

@@ -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;
}

View File

@@ -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;
}
}
}
}