9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-24 01:19:28 +00:00

[Fix] Tripwire for sprinkler

This commit is contained in:
XiaoMoMi
2024-04-20 20:05:01 +08:00
parent 8d3443f989
commit c602ba7c0e
44 changed files with 503 additions and 108 deletions

View File

@@ -19,7 +19,13 @@ package net.momirealms.customcrops.api.common;
public interface Initable { public interface Initable {
/**
* init
*/
void init(); void init();
/**
* disable
*/
void disable(); void disable();
} }

View File

@@ -1,23 +0,0 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customcrops.api.common;
public interface Property<T> {
T get();
void set(T value);
}

View File

@@ -22,6 +22,12 @@ import net.momirealms.customcrops.api.mechanic.requirement.State;
public interface EventItem { public interface EventItem {
/**
* Trigger events
*
* @param actionTrigger trigger
* @param state state
*/
void trigger(ActionTrigger actionTrigger, State state); void trigger(ActionTrigger actionTrigger, State state);
} }

View File

@@ -19,5 +19,10 @@ package net.momirealms.customcrops.api.common.item;
public interface KeyItem { public interface KeyItem {
/**
* Get item's key
*
* @return key
*/
String getKey(); String getKey();
} }

View File

@@ -94,16 +94,31 @@ public class BoneMealDispenseEvent extends Event implements Cancellable {
return boneMealItem; return boneMealItem;
} }
/**
* Get the crop's data
*
* @return crop data
*/
@NotNull @NotNull
public WorldCrop getCrop() { public WorldCrop getCrop() {
return crop; return crop;
} }
/**
* Get the bone meal's config
*
* @return bone meal config
*/
@NotNull @NotNull
public BoneMeal getBoneMeal() { public BoneMeal getBoneMeal() {
return boneMeal; return boneMeal;
} }
/**
* Get the dispenser block
*
* @return dispenser block
*/
@NotNull @NotNull
public Block getDispenser() { public Block getDispenser() {
return dispenser; return dispenser;

View File

@@ -77,6 +77,7 @@ public class BoneMealUseEvent extends Event implements Cancellable {
/** /**
* Get the crop location * Get the crop location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -87,6 +88,7 @@ public class BoneMealUseEvent extends Event implements Cancellable {
/** /**
* Get the item in player's hand * Get the item in player's hand
* If there's nothing in hand, it would return AIR * If there's nothing in hand, it would return AIR
*
* @return item in hand * @return item in hand
*/ */
@NotNull @NotNull
@@ -94,11 +96,21 @@ public class BoneMealUseEvent extends Event implements Cancellable {
return itemInHand; return itemInHand;
} }
/**
* Get the crop's data
*
* @return crop data
*/
@NotNull @NotNull
public WorldCrop getCrop() { public WorldCrop getCrop() {
return crop; return crop;
} }
/**
* Get the bone meal config
*
* @return bone meal config
*/
@NotNull @NotNull
public BoneMeal getBoneMeal() { public BoneMeal getBoneMeal() {
return boneMeal; return boneMeal;

View File

@@ -75,6 +75,7 @@ public class CropBreakEvent extends Event implements Cancellable {
/** /**
* Get the crop's data, it might be null if it's spawned by other plugins in the wild * Get the crop's data, it might be null if it's spawned by other plugins in the wild
*
* @return crop data * @return crop data
*/ */
@Nullable @Nullable
@@ -84,6 +85,7 @@ public class CropBreakEvent extends Event implements Cancellable {
/** /**
* Get the crop location * Get the crop location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -91,6 +93,14 @@ public class CropBreakEvent extends Event implements Cancellable {
return location; return location;
} }
/**
* Get the entity that triggered the event
* This would be null if the crop is broken by respawn anchor
* The breaker can be a TNT, creeper.
* If the pot is a vanilla farmland, it can be trampled by entities
*
* @return entity
*/
@Nullable @Nullable
public Entity getEntity() { public Entity getEntity() {
return entity; return entity;
@@ -104,6 +114,11 @@ public class CropBreakEvent extends Event implements Cancellable {
return null; return null;
} }
/**
* Get the reason
*
* @return reason
*/
@NotNull @NotNull
public Reason getReason() { public Reason getReason() {
return reason; return reason;

View File

@@ -73,6 +73,7 @@ public class CropInteractEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the crop location * Get the crop location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -83,6 +84,7 @@ public class CropInteractEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the item in player's hand * Get the item in player's hand
* If there's nothing in hand, it would return AIR * If there's nothing in hand, it would return AIR
*
* @return item in hand * @return item in hand
*/ */
@NotNull @NotNull
@@ -92,6 +94,7 @@ public class CropInteractEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the crop's data, it might be null if it's spawned by other plugins in the wild * Get the crop's data, it might be null if it's spawned by other plugins in the wild
*
* @return crop data * @return crop data
*/ */
@Nullable @Nullable

View File

@@ -64,6 +64,7 @@ public class CropPlantEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the seed item * Get the seed item
*
* @return seed item * @return seed item
*/ */
@NotNull @NotNull

View File

@@ -74,21 +74,41 @@ public class FertilizerUseEvent extends PlayerEvent implements Cancellable {
return handlers; return handlers;
} }
/**
* Get the fertilizer item in hand
*
* @return item in hand
*/
@NotNull @NotNull
public ItemStack getItemInHand() { public ItemStack getItemInHand() {
return itemInHand; return itemInHand;
} }
/**
* Get the pot's location
*
* @return location
*/
@NotNull @NotNull
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
/**
* Get the pot's data
*
* @return pot data
*/
@NotNull @NotNull
public WorldPot getPot() { public WorldPot getPot() {
return pot; return pot;
} }
/**
* Get the fertilizer's config
*
* @return fertilizer config
*/
@NotNull @NotNull
public Fertilizer getFertilizer() { public Fertilizer getFertilizer() {
return fertilizer; return fertilizer;

View File

@@ -75,6 +75,7 @@ public class GreenhouseGlassBreakEvent extends Event implements Cancellable {
/** /**
* Get the glass location * Get the glass location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -100,6 +101,11 @@ public class GreenhouseGlassBreakEvent extends Event implements Cancellable {
return reason; return reason;
} }
/**
* Get the glass data
*
* @return glass data
*/
@NotNull @NotNull
public WorldGlass getGlass() { public WorldGlass getGlass() {
return glass; return glass;

View File

@@ -64,6 +64,7 @@ public class GreenhouseGlassPlaceEvent extends PlayerEvent implements Cancellabl
/** /**
* Get the glass location * Get the glass location
*
* @return location * @return location
*/ */
@NotNull @NotNull

View File

@@ -75,6 +75,7 @@ public class PotBreakEvent extends Event implements Cancellable {
/** /**
* Get the pot location * Get the pot location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -85,6 +86,7 @@ public class PotBreakEvent extends Event implements Cancellable {
/** /**
* Get the pot's data * Get the pot's data
*
* @return pot * @return pot
*/ */
@NotNull @NotNull

View File

@@ -76,6 +76,7 @@ public class PotFillEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the pot location * Get the pot location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -86,6 +87,7 @@ public class PotFillEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the pot's data * Get the pot's data
*
* @return pot * @return pot
*/ */
@NotNull @NotNull
@@ -93,11 +95,21 @@ public class PotFillEvent extends PlayerEvent implements Cancellable {
return pot; return pot;
} }
/**
* Get the item in hand
*
* @return item in hand
*/
@NotNull @NotNull
public ItemStack getItemInHand() { public ItemStack getItemInHand() {
return itemInHand; return itemInHand;
} }
/**
* Get the passive fill method
*
* @return passive fill method
*/
@NotNull @NotNull
public PassiveFillMethod getFillMethod() { public PassiveFillMethod getFillMethod() {
return fillMethod; return fillMethod;

View File

@@ -54,10 +54,6 @@ public class PotInteractEvent extends PlayerEvent implements Cancellable {
return cancelled; return cancelled;
} }
/**
* Cancelling this event would cancel PotInfoEvent too
* @param cancel true if you wish to cancel this event
*/
@Override @Override
public void setCancelled(boolean cancel) { public void setCancelled(boolean cancel) {
this.cancelled = cancel; this.cancelled = cancel;
@@ -77,6 +73,7 @@ public class PotInteractEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the item in player's hand * Get the item in player's hand
* If there's nothing in hand, it would return AIR * If there's nothing in hand, it would return AIR
*
* @return item in hand * @return item in hand
*/ */
@NotNull @NotNull
@@ -86,6 +83,7 @@ public class PotInteractEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the pot location * Get the pot location
*
* @return pot location * @return pot location
*/ */
@NotNull @NotNull
@@ -95,6 +93,7 @@ public class PotInteractEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the pot's data * Get the pot's data
*
* @return pot key * @return pot key
*/ */
@NotNull @NotNull

View File

@@ -68,6 +68,7 @@ public class PotPlaceEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the pot location * Get the pot location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -77,6 +78,7 @@ public class PotPlaceEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the placed pot's config * Get the placed pot's config
*
* @return pot * @return pot
*/ */
@NotNull @NotNull

View File

@@ -75,6 +75,7 @@ public class ScarecrowBreakEvent extends Event implements Cancellable {
/** /**
* Get the scarecrow location * Get the scarecrow location
*
* @return location * @return location
*/ */
@NotNull @NotNull

View File

@@ -64,6 +64,7 @@ public class ScarecrowPlaceEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the scarecrow location * Get the scarecrow location
*
* @return location * @return location
*/ */
@NotNull @NotNull

View File

@@ -54,6 +54,7 @@ public class SeasonChangeEvent extends Event {
/** /**
* Get the new season * Get the new season
*
* @return season * @return season
*/ */
@NotNull @NotNull
@@ -63,6 +64,7 @@ public class SeasonChangeEvent extends Event {
/** /**
* Get the world * Get the world
*
* @return world * @return world
*/ */
public World getWorld() { public World getWorld() {

View File

@@ -75,6 +75,7 @@ public class SprinklerBreakEvent extends Event implements Cancellable {
/** /**
* Get the sprinkler location * Get the sprinkler location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -84,6 +85,7 @@ public class SprinklerBreakEvent extends Event implements Cancellable {
/** /**
* Get the sprinkler's data * Get the sprinkler's data
*
* @return sprinkler * @return sprinkler
*/ */
@NotNull @NotNull

View File

@@ -76,6 +76,7 @@ public class SprinklerFillEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the item in player's hand * Get the item in player's hand
*
* @return item in hand * @return item in hand
*/ */
@NotNull @NotNull
@@ -85,6 +86,7 @@ public class SprinklerFillEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the sprinkler location * Get the sprinkler location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -92,6 +94,11 @@ public class SprinklerFillEvent extends PlayerEvent implements Cancellable {
return location; return location;
} }
/**
* Get the passive fill method
*
* @return passive fill method
*/
@NotNull @NotNull
public PassiveFillMethod getFillMethod() { public PassiveFillMethod getFillMethod() {
return fillMethod; return fillMethod;

View File

@@ -72,6 +72,7 @@ public class SprinklerInteractEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the sprinkler location * Get the sprinkler location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -81,6 +82,7 @@ public class SprinklerInteractEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the sprinkler's data * Get the sprinkler's data
*
* @return sprinkler * @return sprinkler
*/ */
@NotNull @NotNull
@@ -90,6 +92,7 @@ public class SprinklerInteractEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the item in player's hand * Get the item in player's hand
*
* @return item in hand * @return item in hand
*/ */
@NotNull @NotNull

View File

@@ -72,6 +72,7 @@ public class SprinklerPlaceEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the item in player's hand * Get the item in player's hand
*
* @return item in hand * @return item in hand
*/ */
@NotNull @NotNull
@@ -81,6 +82,7 @@ public class SprinklerPlaceEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the sprinkler location * Get the sprinkler location
*
* @return location * @return location
*/ */
@NotNull @NotNull
@@ -90,6 +92,7 @@ public class SprinklerPlaceEvent extends PlayerEvent implements Cancellable {
/** /**
* Get the sprinkler's config * Get the sprinkler's config
*
* @return sprinkler * @return sprinkler
*/ */
@NotNull @NotNull

View File

@@ -74,21 +74,41 @@ public class WateringCanFillEvent extends PlayerEvent implements Cancellable {
return handlers; return handlers;
} }
/**
* Get the watering can item
*
* @return the watering can item
*/
@NotNull @NotNull
public ItemStack getItemInHand() { public ItemStack getItemInHand() {
return itemInHand; return itemInHand;
} }
/**
* Get watering can config
*
* @return watering can config
*/
@NotNull @NotNull
public WateringCan getWateringCan() { public WateringCan getWateringCan() {
return wateringCan; return wateringCan;
} }
/**
* Get the positive fill method
*
* @return positive fill method
*/
@NotNull @NotNull
public PositiveFillMethod getFillMethod() { public PositiveFillMethod getFillMethod() {
return fillMethod; return fillMethod;
} }
/**
* Get the location
*
* @return location
*/
@NotNull @NotNull
public Location getLocation() { public Location getLocation() {
return location; return location;

View File

@@ -76,21 +76,41 @@ public class WateringCanWaterEvent extends PlayerEvent implements Cancellable {
return handlers; return handlers;
} }
/**
* Get the watering can item
*
* @return watering can item
*/
@NotNull @NotNull
public ItemStack getItemInHand() { public ItemStack getItemInHand() {
return itemInHand; return itemInHand;
} }
/**
* Get the watering can's config
*
* @return watering can config
*/
@NotNull @NotNull
public WateringCan getWateringCan() { public WateringCan getWateringCan() {
return wateringCan; return wateringCan;
} }
/**
* Get the locations that involved in this event
*
* @return locations
*/
@NotNull @NotNull
public Set<Location> getLocation() { public Set<Location> getLocation() {
return location; return location;
} }
/**
* Get the pot/sprinkler's data
*
* @return data
*/
@NotNull @NotNull
public CustomCropsBlock getPotOrSprinkler() { public CustomCropsBlock getPotOrSprinkler() {
return potOrSprinkler; return potOrSprinkler;

View File

@@ -22,9 +22,28 @@ import org.bukkit.inventory.ItemStack;
public interface ItemLibrary { public interface ItemLibrary {
/**
* Get the identification
* for instance "CustomItems"
*
* @return identification
*/
String identification(); String identification();
/**
* Build an item instance for a player
*
* @param player player
* @param id id
* @return item
*/
ItemStack buildItem(Player player, String id); ItemStack buildItem(Player player, String id);
/**
* Get an item's id
*
* @param itemStack item
* @return ID
*/
String getItemID(ItemStack itemStack); String getItemID(ItemStack itemStack);
} }

View File

@@ -28,18 +28,71 @@ import java.util.HashMap;
public interface ActionManager extends Reloadable { public interface ActionManager extends Reloadable {
/**
* Register a custom action type
*
* @param type type
* @param actionFactory action factory
* @return success or not
*/
boolean registerAction(String type, ActionFactory actionFactory); boolean registerAction(String type, ActionFactory actionFactory);
/**
* Unregister an action type by id
*
* @param type type
* @return success or not
*/
boolean unregisterAction(String type); boolean unregisterAction(String type);
/**
* Build an action instance with Bukkit configs
*
* @param section bukkit config
* @return action
*/
Action getAction(ConfigurationSection section); Action getAction(ConfigurationSection section);
/**
* If an action type exists
*
* @param type type
* @return exist or not
*/
default boolean hasAction(String type) {
return getActionFactory(type) != null;
}
/**
* Build an action map with Bukkit configs
*
* @param section bukkit config
* @return action map
*/
HashMap<ActionTrigger, Action[]> getActionMap(ConfigurationSection section); HashMap<ActionTrigger, Action[]> getActionMap(ConfigurationSection section);
/**
* Build actions with Bukkit configs
*
* @param section bukkit config
* @return actions
*/
Action[] getActions(ConfigurationSection section); Action[] getActions(ConfigurationSection section);
/**
* Get an action factory by type
*
* @param type type
* @return action factory
*/
ActionFactory getActionFactory(String type); ActionFactory getActionFactory(String type);
/**
* Trigger actions
*
* @param state state
* @param actions actions
*/
static void triggerActions(State state, Action... actions) { static void triggerActions(State state, Action... actions) {
if (actions != null) if (actions != null)
for (Action action : actions) for (Action action : actions)

View File

@@ -27,21 +27,73 @@ import org.jetbrains.annotations.Nullable;
public interface ConditionManager extends Reloadable { public interface ConditionManager extends Reloadable {
/**
* Register a custom condition type
*
* @param type type
* @param conditionFactory condition factory
* @return success or not
*/
boolean registerCondition(String type, ConditionFactory conditionFactory); boolean registerCondition(String type, ConditionFactory conditionFactory);
/**
* Unregister a condition type by id
*
* @param type type
* @return success or not
*/
boolean unregisterCondition(String type); boolean unregisterCondition(String type);
boolean hasCondition(String type); /**
* If a condition type exists
*
* @param type type
* @return exist or not
*/
default boolean hasCondition(String type) {
return getConditionFactory(type) != null;
}
/**
* Build conditions with Bukkit configs
*
* @param section bukkit config
* @return conditions
*/
@NotNull @NotNull
Condition[] getConditions(ConfigurationSection section); Condition[] getConditions(ConfigurationSection section);
/**
* Build a condition instance with Bukkit configs
*
* @param section bukkit config
* @return condition
*/
Condition getCondition(ConfigurationSection section); Condition getCondition(ConfigurationSection section);
/**
* Build a condition instance with Bukkit configs
*
* @return condition
*/
Condition getCondition(String key, Object args); Condition getCondition(String key, Object args);
/**
* Get a condition factory by type
*
* @param type type
* @return condition factory
*/
@Nullable ConditionFactory getConditionFactory(String type); @Nullable ConditionFactory getConditionFactory(String type);
/**
* Are conditions met for a custom crops block
*
* @param block block
* @param offline is the check for offline ticks
* @param conditions conditions
* @return meet or not
*/
static boolean isConditionMet(CustomCropsBlock block, boolean offline, Condition... conditions) { static boolean isConditionMet(CustomCropsBlock block, boolean offline, Condition... conditions) {
if (conditions == null) return true; if (conditions == null) return true;
for (Condition condition : conditions) { for (Condition condition : conditions) {

View File

@@ -20,8 +20,6 @@ package net.momirealms.customcrops.api.manager;
import net.momirealms.customcrops.api.common.Initable; import net.momirealms.customcrops.api.common.Initable;
import net.momirealms.customcrops.api.integration.LevelInterface; import net.momirealms.customcrops.api.integration.LevelInterface;
import net.momirealms.customcrops.api.integration.SeasonInterface; import net.momirealms.customcrops.api.integration.SeasonInterface;
import net.momirealms.customcrops.api.mechanic.world.season.Season;
import org.bukkit.World;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public interface IntegrationManager extends Initable { public interface IntegrationManager extends Initable {
@@ -51,9 +49,10 @@ public interface IntegrationManager extends Initable {
*/ */
@Nullable LevelInterface getLevelPlugin(String plugin); @Nullable LevelInterface getLevelPlugin(String plugin);
/**
* Get the SeasonInterface provided by a plugin.
*
* @return the season interface
*/
SeasonInterface getSeasonInterface(); SeasonInterface getSeasonInterface();
Season getSeason(World world);
int getDate(World world);
} }

View File

@@ -33,8 +33,20 @@ import java.util.Collection;
public interface ItemManager extends Reloadable { public interface ItemManager extends Reloadable {
/**
* Register an item library
*
* @param itemLibrary item library
* @return success or not
*/
boolean registerItemLibrary(@NotNull ItemLibrary itemLibrary); boolean registerItemLibrary(@NotNull ItemLibrary itemLibrary);
/**
* Unregister an item library by identification
*
* @param identification identification
* @return success or not
*/
boolean unregisterItemLibrary(String identification); boolean unregisterItemLibrary(String identification);
String getItemID(ItemStack itemStack); String getItemID(ItemStack itemStack);

View File

@@ -27,28 +27,81 @@ import org.jetbrains.annotations.Nullable;
public interface RequirementManager extends Reloadable { public interface RequirementManager extends Reloadable {
/**
* Register a custom requirement type
*
* @param type type
* @param requirementFactory requirement factory
* @return success or not
*/
boolean registerRequirement(String type, RequirementFactory requirementFactory); boolean registerRequirement(String type, RequirementFactory requirementFactory);
/**
* Unregister a custom requirement by type
*
* @param type type
* @return success or not
*/
boolean unregisterRequirement(String type); boolean unregisterRequirement(String type);
/**
* Build requirements with Bukkit configs
*
* @param section bukkit config
* @param advanced check "not-met-actions" or not
* @return requirements
*/
@Nullable @Nullable
Requirement[] getRequirements(ConfigurationSection section, boolean advanced); Requirement[] getRequirements(ConfigurationSection section, boolean advanced);
boolean hasRequirement(String type); /**
* If a requirement type exists
*
* @param type type
* @return exist or not
*/
default boolean hasRequirement(String type) {
return getRequirementFactory(type) != null;
}
/**
* Build a requirement instance with Bukkit configs
*
* @param section bukkit config
* @param advanced check "not-met-actions" or not
* @return requirement
*/
@NotNull @NotNull
Requirement getRequirement(ConfigurationSection section, boolean advanced); Requirement getRequirement(ConfigurationSection section, boolean advanced);
/**
* Build a requirement instance with Bukkit configs
*
* @return requirement
*/
@NotNull @NotNull
Requirement getRequirement(String type, Object value); Requirement getRequirement(String type, Object value);
/**
* Get a requirement factory by type
*
* @param type type
* @return requirement factory
*/
@Nullable @Nullable
RequirementFactory getRequirementFactory(String type); RequirementFactory getRequirementFactory(String type);
static boolean isRequirementMet(State condition, Requirement... requirements) { /**
* Are requirements met for a player
*
* @param state state
* @param requirements requirements
* @return meet or not
*/
static boolean isRequirementMet(State state, Requirement... requirements) {
if (requirements == null) return true; if (requirements == null) return true;
for (Requirement requirement : requirements) { for (Requirement requirement : requirements) {
if (!requirement.isStateMet(condition)) { if (!requirement.isStateMet(state)) {
return false; return false;
} }
} }

View File

@@ -68,6 +68,8 @@ public interface CustomCropsWorld {
void unloadChunk(ChunkPos chunkPos); void unloadChunk(ChunkPos chunkPos);
void deleteChunk(ChunkPos chunkPos);
void setInfoData(WorldInfoData infoData); void setInfoData(WorldInfoData infoData);
WorldInfoData getInfoData(); WorldInfoData getInfoData();

View File

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

View File

@@ -51,7 +51,7 @@ dependencies {
implementation(project(":legacy-api")) implementation(project(":legacy-api"))
implementation("net.kyori:adventure-api:4.15.0") implementation("net.kyori:adventure-api:4.15.0")
implementation("net.kyori:adventure-platform-bukkit:4.3.2") implementation("net.kyori:adventure-platform-bukkit:4.3.2")
implementation("com.github.Xiao-MoMi:AntiGriefLib:0.9.1") implementation("com.github.Xiao-MoMi:AntiGriefLib:0.10")
implementation("com.github.Xiao-MoMi:BiomeAPI:0.3") implementation("com.github.Xiao-MoMi:BiomeAPI:0.3")
compileOnly("net.kyori:adventure-text-minimessage:4.15.0") compileOnly("net.kyori:adventure-text-minimessage:4.15.0")

View File

@@ -52,7 +52,6 @@ public class CustomCropsPluginImpl extends CustomCropsPlugin {
private PacketManager packetManager; private PacketManager packetManager;
private CommandManager commandManager; private CommandManager commandManager;
private HologramManager hologramManager; private HologramManager hologramManager;
private AntiGriefLib antiGriefLib;
@Override @Override
public void onLoad() { public void onLoad() {
@@ -71,11 +70,6 @@ public class CustomCropsPluginImpl extends CustomCropsPlugin {
Dependency.BSTATS_BUKKIT Dependency.BSTATS_BUKKIT
) )
)); ));
this.antiGriefLib = AntiGriefLib.builder(this)
.silentLogs(true)
.ignoreOP(true)
.build();
} }
@Override @Override
@@ -91,14 +85,18 @@ public class CustomCropsPluginImpl extends CustomCropsPlugin {
this.requirementManager = new RequirementManagerImpl(this); this.requirementManager = new RequirementManagerImpl(this);
this.coolDownManager = new CoolDownManager(this); this.coolDownManager = new CoolDownManager(this);
this.worldManager = new WorldManagerImpl(this); this.worldManager = new WorldManagerImpl(this);
this.itemManager = new ItemManagerImpl(this, antiGriefLib); this.itemManager = new ItemManagerImpl(this,
AntiGriefLib.builder(this)
.silentLogs(true)
.ignoreOP(true)
.build()
);
this.messageManager = new MessageManagerImpl(this); this.messageManager = new MessageManagerImpl(this);
this.packetManager = new PacketManager(this); this.packetManager = new PacketManager(this);
this.commandManager = new CommandManager(this); this.commandManager = new CommandManager(this);
this.placeholderManager = new PlaceholderManagerImpl(this); this.placeholderManager = new PlaceholderManagerImpl(this);
this.hologramManager = new HologramManager(this); this.hologramManager = new HologramManager(this);
this.commandManager.init(); this.commandManager.init();
this.antiGriefLib.init();
this.integrationManager.init(); this.integrationManager.init();
this.disableNBTAPILogs(); this.disableNBTAPILogs();
Migration.tryUpdating(); Migration.tryUpdating();

View File

@@ -17,12 +17,10 @@
package net.momirealms.customcrops.compatibility; package net.momirealms.customcrops.compatibility;
import com.gamingmesh.jobs.Jobs;
import net.momirealms.customcrops.api.CustomCropsPlugin; import net.momirealms.customcrops.api.CustomCropsPlugin;
import net.momirealms.customcrops.api.integration.LevelInterface; import net.momirealms.customcrops.api.integration.LevelInterface;
import net.momirealms.customcrops.api.integration.SeasonInterface; import net.momirealms.customcrops.api.integration.SeasonInterface;
import net.momirealms.customcrops.api.manager.IntegrationManager; import net.momirealms.customcrops.api.manager.IntegrationManager;
import net.momirealms.customcrops.api.mechanic.world.season.Season;
import net.momirealms.customcrops.api.util.LogUtils; import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.compatibility.item.MMOItemsItemImpl; import net.momirealms.customcrops.compatibility.item.MMOItemsItemImpl;
import net.momirealms.customcrops.compatibility.item.MythicMobsItemImpl; import net.momirealms.customcrops.compatibility.item.MythicMobsItemImpl;
@@ -32,7 +30,6 @@ import net.momirealms.customcrops.compatibility.level.*;
import net.momirealms.customcrops.compatibility.season.AdvancedSeasonsImpl; import net.momirealms.customcrops.compatibility.season.AdvancedSeasonsImpl;
import net.momirealms.customcrops.compatibility.season.InBuiltSeason; import net.momirealms.customcrops.compatibility.season.InBuiltSeason;
import net.momirealms.customcrops.compatibility.season.RealisticSeasonsImpl; import net.momirealms.customcrops.compatibility.season.RealisticSeasonsImpl;
import org.bukkit.World;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.HashMap; import java.util.HashMap;
@@ -110,13 +107,6 @@ public class IntegrationManagerImpl implements IntegrationManager {
} }
/**
* Registers a level plugin with the specified name.
*
* @param plugin The name of the level plugin.
* @param level The implementation of the LevelInterface.
* @return true if the registration was successful, false if the plugin name is already registered.
*/
@Override @Override
public boolean registerLevelPlugin(String plugin, LevelInterface level) { public boolean registerLevelPlugin(String plugin, LevelInterface level) {
if (levelPluginMap.containsKey(plugin)) return false; if (levelPluginMap.containsKey(plugin)) return false;
@@ -124,12 +114,6 @@ public class IntegrationManagerImpl implements IntegrationManager {
return true; return true;
} }
/**
* Unregisters a level plugin with the specified name.
*
* @param plugin The name of the level plugin to unregister.
* @return true if the unregistration was successful, false if the plugin name is not found.
*/
@Override @Override
public boolean unregisterLevelPlugin(String plugin) { public boolean unregisterLevelPlugin(String plugin) {
return levelPluginMap.remove(plugin) != null; return levelPluginMap.remove(plugin) != null;
@@ -139,12 +123,6 @@ public class IntegrationManagerImpl implements IntegrationManager {
LogUtils.info( plugin + " hooked!"); LogUtils.info( plugin + " hooked!");
} }
/**
* Get the LevelInterface provided by a plugin.
*
* @param plugin The name of the plugin providing the LevelInterface.
* @return The LevelInterface provided by the specified plugin, or null if the plugin is not registered.
*/
@Override @Override
@Nullable @Nullable
public LevelInterface getLevelPlugin(String plugin) { public LevelInterface getLevelPlugin(String plugin) {
@@ -155,14 +133,4 @@ public class IntegrationManagerImpl implements IntegrationManager {
public SeasonInterface getSeasonInterface() { public SeasonInterface getSeasonInterface() {
return seasonInterface; return seasonInterface;
} }
@Override
public Season getSeason(World world) {
return seasonInterface.getSeason(world);
}
@Override
public int getDate(World world) {
return seasonInterface.getDate(world);
}
} }

View File

@@ -18,7 +18,6 @@
package net.momirealms.customcrops.compatibility.level; package net.momirealms.customcrops.compatibility.level;
import com.archyx.aureliumskills.api.AureliumAPI; import com.archyx.aureliumskills.api.AureliumAPI;
import com.archyx.aureliumskills.leveler.Leveler;
import net.momirealms.customcrops.api.integration.LevelInterface; import net.momirealms.customcrops.api.integration.LevelInterface;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@@ -74,10 +74,10 @@ public class CCPapi extends PlaceholderExpansion {
switch (split[0]) { switch (split[0]) {
case "season" -> { case "season" -> {
if (split.length == 1) { if (split.length == 1) {
return MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeason(player.getWorld())); return MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeasonInterface().getSeason(player.getWorld()));
} else { } else {
try { try {
return MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeason(Bukkit.getWorld(split[1]))); return MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeasonInterface().getSeason(Bukkit.getWorld(split[1])));
} catch (NullPointerException e) { } catch (NullPointerException e) {
LogUtils.severe("World " + split[1] + " does not exist"); LogUtils.severe("World " + split[1] + " does not exist");
e.printStackTrace(); e.printStackTrace();
@@ -86,10 +86,10 @@ public class CCPapi extends PlaceholderExpansion {
} }
case "date" -> { case "date" -> {
if (split.length == 1) { if (split.length == 1) {
return String.valueOf(plugin.getIntegrationManager().getDate(player.getWorld())); return String.valueOf(plugin.getIntegrationManager().getSeasonInterface().getDate(player.getWorld()));
} else { } else {
try { try {
return String.valueOf(plugin.getIntegrationManager().getDate(Bukkit.getWorld(split[1]))); return String.valueOf(plugin.getIntegrationManager().getSeasonInterface().getDate(Bukkit.getWorld(split[1])));
} catch (NullPointerException e) { } catch (NullPointerException e) {
LogUtils.severe("World " + split[1] + " does not exist"); LogUtils.severe("World " + split[1] + " does not exist");
e.printStackTrace(); e.printStackTrace();

View File

@@ -24,9 +24,11 @@ import dev.jorel.commandapi.arguments.StringArgument;
import net.momirealms.customcrops.api.CustomCropsPlugin; import net.momirealms.customcrops.api.CustomCropsPlugin;
import net.momirealms.customcrops.api.common.Initable; import net.momirealms.customcrops.api.common.Initable;
import net.momirealms.customcrops.api.integration.SeasonInterface; import net.momirealms.customcrops.api.integration.SeasonInterface;
import net.momirealms.customcrops.api.manager.AdventureManager;
import net.momirealms.customcrops.api.manager.ConfigManager; import net.momirealms.customcrops.api.manager.ConfigManager;
import net.momirealms.customcrops.api.manager.MessageManager; import net.momirealms.customcrops.api.manager.MessageManager;
import net.momirealms.customcrops.api.mechanic.item.ItemType; import net.momirealms.customcrops.api.mechanic.item.ItemType;
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock; import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsChunk; import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsChunk;
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsSection; import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsSection;
@@ -61,7 +63,8 @@ public class CommandManager implements Initable {
getAboutCommand(), getAboutCommand(),
getSeasonCommand(), getSeasonCommand(),
getDateCommand(), getDateCommand(),
getForceTickCommand() getForceTickCommand(),
getUnsafeCommand()
) )
.register(); .register();
} }
@@ -81,6 +84,23 @@ public class CommandManager implements Initable {
}); });
} }
private CommandAPICommand getUnsafeCommand() {
return new CommandAPICommand("unsafe")
.withSubcommands(
new CommandAPICommand("delete-chunk-data").executesPlayer((player, args) -> {
CustomCropsPlugin.get().getWorldManager().getCustomCropsWorld(player.getWorld()).ifPresent(customCropsWorld -> {
var optionalChunk = customCropsWorld.getLoadedChunkAt(ChunkPos.getByBukkitChunk(player.getChunk()));
if (optionalChunk.isEmpty()) {
AdventureManager.getInstance().sendMessageWithPrefix(player, "<white>This chunk doesn't have any data.");
return;
}
customCropsWorld.deleteChunk(ChunkPos.getByBukkitChunk(player.getChunk()));
AdventureManager.getInstance().sendMessageWithPrefix(player, "<white>Done.");
});
})
);
}
private CommandAPICommand getAboutCommand() { private CommandAPICommand getAboutCommand() {
return new CommandAPICommand("about").executes((sender, args) -> { return new CommandAPICommand("about").executes((sender, args) -> {
plugin.getAdventure().sendMessage(sender, "<#FFA500>⛈ CustomCrops <gray>- <#87CEEB>" + CustomCropsPlugin.getInstance().getVersionManager().getPluginVersion()); plugin.getAdventure().sendMessage(sender, "<#FFA500>⛈ CustomCrops <gray>- <#87CEEB>" + CustomCropsPlugin.getInstance().getVersionManager().getPluginVersion());
@@ -138,7 +158,7 @@ public class CommandManager implements Initable {
plugin.getAdventure().sendMessageWithPrefix(sender, "CustomCrops is not enabled in that world"); plugin.getAdventure().sendMessageWithPrefix(sender, "CustomCrops is not enabled in that world");
return; return;
} }
plugin.getAdventure().sendMessageWithPrefix(sender, String.valueOf(plugin.getIntegrationManager().getDate(world))); plugin.getAdventure().sendMessageWithPrefix(sender, String.valueOf(plugin.getIntegrationManager().getSeasonInterface().getDate(world)));
}), }),
new CommandAPICommand("set") new CommandAPICommand("set")
.withArguments(new StringArgument("world").replaceSuggestions(ArgumentSuggestions.strings(commandSenderSuggestionInfo -> plugin.getWorldManager().getCustomCropsWorlds().stream() .withArguments(new StringArgument("world").replaceSuggestions(ArgumentSuggestions.strings(commandSenderSuggestionInfo -> plugin.getWorldManager().getCustomCropsWorlds().stream()
@@ -196,7 +216,7 @@ public class CommandManager implements Initable {
plugin.getAdventure().sendMessageWithPrefix(sender, "CustomCrops is not enabled in that world"); plugin.getAdventure().sendMessageWithPrefix(sender, "CustomCrops is not enabled in that world");
return; return;
} }
plugin.getAdventure().sendMessageWithPrefix(sender, MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeason(world))); plugin.getAdventure().sendMessageWithPrefix(sender, MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeasonInterface().getSeason(world)));
}), }),
new CommandAPICommand("set") new CommandAPICommand("set")
.withArguments(new StringArgument("world").replaceSuggestions(ArgumentSuggestions.strings(commandSenderSuggestionInfo -> { .withArguments(new StringArgument("world").replaceSuggestions(ArgumentSuggestions.strings(commandSenderSuggestionInfo -> {

View File

@@ -111,11 +111,6 @@ public class ConditionManagerImpl implements ConditionManager {
return this.conditionBuilderMap.remove(type) != null; return this.conditionBuilderMap.remove(type) != null;
} }
@Override
public boolean hasCondition(String type) {
return conditionBuilderMap.containsKey(type);
}
@Override @Override
public @NotNull Condition[] getConditions(ConfigurationSection section) { public @NotNull Condition[] getConditions(ConfigurationSection section) {
ArrayList<Condition> conditions = new ArrayList<>(); ArrayList<Condition> conditions = new ArrayList<>();
@@ -578,7 +573,7 @@ public class ConditionManagerImpl implements ConditionManager {
registerCondition("suitable_season", (args) -> { registerCondition("suitable_season", (args) -> {
HashSet<String> seasons = new HashSet<>(ConfigUtils.stringListArgs(args).stream().map(it -> it.toUpperCase(Locale.ENGLISH)).toList()); HashSet<String> seasons = new HashSet<>(ConfigUtils.stringListArgs(args).stream().map(it -> it.toUpperCase(Locale.ENGLISH)).toList());
return (block, offline) -> { return (block, offline) -> {
Season season = plugin.getIntegrationManager().getSeason(block.getLocation().getBukkitWorld()); Season season = plugin.getIntegrationManager().getSeasonInterface().getSeason(block.getLocation().getBukkitWorld());
if (season == null) { if (season == null) {
return true; return true;
} }
@@ -602,7 +597,7 @@ public class ConditionManagerImpl implements ConditionManager {
registerCondition("unsuitable_season", (args) -> { registerCondition("unsuitable_season", (args) -> {
HashSet<String> seasons = new HashSet<>(ConfigUtils.stringListArgs(args).stream().map(it -> it.toUpperCase(Locale.ENGLISH)).toList()); HashSet<String> seasons = new HashSet<>(ConfigUtils.stringListArgs(args).stream().map(it -> it.toUpperCase(Locale.ENGLISH)).toList());
return (block, offline) -> { return (block, offline) -> {
Season season = plugin.getIntegrationManager().getSeason(block.getLocation().getBukkitWorld()); Season season = plugin.getIntegrationManager().getSeasonInterface().getSeason(block.getLocation().getBukkitWorld());
if (season == null) { if (season == null) {
return false; return false;
} }

View File

@@ -742,6 +742,79 @@ public class ItemManagerImpl implements ItemManager {
} }
this.registerItemFunction(itemID, FunctionTrigger.INTERACT_AT, this.registerItemFunction(itemID, FunctionTrigger.INTERACT_AT,
/*
* Handle clicking sprinkler with a watering can
*/
new CFunction(conditionWrapper -> {
if (!(conditionWrapper instanceof InteractBlockWrapper blockWrapper)) {
return FunctionResult.PASS;
}
// is a pot
Block block = blockWrapper.getClickedBlock();
Sprinkler sprinkler = getSprinklerBy3DItemID(customProvider.getBlockID(block));
if (sprinkler == null) {
return FunctionResult.PASS;
}
final Player player = blockWrapper.getPlayer();
final ItemStack itemInHand = blockWrapper.getItemInHand();
final Location clicked = block.getLocation();
State state = new State(player, itemInHand, clicked);
// check watering-can requirements
if (!RequirementManager.isRequirementMet(state, wateringCan.getRequirements())) {
return FunctionResult.RETURN;
}
// check whitelist
if (!wateringCan.getSprinklerWhitelist().contains(sprinkler.getKey())) {
wateringCan.trigger(ActionTrigger.WRONG_SPRINKLER, state);
return FunctionResult.RETURN;
}
// get water in can
int waterInCan = wateringCan.getCurrentWater(itemInHand);
// check sprinkler requirements
if (!RequirementManager.isRequirementMet(state, sprinkler.getUseRequirements())) {
return FunctionResult.RETURN;
}
// check whitelist
if (!wateringCan.getSprinklerWhitelist().contains(sprinkler.getKey())) {
wateringCan.trigger(ActionTrigger.WRONG_SPRINKLER, state);
return FunctionResult.RETURN;
}
// check amount of water
if (waterInCan > 0 || wateringCan.isInfinite()) {
// get sprinkler data
SimpleLocation simpleLocation = SimpleLocation.of(clicked);
Optional<WorldSprinkler> worldSprinkler = plugin.getWorldManager().getSprinklerAt(simpleLocation);
if (worldSprinkler.isEmpty()) {
plugin.debug("Player " + player.getName() + " tried to interact a sprinkler which not exists in memory. Fixing the data...");
WorldSprinkler sp = new MemorySprinkler(simpleLocation, sprinkler.getKey(), 0);
plugin.getWorldManager().addSprinklerAt(sp, simpleLocation);
worldSprinkler = Optional.of(sp);
} else {
if (sprinkler.getStorage() <= worldSprinkler.get().getWater()) {
return FunctionResult.RETURN;
}
}
// fire the event
WateringCanWaterEvent waterEvent = new WateringCanWaterEvent(player, itemInHand, new HashSet<>(Set.of(clicked)), wateringCan, worldSprinkler.get());
if (EventUtils.fireAndCheckCancel(waterEvent))
return FunctionResult.CANCEL_EVENT_AND_RETURN;
state.setArg("{storage}", String.valueOf(wateringCan.getStorage()));
state.setArg("{current}", String.valueOf(waterInCan - 1));
state.setArg("{water_bar}", wateringCan.getWaterBar() == null ? "" : wateringCan.getWaterBar().getWaterBar(waterInCan - 1, wateringCan.getStorage()));
wateringCan.updateItem(player, itemInHand, waterInCan - 1, state.getArgs());
wateringCan.trigger(ActionTrigger.CONSUME_WATER, state);
plugin.getWorldManager().addWaterToSprinkler(sprinkler, simpleLocation, 1);
} else {
state.setArg("{storage}", String.valueOf(wateringCan.getStorage()));
state.setArg("{current}", "0");
state.setArg("{water_bar}", wateringCan.getWaterBar() == null ? "" : wateringCan.getWaterBar().getWaterBar(0, wateringCan.getStorage()));
wateringCan.trigger(ActionTrigger.NO_WATER, state);
}
return FunctionResult.RETURN;
}, CFunction.FunctionPriority.HIGH),
/* /*
* Handle clicking pot with a watering can * Handle clicking pot with a watering can
*/ */
@@ -893,6 +966,9 @@ public class ItemManagerImpl implements ItemManager {
} }
return FunctionResult.RETURN; return FunctionResult.RETURN;
}, CFunction.FunctionPriority.NORMAL), }, CFunction.FunctionPriority.NORMAL),
/*
* Handle clicking crop with a watering can
*/
new CFunction(conditionWrapper -> { new CFunction(conditionWrapper -> {
if (!(conditionWrapper instanceof InteractFurnitureWrapper furnitureWrapper)) { if (!(conditionWrapper instanceof InteractFurnitureWrapper furnitureWrapper)) {
return FunctionResult.PASS; return FunctionResult.PASS;
@@ -1316,12 +1392,12 @@ public class ItemManagerImpl implements ItemManager {
* Interact the sprinkler * Interact the sprinkler
*/ */
new CFunction(conditionWrapper -> { new CFunction(conditionWrapper -> {
if (!(conditionWrapper instanceof InteractFurnitureWrapper interactFurnitureWrapper)) { if (!(conditionWrapper instanceof InteractWrapper interactWrapper)) {
return FunctionResult.PASS; return FunctionResult.PASS;
} }
ItemStack itemInHand = interactFurnitureWrapper.getItemInHand(); ItemStack itemInHand = interactWrapper.getItemInHand();
Player player = interactFurnitureWrapper.getPlayer(); Player player = interactWrapper.getPlayer();
Location location = interactFurnitureWrapper.getLocation(); Location location = interactWrapper.getLocation();
// check use requirements // check use requirements
State state = new State(player, itemInHand, location); State state = new State(player, itemInHand, location);
if (!RequirementManager.isRequirementMet(state, sprinkler.getUseRequirements())) { if (!RequirementManager.isRequirementMet(state, sprinkler.getUseRequirements())) {
@@ -1381,6 +1457,7 @@ public class ItemManagerImpl implements ItemManager {
state.setArg("{current}", String.valueOf(sprinkler.getStorage())); state.setArg("{current}", String.valueOf(sprinkler.getStorage()));
state.setArg("{water_bar}", sprinkler.getWaterBar() == null ? "" : sprinkler.getWaterBar().getWaterBar(sprinkler.getStorage(), sprinkler.getStorage())); state.setArg("{water_bar}", sprinkler.getWaterBar() == null ? "" : sprinkler.getWaterBar().getWaterBar(sprinkler.getStorage(), sprinkler.getStorage()));
sprinkler.trigger(ActionTrigger.FULL, state); sprinkler.trigger(ActionTrigger.FULL, state);
return FunctionResult.CANCEL_EVENT_AND_RETURN;
} }
} }
return FunctionResult.RETURN; return FunctionResult.RETURN;
@@ -1394,14 +1471,14 @@ public class ItemManagerImpl implements ItemManager {
this.registerItemFunction(new String[]{sprinkler.get3DItemID(), sprinkler.get3DItemWithWater()}, FunctionTrigger.BE_INTERACTED, this.registerItemFunction(new String[]{sprinkler.get3DItemID(), sprinkler.get3DItemWithWater()}, FunctionTrigger.BE_INTERACTED,
new CFunction(conditionWrapper -> { new CFunction(conditionWrapper -> {
if (!(conditionWrapper instanceof InteractFurnitureWrapper interactFurnitureWrapper)) { if (!(conditionWrapper instanceof InteractWrapper interactWrapper)) {
return FunctionResult.PASS; return FunctionResult.PASS;
} }
Location location = interactFurnitureWrapper.getLocation(); Location location = interactWrapper.getLocation();
// trigger interact actions // trigger interact actions
plugin.getScheduler().runTaskSyncLater(() -> { plugin.getScheduler().runTaskSyncLater(() -> {
State state = new State(interactFurnitureWrapper.getPlayer(), interactFurnitureWrapper.getItemInHand(), location); State state = new State(interactWrapper.getPlayer(), interactWrapper.getItemInHand(), location);
Optional<WorldSprinkler> optionalSprinkler = plugin.getWorldManager().getSprinklerAt(SimpleLocation.of(location)); Optional<WorldSprinkler> optionalSprinkler = plugin.getWorldManager().getSprinklerAt(SimpleLocation.of(location));
if (optionalSprinkler.isEmpty()) { if (optionalSprinkler.isEmpty()) {
return; return;
@@ -2071,6 +2148,7 @@ public class ItemManagerImpl implements ItemManager {
plugin.getWorldManager().addWaterToPot(pot, simpleLocation, method.getAmount()); plugin.getWorldManager().addWaterToPot(pot, simpleLocation, method.getAmount());
} else { } else {
pot.trigger(ActionTrigger.FULL, state); pot.trigger(ActionTrigger.FULL, state);
return FunctionResult.CANCEL_EVENT_AND_RETURN;
} }
} }
return FunctionResult.RETURN; return FunctionResult.RETURN;

View File

@@ -145,9 +145,15 @@ public abstract class AbstractCustomListener implements Listener {
@EventHandler (ignoreCancelled = true) @EventHandler (ignoreCancelled = true)
public void onPlaceBlock(BlockPlaceEvent event) { public void onPlaceBlock(BlockPlaceEvent event) {
onPlaceBlock( final Block block = event.getBlock();
// prevent players from placing blocks on entities (crops/sprinklers)
if (CustomCropsPlugin.get().getWorldManager().getBlockAt(SimpleLocation.of(block.getLocation())).isPresent()) {
event.setCancelled(true);
return;
}
this.onPlaceBlock(
event.getPlayer(), event.getPlayer(),
event.getBlock(), block,
event.getBlockPlaced().getType().name(), event.getBlockPlaced().getType().name(),
event event
); );

View File

@@ -146,11 +146,6 @@ public class RequirementManagerImpl implements RequirementManager {
return requirements.toArray(new Requirement[0]); return requirements.toArray(new Requirement[0]);
} }
@Override
public boolean hasRequirement(String type) {
return requirementBuilderMap.containsKey(type);
}
@NotNull @NotNull
@Override @Override
public Requirement getRequirement(ConfigurationSection section, boolean advanced) { public Requirement getRequirement(ConfigurationSection section, boolean advanced) {

View File

@@ -276,6 +276,11 @@ public class CWorld implements CustomCropsWorld {
} }
} }
@Override
public void deleteChunk(ChunkPos chunkPos) {
CChunk chunk = loadedChunks.remove(chunkPos);
}
@Override @Override
public void setInfoData(WorldInfoData infoData) { public void setInfoData(WorldInfoData infoData) {
this.infoData = infoData; this.infoData = infoData;