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 {
/**
* init
*/
void init();
/**
* 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 {
/**
* Trigger events
*
* @param actionTrigger trigger
* @param state state
*/
void trigger(ActionTrigger actionTrigger, State state);
}

View File

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

View File

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

View File

@@ -77,6 +77,7 @@ public class BoneMealUseEvent extends Event implements Cancellable {
/**
* Get the crop location
*
* @return location
*/
@NotNull
@@ -87,6 +88,7 @@ public class BoneMealUseEvent extends Event implements Cancellable {
/**
* Get the item in player's hand
* If there's nothing in hand, it would return AIR
*
* @return item in hand
*/
@NotNull
@@ -94,11 +96,21 @@ public class BoneMealUseEvent extends Event implements Cancellable {
return itemInHand;
}
/**
* Get the crop's data
*
* @return crop data
*/
@NotNull
public WorldCrop getCrop() {
return crop;
}
/**
* Get the bone meal config
*
* @return bone meal config
*/
@NotNull
public BoneMeal getBoneMeal() {
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
*
* @return crop data
*/
@Nullable
@@ -84,6 +85,7 @@ public class CropBreakEvent extends Event implements Cancellable {
/**
* Get the crop location
*
* @return location
*/
@NotNull
@@ -91,6 +93,14 @@ public class CropBreakEvent extends Event implements Cancellable {
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
public Entity getEntity() {
return entity;
@@ -104,6 +114,11 @@ public class CropBreakEvent extends Event implements Cancellable {
return null;
}
/**
* Get the reason
*
* @return reason
*/
@NotNull
public Reason getReason() {
return reason;

View File

@@ -73,6 +73,7 @@ public class CropInteractEvent extends PlayerEvent implements Cancellable {
/**
* Get the crop location
*
* @return location
*/
@NotNull
@@ -83,6 +84,7 @@ public class CropInteractEvent extends PlayerEvent implements Cancellable {
/**
* Get the item in player's hand
* If there's nothing in hand, it would return AIR
*
* @return item in hand
*/
@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
*
* @return crop data
*/
@Nullable

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -28,18 +28,71 @@ import java.util.HashMap;
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);
/**
* Unregister an action type by id
*
* @param type type
* @return success or not
*/
boolean unregisterAction(String type);
/**
* Build an action instance with Bukkit configs
*
* @param section bukkit config
* @return action
*/
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);
/**
* Build actions with Bukkit configs
*
* @param section bukkit config
* @return actions
*/
Action[] getActions(ConfigurationSection section);
/**
* Get an action factory by type
*
* @param type type
* @return action factory
*/
ActionFactory getActionFactory(String type);
/**
* Trigger actions
*
* @param state state
* @param actions actions
*/
static void triggerActions(State state, Action... actions) {
if (actions != null)
for (Action action : actions)

View File

@@ -27,21 +27,73 @@ import org.jetbrains.annotations.Nullable;
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);
/**
* Unregister a condition type by id
*
* @param type type
* @return success or not
*/
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
Condition[] getConditions(ConfigurationSection section);
/**
* Build a condition instance with Bukkit configs
*
* @param section bukkit config
* @return condition
*/
Condition getCondition(ConfigurationSection section);
/**
* Build a condition instance with Bukkit configs
*
* @return condition
*/
Condition getCondition(String key, Object args);
/**
* Get a condition factory by type
*
* @param type type
* @return condition factory
*/
@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) {
if (conditions == null) return true;
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.integration.LevelInterface;
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;
public interface IntegrationManager extends Initable {
@@ -51,9 +49,10 @@ public interface IntegrationManager extends Initable {
*/
@Nullable LevelInterface getLevelPlugin(String plugin);
/**
* Get the SeasonInterface provided by a plugin.
*
* @return the season interface
*/
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 {
/**
* Register an item library
*
* @param itemLibrary item library
* @return success or not
*/
boolean registerItemLibrary(@NotNull ItemLibrary itemLibrary);
/**
* Unregister an item library by identification
*
* @param identification identification
* @return success or not
*/
boolean unregisterItemLibrary(String identification);
String getItemID(ItemStack itemStack);

View File

@@ -27,28 +27,81 @@ import org.jetbrains.annotations.Nullable;
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);
/**
* Unregister a custom requirement by type
*
* @param type type
* @return success or not
*/
boolean unregisterRequirement(String type);
/**
* Build requirements with Bukkit configs
*
* @param section bukkit config
* @param advanced check "not-met-actions" or not
* @return requirements
*/
@Nullable
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
Requirement getRequirement(ConfigurationSection section, boolean advanced);
/**
* Build a requirement instance with Bukkit configs
*
* @return requirement
*/
@NotNull
Requirement getRequirement(String type, Object value);
/**
* Get a requirement factory by type
*
* @param type type
* @return requirement factory
*/
@Nullable
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;
for (Requirement requirement : requirements) {
if (!requirement.isStateMet(condition)) {
if (!requirement.isStateMet(state)) {
return false;
}
}

View File

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