mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 09:59:20 +00:00
2.0.10
This commit is contained in:
@@ -335,14 +335,19 @@ public abstract class HandlerP extends Function {
|
||||
if (block.getType() == Material.WATER) {
|
||||
if (config.getMax() > water) {
|
||||
|
||||
WateringCanFillEvent wateringCanFillEvent = new WateringCanFillEvent(player, nbtItem, water += MainConfig.waterToWaterCan);
|
||||
water += MainConfig.waterToWaterCan;
|
||||
if (water > config.getMax()) water = config.getMax();
|
||||
|
||||
WateringCanFillEvent wateringCanFillEvent = new WateringCanFillEvent(player, nbtItem, water);
|
||||
Bukkit.getPluginManager().callEvent(wateringCanFillEvent);
|
||||
if (wateringCanFillEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (wateringCanFillEvent.getCurrentWater() > config.getMax()) water = config.getMax();
|
||||
nbtItem.setInteger("WaterAmount", wateringCanFillEvent.getCurrentWater());
|
||||
water = wateringCanFillEvent.getCurrentWater();
|
||||
|
||||
if (water > config.getMax()) water = config.getMax();
|
||||
nbtItem.setInteger("WaterAmount", water);
|
||||
|
||||
if (SoundConfig.addWaterToCan.isEnable()) {
|
||||
AdventureUtil.playerSound(
|
||||
@@ -358,7 +363,7 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
|
||||
if (MainConfig.enableWaterCanLore && !MainConfig.enablePacketLore) {
|
||||
addWaterLore(nbtItem, config, wateringCanFillEvent.getCurrentWater());
|
||||
addWaterLore(nbtItem, config, water);
|
||||
}
|
||||
|
||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
@@ -534,6 +539,41 @@ 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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public boolean plantSeed(Location seedLoc, String cropName, @Nullable Player player, @Nullable ItemStack itemInHand) {
|
||||
Crop crop = CropConfig.CROPS.get(cropName);
|
||||
if (crop == null) return false;
|
||||
@@ -611,38 +651,4 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,11 @@ public class ItemsAdderFrameCropImpl implements CropModeInterface {
|
||||
String id = customInterface.getItemID(itemFrame.getItem());
|
||||
if (id == null) return true;
|
||||
if (id.equals(BasicItemConfig.deadCrop)) return true;
|
||||
String[] cropNameList = StringUtils.split(id,"_");
|
||||
String cropKey = StringUtils.split(cropNameList[0], ":")[1];
|
||||
|
||||
String cropId = StringUtils.split(id, ":")[1];
|
||||
String[] cropNameList = StringUtils.split(cropId, "_");
|
||||
String cropKey = cropNameList[0];
|
||||
|
||||
Crop crop = CropConfig.CROPS.get(cropKey);
|
||||
if (crop == null) return true;
|
||||
if (MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -230,11 +231,11 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
if (seedID.contains("_stage_")) {
|
||||
CustomFurniture.remove(itemFrame, false);
|
||||
if (seedID.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (hasNextStage(namespacedId)) {
|
||||
if (hasNextStage(seedID)) {
|
||||
super.onBreakUnripeCrop(location);
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(location, namespacedId, player, true, true);
|
||||
super.onBreakRipeCrop(location, seedID, player, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,10 @@ import dev.lone.itemsadder.api.Events.*;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.api.event.SeedPlantEvent;
|
||||
import net.momirealms.customcrops.api.event.WaterPotEvent;
|
||||
import net.momirealms.customcrops.api.utils.CCSeason;
|
||||
import net.momirealms.customcrops.api.utils.SeasonUtils;
|
||||
import net.momirealms.customcrops.config.*;
|
||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.integrations.customplugin.HandlerP;
|
||||
@@ -33,19 +36,26 @@ 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.requirements.PlantingCondition;
|
||||
import net.momirealms.customcrops.objects.requirements.RequirementInterface;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import net.momirealms.customcrops.utils.LimitationUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ItemsAdderHandler extends HandlerP {
|
||||
|
||||
|
||||
@@ -48,8 +48,11 @@ public class ItemsAdderWireCropImpl implements CropModeInterface {
|
||||
String blockID = customInterface.getBlockID(location);
|
||||
if (blockID == null) return true;
|
||||
if (!blockID.contains("_stage_")) return true;
|
||||
String[] cropNameList = StringUtils.split(blockID,"_");
|
||||
String cropKey = StringUtils.split(cropNameList[0], ":")[1];
|
||||
|
||||
String cropId = StringUtils.split(blockID, ":")[1];
|
||||
String[] cropNameList = StringUtils.split(cropId, "_");
|
||||
String cropKey = cropNameList[0];
|
||||
|
||||
Crop crop = CropConfig.CROPS.get(cropKey);
|
||||
if (crop == null) return true;
|
||||
|
||||
|
||||
@@ -261,7 +261,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
Crop crop = getCropFromID(id);
|
||||
if (crop == null) return;
|
||||
if (super.onInteractRipeCrop(location, crop, player)) return;
|
||||
CustomBlock.place(crop.getReturnStage(), location);
|
||||
if (crop.getReturnStage() != null) CustomBlock.place(crop.getReturnStage(), location);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,10 @@ import io.th0rgal.oraxen.items.OraxenItems;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.api.event.SeedPlantEvent;
|
||||
import net.momirealms.customcrops.api.event.WaterPotEvent;
|
||||
import net.momirealms.customcrops.api.utils.CCSeason;
|
||||
import net.momirealms.customcrops.api.utils.SeasonUtils;
|
||||
import net.momirealms.customcrops.config.*;
|
||||
import net.momirealms.customcrops.integrations.customplugin.HandlerP;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenBlockListener;
|
||||
@@ -32,13 +35,19 @@ import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.Ora
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.managers.CustomWorld;
|
||||
import net.momirealms.customcrops.objects.WaterCan;
|
||||
import net.momirealms.customcrops.objects.requirements.PlantingCondition;
|
||||
import net.momirealms.customcrops.objects.requirements.RequirementInterface;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import net.momirealms.customcrops.utils.LimitationUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.block.Action;
|
||||
|
||||
@@ -135,8 +135,13 @@ public class CustomWorld {
|
||||
File file = new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data");
|
||||
File[] files = file.listFiles();
|
||||
if (files == null) return;
|
||||
for (File data : files) {
|
||||
FileUtils.copyFileToDirectory(data, new File(CustomCrops.plugin.getDataFolder(), "backup" + File.separator + world.getName() + "_" + format.format(date)));
|
||||
try {
|
||||
for (File data : files) {
|
||||
FileUtils.copyFileToDirectory(data, new File(CustomCrops.plugin.getDataFolder(), "backup" + File.separator + world.getName() + "_" + format.format(date)));
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,8 +451,9 @@ public class CustomWorld {
|
||||
* @param location sprinkler location
|
||||
*/
|
||||
public void sprinklerWork(SimpleLocation location, Sprinkler sprinkler) {
|
||||
if (sprinkler.getWater() <= 1) {
|
||||
if (sprinkler.getWater() < 1) {
|
||||
sprinklerCache.remove(location);
|
||||
return;
|
||||
}
|
||||
Location sprinklerLoc = MiscUtils.getLocation(location);
|
||||
if (sprinklerLoc == null) return;
|
||||
|
||||
Reference in New Issue
Block a user