mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 18:09:28 +00:00
2.0.4
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
@@ -121,6 +121,7 @@ public class MainConfig {
|
||||
public static boolean enableSkillBonus;
|
||||
public static double bonusPerLevel;
|
||||
public static HashMap<Material, String> vanilla2Crops;
|
||||
public static boolean enableEvents;
|
||||
|
||||
public static void load() {
|
||||
ConfigUtil.update("config.yml");
|
||||
@@ -202,6 +203,7 @@ 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-events", false);
|
||||
|
||||
String[] split = StringUtils.split(config.getString("mechanics.default-quality-ratio", "17/2/1"), "/");
|
||||
double[] weight = new double[3];
|
||||
@@ -276,69 +278,99 @@ public class MainConfig {
|
||||
antiGriefs = new ArrayList<>();
|
||||
if (config.getBoolean("integration.Residence",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("Residence") == null) Log.warn("Failed to initialize Residence!");
|
||||
else {antiGriefs.add(new ResidenceHook());hookMessage("Residence");}
|
||||
else {
|
||||
antiGriefs.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());hookMessage("Kingdoms");}
|
||||
else {
|
||||
antiGriefs.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());hookMessage("WorldGuard");}
|
||||
else {
|
||||
antiGriefs.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());hookMessage("GriefDefender");}
|
||||
else {
|
||||
antiGriefs.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());hookMessage("PlotSquared");}
|
||||
else {
|
||||
antiGriefs.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());hookMessage("Towny");}
|
||||
else {
|
||||
antiGriefs.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());hookMessage("Lands");}
|
||||
else {
|
||||
antiGriefs.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());hookMessage("GriefPrevention");}
|
||||
else {
|
||||
antiGriefs.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());hookMessage("CrashClaim");}
|
||||
else {
|
||||
antiGriefs.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());hookMessage("BentoBox");}
|
||||
else {
|
||||
antiGriefs.add(new BentoBoxHook());
|
||||
hookMessage("BentoBox");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.getBoolean("integration.AureliumSkills")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("AureliumSkills") == null) Log.warn("Failed to initialize AureliumSkills!");
|
||||
else {skillXP = new AureliumsHook();}
|
||||
else skillXP = new AureliumsHook();
|
||||
}
|
||||
if (config.getBoolean("integration.mcMMO")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("mcMMO") == null) Log.warn("Failed to initialize mcMMO!");
|
||||
else {skillXP = new mcMMOHook();}
|
||||
else skillXP = new mcMMOHook();
|
||||
}
|
||||
if (config.getBoolean("integration.MMOCore")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("MMOCore") == null) Log.warn("Failed to initialize MMOCore!");
|
||||
else {skillXP = new MMOCoreHook();}
|
||||
else skillXP = new MMOCoreHook();
|
||||
}
|
||||
if (config.getBoolean("integration.EcoSkills")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("EcoSkills") == null) Log.warn("Failed to initialize EcoSkills!");
|
||||
else {skillXP = new EcoSkillsHook();}
|
||||
else skillXP = new EcoSkillsHook();
|
||||
}
|
||||
if (config.getBoolean("integration.JobsReborn")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("Jobs") == null) Log.warn("Failed to initialize JobsReborn!");
|
||||
else {skillXP = new JobsRebornHook();}
|
||||
else skillXP = new JobsRebornHook();
|
||||
}
|
||||
realisticSeasonHook = false;
|
||||
if (config.getBoolean("integration.RealisticSeasons")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("RealisticSeasons") == null) Log.warn("Failed to initialize RealisticSeasons!");
|
||||
else {realisticSeasonHook = true;}
|
||||
else realisticSeasonHook = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -104,10 +105,12 @@ public abstract class HandlerP extends Function {
|
||||
|
||||
if (itemStack.getType() == Material.WATER_BUCKET) {
|
||||
|
||||
SprinklerFillEvent sprinklerFillEvent = new SprinklerFillEvent(player, itemStack);
|
||||
Bukkit.getPluginManager().callEvent(sprinklerFillEvent);
|
||||
if (sprinklerFillEvent.isCancelled()) {
|
||||
return;
|
||||
if (MainConfig.enableEvents) {
|
||||
SprinklerFillEvent sprinklerFillEvent = new SprinklerFillEvent(player, itemStack);
|
||||
Bukkit.getPluginManager().callEvent(sprinklerFillEvent);
|
||||
if (sprinklerFillEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
itemStack.setType(Material.BUCKET);
|
||||
@@ -134,10 +137,12 @@ public abstract class HandlerP extends Function {
|
||||
int canWater = nbtItem.getInteger("WaterAmount");
|
||||
if (canWater > 0) {
|
||||
|
||||
SprinklerFillEvent sprinklerFillEvent = new SprinklerFillEvent(player, itemStack);
|
||||
Bukkit.getPluginManager().callEvent(sprinklerFillEvent);
|
||||
if (sprinklerFillEvent.isCancelled()) {
|
||||
return;
|
||||
if (MainConfig.enableEvents) {
|
||||
SprinklerFillEvent sprinklerFillEvent = new SprinklerFillEvent(player, itemStack);
|
||||
Bukkit.getPluginManager().callEvent(sprinklerFillEvent);
|
||||
if (sprinklerFillEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nbtItem.setInteger("WaterAmount", --canWater);
|
||||
@@ -202,10 +207,12 @@ public abstract class HandlerP extends Function {
|
||||
if (customWorld == null) return false;
|
||||
Fertilizer fertilizer = customWorld.getFertilizer(potLoc);
|
||||
|
||||
SurveyorUseEvent surveyorUseEvent = new SurveyorUseEvent(player, fertilizer, potLoc);
|
||||
Bukkit.getPluginManager().callEvent(surveyorUseEvent);
|
||||
if (surveyorUseEvent.isCancelled()) {
|
||||
return true;
|
||||
if (MainConfig.enableEvents) {
|
||||
SurveyorUseEvent surveyorUseEvent = new SurveyorUseEvent(player, fertilizer, potLoc);
|
||||
Bukkit.getPluginManager().callEvent(surveyorUseEvent);
|
||||
if (surveyorUseEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fertilizer != null) {
|
||||
@@ -291,10 +298,12 @@ public abstract class HandlerP extends Function {
|
||||
return true;
|
||||
}
|
||||
|
||||
SprinklerPlaceEvent sprinklerPlaceEvent = new SprinklerPlaceEvent(player, sprinklerLoc);
|
||||
Bukkit.getPluginManager().callEvent(sprinklerPlaceEvent);
|
||||
if (sprinklerPlaceEvent.isCancelled()) {
|
||||
return true;
|
||||
if (MainConfig.enableEvents) {
|
||||
SprinklerPlaceEvent sprinklerPlaceEvent = new SprinklerPlaceEvent(player, sprinklerLoc);
|
||||
Bukkit.getPluginManager().callEvent(sprinklerPlaceEvent);
|
||||
if (sprinklerPlaceEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (SoundConfig.placeSprinkler.isEnable()) {
|
||||
@@ -335,10 +344,12 @@ public abstract class HandlerP extends Function {
|
||||
if (block.getType() == Material.WATER) {
|
||||
if (config.getMax() > water) {
|
||||
|
||||
WateringCanFillEvent wateringCanFillEvent = new WateringCanFillEvent(player, itemStack);
|
||||
Bukkit.getPluginManager().callEvent(wateringCanFillEvent);
|
||||
if (wateringCanFillEvent.isCancelled()) {
|
||||
return true;
|
||||
if (MainConfig.enableEvents) {
|
||||
WateringCanFillEvent wateringCanFillEvent = new WateringCanFillEvent(player, itemStack);
|
||||
Bukkit.getPluginManager().callEvent(wateringCanFillEvent);
|
||||
if (wateringCanFillEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
water += MainConfig.waterToWaterCan;
|
||||
@@ -429,10 +440,12 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
}
|
||||
|
||||
FertilizerUseEvent fertilizerUseEvent = new FertilizerUseEvent(player, fertilizer, potLoc);
|
||||
Bukkit.getPluginManager().callEvent(fertilizerUseEvent);
|
||||
if (fertilizerUseEvent.isCancelled()) {
|
||||
return true;
|
||||
if (MainConfig.enableEvents) {
|
||||
FertilizerUseEvent fertilizerUseEvent = new FertilizerUseEvent(player, fertilizer, potLoc);
|
||||
Bukkit.getPluginManager().callEvent(fertilizerUseEvent);
|
||||
if (fertilizerUseEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fertilizer.getParticle() != null) {
|
||||
@@ -472,7 +485,7 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
|
||||
public void waterPot(int width, int length, Location location, float yaw){
|
||||
//TODO
|
||||
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
|
||||
@@ -543,17 +556,14 @@ public abstract class HandlerP extends Function {
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(seedLoc.getWorld());
|
||||
if (customWorld == null) return false;
|
||||
|
||||
if (!MainConfig.OraxenHook && FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.5,0.5))) return false;
|
||||
if (MainConfig.OraxenHook && FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.03125,0.5))) return false;
|
||||
if (seedLoc.getBlock().getType() != Material.AIR) return false;
|
||||
|
||||
CCSeason[] seasons = crop.getSeasons();
|
||||
if (SeasonConfig.enable && seasons != null) {
|
||||
if (cropManager.isWrongSeason(seedLoc, seasons)) {
|
||||
if (MainConfig.notifyInWrongSeason) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.wrongSeason.replace("{season}", SeasonUtils.getSeasonText(SeasonUtils.getSeason(seedLoc.getWorld()))));
|
||||
if (MainConfig.preventInWrongSeason) return false;
|
||||
}
|
||||
if (MainConfig.OraxenHook) {
|
||||
if (FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.5,0.5))) return false;
|
||||
}
|
||||
else {
|
||||
if (FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.03125,0.5))) return false;
|
||||
}
|
||||
|
||||
if (seedLoc.getBlock().getType() != Material.AIR) return false;
|
||||
|
||||
if (player != null) {
|
||||
PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player);
|
||||
@@ -566,6 +576,20 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
}
|
||||
|
||||
CCSeason[] seasons = crop.getSeasons();
|
||||
if (SeasonConfig.enable && seasons != null) {
|
||||
if (cropManager.isWrongSeason(seedLoc, seasons)) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < seasons.length; i++) {
|
||||
if (i < seasons.length - 1) stringBuilder.append(SeasonUtils.getSeasonText(seasons[i])).append(", ");
|
||||
else stringBuilder.append(SeasonUtils.getSeasonText(seasons[i]));
|
||||
}
|
||||
if (MainConfig.notifyInWrongSeason) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.wrongSeason.replace("{season}", SeasonUtils.getSeasonText(SeasonUtils.getSeason(seedLoc.getWorld())))
|
||||
.replace("{suitable}", stringBuilder.toString()));
|
||||
if (MainConfig.preventInWrongSeason) return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (MainConfig.limitation) {
|
||||
if (MainConfig.cropMode && LimitationUtil.reachWireLimit(seedLoc)) {
|
||||
if (player != null) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitWire.replace("{max}", String.valueOf(MainConfig.wireAmount)));
|
||||
@@ -577,10 +601,12 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
}
|
||||
|
||||
SeedPlantEvent seedPlantEvent = new SeedPlantEvent(player, seedLoc, crop);
|
||||
Bukkit.getPluginManager().callEvent(seedPlantEvent);
|
||||
if (seedPlantEvent.isCancelled()) {
|
||||
return false;
|
||||
if (MainConfig.enableEvents) {
|
||||
SeedPlantEvent seedPlantEvent = new SeedPlantEvent(player, seedLoc, crop);
|
||||
Bukkit.getPluginManager().callEvent(seedPlantEvent);
|
||||
if (seedPlantEvent.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (SoundConfig.plantSeed.isEnable() && player != null) {
|
||||
@@ -602,4 +628,42 @@ public abstract class HandlerP extends Function {
|
||||
customWorld.addCrop(seedLoc, cropName);
|
||||
return true;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public Crop getCropFromID(String id) {
|
||||
String crop;
|
||||
if (id.contains(":")) {
|
||||
crop = id.split(":")[1].split("_")[0];
|
||||
}
|
||||
else {
|
||||
crop = id.split("_")[0];
|
||||
}
|
||||
return CropConfig.CROPS.get(crop);
|
||||
}
|
||||
|
||||
protected boolean onInteractRipeCrop(Location location, Crop crop, Player player) {
|
||||
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return true;
|
||||
|
||||
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0));
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, true);
|
||||
|
||||
if (crop.getReturnStage() == null) {
|
||||
customWorld.removeCrop(location);
|
||||
return true;
|
||||
}
|
||||
customWorld.addCrop(location, crop.getKey());
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void waterCanSoundsActionBar() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +24,17 @@ import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent;
|
||||
import dev.lone.itemsadder.api.Events.FurnitureBreakEvent;
|
||||
import dev.lone.itemsadder.api.Events.FurnitureInteractEvent;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.api.event.PreActionEvent;
|
||||
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.managers.CropManager;
|
||||
import net.momirealms.customcrops.managers.CustomWorld;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -72,11 +72,13 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
}
|
||||
|
||||
if (namespacedID.contains("_stage_")) {
|
||||
if (!canProceedAction(player, location)) return;
|
||||
if (!namespacedID.equals(BasicItemConfig.deadCrop)) {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
if (!hasNextStage(namespacedID)) {
|
||||
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) {
|
||||
if (!AntiGrief.testBreak(player, entity.getLocation())) return;
|
||||
if (!canProceedAction(player, entity.getLocation())) return;
|
||||
CustomFurniture.remove(entity, false);
|
||||
this.onInteractRipeCrop(location, namespacedID, player);
|
||||
return;
|
||||
@@ -117,7 +119,7 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
|
||||
final Location location = event.getBukkitEntity().getLocation();
|
||||
final Player player = event.getPlayer();
|
||||
//No need for antiGrief checks
|
||||
|
||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(namespacedId);
|
||||
if (sprinkler != null) {
|
||||
super.onBreakSprinkler(location);
|
||||
@@ -176,6 +178,7 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
Location seedLoc = block.getLocation().clone().add(0,1,0);
|
||||
|
||||
if (!AntiGrief.testPlace(player, seedLoc)) return;
|
||||
if (!canProceedAction(player, seedLoc)) return;
|
||||
|
||||
ItemStack itemInHand = event.getItem();
|
||||
Location potLoc = block.getLocation();
|
||||
@@ -208,10 +211,11 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
Location location = event.getBlock().getLocation();
|
||||
|
||||
if (!AntiGrief.testBreak(player, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
//fix buggy chorus duplication
|
||||
chorusFix(event.getBlock());
|
||||
|
||||
@@ -241,20 +245,9 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
}
|
||||
|
||||
private void onInteractRipeCrop(Location location, String id, Player player) {
|
||||
|
||||
Crop crop = getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
|
||||
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0));
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, true);
|
||||
|
||||
if (crop.getReturnStage() == null) {
|
||||
customWorld.removeCrop(location);
|
||||
return;
|
||||
}
|
||||
customWorld.addCrop(location, crop.getKey());
|
||||
if (super.onInteractRipeCrop(location, crop, player)) return;
|
||||
CustomFurniture customFurniture = CustomFurniture.spawn(crop.getReturnStage(), location.getBlock());
|
||||
if (customFurniture != null) {
|
||||
if (customFurniture instanceof ItemFrame itemFrame) {
|
||||
|
||||
@@ -34,6 +34,7 @@ import net.momirealms.customcrops.integrations.customplugin.itemsadder.listeners
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.managers.CustomWorld;
|
||||
import net.momirealms.customcrops.objects.WaterCan;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -109,7 +110,9 @@ public abstract class ItemsAdderHandler extends HandlerP {
|
||||
}
|
||||
|
||||
if (block == null) return;
|
||||
if (!AntiGrief.testPlace(player, block.getLocation())) return;
|
||||
Location location = block.getLocation();
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
if (event.getBlockFace() == BlockFace.UP && placeSprinkler(namespacedID, event.getClickedBlock().getLocation(), player, item)) {
|
||||
return;
|
||||
@@ -147,10 +150,12 @@ public abstract class ItemsAdderHandler extends HandlerP {
|
||||
int water = nbtItem.getInteger("WaterAmount");
|
||||
if (water > 0) {
|
||||
|
||||
WaterEvent waterEvent = new WaterEvent(player, can.getItemStack());
|
||||
Bukkit.getPluginManager().callEvent(waterEvent);
|
||||
if (waterEvent.isCancelled()) {
|
||||
return true;
|
||||
if (MainConfig.enableEvents) {
|
||||
WaterEvent waterEvent = new WaterEvent(player, can.getItemStack());
|
||||
Bukkit.getPluginManager().callEvent(waterEvent);
|
||||
if (waterEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
NBTCompound nbtCompound = nbtItem.getCompound("itemsadder");
|
||||
@@ -207,6 +212,7 @@ public abstract class ItemsAdderHandler extends HandlerP {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Crop getCropFromID(String namespacedID) {
|
||||
String[] cropNameList = StringUtils.split(StringUtils.split(namespacedID, ":")[1], "_");
|
||||
return CropConfig.CROPS.get(cropNameList[0]);
|
||||
|
||||
@@ -30,9 +30,7 @@ import net.momirealms.customcrops.config.SoundConfig;
|
||||
import net.momirealms.customcrops.config.SprinklerConfig;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.managers.CustomWorld;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@@ -65,6 +63,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
Entity entity = event.getBukkitEntity();
|
||||
|
||||
if (!AntiGrief.testPlace(player, entity.getLocation())) return;
|
||||
if (!canProceedAction(player, entity.getLocation())) return;
|
||||
|
||||
String namespacedID = event.getNamespacedID();
|
||||
if (namespacedID == null) return;
|
||||
@@ -110,6 +109,9 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
|
||||
//interact crop
|
||||
if (blockID.contains("_stage_")) {
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
ItemStack itemInHand = event.getItem();
|
||||
if (!blockID.equals(BasicItemConfig.deadCrop)) {
|
||||
if (!hasNextStage(blockID)) {
|
||||
@@ -117,6 +119,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
ItemStack offHand = player.getInventory().getItemInOffHand();
|
||||
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && (mainHand.getType() != Material.AIR || offHand.getType() != Material.AIR))) {
|
||||
if (!AntiGrief.testBreak(player, location)) return;
|
||||
|
||||
CustomBlock.remove(location);
|
||||
this.onInteractRipeCrop(location, blockID, player);
|
||||
return;
|
||||
@@ -151,6 +154,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
else if (blockID.equals(BasicItemConfig.wetPot) || blockID.equals(BasicItemConfig.dryPot)) {
|
||||
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
ItemStack itemInHand = event.getItem();
|
||||
if (super.tryMisc(player, itemInHand, location)) return;
|
||||
@@ -254,22 +258,10 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
private void onInteractRipeCrop(Location location, String id, Player player) {
|
||||
|
||||
Crop crop = getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
|
||||
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0));
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, true);
|
||||
|
||||
if (crop.getReturnStage() == null) {
|
||||
customWorld.removeCrop(location);
|
||||
return;
|
||||
}
|
||||
customWorld.addCrop(location, crop.getKey());
|
||||
if (super.onInteractRipeCrop(location, crop, player)) return;
|
||||
CustomBlock.place(crop.getReturnStage(), location);
|
||||
}
|
||||
|
||||
@@ -296,6 +288,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
//Drop seeds
|
||||
if (player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH) || player.getInventory().getItemInMainHand().getType() == Material.SHEARS){
|
||||
event.setCancelled(true);
|
||||
@@ -323,6 +316,8 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
super.onBreakPot(location);
|
||||
|
||||
//Check if there's crop above
|
||||
@@ -343,7 +338,6 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
else {
|
||||
super.onBreakRipeCrop(seedLocation, seedID, player, false, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
super.onBreakPot(location);
|
||||
|
||||
Location seedLocation = location.clone().add(0.5,1.03125,0.5);
|
||||
@@ -100,7 +102,7 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
|
||||
String id = event.getFurnitureMechanic().getItemID();
|
||||
if (id == null) return;
|
||||
//TODO check if needs anti grief
|
||||
|
||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(id);
|
||||
if (sprinkler != null) {
|
||||
super.onBreakSprinkler(event.getBlock().getLocation());
|
||||
@@ -135,6 +137,7 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
Location potLoc = block.getLocation();
|
||||
|
||||
if (!AntiGrief.testPlace(player, seedLoc)) return;
|
||||
if (!canProceedAction(player, seedLoc)) return;
|
||||
if (super.tryMisc(player, itemInHand, potLoc)) return;
|
||||
if (event.getBlockFace() != BlockFace.UP) return;
|
||||
|
||||
@@ -163,6 +166,7 @@ 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) {
|
||||
@@ -213,16 +217,7 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
private void onInteractRipeCrop(Location location, String id, Player player) {
|
||||
Crop crop = getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
|
||||
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0));
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, true);
|
||||
if (crop.getReturnStage() == null) {
|
||||
customWorld.removeCrop(location);
|
||||
return;
|
||||
}
|
||||
customWorld.addCrop(location, crop.getKey());
|
||||
if (super.onInteractRipeCrop(location, crop, player)) return;
|
||||
ItemFrame itemFrame = cropManager.getCustomInterface().placeFurniture(location, crop.getReturnStage());
|
||||
if (itemFrame != null) {
|
||||
itemFrame.setRotation(FurnitureUtil.getRandomRotation());
|
||||
|
||||
@@ -144,11 +144,14 @@ public abstract class OraxenHandler extends HandlerP {
|
||||
int water = nbtItem.getInteger("WaterAmount");
|
||||
if (water > 0) {
|
||||
|
||||
WaterEvent waterEvent = new WaterEvent(player, can);
|
||||
Bukkit.getPluginManager().callEvent(waterEvent);
|
||||
if (waterEvent.isCancelled()) {
|
||||
return true;
|
||||
if (MainConfig.enableEvents) {
|
||||
WaterEvent waterEvent = new WaterEvent(player, can);
|
||||
Bukkit.getPluginManager().callEvent(waterEvent);
|
||||
if (waterEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
nbtItem.setInteger("WaterAmount", --water);
|
||||
|
||||
if (SoundConfig.waterPot.isEnable()) {
|
||||
@@ -176,18 +179,19 @@ public abstract class OraxenHandler extends HandlerP {
|
||||
addWaterLore(nbtItem, canConfig, water);
|
||||
}
|
||||
|
||||
can.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
|
||||
if (MainConfig.enableWaterCanLore && MainConfig.enablePacketLore) {
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
super.waterPot(canConfig.getWidth(), canConfig.getLength(), potLoc, player.getLocation().getYaw());
|
||||
|
||||
can.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Crop getCropFromID(String id) {
|
||||
return CropConfig.CROPS.get(StringUtils.split(id, "_")[0]);
|
||||
}
|
||||
|
||||
@@ -105,27 +105,30 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
if (id.contains("_stage_")) {
|
||||
|
||||
final Block block = event.getBlock();
|
||||
Location location = block.getLocation();
|
||||
|
||||
if (!AntiGrief.testBreak(player, block.getLocation())) {
|
||||
if (!AntiGrief.testBreak(player, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
//Drop seeds
|
||||
if (player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH) || player.getInventory().getItemInMainHand().getType() == Material.SHEARS){
|
||||
event.setCancelled(true);
|
||||
Drop drop = mechanic.getDrop();
|
||||
if (player.getGameMode() != GameMode.CREATIVE && drop != null)
|
||||
drop.spawns(block.getLocation(), new ItemStack(Material.AIR));
|
||||
drop.spawns(location, new ItemStack(Material.AIR));
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
if (id.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (hasNextStage(id)) {
|
||||
super.onBreakUnripeCrop(block.getLocation());
|
||||
super.onBreakUnripeCrop(location);
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(block.getLocation(), id, player, true, false);
|
||||
super.onBreakRipeCrop(location, id, player, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,8 +136,6 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
public void onBreakFurniture(OraxenFurnitureBreakEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
//TODO Check if triggered in res
|
||||
|
||||
FurnitureMechanic mechanic = event.getFurnitureMechanic();
|
||||
if (mechanic == null) return;
|
||||
String id = mechanic.getItemID();
|
||||
@@ -156,6 +157,7 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
final Location blockLoc = event.getItemFrame().getLocation();
|
||||
|
||||
if (!AntiGrief.testPlace(player, blockLoc)) return;
|
||||
if (!canProceedAction(player, blockLoc)) return;
|
||||
|
||||
FurnitureMechanic mechanic = event.getFurnitureMechanic();
|
||||
if (mechanic == null) return;
|
||||
@@ -179,6 +181,7 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
if (event.getBlockFace() != BlockFace.UP) return;
|
||||
|
||||
Location seedLoc = potLoc.clone().add(0,1,0);
|
||||
if (!canProceedAction(player, seedLoc)) return;
|
||||
|
||||
String id = OraxenItems.getIdByItem(itemInHand);
|
||||
if (id != null) {
|
||||
@@ -209,6 +212,7 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
if (id.contains("_stage_")) {
|
||||
|
||||
Location seedLoc = block.getLocation();
|
||||
if (!canProceedAction(player, seedLoc)) return;
|
||||
ItemStack itemInHand = event.getItemInHand();
|
||||
//ripe crops
|
||||
if (!id.equals(BasicItemConfig.deadCrop)) {
|
||||
@@ -251,20 +255,9 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
}
|
||||
|
||||
private void onInteractRipeCrop(Location location, String id, Player player) {
|
||||
|
||||
Crop crop = getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
|
||||
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0));
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, true);
|
||||
|
||||
if (crop.getReturnStage() == null) {
|
||||
customWorld.removeCrop(location);
|
||||
return;
|
||||
}
|
||||
customWorld.addCrop(location, crop.getKey());
|
||||
if (super.onInteractRipeCrop(location, crop, player)) return;
|
||||
StringBlockMechanicFactory.setBlockModel(location.getBlock(), crop.getReturnStage());
|
||||
}
|
||||
}
|
||||
@@ -328,9 +328,12 @@ public class CropManager extends Function {
|
||||
|
||||
public void proceedHarvest(Crop crop, Player player, Location location, @Nullable Fertilizer fertilizer, boolean isRightClick) {
|
||||
//Call harvest event
|
||||
CropHarvestEvent cropHarvestEvent = new CropHarvestEvent(player, crop, location, fertilizer);
|
||||
Bukkit.getPluginManager().callEvent(cropHarvestEvent);
|
||||
if (cropHarvestEvent.isCancelled()) return;
|
||||
if (MainConfig.enableEvents) {
|
||||
CropHarvestEvent cropHarvestEvent = new CropHarvestEvent(player, crop, location, fertilizer);
|
||||
Bukkit.getPluginManager().callEvent(cropHarvestEvent);
|
||||
if (cropHarvestEvent.isCancelled()) return;
|
||||
}
|
||||
|
||||
if (!isRightClick && player.getGameMode() == GameMode.CREATIVE) return;
|
||||
ActionInterface[] actions = crop.getActions();
|
||||
if (actions != null) performActions(actions, player);
|
||||
@@ -357,7 +360,7 @@ public class CropManager extends Function {
|
||||
qualityRatio = qualityCrop.getQualityRatio();
|
||||
}
|
||||
}
|
||||
if (MainConfig.enableSkillBonus) {
|
||||
if (MainConfig.enableSkillBonus && MainConfig.skillXP != null) {
|
||||
double bonus_chance = MainConfig.skillXP.getLevel(player) * MainConfig.bonusPerLevel;
|
||||
amount *= (bonus_chance + 1);
|
||||
}
|
||||
@@ -437,8 +440,10 @@ public class CropManager extends Function {
|
||||
if (Math.random() < MainConfig.crowChance && !hasScarecrow(location)) {
|
||||
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
CrowAttackEvent crowAttackEvent = new CrowAttackEvent(location);
|
||||
Bukkit.getPluginManager().callEvent(crowAttackEvent);
|
||||
if (MainConfig.enableEvents) {
|
||||
CrowAttackEvent crowAttackEvent = new CrowAttackEvent(location);
|
||||
Bukkit.getPluginManager().callEvent(crowAttackEvent);
|
||||
}
|
||||
for (Player player : location.getNearbyPlayers(48)) {
|
||||
CrowTask crowTask = new CrowTask(player, location.clone().add(0.4,0,0.4), getArmorStandUtil());
|
||||
crowTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1, 1);
|
||||
|
||||
@@ -84,10 +84,12 @@ public class CustomWorld {
|
||||
public void unload(boolean sync) {
|
||||
if (sync) {
|
||||
unloadData();
|
||||
backUp(world.getName());
|
||||
}
|
||||
else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {
|
||||
unloadData();
|
||||
backUp(world.getName());
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
CustomWorldEvent customWorldEvent = new CustomWorldEvent(world, WorldState.UNLOAD);
|
||||
Bukkit.getPluginManager().callEvent(customWorldEvent);
|
||||
@@ -112,7 +114,6 @@ public class CustomWorld {
|
||||
unloadFertilizer();
|
||||
unloadPot();
|
||||
unloadScarecrow();
|
||||
backUp(world.getName());
|
||||
}
|
||||
|
||||
public void backUp(String worldName) {
|
||||
|
||||
Reference in New Issue
Block a user