mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 09:59:20 +00:00
2.2.3
This commit is contained in:
@@ -26,6 +26,7 @@ import net.momirealms.customcrops.commands.PluginCommand;
|
||||
import net.momirealms.customcrops.config.ConfigUtil;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.helper.LibraryLoader;
|
||||
import net.momirealms.customcrops.helper.VersionHelper;
|
||||
import net.momirealms.customcrops.integrations.papi.PlaceholderManager;
|
||||
import net.momirealms.customcrops.integrations.protection.WorldGuardHook;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
@@ -33,7 +34,6 @@ import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.kingdoms.main.ConfigManager;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -41,11 +41,11 @@ public final class CustomCrops extends JavaPlugin {
|
||||
|
||||
public static BukkitAudiences adventure;
|
||||
public static CustomCrops plugin;
|
||||
public static String version;
|
||||
public static ProtocolManager protocolManager;
|
||||
|
||||
private PlaceholderManager placeholderManager;
|
||||
private CropManager cropManager;
|
||||
private VersionHelper versionHelper;
|
||||
|
||||
// _ooOoo_
|
||||
// o8888888o
|
||||
@@ -79,10 +79,8 @@ public final class CustomCrops extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
adventure = BukkitAudiences.create(plugin);
|
||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
AdventureUtil.consoleMessage("[CustomCrops] Running on <white>" + Bukkit.getVersion());
|
||||
|
||||
MinecraftVersion.disableBStats();
|
||||
@@ -112,6 +110,7 @@ public final class CustomCrops extends JavaPlugin {
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setTabCompleter(pluginCommand);
|
||||
|
||||
this.cropManager = new CropManager();
|
||||
this.versionHelper = new VersionHelper();
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
this.placeholderManager = new PlaceholderManager();
|
||||
@@ -148,4 +147,8 @@ public final class CustomCrops extends JavaPlugin {
|
||||
public CropManager getCropManager() {
|
||||
return cropManager;
|
||||
}
|
||||
|
||||
public VersionHelper getVersionHelper() {
|
||||
return versionHelper;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ public interface Crop {
|
||||
|
||||
CCSeason[] getSeasons();
|
||||
|
||||
RequirementInterface[] getRequirements();
|
||||
RequirementInterface[] getPlantRequirements();
|
||||
|
||||
RequirementInterface[] getHarvestRequirements();
|
||||
|
||||
String getReturnStage();
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package net.momirealms.customcrops.api.event;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PreActionEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private final Location location;
|
||||
|
||||
public PreActionEvent(@NotNull Player who, Location location) {
|
||||
super(who);
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.momirealms.customcrops.api.utils;
|
||||
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
|
||||
public class AntiGriefUtils {
|
||||
|
||||
public static void register(CCAntiGrief CCAntiGrief) {
|
||||
MainConfig.registerAntiGrief(CCAntiGrief);
|
||||
}
|
||||
|
||||
public static void unregister(CCAntiGrief CCAntiGrief) {
|
||||
MainConfig.unregisterAntiGrief(CCAntiGrief);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class BackUpCommand extends AbstractSubCommand {
|
||||
String worldName = args.get(0);
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) {
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists);
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists.replace("{world}", worldName));
|
||||
return true;
|
||||
}
|
||||
CustomWorld customWorld = CustomCrops.plugin.getCropManager().getCustomWorld(world);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class GrowCommand extends AbstractSubCommand {
|
||||
else {
|
||||
World world = Bukkit.getWorld(args.get(0));
|
||||
if (world == null) {
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists);
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists.replace("{world}", args.get(0)));
|
||||
return true;
|
||||
}
|
||||
int growTime;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class SaveCacheCommand extends AbstractSubCommand {
|
||||
String worldName = args.get(0);
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) {
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists);
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists.replace("{world}", worldName));
|
||||
return true;
|
||||
}
|
||||
CustomWorld customWorld = CustomCrops.plugin.getCropManager().getCustomWorld(world);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class SetSeasonCommand extends AbstractSubCommand {
|
||||
else {
|
||||
World world = Bukkit.getWorld(args.get(0));
|
||||
if (world == null) {
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists);
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists.replace("{world}", args.get(0)));
|
||||
return true;
|
||||
}
|
||||
CCSeason ccSeason;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class SimulateCommand extends AbstractSubCommand {
|
||||
else {
|
||||
World world = Bukkit.getWorld(args.get(0));
|
||||
if (world == null) {
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists);
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists.replace("{world}", args.get(0)));
|
||||
return true;
|
||||
}
|
||||
int sprinklerTime;
|
||||
|
||||
@@ -155,49 +155,50 @@ public class CropConfig {
|
||||
case "return" -> {
|
||||
crop.setReturnStage(config.getString(key + ".return"));
|
||||
}
|
||||
case "requirements" -> {
|
||||
case "requirements", "plant-requirements", "harvest-requirements" -> {
|
||||
List<RequirementInterface> requirementList = new ArrayList<>();
|
||||
for (String requirement : Objects.requireNonNull(config.getConfigurationSection(key + ".requirements")).getKeys(false)) {
|
||||
String type = config.getString(key + ".requirements." + requirement + ".type");
|
||||
for (String requirement : Objects.requireNonNull(config.getConfigurationSection(key + "." + option)).getKeys(false)) {
|
||||
String type = config.getString(key + "." + option + "." + requirement + ".type");
|
||||
if (type == null) continue;
|
||||
switch (type) {
|
||||
case "time" -> requirementList.add(new RequirementTime(
|
||||
config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + ".requirements." + requirement + ".message")
|
||||
config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + "." + option + "." + requirement + ".message")
|
||||
));
|
||||
case "weather" -> requirementList.add(new RequirementWeather(
|
||||
config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + ".requirements." + requirement + ".message")
|
||||
config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + "." + option + "." + requirement + ".message")
|
||||
));
|
||||
case "yPos" -> requirementList.add(new RequirementYPos(
|
||||
config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + ".requirements." + requirement + ".message")
|
||||
config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + "." + option + "." + requirement + ".message")
|
||||
));
|
||||
case "biome" -> requirementList.add(new RequirementBiome(
|
||||
config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + ".requirements." + requirement + ".message")
|
||||
config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + "." + option + "." + requirement + ".message")
|
||||
));
|
||||
case "world" -> requirementList.add(new RequirementWorld(
|
||||
config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + ".requirements." + requirement + ".message")
|
||||
config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + "." + option + "." + requirement + ".message")
|
||||
));
|
||||
case "permission" -> requirementList.add(new RequirementPermission(
|
||||
config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + ".requirements." + requirement + ".message")
|
||||
config.getStringList(key + "." + option + "." + requirement + ".value").toArray(new String[0]),
|
||||
Objects.equals(config.getString(key + "." + option + "." + requirement + ".mode"), "&&"),
|
||||
config.getString(key + "." + option + "." + requirement + ".message")
|
||||
));
|
||||
case "papi-condition" -> requirementList.add(new CustomPapi(
|
||||
Objects.requireNonNull(config.getConfigurationSection(key + ".requirements." + requirement + ".value")).getValues(false),
|
||||
config.getString(key + ".requirements." + requirement + ".message")
|
||||
Objects.requireNonNull(config.getConfigurationSection(key + "." + option + "." + requirement + ".value")).getValues(false),
|
||||
config.getString(key + "." + option + "." + requirement + ".message")
|
||||
));
|
||||
}
|
||||
}
|
||||
crop.setRequirements(requirementList.toArray(new RequirementInterface[0]));
|
||||
if (option.equals("harvest-requirements")) crop.setHarvestRequirements(requirementList.toArray(new RequirementInterface[0]));
|
||||
else crop.setPlantRequirements(requirementList.toArray(new RequirementInterface[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
package net.momirealms.customcrops.config;
|
||||
|
||||
import net.momirealms.customcrops.helper.Log;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import net.momirealms.customcrops.integrations.SkillXP;
|
||||
import net.momirealms.customcrops.integrations.protection.*;
|
||||
import net.momirealms.customcrops.integrations.skill.*;
|
||||
@@ -48,7 +48,8 @@ public class MainConfig {
|
||||
public static boolean OraxenHook;
|
||||
public static boolean realisticSeasonHook;
|
||||
public static boolean cropMode;
|
||||
public static List<AntiGrief> antiGriefs;
|
||||
public static List<CCAntiGrief> internalAntiGriefs = new ArrayList<>();
|
||||
public static List<CCAntiGrief> externalAntiGriefs = new ArrayList<>();
|
||||
public static SkillXP skillXP;
|
||||
public static double dryGrowChance;
|
||||
public static boolean limitation;
|
||||
@@ -89,6 +90,7 @@ public class MainConfig {
|
||||
public static String fertilizerInfo;
|
||||
public static boolean enableParticles;
|
||||
public static boolean enableAnimations;
|
||||
public static double animationYOffset;
|
||||
public static boolean autoGrow;
|
||||
public static boolean enableCompensation;
|
||||
public static boolean syncSeason;
|
||||
@@ -122,7 +124,6 @@ public class MainConfig {
|
||||
public static boolean enableSkillBonus;
|
||||
public static double bonusPerLevel;
|
||||
public static HashMap<Material, String> vanilla2Crops;
|
||||
public static boolean enableEvents;
|
||||
public static int saveInterval;
|
||||
public static boolean dryMakesCropDead;
|
||||
public static double dryDeadChance;
|
||||
@@ -191,7 +192,8 @@ public class MainConfig {
|
||||
autoBackUp = config.getBoolean("optimization.auto-back-up", true);
|
||||
|
||||
enableParticles = !config.getBoolean("optimization.disable-water-particles", false);
|
||||
enableAnimations = !config.getBoolean("optimization.disable-sprinkler-animation", false);
|
||||
enableAnimations = config.getBoolean("mechanics.sprinkler-animation.enable", true);
|
||||
animationYOffset = config.getDouble("mechanics.sprinkler-animation.y-offset", 1);
|
||||
|
||||
enableSeasonBroadcast = config.getBoolean("season-broadcast.enable", true);
|
||||
springMsg = config.getStringList("season-broadcast.spring").toArray(new String[0]);
|
||||
@@ -216,7 +218,6 @@ public class MainConfig {
|
||||
|
||||
skyLightLevel = config.getInt("mechanics.dead-if-no-sky-light.level", 10);
|
||||
needSkyLight = config.getBoolean("mechanics.dead-if-no-sky-light.enable", true);
|
||||
enableEvents = config.getBoolean("other-settings.enable-additional-events", false);
|
||||
|
||||
String[] split = StringUtils.split(config.getString("mechanics.default-quality-ratio", "17/2/1"), "/");
|
||||
double[] weight = new double[3];
|
||||
@@ -290,81 +291,81 @@ public class MainConfig {
|
||||
|
||||
saveInterval = config.getInt("other-settings.data-save-interval", 3);
|
||||
|
||||
antiGriefs = new ArrayList<>();
|
||||
internalAntiGriefs.clear();
|
||||
if (config.getBoolean("integration.Residence",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("Residence") == null) Log.warn("Failed to initialize Residence!");
|
||||
else {
|
||||
antiGriefs.add(new ResidenceHook());
|
||||
internalAntiGriefs.add(new ResidenceHook());
|
||||
hookMessage("Residence");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.Kingdoms",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("Kingdoms") == null) Log.warn("Failed to initialize Kingdoms!");
|
||||
else {
|
||||
antiGriefs.add(new KingdomsXHook());
|
||||
internalAntiGriefs.add(new KingdomsXHook());
|
||||
hookMessage("Kingdoms");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.WorldGuard",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) Log.warn("Failed to initialize WorldGuard!");
|
||||
else {
|
||||
antiGriefs.add(new WorldGuardHook());
|
||||
internalAntiGriefs.add(new WorldGuardHook());
|
||||
hookMessage("WorldGuard");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.GriefDefender",false)){
|
||||
if(Bukkit.getPluginManager().getPlugin("GriefDefender") == null) Log.warn("Failed to initialize GriefDefender!");
|
||||
else {
|
||||
antiGriefs.add(new GriefDefenderHook());
|
||||
internalAntiGriefs.add(new GriefDefenderHook());
|
||||
hookMessage("GriefDefender");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.PlotSquared",false)){
|
||||
if(Bukkit.getPluginManager().getPlugin("PlotSquared") == null) Log.warn("Failed to initialize PlotSquared!");
|
||||
else {
|
||||
antiGriefs.add(new PlotSquaredHook());
|
||||
internalAntiGriefs.add(new PlotSquaredHook());
|
||||
hookMessage("PlotSquared");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.Towny",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("Towny") == null) Log.warn("Failed to initialize Towny!");
|
||||
else {
|
||||
antiGriefs.add(new TownyHook());
|
||||
internalAntiGriefs.add(new TownyHook());
|
||||
hookMessage("Towny");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.Lands",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("Lands") == null) Log.warn("Failed to initialize Lands!");
|
||||
else {
|
||||
antiGriefs.add(new LandsHook());
|
||||
internalAntiGriefs.add(new LandsHook());
|
||||
hookMessage("Lands");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.GriefPrevention",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("GriefPrevention") == null) Log.warn("Failed to initialize GriefPrevention!");
|
||||
else {
|
||||
antiGriefs.add(new GriefPreventionHook());
|
||||
internalAntiGriefs.add(new GriefPreventionHook());
|
||||
hookMessage("GriefPrevention");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.CrashClaim",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("CrashClaim") == null) Log.warn("Failed to initialize CrashClaim!");
|
||||
else {
|
||||
antiGriefs.add(new CrashClaimHook());
|
||||
internalAntiGriefs.add(new CrashClaimHook());
|
||||
hookMessage("CrashClaim");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.BentoBox",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("BentoBox") == null) Log.warn("Failed to initialize BentoBox!");
|
||||
else {
|
||||
antiGriefs.add(new BentoBoxHook());
|
||||
internalAntiGriefs.add(new BentoBoxHook());
|
||||
hookMessage("BentoBox");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.IridiumSkyblock",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("IridiumSkyblock") == null) Log.warn("Failed to initialize IridiumSkyblock!");
|
||||
else {
|
||||
antiGriefs.add(new IridiumSkyblockHook());
|
||||
internalAntiGriefs.add(new IridiumSkyblockHook());
|
||||
hookMessage("IridiumSkyblock");
|
||||
}
|
||||
}
|
||||
@@ -435,4 +436,13 @@ public class MainConfig {
|
||||
private static void hookMessage(String plugin){
|
||||
AdventureUtil.consoleMessage("[CustomCrops] <white>" + plugin + " Hooked!");
|
||||
}
|
||||
|
||||
public static void registerAntiGrief(CCAntiGrief ccAntiGrief) {
|
||||
externalAntiGriefs.add(ccAntiGrief);
|
||||
hookMessage(ccAntiGrief.getName());
|
||||
}
|
||||
|
||||
public static void unregisterAntiGrief(CCAntiGrief ccAntiGrief) {
|
||||
externalAntiGriefs.remove(ccAntiGrief);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.momirealms.customcrops.helper;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class VersionHelper {
|
||||
|
||||
private boolean isNewerThan1_19_R2;
|
||||
private String version;
|
||||
|
||||
public boolean isVersionNewerThan1_19_R2() {
|
||||
if (version == null) {
|
||||
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
String[] split = version.split("_");
|
||||
int main_ver = Integer.parseInt(split[1]);
|
||||
if (main_ver >= 20) isNewerThan1_19_R2 = true;
|
||||
else if (main_ver == 19) isNewerThan1_19_R2 = Integer.parseInt(split[2].substring(1)) >= 2;
|
||||
else isNewerThan1_19_R2 = false;
|
||||
}
|
||||
return isNewerThan1_19_R2;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@ import net.momirealms.customcrops.config.MainConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface AntiGrief {
|
||||
public interface CCAntiGrief {
|
||||
|
||||
String getName();
|
||||
|
||||
boolean canBreak(Location location, Player player);
|
||||
|
||||
@@ -29,8 +31,13 @@ public interface AntiGrief {
|
||||
|
||||
static boolean testBreak(Player player, Location location) {
|
||||
if (player.isOp()) return true;
|
||||
for (AntiGrief antiGrief : MainConfig.antiGriefs) {
|
||||
if(!antiGrief.canBreak(location, player)) {
|
||||
for (CCAntiGrief CCAntiGrief : MainConfig.internalAntiGriefs) {
|
||||
if(!CCAntiGrief.canBreak(location, player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (CCAntiGrief CCAntiGrief : MainConfig.externalAntiGriefs) {
|
||||
if(!CCAntiGrief.canBreak(location, player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -39,8 +46,13 @@ public interface AntiGrief {
|
||||
|
||||
static boolean testPlace(Player player, Location location) {
|
||||
if (player.isOp()) return true;
|
||||
for (AntiGrief antiGrief : MainConfig.antiGriefs) {
|
||||
if(!antiGrief.canPlace(location, player)) {
|
||||
for (CCAntiGrief CCAntiGrief : MainConfig.internalAntiGriefs) {
|
||||
if(!CCAntiGrief.canPlace(location, player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (CCAntiGrief CCAntiGrief : MainConfig.externalAntiGriefs) {
|
||||
if(!CCAntiGrief.canPlace(location, player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package net.momirealms.customcrops.integrations.customplugin;
|
||||
|
||||
import com.willfp.eco.core.items.Items;
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -35,13 +34,12 @@ import net.momirealms.customcrops.objects.Function;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.objects.WaterCan;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.objects.requirements.PlantingCondition;
|
||||
import net.momirealms.customcrops.objects.requirements.PlayerCondition;
|
||||
import net.momirealms.customcrops.objects.requirements.RequirementInterface;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import net.momirealms.customcrops.utils.HologramUtil;
|
||||
import net.momirealms.customcrops.utils.LimitationUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
@@ -228,29 +226,20 @@ public abstract class HandlerP extends Function {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void removeCropCache(Location location) {
|
||||
public void onBreakUnripeCrop(Location location) {
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
customWorld.removeCropCache(location);
|
||||
}
|
||||
|
||||
public void onBreakUnripeCrop(Location location) {
|
||||
removeCropCache(location);
|
||||
}
|
||||
|
||||
public void onBreakRipeCrop(Location location, String id, Player player, boolean instant) {
|
||||
removeCropCache(location);
|
||||
String[] ns = StringUtils.split(id, ":");
|
||||
String cropNameWithoutNS = ns[ns.length-1];
|
||||
String cropName = cropNameWithoutNS.substring(0, cropNameWithoutNS.indexOf("_stage_"));
|
||||
|
||||
Crop crop = CropConfig.CROPS.get(cropName);
|
||||
if (crop == null) return;
|
||||
|
||||
public void onBreakRipeCrop(Location location, Crop crop, Player player, boolean instant) {
|
||||
if (isInCoolDown(player, 50)) return;
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld != null) {
|
||||
customWorld.removeCropCache(location);
|
||||
Fertilizer fertilizer = customWorld.getFertilizerCache(location.clone().subtract(0,1,0));
|
||||
if (instant) {
|
||||
//To prevent some unhooked region plugin duplication
|
||||
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, ()-> {
|
||||
if (location.getBlock().getType() != Material.AIR) return;
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, false);
|
||||
@@ -273,7 +262,7 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
}
|
||||
|
||||
public void removeScarecrow(Location location) {
|
||||
public void removeScarecrowCache(Location location) {
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
customWorld.removeScarecrowCache(location);
|
||||
@@ -534,36 +523,20 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canProceedAction(Player player, Location location) {
|
||||
if (MainConfig.enableEvents) return true;
|
||||
PreActionEvent preActionEvent = new PreActionEvent(player, location);
|
||||
Bukkit.getPluginManager().callEvent(preActionEvent);
|
||||
return !preActionEvent.isCancelled();
|
||||
}
|
||||
|
||||
protected boolean onInteractRipeCrop(Location location, Crop crop, Player player) {
|
||||
protected void onInteractRipeCrop(Location location, Crop crop, Player player) {
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld != null) {
|
||||
Fertilizer fertilizer = customWorld.getFertilizerCache(location.clone().subtract(0,1,0));
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, true);
|
||||
|
||||
String returnStage = crop.getReturnStage();
|
||||
if (returnStage == null) {
|
||||
customWorld.removeCropCache(location);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
customWorld.addCropCache(location, crop.getKey(), Integer.parseInt(returnStage.substring(returnStage.indexOf("_stage_") + 7)));
|
||||
return false;
|
||||
}
|
||||
if (returnStage == null) customWorld.removeCropCache(location);
|
||||
else customWorld.addCropCache(location, crop.getKey(), Integer.parseInt(returnStage.substring(returnStage.indexOf("_stage_") + 7)));
|
||||
}
|
||||
else if (MainConfig.dropLootsInAllWorlds) {
|
||||
cropManager.proceedHarvest(crop, player, location, null, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean plantSeed(Location seedLoc, String cropName, @Nullable Player player, @Nullable ItemStack itemInHand) {
|
||||
Crop crop = CropConfig.CROPS.get(cropName);
|
||||
if (crop == null) return false;
|
||||
@@ -574,10 +547,10 @@ public abstract class HandlerP extends Function {
|
||||
if (FurnitureUtil.hasFurniture(customInterface.getFrameCropLocation(seedLoc)) || seedLoc.getBlock().getType() != Material.AIR) return false;
|
||||
|
||||
if (player != null) {
|
||||
PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player);
|
||||
if (crop.getRequirements() != null) {
|
||||
for (RequirementInterface requirement : crop.getRequirements()) {
|
||||
if (!requirement.isConditionMet(plantingCondition)) {
|
||||
PlayerCondition playerCondition = new PlayerCondition(seedLoc, player);
|
||||
if (crop.getPlantRequirements() != null) {
|
||||
for (RequirementInterface requirement : crop.getPlantRequirements()) {
|
||||
if (!requirement.isConditionMet(playerCondition)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -666,4 +639,16 @@ public abstract class HandlerP extends Function {
|
||||
int stage = Integer.parseInt(id.substring(id.indexOf("_stage_") + 7));
|
||||
return stage == crop.getMax_stage();
|
||||
}
|
||||
|
||||
protected boolean checkHarvestRequirements(Player player, Location location, Crop crop) {
|
||||
PlayerCondition playerCondition = new PlayerCondition(location, player);
|
||||
if (crop.getHarvestRequirements() != null) {
|
||||
for (RequirementInterface requirement : crop.getHarvestRequirements()) {
|
||||
if (!requirement.isConditionMet(playerCondition)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.config.SoundConfig;
|
||||
import net.momirealms.customcrops.config.SprinklerConfig;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
@@ -44,6 +44,7 @@ import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
@@ -55,40 +56,47 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
public void onInteractFurniture(FurnitureInteractEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
final String namespacedID = event.getNamespacedID();
|
||||
if (namespacedID == null) return;
|
||||
final String entityNamespacedID = event.getNamespacedID();
|
||||
if (entityNamespacedID == null) return;
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final Entity entity = event.getBukkitEntity();
|
||||
final Location location = entity.getLocation();;
|
||||
final Location entityLocation = entity.getLocation();;
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(namespacedID);
|
||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(entityNamespacedID);
|
||||
if (sprinkler != null) {
|
||||
if (!AntiGrief.testPlace(player, entity.getLocation())) return;
|
||||
if (!CCAntiGrief.testPlace(player, entity.getLocation())) return;
|
||||
super.onInteractSprinkler(entity.getLocation(), player, player.getInventory().getItemInMainHand(), sprinkler);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!namespacedID.contains("_stage_")) return;
|
||||
if (!namespacedID.equals(BasicItemConfig.deadCrop)) {
|
||||
if (!entityNamespacedID.contains("_stage_")) return;
|
||||
if (!entityNamespacedID.equals(BasicItemConfig.deadCrop)) {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
if (isRipe(namespacedID)) {
|
||||
if (isRipe(entityNamespacedID)) {
|
||||
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) {
|
||||
if (!AntiGrief.testBreak(player, entity.getLocation())) return;
|
||||
if (!canProceedAction(player, entity.getLocation())) return;
|
||||
if (!CCAntiGrief.testBreak(player, entity.getLocation())) return;
|
||||
Crop crop = customInterface.getCropFromID(entityNamespacedID);
|
||||
if (crop == null) return;
|
||||
if (!checkHarvestRequirements(player, entityLocation, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
customInterface.removeFurniture(entity);
|
||||
if (entity.isValid()) entity.remove();
|
||||
this.onInteractRipeCrop(location, namespacedID, player);
|
||||
super.onInteractRipeCrop(entityLocation, crop, player);
|
||||
if (crop.getReturnStage() != null) {
|
||||
CustomFurniture customFurniture = CustomFurniture.spawn(crop.getReturnStage(), entityLocation.getBlock());
|
||||
if (crop.canRotate() && customFurniture instanceof ItemFrame itemFrame) itemFrame.setRotation(FurnitureUtil.getRandomRotation());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (MainConfig.enableBoneMeal && itemInHand.getType() == Material.BONE_MEAL) {
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
if (!CCAntiGrief.testPlace(player, entityLocation)) return;
|
||||
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
if (Math.random() < MainConfig.boneMealChance) {
|
||||
entity.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0,0.5, 0),3,0.2,0.2,0.2);
|
||||
entity.getWorld().spawnParticle(MainConfig.boneMealSuccess, entityLocation.clone().add(0,0.5, 0),3,0.2,0.2,0.2);
|
||||
if (SoundConfig.boneMeal.isEnable()) {
|
||||
AdventureUtil.playerSound(
|
||||
player,
|
||||
@@ -98,48 +106,54 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
);
|
||||
}
|
||||
customInterface.removeFurniture(entity);
|
||||
customInterface.placeFurniture(location, customInterface.getNextStage(namespacedID));
|
||||
customInterface.placeFurniture(entityLocation, customInterface.getNextStage(entityNamespacedID));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.tryMisc(player, player.getInventory().getItemInMainHand(), MiscUtils.getItemFrameBlockLocation(location.clone().subtract(0,1,0)));
|
||||
super.tryMisc(player, player.getInventory().getItemInMainHand(), MiscUtils.getItemFrameBlockLocation(entityLocation.clone().subtract(0,1,0)));
|
||||
}
|
||||
|
||||
public void onBreakFurniture(FurnitureBreakEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
final String namespacedId = event.getNamespacedID();
|
||||
if (namespacedId == null) return;
|
||||
final String entityNamespacedId = event.getNamespacedID();
|
||||
if (entityNamespacedId == null) return;
|
||||
|
||||
final Location location = event.getBukkitEntity().getLocation();
|
||||
final Location entityLocation = event.getBukkitEntity().getLocation();
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(namespacedId);
|
||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(entityNamespacedId);
|
||||
if (sprinkler != null) {
|
||||
super.onBreakSprinkler(location);
|
||||
super.onBreakSprinkler(entityLocation);
|
||||
return;
|
||||
}
|
||||
|
||||
if (MainConfig.enableCrow && namespacedId.equals(BasicItemConfig.scarecrow)) {
|
||||
super.removeScarecrow(event.getBukkitEntity().getLocation());
|
||||
if (MainConfig.enableCrow && entityNamespacedId.equals(BasicItemConfig.scarecrow)) {
|
||||
super.removeScarecrowCache(event.getBukkitEntity().getLocation());
|
||||
return;
|
||||
}
|
||||
|
||||
if (namespacedId.contains("_stage_")) {
|
||||
if (namespacedId.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (!isRipe(namespacedId)) super.onBreakUnripeCrop(location);
|
||||
else super.onBreakRipeCrop(location, namespacedId, player, false);
|
||||
if (entityNamespacedId.contains("_stage_") && !entityNamespacedId.equals(BasicItemConfig.deadCrop)) {
|
||||
if (!isRipe(entityNamespacedId)) {
|
||||
super.onBreakUnripeCrop(entityLocation);
|
||||
} else {
|
||||
Crop crop = customInterface.getCropFromID(entityNamespacedId);
|
||||
if (crop == null) return;
|
||||
if (!checkHarvestRequirements(player, entityLocation, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(entityLocation, crop, player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||
super.onPlayerInteract(event);
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) return;
|
||||
@@ -150,7 +164,6 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
|
||||
if (!blockID.equals(BasicItemConfig.wetPot) && !blockID.equals(BasicItemConfig.dryPot)) return;
|
||||
Location seedLoc = block.getLocation().clone().add(0,1,0);
|
||||
if (!canProceedAction(player, seedLoc)) return;
|
||||
|
||||
ItemStack itemInHand = event.getItem();
|
||||
Location potLoc = block.getLocation();
|
||||
@@ -180,33 +193,41 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
final Player player = event.getPlayer();
|
||||
final Location location = event.getBlock().getLocation();
|
||||
|
||||
if (!AntiGrief.testBreak(player, location)) return;
|
||||
if (!canProceedAction(player, location)) return;
|
||||
if (!CCAntiGrief.testBreak(player, location)) return;
|
||||
|
||||
if (namespacedId.equals(BasicItemConfig.dryPot) || namespacedId.equals(BasicItemConfig.wetPot)) {
|
||||
super.onBreakPot(location);
|
||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(location.clone().add(0,1,0)));
|
||||
if (itemFrame == null) return;
|
||||
CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(itemFrame);
|
||||
if (customFurniture == null) return;
|
||||
String seedID = customFurniture.getNamespacedID();
|
||||
if (seedID.contains("_stage_")) {
|
||||
CustomFurniture.remove(itemFrame, false);
|
||||
if (itemFrame.isValid()) itemFrame.remove();
|
||||
if (seedID.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (!isRipe(seedID)) super.onBreakUnripeCrop(location.clone().add(0,1,0));
|
||||
else super.onBreakRipeCrop(location.clone().add(0,1,0), seedID, player, true);
|
||||
label_out: {
|
||||
Location seedLoc = location.clone().add(0,1,0);
|
||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(seedLoc));
|
||||
if (itemFrame == null) break label_out;
|
||||
CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(itemFrame);
|
||||
if (customFurniture == null) break label_out;
|
||||
String seedID = customFurniture.getNamespacedID();
|
||||
if (seedID.contains("_stage_")) {
|
||||
if (seedID.equals(BasicItemConfig.deadCrop)) {
|
||||
CustomFurniture.remove(itemFrame, false);
|
||||
if (itemFrame.isValid()) itemFrame.remove();
|
||||
break label_out;
|
||||
}
|
||||
if (!isRipe(seedID)) {
|
||||
CustomFurniture.remove(itemFrame, false);
|
||||
if (itemFrame.isValid()) itemFrame.remove();
|
||||
super.onBreakUnripeCrop(location.clone().add(0,1,0));
|
||||
}
|
||||
else {
|
||||
Crop crop = customInterface.getCropFromID(seedID);
|
||||
if (crop == null) break label_out;
|
||||
if (!checkHarvestRequirements(player, seedLoc, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
CustomFurniture.remove(itemFrame, false);
|
||||
if (itemFrame.isValid()) itemFrame.remove();
|
||||
super.onBreakRipeCrop(seedLoc, crop, player, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onInteractRipeCrop(Location location, String id, Player player) {
|
||||
Crop crop = customInterface.getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
if (super.onInteractRipeCrop(location, crop, player)) return;
|
||||
if (crop.getReturnStage() != null) {
|
||||
CustomFurniture customFurniture = CustomFurniture.spawn(crop.getReturnStage(), location.getBlock());
|
||||
if (crop.canRotate() && customFurniture instanceof ItemFrame itemFrame) itemFrame.setRotation(FurnitureUtil.getRandomRotation());
|
||||
super.onBreakPot(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.config.SoundConfig;
|
||||
import net.momirealms.customcrops.config.WaterCanConfig;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import net.momirealms.customcrops.integrations.customplugin.HandlerP;
|
||||
import net.momirealms.customcrops.integrations.customplugin.itemsadder.listeners.ItemsAdderBlockListener;
|
||||
import net.momirealms.customcrops.integrations.customplugin.itemsadder.listeners.ItemsAdderFurnitureListener;
|
||||
@@ -114,8 +114,7 @@ public abstract class ItemsAdderHandler extends HandlerP {
|
||||
if (block == null) return;
|
||||
|
||||
Location location = block.getLocation();
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
if (!canProceedAction(player, location)) return;
|
||||
if (!CCAntiGrief.testPlace(player, location)) return;
|
||||
if (event.getBlockFace() == BlockFace.UP) {
|
||||
placeSprinkler(namespacedID, event.getClickedBlock().getLocation(), player, item);
|
||||
}
|
||||
@@ -123,7 +122,7 @@ public abstract class ItemsAdderHandler extends HandlerP {
|
||||
}
|
||||
|
||||
public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) {
|
||||
if (!AntiGrief.testPlace(player, potLoc)) return true;
|
||||
if (!CCAntiGrief.testPlace(player, potLoc)) return true;
|
||||
if (itemInHand == null || itemInHand.getType() == Material.AIR) return true;
|
||||
|
||||
if (useBucket(potLoc, player, itemInHand)) {
|
||||
|
||||
@@ -27,7 +27,7 @@ import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.config.SoundConfig;
|
||||
import net.momirealms.customcrops.config.SprinklerConfig;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
@@ -41,6 +41,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
@@ -52,16 +53,9 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
//interact sprinkler
|
||||
public void onInteractFurniture(FurnitureInteractEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (isInCoolDown(player, 100)) return;
|
||||
|
||||
Entity entity = event.getBukkitEntity();
|
||||
|
||||
if (!AntiGrief.testPlace(player, entity.getLocation())) return;
|
||||
if (!canProceedAction(player, entity.getLocation())) return;
|
||||
|
||||
if (!CCAntiGrief.testPlace(player, entity.getLocation())) return;
|
||||
String namespacedID = event.getNamespacedID();
|
||||
if (namespacedID == null) return;
|
||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(namespacedID);
|
||||
@@ -73,7 +67,6 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
//break sprinkler
|
||||
public void onBreakFurniture(FurnitureBreakEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
String namespacedID = event.getNamespacedID();
|
||||
if (namespacedID == null) return;
|
||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(namespacedID);
|
||||
@@ -81,30 +74,23 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
super.onBreakSprinkler(event.getBukkitEntity().getLocation());
|
||||
return;
|
||||
}
|
||||
|
||||
if (MainConfig.enableCrow && namespacedID.equals(BasicItemConfig.scarecrow)) {
|
||||
super.removeScarecrow(event.getBukkitEntity().getLocation());
|
||||
super.removeScarecrowCache(event.getBukkitEntity().getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||
super.onPlayerInteract(event);
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) return;
|
||||
CustomBlock cb = CustomBlock.byAlreadyPlaced(block);
|
||||
if (cb == null) return;
|
||||
Location location = block.getLocation();
|
||||
|
||||
final String blockID = cb.getNamespacedID();
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
if (blockID.contains("_stage_")) {
|
||||
ItemStack itemInHand = event.getItem();
|
||||
if (!blockID.equals(BasicItemConfig.deadCrop)) {
|
||||
@@ -112,15 +98,22 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
ItemStack mainHand = player.getInventory().getItemInMainHand();
|
||||
ItemStack offHand = player.getInventory().getItemInOffHand();
|
||||
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && (mainHand.getType() != Material.AIR || offHand.getType() != Material.AIR))) {
|
||||
if (!AntiGrief.testBreak(player, location)) return;
|
||||
if (!CCAntiGrief.testBreak(player, location)) return;
|
||||
Crop crop = customInterface.getCropFromID(blockID);
|
||||
if (crop == null) return;
|
||||
if (!checkHarvestRequirements(player, location, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
CustomBlock.remove(location);
|
||||
this.onInteractRipeCrop(location, blockID, player);
|
||||
super.onInteractRipeCrop(location, crop, player);
|
||||
if (crop.getReturnStage() != null) CustomBlock.place(crop.getReturnStage(), location);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//has next stage
|
||||
else if (MainConfig.enableBoneMeal && itemInHand != null && itemInHand.getType() == Material.BONE_MEAL) {
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
if (!CCAntiGrief.testPlace(player, location)) return;
|
||||
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
if (Math.random() < MainConfig.boneMealChance) {
|
||||
location.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0.5,0.5, 0.5),3,0.2,0.2,0.2);
|
||||
@@ -164,68 +157,63 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void onInteractRipeCrop(Location location, String id, Player player) {
|
||||
Crop crop = customInterface.getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
if (super.onInteractRipeCrop(location, crop, player)) return;
|
||||
if (crop.getReturnStage() != null) CustomBlock.place(crop.getReturnStage(), location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBreakBlock(CustomBlockBreakEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
if (isInCoolDown(player, 50)) return;
|
||||
|
||||
final String namespacedId = event.getNamespacedID();
|
||||
final Location location = event.getBlock().getLocation();
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
if (!CCAntiGrief.testBreak(player, location)) return;
|
||||
|
||||
if (namespacedId.contains("_stage_")) {
|
||||
if (!AntiGrief.testBreak(player, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH) || player.getInventory().getItemInMainHand().getType() == Material.SHEARS){
|
||||
event.setCancelled(true);
|
||||
CustomBlock.place(namespacedId, location);
|
||||
if (player.getGameMode() != GameMode.CREATIVE) CustomBlock.byAlreadyPlaced(location.getBlock()).getLoot().forEach(itemStack -> location.getWorld().dropItemNaturally(location, itemStack));
|
||||
CustomBlock.remove(location);
|
||||
}
|
||||
|
||||
if (namespacedId.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (!isRipe(namespacedId)) super.onBreakUnripeCrop(location);
|
||||
else super.onBreakRipeCrop(location, namespacedId, player, true);
|
||||
else {
|
||||
Crop crop = customInterface.getCropFromID(namespacedId);
|
||||
if (crop == null) return;
|
||||
if (!checkHarvestRequirements(player, location, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(location, crop, player, true);
|
||||
}
|
||||
}
|
||||
|
||||
else if (namespacedId.equals(BasicItemConfig.dryPot) || namespacedId.equals(BasicItemConfig.wetPot)) {
|
||||
|
||||
if (!AntiGrief.testBreak(player, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
label_out: {
|
||||
Location seedLocation = location.clone().add(0,1,0);
|
||||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(seedLocation.getBlock());
|
||||
if (customBlock == null) break label_out;
|
||||
String seedID = customBlock.getNamespacedID();
|
||||
if (seedID.contains("_stage_")) {
|
||||
if (seedID.equals(BasicItemConfig.deadCrop)) {
|
||||
CustomBlock.remove(seedLocation);
|
||||
break label_out;
|
||||
}
|
||||
if (!isRipe(seedID)) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE) break label_out;
|
||||
CustomBlock.remove(seedLocation);
|
||||
customBlock.getLoot().forEach(loot -> location.getWorld().dropItemNaturally(seedLocation.getBlock().getLocation(), loot));
|
||||
}
|
||||
else {
|
||||
Crop crop = customInterface.getCropFromID(seedID);
|
||||
if (crop == null) break label_out;
|
||||
if (!checkHarvestRequirements(player, seedLocation, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
CustomBlock.remove(seedLocation);
|
||||
super.onBreakRipeCrop(seedLocation, crop, player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.onBreakPot(location);
|
||||
|
||||
Location seedLocation = location.clone().add(0,1,0);
|
||||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(seedLocation.getBlock());
|
||||
if (customBlock == null) return;
|
||||
String seedID = customBlock.getNamespacedID();
|
||||
|
||||
if (seedID.contains("_stage_")) {
|
||||
CustomBlock.remove(seedLocation);
|
||||
if (seedID.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (!isRipe(seedID)) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE) return;
|
||||
customBlock.getLoot().forEach(loot -> location.getWorld().dropItemNaturally(seedLocation.getBlock().getLocation(), loot));
|
||||
}
|
||||
else {
|
||||
super.onBreakRipeCrop(seedLocation, seedID, player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.config.SoundConfig;
|
||||
import net.momirealms.customcrops.config.SprinklerConfig;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
@@ -61,35 +61,45 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
final Location location = event.getBlock().getLocation();
|
||||
|
||||
if (!id.equals(BasicItemConfig.dryPot) && !id.equals(BasicItemConfig.wetPot)) return;
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
if (!AntiGrief.testBreak(player, location)) {
|
||||
if (!CCAntiGrief.testBreak(player, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
super.onBreakPot(location);
|
||||
Location seedLocation = location.clone().add(0,1,0);
|
||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(seedLocation));
|
||||
if (itemFrame == null) return;
|
||||
String furnitureID = itemFrame.getPersistentDataContainer().get(OraxenHook.FURNITURE, PersistentDataType.STRING);
|
||||
if (furnitureID == null) return;
|
||||
if (furnitureID.contains("_stage_")) {
|
||||
itemFrame.remove();
|
||||
if (furnitureID.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (!isRipe(furnitureID)) {
|
||||
FurnitureMechanic mechanic = (FurnitureMechanic) FurnitureFactory.instance.getMechanic(furnitureID);
|
||||
if (mechanic == null) return;
|
||||
Drop drop = mechanic.getDrop();
|
||||
if (drop != null && player.getGameMode() != GameMode.CREATIVE) {
|
||||
drop.spawns(seedLocation, new ItemStack(Material.AIR));
|
||||
label_out: {
|
||||
Location seedLocation = location.clone().add(0,1,0);
|
||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(seedLocation));
|
||||
if (itemFrame == null) break label_out;
|
||||
String furnitureID = itemFrame.getPersistentDataContainer().get(OraxenHook.FURNITURE, PersistentDataType.STRING);
|
||||
if (furnitureID == null) break label_out;
|
||||
if (furnitureID.contains("_stage_")) {
|
||||
if (furnitureID.equals(BasicItemConfig.deadCrop)) {
|
||||
itemFrame.remove();
|
||||
break label_out;
|
||||
}
|
||||
if (!isRipe(furnitureID)) {
|
||||
itemFrame.remove();
|
||||
FurnitureMechanic mechanic = (FurnitureMechanic) FurnitureFactory.instance.getMechanic(furnitureID);
|
||||
if (mechanic == null) break label_out;
|
||||
Drop drop = mechanic.getDrop();
|
||||
if (drop != null && player.getGameMode() != GameMode.CREATIVE) {
|
||||
drop.spawns(seedLocation, new ItemStack(Material.AIR));
|
||||
}
|
||||
super.onBreakUnripeCrop(seedLocation);
|
||||
}
|
||||
else {
|
||||
Crop crop = customInterface.getCropFromID(furnitureID);
|
||||
if (crop == null) break label_out;
|
||||
if (!checkHarvestRequirements(player, seedLocation, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
itemFrame.remove();
|
||||
super.onBreakRipeCrop(seedLocation, crop, player, false);
|
||||
}
|
||||
super.onBreakUnripeCrop(seedLocation);
|
||||
}
|
||||
else {
|
||||
super.onBreakRipeCrop(seedLocation, furnitureID, player, false);
|
||||
}
|
||||
}
|
||||
super.onBreakPot(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,20 +116,28 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
}
|
||||
|
||||
if (MainConfig.enableCrow && id.equals(BasicItemConfig.scarecrow)) {
|
||||
super.removeScarecrow(event.getBlock().getLocation());
|
||||
super.removeScarecrowCache(event.getBlock().getLocation());
|
||||
return;
|
||||
}
|
||||
|
||||
if (id.contains("_stage_")) {
|
||||
if (id.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (!isRipe(id)) super.onBreakUnripeCrop(event.getBlock().getLocation());
|
||||
else super.onBreakRipeCrop(event.getBlock().getLocation(), id, event.getPlayer(), false);
|
||||
Location seedLoc = event.getBlock().getLocation();
|
||||
if (!isRipe(id)) super.onBreakUnripeCrop(seedLoc);
|
||||
else {
|
||||
Crop crop = customInterface.getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
if (!checkHarvestRequirements(event.getPlayer(), seedLoc, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(seedLoc, crop, event.getPlayer(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInteractNoteBlock(OraxenNoteBlockInteractEvent event) {
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final ItemStack itemInHand = event.getItemInHand();
|
||||
final Block block = event.getBlock();
|
||||
@@ -130,10 +148,8 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
Location potLoc = block.getLocation();
|
||||
Location seedLoc = potLoc.clone().add(0,1,0);
|
||||
|
||||
if (!canProceedAction(player, potLoc)) return;
|
||||
if (super.tryMisc(player, itemInHand, potLoc)) return;
|
||||
if (event.getBlockFace() != BlockFace.UP) return;
|
||||
if (isInCoolDown(player, 50)) return;
|
||||
|
||||
String id = OraxenItems.getIdByItem(itemInHand);
|
||||
if (id != null) {
|
||||
@@ -159,11 +175,10 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
final Player player = event.getPlayer();
|
||||
final ItemFrame itemFrame = event.getItemFrame();
|
||||
final Location location = itemFrame.getLocation();
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(id);
|
||||
if (sprinkler != null) {
|
||||
if (!AntiGrief.testPlace(player, itemFrame.getLocation())) return;
|
||||
if (!CCAntiGrief.testPlace(player, itemFrame.getLocation())) return;
|
||||
super.onInteractSprinkler(location, player, player.getInventory().getItemInMainHand(), sprinkler);
|
||||
return;
|
||||
}
|
||||
@@ -173,14 +188,24 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
if (isRipe(id)) {
|
||||
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) {
|
||||
if (!AntiGrief.testBreak(player, location)) return;
|
||||
if (!CCAntiGrief.testBreak(player, location)) return;
|
||||
Crop crop = customInterface.getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
if (!checkHarvestRequirements(player, location, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
itemFrame.remove();
|
||||
this.onInteractRipeCrop(location, id, player);
|
||||
super.onInteractRipeCrop(location, crop, player);
|
||||
if (crop.getReturnStage() != null) {
|
||||
ItemFrame placedFurniture = cropManager.getCustomInterface().placeFurniture(location, crop.getReturnStage());
|
||||
if (crop.canRotate() && placedFurniture != null) itemFrame.setRotation(FurnitureUtil.getRandomRotation());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (MainConfig.enableBoneMeal && itemInHand.getType() == Material.BONE_MEAL) {
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
if (!CCAntiGrief.testPlace(player, location)) return;
|
||||
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
if (Math.random() < MainConfig.boneMealChance) {
|
||||
itemFrame.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0,0.5, 0),3,0.2,0.2,0.2);
|
||||
@@ -201,14 +226,4 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
}
|
||||
super.tryMisc(player, player.getInventory().getItemInMainHand(), MiscUtils.getItemFrameBlockLocation(location.clone().subtract(0,1,0)));
|
||||
}
|
||||
|
||||
private void onInteractRipeCrop(Location location, String id, Player player) {
|
||||
Crop crop = customInterface.getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
if (super.onInteractRipeCrop(location, crop, player)) return;
|
||||
if (crop.getReturnStage() != null) {
|
||||
ItemFrame itemFrame = cropManager.getCustomInterface().placeFurniture(location, crop.getReturnStage());
|
||||
if (crop.canRotate() && itemFrame != null) itemFrame.setRotation(FurnitureUtil.getRandomRotation());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.config.SoundConfig;
|
||||
import net.momirealms.customcrops.config.WaterCanConfig;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import net.momirealms.customcrops.integrations.customplugin.HandlerP;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenBlockListener;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenFurnitureListener;
|
||||
@@ -86,7 +86,7 @@ public abstract class OraxenHandler extends HandlerP {
|
||||
}
|
||||
|
||||
public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) {
|
||||
if (!AntiGrief.testPlace(player, potLoc)) return true;
|
||||
if (!CCAntiGrief.testPlace(player, potLoc)) return true;
|
||||
if (itemInHand == null || itemInHand.getType() == Material.AIR) return true;
|
||||
|
||||
if (useBucket(potLoc, player, itemInHand)) {
|
||||
|
||||
@@ -29,7 +29,7 @@ import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.config.SoundConfig;
|
||||
import net.momirealms.customcrops.config.SprinklerConfig;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
@@ -61,13 +61,11 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
final Block block = event.getBlock();
|
||||
Location location = block.getLocation();
|
||||
|
||||
if (!AntiGrief.testBreak(player, location)) {
|
||||
if (!CCAntiGrief.testBreak(player, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
if (player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH) || player.getInventory().getItemInMainHand().getType() == Material.SHEARS){
|
||||
event.setCancelled(true);
|
||||
Drop drop = mechanic.getDrop();
|
||||
@@ -78,7 +76,15 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
|
||||
if (id.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (!isRipe(id)) super.onBreakUnripeCrop(location);
|
||||
else super.onBreakRipeCrop(location, id, player, true);
|
||||
else {
|
||||
Crop crop = customInterface.getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
if (!checkHarvestRequirements(player, location, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(location, crop, player, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,7 +100,7 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
return;
|
||||
}
|
||||
if (MainConfig.enableCrow && id.equals(BasicItemConfig.scarecrow)) {
|
||||
super.removeScarecrow(event.getBlock().getLocation());
|
||||
super.removeScarecrowCache(event.getBlock().getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,8 +111,7 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
final Player player = event.getPlayer();
|
||||
final Location blockLoc = event.getItemFrame().getLocation();
|
||||
|
||||
if (!AntiGrief.testPlace(player, blockLoc)) return;
|
||||
if (!canProceedAction(player, blockLoc)) return;
|
||||
if (!CCAntiGrief.testPlace(player, blockLoc)) return;
|
||||
|
||||
FurnitureMechanic mechanic = event.getMechanic();
|
||||
if (mechanic == null) return;
|
||||
@@ -125,8 +130,6 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
final Location potLoc = event.getBlock().getLocation();
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (isInCoolDown(player, 50)) return;
|
||||
if (!canProceedAction(player, potLoc)) return;
|
||||
if (super.tryMisc(event.getPlayer(), itemInHand, potLoc)) return;
|
||||
if (event.getBlockFace() != BlockFace.UP) return;
|
||||
|
||||
@@ -151,29 +154,32 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (isInCoolDown(player, 50)) return;
|
||||
|
||||
final Block block = event.getBlock();
|
||||
final String id = event.getMechanic().getItemID();
|
||||
|
||||
if (!id.contains("_stage_")) return;
|
||||
|
||||
Location seedLoc = block.getLocation();
|
||||
if (!canProceedAction(player, seedLoc)) return;
|
||||
ItemStack itemInHand = event.getItemInHand();
|
||||
if (!id.equals(BasicItemConfig.deadCrop)) {
|
||||
if (isRipe(id)) {
|
||||
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand != null && itemInHand.getType() != Material.AIR)) {
|
||||
if (!AntiGrief.testBreak(player, seedLoc)) return;
|
||||
if (!CCAntiGrief.testBreak(player, seedLoc)) return;
|
||||
Crop crop = customInterface.getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
if (!checkHarvestRequirements(player, seedLoc, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
block.setType(Material.AIR);
|
||||
this.onInteractRipeCrop(seedLoc, id, player);
|
||||
super.onInteractRipeCrop(seedLoc, crop, player);
|
||||
if (crop.getReturnStage() != null) StringBlockMechanicFactory.setBlockModel(seedLoc.getBlock(), crop.getReturnStage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
//has next stage
|
||||
else if (MainConfig.enableBoneMeal && itemInHand != null && itemInHand.getType() == Material.BONE_MEAL) {
|
||||
if (!AntiGrief.testPlace(player, seedLoc)) return;
|
||||
if (!CCAntiGrief.testPlace(player, seedLoc)) return;
|
||||
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
if (Math.random() < MainConfig.boneMealChance) {
|
||||
seedLoc.getWorld().spawnParticle(MainConfig.boneMealSuccess, seedLoc.clone().add(0.5,0.5, 0.5),3,0.2,0.2,0.2);
|
||||
@@ -202,39 +208,39 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
final Location location = event.getBlock().getLocation();
|
||||
|
||||
if (!id.equals(BasicItemConfig.dryPot) && !id.equals(BasicItemConfig.wetPot)) return;
|
||||
if (!canProceedAction(player, location)) return;
|
||||
if (!CCAntiGrief.testBreak(player, location)) return;
|
||||
|
||||
if (!AntiGrief.testBreak(player, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
super.onBreakPot(location);
|
||||
Location seedLocation = location.clone().add(0,1,0);
|
||||
String blockID = customInterface.getBlockID(seedLocation);
|
||||
if (blockID == null) return;
|
||||
if (blockID.contains("_stage_")) {
|
||||
customInterface.removeBlock(seedLocation);
|
||||
if (blockID.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (!isRipe(blockID)) {
|
||||
StringBlockMechanic mechanic = (StringBlockMechanic) FurnitureFactory.instance.getMechanic(blockID);
|
||||
if (mechanic == null) return;
|
||||
Drop drop = mechanic.getDrop();
|
||||
if (drop != null && player.getGameMode() != GameMode.CREATIVE) {
|
||||
drop.spawns(seedLocation, new ItemStack(Material.AIR));
|
||||
label_out: {
|
||||
Location seedLocation = location.clone().add(0,1,0);
|
||||
String blockID = customInterface.getBlockID(seedLocation);
|
||||
if (blockID == null) break label_out;
|
||||
if (blockID.contains("_stage_")) {
|
||||
if (blockID.equals(BasicItemConfig.deadCrop)) {
|
||||
customInterface.removeBlock(seedLocation);
|
||||
break label_out;
|
||||
}
|
||||
if (!isRipe(blockID)) {
|
||||
StringBlockMechanic mechanic = (StringBlockMechanic) FurnitureFactory.instance.getMechanic(blockID);
|
||||
if (mechanic == null) break label_out;
|
||||
Drop drop = mechanic.getDrop();
|
||||
if (drop != null && player.getGameMode() != GameMode.CREATIVE) {
|
||||
drop.spawns(seedLocation, new ItemStack(Material.AIR));
|
||||
}
|
||||
customInterface.removeBlock(seedLocation);
|
||||
super.onBreakUnripeCrop(seedLocation);
|
||||
}
|
||||
else {
|
||||
Crop crop = customInterface.getCropFromID(id);
|
||||
if (crop == null) break label_out;
|
||||
if (!checkHarvestRequirements(player, seedLocation, crop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
customInterface.removeBlock(seedLocation);
|
||||
super.onBreakRipeCrop(seedLocation, crop, player, false);
|
||||
}
|
||||
super.onBreakUnripeCrop(seedLocation);
|
||||
}
|
||||
else {
|
||||
super.onBreakRipeCrop(seedLocation, blockID, player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onInteractRipeCrop(Location location, String id, Player player) {
|
||||
Crop crop = customInterface.getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
if (super.onInteractRipeCrop(location, crop, player)) return;
|
||||
if (crop.getReturnStage() != null) StringBlockMechanicFactory.setBlockModel(location.getBlock(), crop.getReturnStage());
|
||||
super.onBreakPot(location);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package net.momirealms.customcrops.integrations.protection;
|
||||
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
@@ -27,7 +27,12 @@ import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class BentoBoxHook implements AntiGrief {
|
||||
public class BentoBoxHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BentoBox";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Location location, Player player) {
|
||||
|
||||
@@ -19,11 +19,16 @@ package net.momirealms.customcrops.integrations.protection;
|
||||
|
||||
import net.crashcraft.crashclaim.api.CrashClaimAPI;
|
||||
import net.crashcraft.crashclaim.permissions.PermissionRoute;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CrashClaimHook implements AntiGrief {
|
||||
public class CrashClaimHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CrashClaim";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Location location, Player player) {
|
||||
|
||||
@@ -17,11 +17,16 @@
|
||||
|
||||
package net.momirealms.customcrops.integrations.protection;
|
||||
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class GriefDefenderHook implements AntiGrief {
|
||||
public class GriefDefenderHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "GriefDefender";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Location location, Player player) {
|
||||
|
||||
@@ -17,11 +17,16 @@
|
||||
|
||||
package net.momirealms.customcrops.integrations.protection;
|
||||
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class GriefPreventionHook implements AntiGrief {
|
||||
public class GriefPreventionHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "GriefPrevention";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Location location, Player player) {
|
||||
|
||||
@@ -21,13 +21,18 @@ import com.iridium.iridiumskyblock.PermissionType;
|
||||
import com.iridium.iridiumskyblock.api.IridiumSkyblockAPI;
|
||||
import com.iridium.iridiumskyblock.database.Island;
|
||||
import com.iridium.iridiumskyblock.database.User;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class IridiumSkyblockHook implements AntiGrief {
|
||||
public class IridiumSkyblockHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "IridiumSkyblock";
|
||||
}
|
||||
|
||||
private final IridiumSkyblockAPI api;
|
||||
|
||||
|
||||
@@ -17,14 +17,19 @@
|
||||
|
||||
package net.momirealms.customcrops.integrations.protection;
|
||||
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.kingdoms.constants.group.Kingdom;
|
||||
import org.kingdoms.constants.land.Land;
|
||||
import org.kingdoms.constants.player.KingdomPlayer;
|
||||
|
||||
public class KingdomsXHook implements AntiGrief {
|
||||
public class KingdomsXHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "KingdomsX";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Location location, Player player) {
|
||||
|
||||
@@ -18,19 +18,19 @@
|
||||
package net.momirealms.customcrops.integrations.protection;
|
||||
|
||||
import me.angeschossen.lands.api.LandsIntegration;
|
||||
import me.angeschossen.lands.api.flags.Flags;
|
||||
import me.angeschossen.lands.api.flags.enums.FlagTarget;
|
||||
import me.angeschossen.lands.api.flags.enums.RoleFlagCategory;
|
||||
import me.angeschossen.lands.api.flags.types.RoleFlag;
|
||||
import me.angeschossen.lands.api.land.Area;
|
||||
import me.angeschossen.lands.api.land.LandWorld;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LandsHook implements AntiGrief {
|
||||
public class LandsHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Lands";
|
||||
}
|
||||
|
||||
private final LandsIntegration api;
|
||||
|
||||
|
||||
@@ -18,10 +18,15 @@
|
||||
package net.momirealms.customcrops.integrations.protection;
|
||||
|
||||
import com.plotsquared.core.location.Location;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlotSquaredHook implements AntiGrief {
|
||||
public class PlotSquaredHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "PlotSquared";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(org.bukkit.Location location, Player player) {
|
||||
|
||||
@@ -20,11 +20,16 @@ package net.momirealms.customcrops.integrations.protection;
|
||||
import com.bekvon.bukkit.residence.containers.Flags;
|
||||
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
||||
import com.bekvon.bukkit.residence.protection.ResidencePermissions;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ResidenceHook implements AntiGrief {
|
||||
public class ResidenceHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Residence";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Location location, Player player) {
|
||||
|
||||
@@ -19,11 +19,16 @@ package net.momirealms.customcrops.integrations.protection;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.TownyPermission;
|
||||
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TownyHook implements AntiGrief {
|
||||
public class TownyHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Towny";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Location location, Player player) {
|
||||
|
||||
@@ -29,11 +29,16 @@ import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class WorldGuardHook implements AntiGrief {
|
||||
public class WorldGuardHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "WorldGuard";
|
||||
}
|
||||
|
||||
public static StateFlag HARVEST_FLAG;
|
||||
public static StateFlag PLACE_FLAG;
|
||||
|
||||
@@ -61,7 +61,7 @@ public class InternalSeason extends Function implements SeasonInterface {
|
||||
public boolean isWrongSeason(World world, @Nullable CCSeason[] seasonList) {
|
||||
if (seasonList == null) return false;
|
||||
for (CCSeason season : seasonList) {
|
||||
if (season == seasonHashMap.get(world)) {
|
||||
if (season == getSeason(world)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ public class CustomWorld {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : sprinklerLoc.getNearbyPlayers(48)) {
|
||||
cropManager.getArmorStandUtil().playWaterAnimation(player, sprinklerLoc.clone().add(0.5, 0.3, 0.5));
|
||||
cropManager.getArmorStandUtil().playWaterAnimation(player, sprinklerLoc.clone().add(0.5, MainConfig.animationYOffset, 0.5));
|
||||
}
|
||||
}
|
||||
}.runTask(CustomCrops.plugin);
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Random;
|
||||
|
||||
public class CrowTask extends BukkitRunnable {
|
||||
|
||||
@@ -25,7 +25,8 @@ import net.momirealms.customcrops.objects.requirements.RequirementInterface;
|
||||
public class CCCrop implements Crop {
|
||||
|
||||
private CCSeason[] seasons;
|
||||
private RequirementInterface[] requirementInterfaces;
|
||||
private RequirementInterface[] plantRequirements;
|
||||
private RequirementInterface[] harvestRequirements;
|
||||
private String returnStage;
|
||||
private QualityLoot qualityLoot;
|
||||
private GiganticCrop giganticCrop;
|
||||
@@ -56,8 +57,8 @@ public class CCCrop implements Crop {
|
||||
return seasons;
|
||||
}
|
||||
|
||||
public RequirementInterface[] getRequirements() {
|
||||
return requirementInterfaces;
|
||||
public RequirementInterface[] getPlantRequirements() {
|
||||
return plantRequirements;
|
||||
}
|
||||
|
||||
public String getReturnStage() {
|
||||
@@ -80,8 +81,8 @@ public class CCCrop implements Crop {
|
||||
this.seasons = seasons;
|
||||
}
|
||||
|
||||
public void setRequirements(RequirementInterface[] requirementInterfaces) {
|
||||
this.requirementInterfaces = requirementInterfaces;
|
||||
public void setPlantRequirements(RequirementInterface[] requirementInterfaces) {
|
||||
this.plantRequirements = requirementInterfaces;
|
||||
}
|
||||
|
||||
public void setReturnStage(String returnStage) {
|
||||
@@ -111,4 +112,12 @@ public class CCCrop implements Crop {
|
||||
public int getMax_stage() {
|
||||
return max_stage;
|
||||
}
|
||||
|
||||
public RequirementInterface[] getHarvestRequirements() {
|
||||
return harvestRequirements;
|
||||
}
|
||||
|
||||
public void setHarvestRequirements(RequirementInterface[] harvestRequirements) {
|
||||
this.harvestRequirements = harvestRequirements;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,9 +73,9 @@ public class CustomPapi implements RequirementInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlantingCondition plantingCondition) {
|
||||
if (!papiRequirement.isMet(plantingCondition.getPapiMap(), plantingCondition.getPlayer())) {
|
||||
if (msg != null) AdventureUtil.playerMessage(plantingCondition.getPlayer(), msg);
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
if (!papiRequirement.isMet(playerCondition.getPapiMap(), playerCondition.getPlayer())) {
|
||||
if (msg != null) AdventureUtil.playerMessage(playerCondition.getPlayer(), msg);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -25,13 +25,13 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PlantingCondition {
|
||||
public class PlayerCondition {
|
||||
|
||||
private final Location location;
|
||||
private final Player player;
|
||||
private HashMap<String, String> papiMap;
|
||||
|
||||
public PlantingCondition(Location location, Player player) {
|
||||
public PlayerCondition(Location location, Player player) {
|
||||
this.location = location;
|
||||
this.player = player;
|
||||
if (CustomCrops.plugin.hasPapi()){
|
||||
@@ -24,12 +24,12 @@ public class RequirementBiome extends Requirement implements RequirementInterfac
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlantingCondition plantingCondition) {
|
||||
String currentBiome = plantingCondition.getLocation().getBlock().getBiome().getKey().toString();
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
String currentBiome = playerCondition.getLocation().getBlock().getBiome().getKey().toString();
|
||||
if (mode) {
|
||||
for (String value : values) {
|
||||
if (!(currentBiome.equalsIgnoreCase(value))) {
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class RequirementBiome extends Requirement implements RequirementInterfac
|
||||
return true;
|
||||
}
|
||||
}
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@
|
||||
package net.momirealms.customcrops.objects.requirements;
|
||||
|
||||
public interface RequirementInterface {
|
||||
boolean isConditionMet(PlantingCondition plantingCondition);
|
||||
boolean isConditionMet(PlayerCondition playerCondition);
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ public class RequirementPermission extends Requirement implements RequirementInt
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlantingCondition plantingCondition) {
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
if (mode) {
|
||||
for (String value : values) {
|
||||
if (!(plantingCondition.getPlayer().hasPermission(value))) {
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
if (!(playerCondition.getPlayer().hasPermission(value))) {
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -36,11 +36,11 @@ public class RequirementPermission extends Requirement implements RequirementInt
|
||||
}
|
||||
else {
|
||||
for (String value : values) {
|
||||
if (plantingCondition.getPlayer().hasPermission(value)) {
|
||||
if (playerCondition.getPlayer().hasPermission(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ public class RequirementTime extends Requirement implements RequirementInterface
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlantingCondition plantingCondition) {
|
||||
long time = plantingCondition.getLocation().getWorld().getTime();
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
long time = playerCondition.getLocation().getWorld().getTime();
|
||||
if (mode) {
|
||||
for (String value : values) {
|
||||
String[] timeMinMax = StringUtils.split(value, "~");
|
||||
if (!(time > Long.parseLong(timeMinMax[0]) && time < Long.parseLong(timeMinMax[1]))) {
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class RequirementTime extends Requirement implements RequirementInterface
|
||||
return true;
|
||||
}
|
||||
}
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public class RequirementWeather extends Requirement implements RequirementInterf
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlantingCondition plantingCondition) {
|
||||
World world = plantingCondition.getLocation().getWorld();
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
World world = playerCondition.getLocation().getWorld();
|
||||
String weather;
|
||||
if (world.isThundering()) weather = "thunder";
|
||||
else if (world.isClearWeather()) weather = "clear";
|
||||
@@ -37,7 +37,7 @@ public class RequirementWeather extends Requirement implements RequirementInterf
|
||||
if (mode) {
|
||||
for (String value : values) {
|
||||
if (!value.equalsIgnoreCase(weather)) {
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class RequirementWeather extends Requirement implements RequirementInterf
|
||||
return true;
|
||||
}
|
||||
}
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ public class RequirementWorld extends Requirement implements RequirementInterfac
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlantingCondition plantingCondition) {
|
||||
String worldName = plantingCondition.getLocation().getWorld().getName();
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
String worldName = playerCondition.getLocation().getWorld().getName();
|
||||
if (mode) {
|
||||
for (String value : values) {
|
||||
if (!value.equals(worldName)) {
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class RequirementWorld extends Requirement implements RequirementInterfac
|
||||
return true;
|
||||
}
|
||||
}
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ public class RequirementYPos extends Requirement implements RequirementInterface
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlantingCondition plantingCondition) {
|
||||
int y = plantingCondition.getLocation().getBlockY();
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
int y = playerCondition.getLocation().getBlockY();
|
||||
if (mode) {
|
||||
for (String value : values) {
|
||||
String[] yMinMax = StringUtils.split(value, "~");
|
||||
if (!(y > Long.parseLong(yMinMax[0]) && y < Long.parseLong(yMinMax[1]))) {
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class RequirementYPos extends Requirement implements RequirementInterface
|
||||
return true;
|
||||
}
|
||||
}
|
||||
notMetMessage(plantingCondition.getPlayer());
|
||||
notMetMessage(playerCondition.getPlayer());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
|
||||
public class ArmorStandUtil {
|
||||
@@ -90,7 +89,7 @@ public class ArmorStandUtil {
|
||||
public PacketContainer getMetaPacket(int id) {
|
||||
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
metaPacket.getIntegers().write(0, id);
|
||||
if (CustomCrops.version.equals("v1_19_R2")) {
|
||||
if (CustomCrops.plugin.getVersionHelper().isVersionNewerThan1_19_R2()) {
|
||||
WrappedDataWatcher wrappedDataWatcher = createDataWatcher();
|
||||
List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> {
|
||||
|
||||
@@ -68,7 +68,7 @@ public class HologramUtil {
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), mask2);
|
||||
metaPacket.getModifier().write(0,id);
|
||||
|
||||
if (CustomCrops.version.equals("v1_19_R2")) {
|
||||
if (CustomCrops.plugin.getVersionHelper().isVersionNewerThan1_19_R2()) {
|
||||
List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> {
|
||||
final WrappedDataWatcher.WrappedDataWatcherObject dataWatcherObject = entry.getWatcherObject();
|
||||
|
||||
Reference in New Issue
Block a user