mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 18:09:28 +00:00
2.1.0-r1
This commit is contained in:
@@ -41,7 +41,6 @@ public final class CustomCrops extends JavaPlugin {
|
||||
|
||||
private PlaceholderManager placeholderManager;
|
||||
private CropManager cropManager;
|
||||
private PluginCommand pluginCommand;
|
||||
|
||||
// _ooOoo_
|
||||
// o8888888o
|
||||
@@ -79,12 +78,10 @@ public final class CustomCrops extends JavaPlugin {
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("ItemsAdder") != null) {
|
||||
MainConfig.customPlugin = "itemsadder";
|
||||
MainConfig.OraxenHook = false;
|
||||
AdventureUtil.consoleMessage("[CustomCrops] Custom Item Plugin Platform: <#BA55D3><u>ItemsAdder");
|
||||
}
|
||||
else if (Bukkit.getPluginManager().getPlugin("Oraxen") != null) {
|
||||
MainConfig.customPlugin = "oraxen";
|
||||
MainConfig.OraxenHook = true;
|
||||
AdventureUtil.consoleMessage("[CustomCrops] Custom Item Plugin Platform: <#6495ED><u>Oraxen");
|
||||
}
|
||||
else {
|
||||
@@ -98,7 +95,7 @@ public final class CustomCrops extends JavaPlugin {
|
||||
if (MainConfig.cropMode) AdventureUtil.consoleMessage("[CustomCrops] Crop Mode: Tripwire");
|
||||
else AdventureUtil.consoleMessage("[CustomCrops] Crop Mode: ItemFrame");
|
||||
|
||||
this.pluginCommand = new PluginCommand();
|
||||
PluginCommand pluginCommand = new PluginCommand();
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setExecutor(pluginCommand);
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setTabCompleter(pluginCommand);
|
||||
|
||||
|
||||
@@ -43,4 +43,6 @@ public interface Crop {
|
||||
String getKey();
|
||||
|
||||
boolean canRotate();
|
||||
|
||||
int getMax_stage();
|
||||
}
|
||||
|
||||
@@ -77,10 +77,7 @@ public class ConfigUtil {
|
||||
CustomCrops.plugin.getPlaceholderManager().load();
|
||||
}
|
||||
if (CustomCrops.plugin.getCropManager() != null) {
|
||||
CustomCrops.plugin.getCropManager().loadMode();
|
||||
CustomCrops.plugin.getCropManager().loadSeason();
|
||||
CustomCrops.plugin.getCropManager().loadPacket();
|
||||
CustomCrops.plugin.getCropManager().loadVanillaMechanic();
|
||||
CustomCrops.plugin.getCropManager().reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package net.momirealms.customcrops.config;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.api.utils.CCSeason;
|
||||
import net.momirealms.customcrops.objects.CCCrop;
|
||||
@@ -28,6 +29,8 @@ import net.momirealms.customcrops.objects.requirements.*;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -36,12 +39,58 @@ import java.util.Objects;
|
||||
public class CropConfig {
|
||||
|
||||
public static HashMap<String, Crop> CROPS;
|
||||
public static String namespace = "";
|
||||
|
||||
public static void load() {
|
||||
|
||||
CROPS = new HashMap<>(16);
|
||||
YamlConfiguration config = ConfigUtil.getConfig("crops_" + MainConfig.customPlugin + ".yml");
|
||||
|
||||
if (config.contains("tomato") && !config.contains("tomato.max-stage")) config.set("tomato.max-stage", 4);
|
||||
if (config.contains("grape") && !config.contains("grape.max-stage")) config.set("grape.max-stage", 6);
|
||||
if (config.contains("garlic") && !config.contains("garlic.max-stage")) config.set("garlic.max-stage", 4);
|
||||
if (config.contains("redpacket") && !config.contains("redpacket.max-stage")) config.set("redpacket.max-stage", 6);
|
||||
if (config.contains("cabbage") && !config.contains("cabbage.max-stage")) config.set("cabbage.max-stage", 4);
|
||||
if (config.contains("pepper") && !config.contains("pepper.max-stage")) config.set("pepper.max-stage", 5);
|
||||
if (config.contains("corn") && !config.contains("corn.max-stage")) config.set("corn.max-stage", 4);
|
||||
if (config.contains("apple") && !config.contains("apple.max-stage")) config.set("apple.max-stage", 6);
|
||||
if (config.contains("pineapple") && !config.contains("pineapple.max-stage")) config.set("pineapple.max-stage", 4);
|
||||
if (config.contains("pitaya") && !config.contains("pitaya.max-stage")) config.set("pitaya.max-stage", 6);
|
||||
if (config.contains("eggplant") && !config.contains("eggplant.max-stage")) config.set("eggplant.max-stage", 4);
|
||||
if (config.contains("chinesecabbage") && !config.contains("chinesecabbage.max-stage")) config.set("chinesecabbage.max-stage", 4);
|
||||
if (config.contains("hop") && !config.contains("hop.max-stage")) config.set("hop.max-stage", 4);
|
||||
|
||||
if (MainConfig.customPlugin.equals("itemsadder")) {
|
||||
namespace = config.getString("namespace");
|
||||
if (namespace == null) {
|
||||
namespace = "customcrops:";
|
||||
config.set("namespace", "customcrops");
|
||||
}
|
||||
else {
|
||||
namespace = namespace + ":";
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
config.save(new File(CustomCrops.plugin.getDataFolder(), "crops_" + MainConfig.customPlugin + ".yml"));
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (String key : config.getKeys(false)) {
|
||||
CCCrop crop = new CCCrop(key);
|
||||
if (key.equals("namespace")) continue;
|
||||
int max_stage;
|
||||
if (config.contains(key + ".max-stage")) {
|
||||
max_stage = config.getInt(key + ".max-stage");
|
||||
}
|
||||
else {
|
||||
AdventureUtil.consoleMessage("<red>[CustomCrops] No \"max-stage\" set for crop: " + key);
|
||||
AdventureUtil.consoleMessage("<red>[CustomCrops] Please read the update log (v2.1.0), this is for better performance :)");
|
||||
continue;
|
||||
}
|
||||
|
||||
CCCrop crop = new CCCrop(key, max_stage);
|
||||
for (String option : config.getConfigurationSection(key).getKeys(false)) {
|
||||
if (option.equals("quality-loots")) {
|
||||
String amount = config.getString(key + ".quality-loots.amount", "1~2");
|
||||
|
||||
@@ -43,6 +43,7 @@ public class MainConfig {
|
||||
public static List<World> worldList;
|
||||
public static List<String> worldNameList;
|
||||
public static boolean whiteOrBlack;
|
||||
public static boolean dropLootsInAllWorlds;
|
||||
public static String customPlugin;
|
||||
public static boolean OraxenHook;
|
||||
public static boolean realisticSeasonHook;
|
||||
@@ -160,6 +161,7 @@ public class MainConfig {
|
||||
timeToWork = config.getInt("mechanics.auto-grow.sprinkler-work-time", 300);
|
||||
timeToDry = config.getInt("mechanics.auto-grow.pot-dry-time", 200);
|
||||
dryGrowChance = config.getDouble("mechanics.dry-pot-grow-chance", 0.5);
|
||||
dropLootsInAllWorlds = config.getBoolean("mechanics.drop-loots-in-all-worlds", false);
|
||||
|
||||
waterBucketToSprinkler = config.getInt("mechanics.fill.water-bucket-to-sprinkler", 3);
|
||||
waterToWaterCan = config.getInt("mechanics.fill.waterblock-to-watering-can", 1);
|
||||
|
||||
@@ -56,4 +56,8 @@ public interface CustomInterface {
|
||||
Crop getCropFromID(String id);
|
||||
|
||||
Location getFrameCropLocation(Location seedLoc);
|
||||
|
||||
void addFrameStage(ItemFrame itemFrame, String stage, boolean rotate);
|
||||
|
||||
void addWireStage(Location seedLoc, String stage);
|
||||
}
|
||||
|
||||
@@ -82,22 +82,15 @@ public abstract class HandlerP extends Function {
|
||||
//null
|
||||
}
|
||||
|
||||
public boolean coolDownJudge(Player player) {
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 50)) < 50) return false;
|
||||
coolDown.put(player, time);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onInteractSprinkler(Location location, Player player, @Nullable ItemStack itemStack, Sprinkler config) {
|
||||
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
|
||||
Sprinkler sprinkler = customWorld.getSprinkler(location);
|
||||
Sprinkler sprinkler = customWorld.getSprinklerCache(location);
|
||||
if (sprinkler == null) {
|
||||
sprinkler = new Sprinkler(config.getKey(), config.getRange(), 0);
|
||||
customWorld.addSprinkler(location, sprinkler);
|
||||
customWorld.addSprinklerCache(location, sprinkler);
|
||||
}
|
||||
|
||||
if (itemStack != null) {
|
||||
@@ -197,9 +190,10 @@ public abstract class HandlerP extends Function {
|
||||
public boolean useSurveyor(Location potLoc, String id, Player player) {
|
||||
|
||||
if (!id.equals(BasicItemConfig.soilSurveyor)) return false;
|
||||
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(potLoc.getWorld());
|
||||
if (customWorld == null) return false;
|
||||
Fertilizer fertilizer = customWorld.getFertilizer(potLoc);
|
||||
Fertilizer fertilizer = customWorld.getFertilizerCache(potLoc);
|
||||
|
||||
SurveyorUseEvent surveyorUseEvent = new SurveyorUseEvent(player, fertilizer, potLoc);
|
||||
Bukkit.getPluginManager().callEvent(surveyorUseEvent);
|
||||
@@ -233,43 +227,55 @@ public abstract class HandlerP extends Function {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBreakUnripeCrop(Location location) {
|
||||
private void removeCropCache(Location location) {
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
//remove crop cache
|
||||
customWorld.removeCrop(location);
|
||||
customWorld.removeCropCache(location);
|
||||
}
|
||||
|
||||
public void onBreakRipeCrop(Location location, String id, Player player, boolean instant, boolean hasNamespace) {
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
//remove crop cache
|
||||
customWorld.removeCrop(location);
|
||||
public void onBreakUnripeCrop(Location location) {
|
||||
removeCropCache(location);
|
||||
}
|
||||
|
||||
String[] cropNameList;
|
||||
if (hasNamespace) cropNameList = StringUtils.split(StringUtils.split(id, ":")[1], "_");
|
||||
else cropNameList = StringUtils.split(id, "_");
|
||||
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(cropNameList[0]);
|
||||
Crop crop = CropConfig.CROPS.get(cropName);
|
||||
if (crop == null) return;
|
||||
|
||||
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0));
|
||||
//double check to prevent dupe when there's no antiGrief integration
|
||||
if (instant) {
|
||||
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, ()-> {
|
||||
if (location.getBlock().getType() != Material.AIR) return;
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld != null) {
|
||||
Fertilizer fertilizer = customWorld.getFertilizerCache(location.clone().subtract(0,1,0));
|
||||
if (instant) {
|
||||
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, ()-> {
|
||||
if (location.getBlock().getType() != Material.AIR) return;
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, false);
|
||||
},1);
|
||||
}
|
||||
else {
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, false);
|
||||
},1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, false);
|
||||
else if (MainConfig.dropLootsInAllWorlds) {
|
||||
if (instant) {
|
||||
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, ()-> {
|
||||
if (location.getBlock().getType() != Material.AIR) return;
|
||||
cropManager.proceedHarvest(crop, player, location, null, false);
|
||||
},1);
|
||||
}
|
||||
else {
|
||||
cropManager.proceedHarvest(crop, player, location, null, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeScarecrow(Location location) {
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
customWorld.removeScarecrow(location);
|
||||
customWorld.removeScarecrowCache(location);
|
||||
}
|
||||
|
||||
public boolean placeSprinkler(String id, Location location, Player player, ItemStack item) {
|
||||
@@ -306,7 +312,7 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
|
||||
if (player.getGameMode() != GameMode.CREATIVE) item.setAmount(item.getAmount() - 1);
|
||||
customWorld.addSprinkler(sprinklerLoc, sprinkler);
|
||||
customWorld.addSprinklerCache(sprinklerLoc, sprinkler);
|
||||
customInterface.placeFurniture(sprinklerLoc, config.getThreeD());
|
||||
|
||||
return true;
|
||||
@@ -441,22 +447,22 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
|
||||
if (player.getGameMode() != GameMode.CREATIVE) itemStack.setAmount(itemStack.getAmount() - 1);
|
||||
customWorld.addFertilizer(potLoc, fertilizer.getWithTimes(fertilizer.getTimes()));
|
||||
customWorld.addFertilizerCache(potLoc, fertilizer.getWithTimes(fertilizer.getTimes()));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBreakSprinkler(Location location) {
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
customWorld.removeSprinkler(location);
|
||||
customWorld.removeSprinklerCache(location);
|
||||
}
|
||||
|
||||
public void onBreakPot(Location location) {
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
//remove fertilizer
|
||||
customWorld.removeFertilizer(location);
|
||||
customWorld.removeWatered(location);
|
||||
customWorld.removeFertilizerCache(location);
|
||||
customWorld.removePotFromWatered(location);
|
||||
}
|
||||
|
||||
public void onQuit(Player player) {
|
||||
@@ -536,19 +542,25 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
|
||||
protected boolean onInteractRipeCrop(Location location, Crop crop, Player player) {
|
||||
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return true;
|
||||
if (customWorld != null) {
|
||||
Fertilizer fertilizer = customWorld.getFertilizerCache(location.clone().subtract(0,1,0));
|
||||
cropManager.proceedHarvest(crop, player, location, fertilizer, 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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
customWorld.addCrop(location, crop.getKey());
|
||||
return false;
|
||||
else if (MainConfig.dropLootsInAllWorlds) {
|
||||
cropManager.proceedHarvest(crop, player, location, null, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -559,8 +571,7 @@ public abstract class HandlerP extends Function {
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(seedLoc.getWorld());
|
||||
if (customWorld == null) return false;
|
||||
|
||||
if (FurnitureUtil.hasFurniture(customInterface.getFrameCropLocation(seedLoc))) return false;
|
||||
if (seedLoc.getBlock().getType() != Material.AIR) return false;
|
||||
if (FurnitureUtil.hasFurniture(customInterface.getFrameCropLocation(seedLoc)) || seedLoc.getBlock().getType() != Material.AIR) return false;
|
||||
|
||||
if (player != null) {
|
||||
PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player);
|
||||
@@ -618,13 +629,27 @@ public abstract class HandlerP extends Function {
|
||||
}
|
||||
|
||||
if (itemInHand != null && player != null && player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
if (MainConfig.cropMode) customInterface.placeWire(seedLoc, cropName + "_stage_1");
|
||||
if (MainConfig.cropMode) customInterface.placeWire(seedLoc, CropConfig.namespace + cropName + "_stage_1");
|
||||
else {
|
||||
ItemFrame itemFrame = customInterface.placeFurniture(seedLoc, cropName + "_stage_1");
|
||||
ItemFrame itemFrame = customInterface.placeFurniture(seedLoc, CropConfig.namespace + cropName + "_stage_1");
|
||||
if (itemFrame == null) return false;
|
||||
if (crop.canRotate()) itemFrame.setRotation(FurnitureUtil.getRandomRotation());
|
||||
}
|
||||
customWorld.addCrop(seedLoc, cropName);
|
||||
customWorld.addCropCache(seedLoc, cropName, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean isInCoolDown(Player player, int delay) {
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - delay)) < delay) return true;
|
||||
coolDown.put(player, time);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRipe(String id) {
|
||||
Crop crop = customInterface.getCropFromID(id);
|
||||
if (crop == null) return false;
|
||||
int stage = Integer.parseInt(id.substring(id.indexOf("_stage_") + 7));
|
||||
return stage == crop.getMax_stage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.integrations.customplugin.itemsadder;
|
||||
|
||||
import dev.lone.itemsadder.api.CustomFurniture;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.CropConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.integrations.customplugin.CustomInterface;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.managers.CropModeInterface;
|
||||
import net.momirealms.customcrops.objects.GiganticCrop;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Gigantic;
|
||||
import net.momirealms.customcrops.objects.fertilizer.SpeedGrow;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
|
||||
public class ItemsAdderFrameCropImpl implements CropModeInterface {
|
||||
|
||||
private final CropManager cropManager;
|
||||
private final CustomInterface customInterface;
|
||||
|
||||
public ItemsAdderFrameCropImpl(CropManager cropManager) {
|
||||
this.cropManager = cropManager;
|
||||
this.customInterface = cropManager.getCustomInterface();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean growJudge(Location location) {
|
||||
|
||||
Chunk chunk = location.getChunk();
|
||||
|
||||
if (chunk.isEntitiesLoaded()) return false;
|
||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(location));
|
||||
if (itemFrame == null) return true;
|
||||
|
||||
String id = customInterface.getItemID(itemFrame.getItem());
|
||||
if (id == null || id.equals(BasicItemConfig.deadCrop)) return true;
|
||||
|
||||
String[] cropNameList = StringUtils.split(StringUtils.split(id, ":")[1], "_");
|
||||
Crop crop = CropConfig.CROPS.get(cropNameList[0]);
|
||||
if (crop == null) return true;
|
||||
if ((MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) || cropManager.isWrongSeason(location, crop.getSeasons())) {
|
||||
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
Location potLoc = location.clone().subtract(0,1,0);
|
||||
String potID = customInterface.getBlockID(potLoc);
|
||||
if (potID == null || (!potID.equals(BasicItemConfig.wetPot) && !potID.equals(BasicItemConfig.dryPot))) return true;
|
||||
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true;
|
||||
|
||||
Fertilizer fertilizer = cropManager.getFertilizer(potLoc);
|
||||
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
|
||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||
String temp = id.substring(0, id.length() - cropNameList[2].length());
|
||||
|
||||
if (customInterface.doesExist(temp + nextStage)) {
|
||||
if (fertilizer instanceof SpeedGrow speedGrow
|
||||
&& Math.random() < speedGrow.getChance()
|
||||
&& customInterface.doesExist(temp + (nextStage+1))
|
||||
)
|
||||
addStage(itemFrame, temp + (nextStage+1), crop.canRotate());
|
||||
else if (certainGrow || Math.random() < MainConfig.dryGrowChance)
|
||||
addStage(itemFrame, temp + nextStage, crop.canRotate());
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
GiganticCrop giganticCrop = crop.getGiganticCrop();
|
||||
if (giganticCrop != null) {
|
||||
double chance = giganticCrop.getChance();
|
||||
if (fertilizer instanceof Gigantic gigantic) chance += gigantic.getChance();
|
||||
if (Math.random() < chance) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
customInterface.removeFurniture(itemFrame);
|
||||
if (giganticCrop.isBlock()) customInterface.placeWire(location, giganticCrop.getBlockID());
|
||||
else customInterface.placeFurniture(location, giganticCrop.getBlockID());
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void addStage(ItemFrame itemFrame, String stage, boolean rotate) {
|
||||
CustomFurniture.remove(itemFrame, false);
|
||||
CustomFurniture customFurniture = CustomFurniture.spawn(stage, itemFrame.getLocation().getBlock());
|
||||
if (rotate && customFurniture.getArmorstand() instanceof ItemFrame frame) {
|
||||
frame.setRotation(FurnitureUtil.getRandomRotation());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 net.momirealms.customcrops.utils.MiscUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -51,7 +52,6 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
super(cropManager);
|
||||
}
|
||||
|
||||
//maybe crop or sprinkler
|
||||
public void onInteractFurniture(FurnitureInteractEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
@@ -62,6 +62,8 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
final Entity entity = event.getBukkitEntity();
|
||||
final Location location = entity.getLocation();;
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(namespacedID);
|
||||
if (sprinkler != null) {
|
||||
if (!AntiGrief.testPlace(player, entity.getLocation())) return;
|
||||
@@ -70,10 +72,9 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
}
|
||||
|
||||
if (!namespacedID.contains("_stage_")) return;
|
||||
if (!canProceedAction(player, location)) return;
|
||||
if (!namespacedID.equals(BasicItemConfig.deadCrop)) {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
if (!customInterface.hasNextStage(namespacedID)) {
|
||||
if (isRipe(namespacedID)) {
|
||||
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) {
|
||||
if (!AntiGrief.testBreak(player, entity.getLocation())) return;
|
||||
if (!canProceedAction(player, entity.getLocation())) return;
|
||||
@@ -83,7 +84,6 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
return;
|
||||
}
|
||||
}
|
||||
//has next stage
|
||||
else if (MainConfig.enableBoneMeal && itemInHand.getType() == Material.BONE_MEAL) {
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
@@ -103,10 +103,7 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
Location potLoc = location.clone().subtract(0, 1, 0).getBlock().getLocation();
|
||||
super.tryMisc(player, player.getInventory().getItemInMainHand(), potLoc);
|
||||
super.tryMisc(player, player.getInventory().getItemInMainHand(), MiscUtils.getItemFrameBlockLocation(location.clone().subtract(0,1,0)));
|
||||
}
|
||||
|
||||
public void onBreakFurniture(FurnitureBreakEvent event) {
|
||||
@@ -131,11 +128,8 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
|
||||
if (namespacedId.contains("_stage_")) {
|
||||
if (namespacedId.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (customInterface.hasNextStage(namespacedId)) {
|
||||
super.onBreakUnripeCrop(location);
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(location, namespacedId, player, false, true);
|
||||
if (!isRipe(namespacedId)) super.onBreakUnripeCrop(location);
|
||||
else super.onBreakRipeCrop(location, namespacedId, player, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,10 +138,6 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 50)) < 50) return;
|
||||
coolDown.put(player, time);
|
||||
|
||||
super.onPlayerInteract(event);
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
@@ -158,57 +148,44 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
|
||||
final String blockID = cb.getNamespacedID();
|
||||
|
||||
if (!AntiGrief.testPlace(player, block.getLocation())) return;
|
||||
if (!blockID.equals(BasicItemConfig.wetPot) && !blockID.equals(BasicItemConfig.dryPot)) return;
|
||||
Location seedLoc = block.getLocation().clone().add(0,1,0);
|
||||
if (!canProceedAction(player, seedLoc)) return;
|
||||
|
||||
//interact crop
|
||||
if (blockID.equals(BasicItemConfig.wetPot) || blockID.equals(BasicItemConfig.dryPot)) {
|
||||
ItemStack itemInHand = event.getItem();
|
||||
Location potLoc = block.getLocation();
|
||||
if (super.tryMisc(player, itemInHand, potLoc)) return;
|
||||
if (event.getBlockFace() != BlockFace.UP) return;
|
||||
|
||||
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();
|
||||
if (super.tryMisc(player, itemInHand, potLoc)) return;
|
||||
|
||||
if (event.getBlockFace() != BlockFace.UP) return;
|
||||
|
||||
CustomStack customStack = CustomStack.byItemStack(itemInHand);
|
||||
if (customStack != null) {
|
||||
String namespacedID = customStack.getNamespacedID();
|
||||
if (namespacedID.endsWith("_seeds")) {
|
||||
String cropName = customStack.getId().substring(0, customStack.getId().length() - 6);
|
||||
plantSeed(seedLoc, cropName, player, itemInHand);
|
||||
}
|
||||
}
|
||||
else if (MainConfig.enableConvert) {
|
||||
String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType());
|
||||
if (cropName == null) return;
|
||||
CustomStack customStack = CustomStack.byItemStack(itemInHand);
|
||||
if (customStack != null) {
|
||||
String id = customStack.getId();
|
||||
if (id.endsWith("_seeds")) {
|
||||
String cropName = customStack.getId().substring(0, customStack.getId().length() - 6);
|
||||
plantSeed(seedLoc, cropName, player, itemInHand);
|
||||
}
|
||||
}
|
||||
else if (MainConfig.enableConvert) {
|
||||
String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType());
|
||||
if (cropName == null) return;
|
||||
plantSeed(seedLoc, cropName, player, itemInHand);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBreakBlock(CustomBlockBreakEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
String namespacedId = event.getNamespacedID();
|
||||
Player player = event.getPlayer();
|
||||
Location location = event.getBlock().getLocation();
|
||||
final String namespacedId = event.getNamespacedID();
|
||||
final Player player = event.getPlayer();
|
||||
final Location location = event.getBlock().getLocation();
|
||||
|
||||
if (!AntiGrief.testBreak(player, location)) return;
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
if (namespacedId.equals(BasicItemConfig.dryPot)
|
||||
|| namespacedId.equals(BasicItemConfig.wetPot)
|
||||
) {
|
||||
if (namespacedId.equals(BasicItemConfig.dryPot) || namespacedId.equals(BasicItemConfig.wetPot)) {
|
||||
super.onBreakPot(location);
|
||||
//Check if there's crop above
|
||||
Location seedLocation = location.clone().add(0.5,1.5,0.5);
|
||||
|
||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(seedLocation);
|
||||
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;
|
||||
@@ -217,11 +194,8 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
|
||||
CustomFurniture.remove(itemFrame, false);
|
||||
if (itemFrame.isValid()) itemFrame.remove();
|
||||
if (seedID.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (customInterface.hasNextStage(seedID)) {
|
||||
super.onBreakUnripeCrop(location);
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(location, seedID, player, true, true);
|
||||
if (!isRipe(seedID)) super.onBreakUnripeCrop(location.clone().add(0,1,0));
|
||||
else super.onBreakRipeCrop(location.clone().add(0,1,0), seedID, player, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public abstract class ItemsAdderHandler extends HandlerP {
|
||||
Location location = event.getBukkitEntity().getLocation();
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
customWorld.addScarecrow(location);
|
||||
customWorld.addScarecrowCache(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,17 +112,18 @@ 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 (event.getBlockFace() == BlockFace.UP && placeSprinkler(namespacedID, event.getClickedBlock().getLocation(), player, item)) {
|
||||
return;
|
||||
if (event.getBlockFace() == BlockFace.UP) {
|
||||
placeSprinkler(namespacedID, event.getClickedBlock().getLocation(), player, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) {
|
||||
if (!AntiGrief.testPlace(player, potLoc)) return true;
|
||||
if (itemInHand == null || itemInHand.getType() == Material.AIR) return true;
|
||||
CustomStack customStack = CustomStack.byItemStack(itemInHand);
|
||||
|
||||
@@ -138,8 +139,8 @@ public abstract class ItemsAdderHandler extends HandlerP {
|
||||
if (useWateringCan(potLoc, itemID, player, customStack)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
//for future misc
|
||||
}
|
||||
|
||||
private boolean useWateringCan(Location potLoc, String namespacedID, Player player, @NotNull CustomStack can) {
|
||||
|
||||
@@ -22,10 +22,13 @@ import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import dev.lone.itemsadder.api.CustomBlock;
|
||||
import dev.lone.itemsadder.api.CustomFurniture;
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.config.CropConfig;
|
||||
import net.momirealms.customcrops.integrations.customplugin.CustomInterface;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -108,20 +111,36 @@ public class ItemsAdderHook implements CustomInterface {
|
||||
|
||||
@Override
|
||||
public String getNextStage(String id) {
|
||||
String[] split = StringUtils.split(id, ":");
|
||||
String[] crop = StringUtils.split(split[1], "_");
|
||||
int nextStage = Integer.parseInt(crop[2]) + 1;
|
||||
return split[0] + ":" + crop[0] + "_" + crop[1] + "_" + nextStage;
|
||||
String stageStr = id.substring(id.indexOf("_stage_") + 7);
|
||||
int nextStage = Integer.parseInt(stageStr) + 1;
|
||||
return id.substring(0, id.length() - stageStr.length()) + nextStage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Crop getCropFromID(String id) {
|
||||
String[] cropNameList = StringUtils.split(StringUtils.split(id, ":")[1], "_");
|
||||
return CropConfig.CROPS.get(cropNameList[0]);
|
||||
String cropNameWithoutNS = StringUtils.split(id, ":")[1];
|
||||
return CropConfig.CROPS.get(cropNameWithoutNS.substring(0, cropNameWithoutNS.indexOf("_stage_")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getFrameCropLocation(Location seedLoc) {
|
||||
return seedLoc.clone().add(0.5,0.5,0.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFrameStage(ItemFrame itemFrame, String stage, boolean rotate) {
|
||||
CustomFurniture.remove(itemFrame, false);
|
||||
CustomFurniture customFurniture = CustomFurniture.spawn(stage, itemFrame.getLocation().getBlock());
|
||||
if (rotate && customFurniture.getArmorstand() instanceof ItemFrame frame) {
|
||||
frame.setRotation(FurnitureUtil.getRandomRotation());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWireStage(Location seedLoc, String stage) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
removeBlock(seedLoc);
|
||||
placeWire(seedLoc, stage);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.integrations.customplugin.itemsadder;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.CropConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.integrations.customplugin.CustomInterface;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.managers.CropModeInterface;
|
||||
import net.momirealms.customcrops.objects.GiganticCrop;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Gigantic;
|
||||
import net.momirealms.customcrops.objects.fertilizer.SpeedGrow;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class ItemsAdderWireCropImpl implements CropModeInterface {
|
||||
|
||||
private final CropManager cropManager;
|
||||
private final CustomInterface customInterface;
|
||||
|
||||
public ItemsAdderWireCropImpl(CropManager cropManager) {
|
||||
this.cropManager = cropManager;
|
||||
this.customInterface = cropManager.getCustomInterface();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean growJudge(Location location) {
|
||||
String blockID = customInterface.getBlockID(location);
|
||||
if (blockID == null || !blockID.contains("_stage_")) return true;
|
||||
|
||||
String[] cropNameList = StringUtils.split(StringUtils.split(blockID, ":")[1], "_");
|
||||
Crop crop = CropConfig.CROPS.get(cropNameList[0]);
|
||||
if (crop == null) return true;
|
||||
|
||||
if ((MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) || cropManager.isWrongSeason(location, crop.getSeasons())) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
customInterface.removeBlock(location);
|
||||
customInterface.placeWire(location, BasicItemConfig.deadCrop);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
Location potLoc = location.clone().subtract(0,1,0);
|
||||
String potID = customInterface.getBlockID(potLoc);
|
||||
if (potID == null || (!potID.equals(BasicItemConfig.wetPot) && !potID.equals(BasicItemConfig.dryPot))) return true;
|
||||
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true;
|
||||
|
||||
Fertilizer fertilizer = cropManager.getFertilizer(potLoc);
|
||||
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
|
||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||
|
||||
String temp = blockID.substring(0, blockID.length() - cropNameList[2].length());
|
||||
if (customInterface.doesExist(temp + nextStage)) {
|
||||
if (fertilizer instanceof SpeedGrow speedGrow
|
||||
&& Math.random() < speedGrow.getChance()
|
||||
&& customInterface.doesExist(temp + (nextStage+1))
|
||||
)
|
||||
addStage(location, temp + (nextStage+1));
|
||||
else if (certainGrow || Math.random() < MainConfig.dryGrowChance)
|
||||
addStage(location, temp + nextStage);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
GiganticCrop giganticCrop = crop.getGiganticCrop();
|
||||
if (giganticCrop != null) {
|
||||
double chance = giganticCrop.getChance();
|
||||
if (fertilizer instanceof Gigantic gigantic) chance += gigantic.getChance();
|
||||
if (Math.random() < chance) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
customInterface.removeBlock(location);
|
||||
if (giganticCrop.isBlock()) customInterface.placeWire(location, giganticCrop.getBlockID());
|
||||
else customInterface.placeFurniture(location, giganticCrop.getBlockID());
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void addStage(Location seedLoc, String stage) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
customInterface.removeBlock(seedLoc);
|
||||
customInterface.placeWire(seedLoc, stage);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -55,9 +55,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(event.getPlayer(), time - 100)) < 100) return;
|
||||
coolDown.put(player, time);
|
||||
if (isInCoolDown(player, 100)) return;
|
||||
|
||||
Entity entity = event.getBukkitEntity();
|
||||
|
||||
@@ -95,10 +93,6 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 50)) < 50) return;
|
||||
coolDown.put(player, time);
|
||||
|
||||
super.onPlayerInteract(event);
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
@@ -110,14 +104,11 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
|
||||
final String blockID = cb.getNamespacedID();
|
||||
|
||||
//interact crop
|
||||
if (!canProceedAction(player, location)) return;
|
||||
if (blockID.contains("_stage_")) {
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
ItemStack itemInHand = event.getItem();
|
||||
if (!blockID.equals(BasicItemConfig.deadCrop)) {
|
||||
if (!customInterface.hasNextStage(blockID)) {
|
||||
if (isRipe(blockID)) {
|
||||
ItemStack mainHand = player.getInventory().getItemInMainHand();
|
||||
ItemStack offHand = player.getInventory().getItemInOffHand();
|
||||
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && (mainHand.getType() != Material.AIR || offHand.getType() != Material.AIR))) {
|
||||
@@ -147,28 +138,21 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
Location potLoc = location.clone().subtract(0,1,0);
|
||||
super.tryMisc(player, itemInHand, potLoc);
|
||||
super.tryMisc(player, itemInHand, location.clone().subtract(0,1,0));
|
||||
}
|
||||
|
||||
//interact pot (must have an item)
|
||||
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;
|
||||
|
||||
if (event.getBlockFace() != BlockFace.UP) return;
|
||||
|
||||
Location seedLoc = location.clone().add(0,1,0);
|
||||
CustomStack customStack = CustomStack.byItemStack(itemInHand);
|
||||
if (customStack != null) {
|
||||
String namespacedID = customStack.getNamespacedID();
|
||||
if (namespacedID.endsWith("_seeds")) {
|
||||
String cropName = customStack.getId().substring(0, customStack.getId().length() - 6);
|
||||
String id = customStack.getId();
|
||||
if (id.endsWith("_seeds")) {
|
||||
String cropName = customStack.getId().substring(0, id.length() - 6);
|
||||
plantSeed(seedLoc, cropName, player, itemInHand);
|
||||
}
|
||||
}
|
||||
@@ -191,71 +175,55 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
|
||||
public void onBreakBlock(CustomBlockBreakEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 50)) < 50) return;
|
||||
coolDown.put(player, time);
|
||||
final Player player = event.getPlayer();
|
||||
if (isInCoolDown(player, 50)) return;
|
||||
|
||||
String namespacedId = event.getNamespacedID();
|
||||
Location location = event.getBlock().getLocation();
|
||||
final String namespacedId = event.getNamespacedID();
|
||||
final Location location = event.getBlock().getLocation();
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
//break crop
|
||||
if (namespacedId.contains("_stage_")) {
|
||||
|
||||
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);
|
||||
CustomBlock.place(namespacedId, location);
|
||||
if (player.getGameMode() != GameMode.CREATIVE)
|
||||
CustomBlock.byAlreadyPlaced(location.getBlock()).getLoot().forEach(itemStack -> location.getWorld().dropItemNaturally(location, itemStack));
|
||||
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 (customInterface.hasNextStage(namespacedId)) {
|
||||
super.onBreakUnripeCrop(location);
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(location, namespacedId, player, true, true);
|
||||
|
||||
if (!isRipe(namespacedId)) super.onBreakUnripeCrop(location);
|
||||
else super.onBreakRipeCrop(location, namespacedId, player, true);
|
||||
}
|
||||
|
||||
//break pot
|
||||
else if (namespacedId.equals(BasicItemConfig.dryPot)
|
||||
|| namespacedId.equals(BasicItemConfig.wetPot)) {
|
||||
else if (namespacedId.equals(BasicItemConfig.dryPot) || namespacedId.equals(BasicItemConfig.wetPot)) {
|
||||
|
||||
if (!AntiGrief.testBreak(player, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
super.onBreakPot(location);
|
||||
|
||||
//Check if there's crop above
|
||||
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;
|
||||
//ripe or not
|
||||
if (customInterface.hasNextStage(seedID)) {
|
||||
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, true);
|
||||
super.onBreakRipeCrop(seedLocation, seedID, player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package net.momirealms.customcrops.integrations.customplugin.itemsadder.listeners;
|
||||
|
||||
import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent;
|
||||
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
|
||||
import net.momirealms.customcrops.integrations.customplugin.itemsadder.ItemsAdderHandler;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.integrations.customplugin.oraxen;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.CropConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.integrations.customplugin.CustomInterface;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.managers.CropModeInterface;
|
||||
import net.momirealms.customcrops.objects.GiganticCrop;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Gigantic;
|
||||
import net.momirealms.customcrops.objects.fertilizer.SpeedGrow;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class OraxenFrameCropImpl implements CropModeInterface {
|
||||
|
||||
private final CropManager cropManager;
|
||||
private final CustomInterface customInterface;
|
||||
|
||||
public OraxenFrameCropImpl(CropManager cropManager) {
|
||||
this.cropManager = cropManager;
|
||||
this.customInterface = cropManager.getCustomInterface();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean growJudge(Location location) {
|
||||
|
||||
Chunk chunk = location.getChunk();
|
||||
|
||||
if (chunk.isEntitiesLoaded()) return false;
|
||||
|
||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(location));
|
||||
if (itemFrame == null) return true;
|
||||
|
||||
String id = customInterface.getItemID(itemFrame.getItem());
|
||||
if (id == null || id.equals(BasicItemConfig.deadCrop)) return true;
|
||||
|
||||
String[] cropNameList = StringUtils.split(id,"_");
|
||||
Crop crop = CropConfig.CROPS.get(cropNameList[0]);
|
||||
if (crop == null) return true;
|
||||
|
||||
if ((MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) || cropManager.isWrongSeason(location, crop.getSeasons())) {
|
||||
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false);
|
||||
itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, BasicItemConfig.deadCrop);
|
||||
return true;
|
||||
}
|
||||
|
||||
Location potLoc = location.clone().subtract(0,1,0);
|
||||
String potID = customInterface.getBlockID(potLoc);
|
||||
if (potID == null || (!potID.equals(BasicItemConfig.wetPot) && !potID.equals(BasicItemConfig.dryPot))) return true;
|
||||
|
||||
Fertilizer fertilizer = cropManager.getFertilizer(potLoc);
|
||||
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
|
||||
|
||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||
String temp = StringUtils.chop(id);
|
||||
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true;
|
||||
if (customInterface.doesExist(temp + nextStage)) {
|
||||
if (fertilizer instanceof SpeedGrow speedGrow
|
||||
&& Math.random() < speedGrow.getChance()
|
||||
&& customInterface.doesExist(temp + (nextStage+1))
|
||||
)
|
||||
addStage(itemFrame, temp + (nextStage+1));
|
||||
else if (certainGrow || Math.random() < MainConfig.dryGrowChance)
|
||||
addStage(itemFrame, temp + nextStage);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
GiganticCrop giganticCrop = crop.getGiganticCrop();
|
||||
if (giganticCrop != null) {
|
||||
double chance = giganticCrop.getChance();
|
||||
if (fertilizer instanceof Gigantic gigantic) chance += gigantic.getChance();
|
||||
if (Math.random() < chance) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
customInterface.removeFurniture(itemFrame);
|
||||
if (giganticCrop.isBlock()) customInterface.placeWire(location, giganticCrop.getBlockID());
|
||||
else customInterface.placeFurniture(location, giganticCrop.getBlockID());
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void addStage(ItemFrame itemFrame, String stage) {
|
||||
itemFrame.setItem(customInterface.getItemStack(stage), false);
|
||||
itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, stage);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,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 net.momirealms.customcrops.utils.MiscUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -55,41 +56,38 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
public void onBreakNoteBlock(OraxenNoteBlockBreakEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
String id = event.getMechanic().getItemID();
|
||||
Player player = event.getPlayer();
|
||||
Location location = event.getBlock().getLocation();
|
||||
final String id = event.getMechanic().getItemID();
|
||||
final Player player = event.getPlayer();
|
||||
final Location location = event.getBlock().getLocation();
|
||||
|
||||
if (id.equals(BasicItemConfig.dryPot)
|
||||
|| id.equals(BasicItemConfig.wetPot)) {
|
||||
if (!id.equals(BasicItemConfig.dryPot) && !id.equals(BasicItemConfig.wetPot)) return;
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
if (!AntiGrief.testBreak(player, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!AntiGrief.testBreak(player, location)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canProceedAction(player, location)) return;
|
||||
|
||||
super.onBreakPot(location);
|
||||
|
||||
Location seedLocation = location.clone().add(0.5,1.03125,0.5);
|
||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(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 (customInterface.hasNextStage(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(location, new ItemStack(Material.AIR));
|
||||
}
|
||||
super.onBreakUnripeCrop(location);
|
||||
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));
|
||||
}
|
||||
super.onBreakRipeCrop(seedLocation, furnitureID, player, false, false);
|
||||
super.onBreakUnripeCrop(seedLocation);
|
||||
}
|
||||
else {
|
||||
super.onBreakRipeCrop(seedLocation, furnitureID, player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,6 +104,7 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
super.onBreakSprinkler(event.getBlock().getLocation());
|
||||
return;
|
||||
}
|
||||
|
||||
if (MainConfig.enableCrow && id.equals(BasicItemConfig.scarecrow)) {
|
||||
super.removeScarecrow(event.getBlock().getLocation());
|
||||
return;
|
||||
@@ -113,11 +112,8 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
|
||||
if (id.contains("_stage_")) {
|
||||
if (id.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (customInterface.hasNextStage(id)) {
|
||||
super.onBreakUnripeCrop(event.getBlock().getLocation());
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(event.getBlock().getLocation(), id, event.getPlayer(), false, false);
|
||||
if (!isRipe(id)) super.onBreakUnripeCrop(event.getBlock().getLocation());
|
||||
else super.onBreakRipeCrop(event.getBlock().getLocation(), id, event.getPlayer(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,34 +124,29 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
final ItemStack itemInHand = event.getItemInHand();
|
||||
final Block block = event.getBlock();
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 50)) < 50) return;
|
||||
coolDown.put(player, time);
|
||||
|
||||
String blockID = event.getMechanic().getItemID();
|
||||
if (blockID.equals(BasicItemConfig.dryPot) || blockID.equals(BasicItemConfig.wetPot)) {
|
||||
if (!blockID.equals(BasicItemConfig.dryPot) && !blockID.equals(BasicItemConfig.wetPot)) return;
|
||||
|
||||
Location seedLoc = block.getLocation().clone().add(0,1,0);
|
||||
Location potLoc = block.getLocation();
|
||||
Location potLoc = block.getLocation();
|
||||
Location seedLoc = potLoc.clone().add(0,1,0);
|
||||
|
||||
if (!AntiGrief.testPlace(player, seedLoc)) return;
|
||||
if (!canProceedAction(player, seedLoc)) return;
|
||||
if (super.tryMisc(player, itemInHand, potLoc)) return;
|
||||
if (event.getBlockFace() != BlockFace.UP) return;
|
||||
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) {
|
||||
if (id.endsWith("_seeds")) {
|
||||
String cropName = id.substring(0, id.length() - 6);
|
||||
plantSeed(seedLoc, cropName, player, itemInHand);
|
||||
}
|
||||
}
|
||||
else if (MainConfig.enableConvert) {
|
||||
String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType());
|
||||
if (cropName == null) return;
|
||||
String id = OraxenItems.getIdByItem(itemInHand);
|
||||
if (id != null) {
|
||||
if (id.endsWith("_seeds")) {
|
||||
String cropName = id.substring(0, id.length() - 6);
|
||||
plantSeed(seedLoc, cropName, player, itemInHand);
|
||||
}
|
||||
}
|
||||
else if (MainConfig.enableConvert) {
|
||||
String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType());
|
||||
if (cropName == null) return;
|
||||
plantSeed(seedLoc, cropName, player, itemInHand);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,7 +171,7 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
if (!id.contains("_stage_")) return;
|
||||
if (!id.equals(BasicItemConfig.deadCrop)) {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
if (!customInterface.hasNextStage(id)) {
|
||||
if (isRipe(id)) {
|
||||
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) {
|
||||
if (!AntiGrief.testBreak(player, location)) return;
|
||||
itemFrame.remove();
|
||||
@@ -188,7 +179,6 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
return;
|
||||
}
|
||||
}
|
||||
//has next stage
|
||||
else if (MainConfig.enableBoneMeal && itemInHand.getType() == Material.BONE_MEAL) {
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
@@ -209,10 +199,7 @@ public class OraxenFrameHandler extends OraxenHandler {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!AntiGrief.testPlace(player, location)) return;
|
||||
Location potLoc = location.clone().subtract(0,1,0).getBlock().getLocation();
|
||||
super.tryMisc(player, player.getInventory().getItemInMainHand(), potLoc);
|
||||
super.tryMisc(player, player.getInventory().getItemInMainHand(), MiscUtils.getItemFrameBlockLocation(location.clone().subtract(0,1,0)));
|
||||
}
|
||||
|
||||
private void onInteractRipeCrop(Location location, String id, Player player) {
|
||||
|
||||
@@ -28,6 +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.customplugin.HandlerP;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenBlockListener;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenFurnitureListener;
|
||||
@@ -81,10 +82,11 @@ public abstract class OraxenHandler extends HandlerP {
|
||||
Location location = event.getItemFrame().getLocation();
|
||||
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||
if (customWorld == null) return;
|
||||
customWorld.addScarecrow(location);
|
||||
customWorld.addScarecrowCache(location);
|
||||
}
|
||||
|
||||
public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) {
|
||||
if (!AntiGrief.testPlace(player, potLoc)) return true;
|
||||
if (itemInHand == null || itemInHand.getType() == Material.AIR) return true;
|
||||
String id = OraxenItems.getIdByItem(itemInHand);
|
||||
if (id == null) return false;
|
||||
|
||||
@@ -27,19 +27,17 @@ import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanic
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicFactory;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanic;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanicFactory;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.config.CropConfig;
|
||||
import net.momirealms.customcrops.integrations.customplugin.CustomInterface;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Rotation;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class OraxenHook implements CustomInterface {
|
||||
@@ -116,18 +114,29 @@ public class OraxenHook implements CustomInterface {
|
||||
|
||||
@Override
|
||||
public String getNextStage(String id) {
|
||||
String[] crop = StringUtils.split(id,"_");
|
||||
int nextStage = Integer.parseInt(crop[2]) + 1;
|
||||
return crop[0] + "_" + crop[1] + "_" + nextStage;
|
||||
String stageStr = id.substring(id.indexOf("_stage_") + 7);
|
||||
int nextStage = Integer.parseInt(stageStr) + 1;
|
||||
return id.substring(0, id.length() - stageStr.length()) + nextStage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Crop getCropFromID(String id) {
|
||||
return CropConfig.CROPS.get(StringUtils.split(id, "_")[0]);
|
||||
return CropConfig.CROPS.get(id.substring(0, id.indexOf("_stage_")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getFrameCropLocation(Location seedLoc) {
|
||||
return seedLoc.clone().add(0.5,0.03125,0.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFrameStage(ItemFrame itemFrame, String stage, boolean rotate) {
|
||||
itemFrame.setItem(getItemStack(stage), false);
|
||||
itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWireStage(Location seedLoc, String stage) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> placeWire(seedLoc, stage));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.integrations.customplugin.oraxen;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.CropConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.integrations.customplugin.CustomInterface;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.managers.CropModeInterface;
|
||||
import net.momirealms.customcrops.objects.GiganticCrop;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Gigantic;
|
||||
import net.momirealms.customcrops.objects.fertilizer.SpeedGrow;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class OraxenWireCropImpl implements CropModeInterface {
|
||||
|
||||
private final CropManager cropManager;
|
||||
private final CustomInterface customInterface;
|
||||
|
||||
public OraxenWireCropImpl(CropManager cropManager) {
|
||||
this.cropManager = cropManager;
|
||||
this.customInterface = cropManager.getCustomInterface();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean growJudge(Location location) {
|
||||
String blockID = customInterface.getBlockID(location);
|
||||
if (blockID == null || !blockID.contains("_stage_")) return true;
|
||||
|
||||
String[] cropNameList = StringUtils.split(blockID,"_");
|
||||
Crop crop = CropConfig.CROPS.get(cropNameList[0]);
|
||||
if (crop == null) return true;
|
||||
|
||||
if ((MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) || cropManager.isWrongSeason(location, crop.getSeasons())) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> customInterface.placeWire(location, BasicItemConfig.deadCrop));
|
||||
return true;
|
||||
}
|
||||
|
||||
Location potLoc = location.clone().subtract(0,1,0);
|
||||
String potID = customInterface.getBlockID(potLoc);
|
||||
if (potID == null || (!potID.equals(BasicItemConfig.wetPot) && !potID.equals(BasicItemConfig.dryPot))) return true;
|
||||
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true;
|
||||
|
||||
Fertilizer fertilizer = cropManager.getFertilizer(potLoc);
|
||||
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
|
||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||
|
||||
String temp = cropNameList[0] + "_" + cropNameList[1] + "_";
|
||||
if (customInterface.doesExist(temp + nextStage)) {
|
||||
if (fertilizer instanceof SpeedGrow speedGrow
|
||||
&& Math.random() < speedGrow.getChance()
|
||||
&& customInterface.doesExist(temp + (nextStage+1))
|
||||
)
|
||||
addStage(location, temp + (nextStage+1));
|
||||
else if (certainGrow || Math.random() < MainConfig.dryGrowChance)
|
||||
addStage(location, temp + nextStage);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
GiganticCrop giganticCrop = crop.getGiganticCrop();
|
||||
if (giganticCrop != null) {
|
||||
double chance = giganticCrop.getChance();
|
||||
if (fertilizer instanceof Gigantic gigantic) chance += gigantic.getChance();
|
||||
if (Math.random() < chance) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
customInterface.removeBlock(location);
|
||||
if (giganticCrop.isBlock()) customInterface.placeWire(location, giganticCrop.getBlockID());
|
||||
else customInterface.placeFurniture(location, giganticCrop.getBlockID());
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void addStage(Location seedLoc, String stage) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> customInterface.placeWire(seedLoc, stage));
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,10 @@
|
||||
|
||||
package net.momirealms.customcrops.integrations.customplugin.oraxen;
|
||||
|
||||
import io.th0rgal.oraxen.OraxenPlugin;
|
||||
import io.th0rgal.oraxen.api.OraxenItems;
|
||||
import io.th0rgal.oraxen.api.events.*;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureFactory;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanic;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanicFactory;
|
||||
@@ -32,14 +34,17 @@ import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
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.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class OraxenWireHandler extends OraxenHandler{
|
||||
|
||||
@@ -55,38 +60,29 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
String id = mechanic.getItemID();
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 50)) < 50) return;
|
||||
coolDown.put(player, time);
|
||||
if (!id.contains("_stage_")) return;
|
||||
|
||||
if (id.contains("_stage_")) {
|
||||
final Block block = event.getBlock();
|
||||
Location location = block.getLocation();
|
||||
|
||||
final Block block = event.getBlock();
|
||||
Location location = 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(location, new ItemStack(Material.AIR));
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
if (id.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (customInterface.hasNextStage(id)) {
|
||||
super.onBreakUnripeCrop(location);
|
||||
return;
|
||||
}
|
||||
super.onBreakRipeCrop(location, id, player, true, false);
|
||||
if (!AntiGrief.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();
|
||||
if (player.getGameMode() != GameMode.CREATIVE && drop != null)
|
||||
drop.spawns(location, new ItemStack(Material.AIR));
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
if (id.equals(BasicItemConfig.deadCrop)) return;
|
||||
if (!isRipe(id)) super.onBreakUnripeCrop(location);
|
||||
else super.onBreakRipeCrop(location, id, player, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,20 +125,16 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
public void onInteractNoteBlock(OraxenNoteBlockInteractEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
ItemStack itemInHand = event.getItemInHand();
|
||||
Location potLoc = event.getBlock().getLocation();
|
||||
Player player = event.getPlayer();
|
||||
final ItemStack itemInHand = event.getItemInHand();
|
||||
final Location potLoc = event.getBlock().getLocation();
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 50)) < 50) return;
|
||||
coolDown.put(player, time);
|
||||
|
||||
if (!AntiGrief.testPlace(player, potLoc)) return;
|
||||
if (isInCoolDown(player, 50)) return;
|
||||
if (!canProceedAction(player, potLoc)) return;
|
||||
if (super.tryMisc(event.getPlayer(), itemInHand, potLoc)) return;
|
||||
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) {
|
||||
@@ -161,57 +153,85 @@ public class OraxenWireHandler extends OraxenHandler{
|
||||
@Override
|
||||
public void onInteractStringBlock(OraxenStringBlockInteractEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 50)) < 50) return;
|
||||
coolDown.put(player, time);
|
||||
if (isInCoolDown(player, 50)) return;
|
||||
|
||||
final Block block = event.getBlock();
|
||||
final String id = event.getMechanic().getItemID();
|
||||
|
||||
if (id.contains("_stage_")) {
|
||||
if (!id.contains("_stage_")) return;
|
||||
|
||||
Location seedLoc = block.getLocation();
|
||||
if (!canProceedAction(player, seedLoc)) return;
|
||||
ItemStack itemInHand = event.getItemInHand();
|
||||
//ripe crops
|
||||
if (!id.equals(BasicItemConfig.deadCrop)) {
|
||||
|
||||
if (!customInterface.hasNextStage(id)) {
|
||||
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand != null && itemInHand.getType() != Material.AIR)) {
|
||||
if (!AntiGrief.testBreak(player, seedLoc)) return;
|
||||
|
||||
block.setType(Material.AIR);
|
||||
this.onInteractRipeCrop(seedLoc, id, player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//has next stage
|
||||
else if (MainConfig.enableBoneMeal && itemInHand != null && itemInHand.getType() == Material.BONE_MEAL) {
|
||||
if (!AntiGrief.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);
|
||||
if (SoundConfig.boneMeal.isEnable()) {
|
||||
AdventureUtil.playerSound(
|
||||
player,
|
||||
SoundConfig.boneMeal.getSource(),
|
||||
SoundConfig.boneMeal.getKey(),
|
||||
1,1
|
||||
);
|
||||
}
|
||||
StringBlockMechanicFactory.setBlockModel(block, customInterface.getNextStage(id));
|
||||
}
|
||||
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;
|
||||
block.setType(Material.AIR);
|
||||
this.onInteractRipeCrop(seedLoc, id, player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//has next stage
|
||||
else if (MainConfig.enableBoneMeal && itemInHand != null && itemInHand.getType() == Material.BONE_MEAL) {
|
||||
if (!AntiGrief.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);
|
||||
if (SoundConfig.boneMeal.isEnable()) {
|
||||
AdventureUtil.playerSound(
|
||||
player,
|
||||
SoundConfig.boneMeal.getSource(),
|
||||
SoundConfig.boneMeal.getKey(),
|
||||
1,1
|
||||
);
|
||||
}
|
||||
StringBlockMechanicFactory.setBlockModel(block, customInterface.getNextStage(id));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.tryMisc(player, event.getItemInHand(), block.getLocation().clone().subtract(0,1,0));
|
||||
}
|
||||
|
||||
if (!AntiGrief.testPlace(player, seedLoc)) return;
|
||||
@Override
|
||||
public void onBreakNoteBlock(OraxenNoteBlockBreakEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
Location potLoc = block.getLocation().clone().subtract(0,1,0);
|
||||
super.tryMisc(player, event.getItemInHand(), potLoc);
|
||||
final String id = event.getMechanic().getItemID();
|
||||
final Player player = event.getPlayer();
|
||||
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)) {
|
||||
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));
|
||||
}
|
||||
super.onBreakUnripeCrop(seedLocation);
|
||||
}
|
||||
else {
|
||||
super.onBreakRipeCrop(seedLocation, blockID, player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,10 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class PlaceholderManager extends Function {
|
||||
|
||||
private SeasonPapi seasonPapi;
|
||||
private final SeasonPapi seasonPapi;
|
||||
|
||||
public PlaceholderManager() {
|
||||
this.seasonPapi = new SeasonPapi();
|
||||
load();
|
||||
}
|
||||
|
||||
@@ -34,7 +35,6 @@ public class PlaceholderManager extends Function {
|
||||
public void load() {
|
||||
super.load();
|
||||
if (SeasonConfig.enable) {
|
||||
this.seasonPapi = new SeasonPapi();
|
||||
this.seasonPapi.register();
|
||||
}
|
||||
}
|
||||
@@ -42,9 +42,7 @@ public class PlaceholderManager extends Function {
|
||||
@Override
|
||||
public void unload() {
|
||||
super.unload();
|
||||
if (this.seasonPapi != null) {
|
||||
this.seasonPapi.unregister();
|
||||
}
|
||||
this.seasonPapi.unregister();
|
||||
}
|
||||
|
||||
public String parse(Player player, String text) {
|
||||
|
||||
@@ -22,31 +22,27 @@ import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.api.event.CropHarvestEvent;
|
||||
import net.momirealms.customcrops.api.event.CrowAttackEvent;
|
||||
import net.momirealms.customcrops.api.utils.CCSeason;
|
||||
import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.config.SeasonConfig;
|
||||
import net.momirealms.customcrops.config.SoundConfig;
|
||||
import net.momirealms.customcrops.config.*;
|
||||
import net.momirealms.customcrops.integrations.customplugin.CustomInterface;
|
||||
import net.momirealms.customcrops.integrations.customplugin.HandlerP;
|
||||
import net.momirealms.customcrops.integrations.customplugin.itemsadder.*;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.*;
|
||||
import net.momirealms.customcrops.integrations.customplugin.itemsadder.ItemsAdderFrameHandler;
|
||||
import net.momirealms.customcrops.integrations.customplugin.itemsadder.ItemsAdderHook;
|
||||
import net.momirealms.customcrops.integrations.customplugin.itemsadder.ItemsAdderWireHandler;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.OraxenFrameHandler;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.OraxenHook;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.OraxenWireHandler;
|
||||
import net.momirealms.customcrops.integrations.season.InternalSeason;
|
||||
import net.momirealms.customcrops.integrations.season.RealisticSeasonsHook;
|
||||
import net.momirealms.customcrops.integrations.season.SeasonInterface;
|
||||
import net.momirealms.customcrops.managers.listener.*;
|
||||
import net.momirealms.customcrops.managers.timer.CrowTask;
|
||||
import net.momirealms.customcrops.managers.timer.TimerTask;
|
||||
import net.momirealms.customcrops.objects.Function;
|
||||
import net.momirealms.customcrops.objects.OtherLoot;
|
||||
import net.momirealms.customcrops.objects.QualityLoot;
|
||||
import net.momirealms.customcrops.objects.QualityRatio;
|
||||
import net.momirealms.customcrops.objects.*;
|
||||
import net.momirealms.customcrops.objects.actions.ActionInterface;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.objects.fertilizer.QualityCrop;
|
||||
import net.momirealms.customcrops.objects.fertilizer.RetainingSoil;
|
||||
import net.momirealms.customcrops.objects.fertilizer.YieldIncreasing;
|
||||
import net.momirealms.customcrops.objects.fertilizer.*;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import net.momirealms.customcrops.utils.ArmorStandUtil;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import net.momirealms.customcrops.utils.MiscUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Item;
|
||||
@@ -56,17 +52,13 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class CropManager extends Function {
|
||||
|
||||
private ItemSpawnListener itemSpawnListener;
|
||||
private WorldListener worldListener;
|
||||
private TimerTask timerTask;
|
||||
private ConcurrentHashMap<World, CustomWorld> customWorlds;
|
||||
private CropModeInterface cropMode;
|
||||
private SeasonInterface seasonInterface;
|
||||
private CustomInterface customInterface;
|
||||
private ArmorStandUtil armorStandUtil;
|
||||
@@ -74,6 +66,8 @@ public class CropManager extends Function {
|
||||
private PlayerModeListener playerModeListener;
|
||||
private VanillaCropPlaceListener vanillaCropPlaceListener;
|
||||
private VanillaCropHarvestListener vanillaCropHarvestListener;
|
||||
private ItemSpawnListener itemSpawnListener;
|
||||
private WorldListener worldListener;
|
||||
private HandlerP handler;
|
||||
|
||||
public CropManager() {
|
||||
@@ -82,64 +76,87 @@ public class CropManager extends Function {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
|
||||
this.customWorlds = new ConcurrentHashMap<>();
|
||||
this.itemSpawnListener = new ItemSpawnListener(this);
|
||||
this.worldListener = new WorldListener(this);
|
||||
this.armorStandUtil = new ArmorStandUtil(this);
|
||||
this.vanillaCropPlaceListener = new VanillaCropPlaceListener();
|
||||
this.vanillaCropHarvestListener = new VanillaCropHarvestListener();
|
||||
this.containerListener = new ContainerListener(this);
|
||||
this.playerModeListener = new PlayerModeListener();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(itemSpawnListener, CustomCrops.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(worldListener, CustomCrops.plugin);
|
||||
|
||||
loadMode();
|
||||
loadSeason();
|
||||
loadPacket();
|
||||
loadVanillaMechanic();
|
||||
this.reload();
|
||||
|
||||
//load Worlds
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
onWorldLoad(world);
|
||||
}
|
||||
//new Time Check task
|
||||
|
||||
this.timerTask = new TimerTask(this);
|
||||
this.timerTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1,100);
|
||||
}
|
||||
|
||||
public void loadVanillaMechanic() {
|
||||
if (this.vanillaCropHarvestListener != null) {
|
||||
HandlerList.unregisterAll(vanillaCropHarvestListener);
|
||||
}
|
||||
if (this.vanillaCropPlaceListener != null) {
|
||||
HandlerList.unregisterAll(vanillaCropPlaceListener);
|
||||
}
|
||||
if (MainConfig.preventPlantVanilla) {
|
||||
this.vanillaCropPlaceListener = new VanillaCropPlaceListener();
|
||||
Bukkit.getPluginManager().registerEvents(vanillaCropPlaceListener, CustomCrops.plugin);
|
||||
}
|
||||
if (MainConfig.rightHarvestVanilla) {
|
||||
this.vanillaCropHarvestListener = new VanillaCropHarvestListener();
|
||||
Bukkit.getPluginManager().registerEvents(vanillaCropHarvestListener, CustomCrops.plugin);
|
||||
}
|
||||
public void reload() {
|
||||
|
||||
unloadMode();
|
||||
loadMode();
|
||||
|
||||
unloadSeason();
|
||||
loadSeason();
|
||||
|
||||
unloadPacket();
|
||||
loadPacket();
|
||||
|
||||
unloadVanillaMechanic();
|
||||
loadVanillaMechanic();
|
||||
}
|
||||
|
||||
public void loadMode() {
|
||||
@Override
|
||||
public void unload() {
|
||||
HandlerList.unregisterAll(this.itemSpawnListener);
|
||||
HandlerList.unregisterAll(this.worldListener);
|
||||
if (this.handler != null) handler.unload();
|
||||
if (this.timerTask != null) this.timerTask.cancel();
|
||||
|
||||
for (CustomWorld customWorld : customWorlds.values()) {
|
||||
customWorld.unload(true);
|
||||
}
|
||||
customWorlds.clear();
|
||||
|
||||
if (this.seasonInterface != null) seasonInterface.unload();
|
||||
if (this.containerListener != null) CustomCrops.protocolManager.removePacketListener(containerListener);
|
||||
}
|
||||
|
||||
public void loadVanillaMechanic() {
|
||||
if (MainConfig.preventPlantVanilla) Bukkit.getPluginManager().registerEvents(vanillaCropPlaceListener, CustomCrops.plugin);
|
||||
if (MainConfig.rightHarvestVanilla) Bukkit.getPluginManager().registerEvents(vanillaCropHarvestListener, CustomCrops.plugin);
|
||||
}
|
||||
|
||||
public void unloadVanillaMechanic() {
|
||||
HandlerList.unregisterAll(vanillaCropHarvestListener);
|
||||
HandlerList.unregisterAll(vanillaCropPlaceListener);
|
||||
}
|
||||
|
||||
public void unloadMode() {
|
||||
if (this.handler != null) {
|
||||
handler.unload();
|
||||
handler = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void loadMode() {
|
||||
//Custom Plugin
|
||||
if (MainConfig.customPlugin.equals("itemsadder")) {
|
||||
customInterface = new ItemsAdderHook();
|
||||
if (MainConfig.cropMode) {
|
||||
this.handler = new ItemsAdderWireHandler(this);
|
||||
this.cropMode = new ItemsAdderWireCropImpl(this);
|
||||
this.handler.load();
|
||||
}
|
||||
else {
|
||||
this.handler = new ItemsAdderFrameHandler(this);
|
||||
this.cropMode = new ItemsAdderFrameCropImpl(this);
|
||||
this.handler.load();
|
||||
}
|
||||
}
|
||||
@@ -147,69 +164,37 @@ public class CropManager extends Function {
|
||||
customInterface = new OraxenHook();
|
||||
if (MainConfig.cropMode) {
|
||||
this.handler = new OraxenWireHandler(this);
|
||||
this.cropMode = new OraxenWireCropImpl(this);
|
||||
this.handler.load();
|
||||
}
|
||||
else {
|
||||
this.handler = new OraxenFrameHandler(this);
|
||||
this.cropMode = new OraxenFrameCropImpl(this);
|
||||
this.handler.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadSeason() {
|
||||
if (SeasonConfig.enable) {
|
||||
for (CustomWorld customWorld : customWorlds.values()) {
|
||||
customWorld.unloadSeason();
|
||||
}
|
||||
if (seasonInterface != null) {
|
||||
seasonInterface.unload();
|
||||
this.seasonInterface = null;
|
||||
}
|
||||
if (MainConfig.realisticSeasonHook) seasonInterface = new RealisticSeasonsHook();
|
||||
else seasonInterface = new InternalSeason();
|
||||
//empty when enabling
|
||||
for (CustomWorld customWorld : customWorlds.values()) {
|
||||
customWorld.loadSeason();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (seasonInterface != null) {
|
||||
seasonInterface.unload();
|
||||
this.seasonInterface = null;
|
||||
if (!SeasonConfig.enable) return;
|
||||
if (MainConfig.realisticSeasonHook) seasonInterface = new RealisticSeasonsHook();
|
||||
else seasonInterface = new InternalSeason();
|
||||
}
|
||||
|
||||
public void unloadSeason() {
|
||||
for (CustomWorld customWorld : customWorlds.values()) {
|
||||
customWorld.unloadSeason();
|
||||
}
|
||||
if (seasonInterface != null) seasonInterface.unload();
|
||||
}
|
||||
|
||||
public void loadPacket() {
|
||||
if (this.containerListener != null) {
|
||||
CustomCrops.protocolManager.removePacketListener(containerListener);
|
||||
this.containerListener = null;
|
||||
}
|
||||
if (this.playerModeListener != null) {
|
||||
HandlerList.unregisterAll(playerModeListener);
|
||||
this.playerModeListener = null;
|
||||
}
|
||||
if (!MainConfig.enableWaterCanLore || !MainConfig.enablePacketLore) return;
|
||||
containerListener = new ContainerListener(this);
|
||||
CustomCrops.protocolManager.addPacketListener(containerListener);
|
||||
playerModeListener = new PlayerModeListener();
|
||||
Bukkit.getPluginManager().registerEvents(playerModeListener, CustomCrops.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
super.unload();
|
||||
HandlerList.unregisterAll(this.itemSpawnListener);
|
||||
HandlerList.unregisterAll(this.worldListener);
|
||||
if (this.handler != null) handler.unload();
|
||||
if (this.timerTask != null) this.timerTask.cancel();
|
||||
for (CustomWorld customWorld : customWorlds.values()) {
|
||||
customWorld.unload(true);
|
||||
}
|
||||
customWorlds.clear();
|
||||
if (this.seasonInterface != null) seasonInterface.unload();
|
||||
if (this.containerListener != null) CustomCrops.protocolManager.removePacketListener(containerListener);
|
||||
public void unloadPacket() {
|
||||
CustomCrops.protocolManager.removePacketListener(containerListener);
|
||||
HandlerList.unregisterAll(playerModeListener);
|
||||
}
|
||||
|
||||
public void onItemSpawn(Item item) {
|
||||
@@ -217,7 +202,10 @@ public class CropManager extends Function {
|
||||
if (id == null) return;
|
||||
if (id.contains("_stage_")) item.remove();
|
||||
if (id.equals(BasicItemConfig.wetPot)) {
|
||||
item.setItemStack(Objects.requireNonNull(customInterface.getItemStack(BasicItemConfig.dryPot)));
|
||||
ItemStack dryPots = customInterface.getItemStack(BasicItemConfig.dryPot);
|
||||
if (dryPots == null) return;
|
||||
dryPots.setAmount(item.getItemStack().getAmount());
|
||||
item.setItemStack(dryPots);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,10 +238,6 @@ public class CropManager extends Function {
|
||||
else customWorld.growFrame(cropTime, sprinklerTime, dryTime, compensation, force);
|
||||
}
|
||||
|
||||
public CropModeInterface getCropMode() {
|
||||
return cropMode;
|
||||
}
|
||||
|
||||
public SeasonInterface getSeasonAPI() {
|
||||
return seasonInterface;
|
||||
}
|
||||
@@ -269,7 +253,7 @@ public class CropManager extends Function {
|
||||
public boolean hasScarecrow(Location location) {
|
||||
CustomWorld customWorld = customWorlds.get(location.getWorld());
|
||||
if (customWorld == null) return true;
|
||||
return customWorld.hasScarecrow(location);
|
||||
return customWorld.hasScarecrowCache(location);
|
||||
}
|
||||
|
||||
public CustomInterface getCustomInterface() {
|
||||
@@ -290,29 +274,17 @@ public class CropManager extends Function {
|
||||
World world = potLoc.getWorld();
|
||||
CustomWorld customWorld = customWorlds.get(world);
|
||||
if (customWorld == null) return null;
|
||||
return customWorld.getFertilizer(potLoc);
|
||||
}
|
||||
|
||||
public void potDryJudge(Location potLoc) {
|
||||
World world = potLoc.getWorld();
|
||||
CustomWorld customWorld = customWorlds.get(world);
|
||||
if (customWorld == null) return;
|
||||
if (!customWorld.isPotWet(potLoc)) {
|
||||
makePotDry(potLoc);
|
||||
return;
|
||||
}
|
||||
Fertilizer fertilizer = customWorld.getFertilizer(potLoc);
|
||||
if (!(fertilizer instanceof RetainingSoil retainingSoil && Math.random() < retainingSoil.getChance())) {
|
||||
makePotDry(potLoc);
|
||||
}
|
||||
return customWorld.getFertilizerCache(potLoc);
|
||||
}
|
||||
|
||||
public void makePotDry(Location potLoc) {
|
||||
String potID = customInterface.getBlockID(potLoc);
|
||||
if (potID == null) return;
|
||||
if (!potID.equals(BasicItemConfig.wetPot)) return;
|
||||
customInterface.removeBlock(potLoc);
|
||||
customInterface.placeNoteBlock(potLoc, BasicItemConfig.dryPot);
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
customInterface.removeBlock(potLoc);
|
||||
customInterface.placeNoteBlock(potLoc, BasicItemConfig.dryPot);
|
||||
});
|
||||
}
|
||||
|
||||
public void makePotWet(Location potLoc) {
|
||||
@@ -440,7 +412,6 @@ public class CropManager extends Function {
|
||||
|
||||
public boolean crowJudge(Location location) {
|
||||
if (Math.random() < MainConfig.crowChance && !hasScarecrow(location)) {
|
||||
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
CrowAttackEvent crowAttackEvent = new CrowAttackEvent(location);
|
||||
Bukkit.getPluginManager().callEvent(crowAttackEvent);
|
||||
@@ -472,4 +443,114 @@ public class CropManager extends Function {
|
||||
public HandlerP getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public boolean wireGrowJudge(Location location, GrowingCrop growingCrop) {
|
||||
Crop crop = CropConfig.CROPS.get(growingCrop.getType());
|
||||
if (crop == null) return true;
|
||||
|
||||
Location potLoc = location.clone().subtract(0,1,0);
|
||||
Fertilizer fertilizer = getFertilizer(potLoc);
|
||||
|
||||
int current_stage = growingCrop.getStage();
|
||||
if (current_stage == crop.getMax_stage()) {
|
||||
GiganticCrop giganticCrop = crop.getGiganticCrop();
|
||||
if (giganticCrop != null) {
|
||||
double chance = giganticCrop.getChance();
|
||||
if (fertilizer instanceof Gigantic gigantic) chance += gigantic.getChance();
|
||||
if (Math.random() < chance) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
customInterface.removeBlock(location);
|
||||
if (giganticCrop.isBlock()) customInterface.placeWire(location, giganticCrop.getBlockID());
|
||||
else customInterface.placeFurniture(location, giganticCrop.getBlockID());
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
String blockID = customInterface.getBlockID(location);
|
||||
if (blockID == null) return true;
|
||||
|
||||
if ((MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) || isWrongSeason(location, crop.getSeasons())) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
customInterface.removeBlock(location);
|
||||
customInterface.placeWire(location, BasicItemConfig.deadCrop);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
if (MainConfig.enableCrow && crowJudge(location)) return true;
|
||||
|
||||
String potID = customInterface.getBlockID(potLoc);
|
||||
if (potID == null) return true;
|
||||
|
||||
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
|
||||
|
||||
String temp = CropConfig.namespace + growingCrop.getType() + "_stage_";
|
||||
|
||||
if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance() && current_stage+2 <= crop.getMax_stage()) {
|
||||
customInterface.addWireStage(location, temp + (current_stage+2));
|
||||
growingCrop.setStage(current_stage+2);
|
||||
}
|
||||
else if (certainGrow || Math.random() < MainConfig.dryGrowChance) {
|
||||
customInterface.addWireStage(location, temp + (current_stage+1));
|
||||
growingCrop.setStage(current_stage+1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean itemFrameGrowJudge(Location location, GrowingCrop growingCrop) {
|
||||
|
||||
Crop crop = CropConfig.CROPS.get(growingCrop.getType());
|
||||
if (crop == null) return true;
|
||||
|
||||
Location potLoc = location.clone().subtract(0,1,0);
|
||||
Fertilizer fertilizer = getFertilizer(potLoc);
|
||||
|
||||
int current_stage = growingCrop.getStage();
|
||||
if (current_stage == crop.getMax_stage()) {
|
||||
GiganticCrop giganticCrop = crop.getGiganticCrop();
|
||||
if (giganticCrop != null) {
|
||||
double chance = giganticCrop.getChance();
|
||||
if (fertilizer instanceof Gigantic gigantic) chance += gigantic.getChance();
|
||||
if (Math.random() < chance) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(location));
|
||||
if (itemFrame != null) {
|
||||
customInterface.removeFurniture(itemFrame);
|
||||
if (giganticCrop.isBlock()) customInterface.placeWire(location, giganticCrop.getBlockID());
|
||||
else customInterface.placeFurniture(location, giganticCrop.getBlockID());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(location));
|
||||
if (itemFrame == null) return true;
|
||||
|
||||
if ((MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) || isWrongSeason(location, crop.getSeasons())) {
|
||||
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (MainConfig.enableCrow && crowJudge(location, itemFrame)) return true;
|
||||
|
||||
String potID = customInterface.getBlockID(potLoc);
|
||||
if (potID == null) return true;
|
||||
|
||||
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
|
||||
|
||||
String temp = CropConfig.namespace + growingCrop.getType() + "_stage_";
|
||||
if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance() && current_stage+2 <= crop.getMax_stage()) {
|
||||
customInterface.addFrameStage(itemFrame, temp + (current_stage+2), crop.canRotate());
|
||||
growingCrop.setStage(current_stage+2);
|
||||
}
|
||||
else if (certainGrow || Math.random() < MainConfig.dryGrowChance) {
|
||||
customInterface.addFrameStage(itemFrame, temp + (current_stage+1), crop.canRotate());
|
||||
growingCrop.setStage(current_stage+1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,13 @@
|
||||
|
||||
package net.momirealms.customcrops.managers;
|
||||
|
||||
import net.momirealms.customcrops.objects.GrowingCrop;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface CropModeInterface {
|
||||
|
||||
boolean growJudge(Location location);
|
||||
boolean growJudge(Location location, GrowingCrop growingCrop);
|
||||
|
||||
default void loadChunk(Location location) {
|
||||
Chunk chunk = location.getChunk();
|
||||
|
||||
@@ -23,10 +23,12 @@ import net.momirealms.customcrops.api.event.CustomWorldEvent;
|
||||
import net.momirealms.customcrops.api.utils.CCSeason;
|
||||
import net.momirealms.customcrops.api.utils.SeasonUtils;
|
||||
import net.momirealms.customcrops.config.*;
|
||||
import net.momirealms.customcrops.objects.GrowingCrop;
|
||||
import net.momirealms.customcrops.objects.SimpleLocation;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.objects.WorldState;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.objects.fertilizer.RetainingSoil;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import net.momirealms.customcrops.utils.MiscUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@@ -37,6 +39,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -51,17 +54,17 @@ public class CustomWorld {
|
||||
private final ConcurrentHashMap<SimpleLocation, Sprinkler> sprinklerCache;
|
||||
private final ConcurrentHashMap<SimpleLocation, Fertilizer> fertilizerCache;
|
||||
private final ConcurrentHashMap<String, HashSet<SimpleLocation>> scarecrowCache;
|
||||
private final ConcurrentHashMap<SimpleLocation, String> cropData;
|
||||
private final ConcurrentHashMap<SimpleLocation, GrowingCrop> cropData;
|
||||
private final Set<SimpleLocation> watered;
|
||||
private HashSet<SimpleLocation> tempWatered;
|
||||
private final HashSet<SimpleLocation> playerWatered;
|
||||
private final CropManager cropManager;
|
||||
private final BukkitScheduler bukkitScheduler;
|
||||
private final HashSet<SimpleLocation> plantedToday;
|
||||
private final CropModeInterface cropMode;
|
||||
private int timer;
|
||||
|
||||
public CustomWorld(World world, CropManager cropManager) {
|
||||
|
||||
this.world = world;
|
||||
this.fertilizerCache = new ConcurrentHashMap<>(2048);
|
||||
this.sprinklerCache = new ConcurrentHashMap<>(512);
|
||||
@@ -74,9 +77,10 @@ public class CustomWorld {
|
||||
this.tempWatered = new HashSet<>();
|
||||
this.plantedToday = new HashSet<>();
|
||||
this.timer = 0;
|
||||
this.cropMode = cropManager.getCropMode();
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {
|
||||
loadData();
|
||||
loadSeason();
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
CustomWorldEvent customWorldEvent = new CustomWorldEvent(world, WorldState.LOAD);
|
||||
Bukkit.getPluginManager().callEvent(customWorldEvent);
|
||||
@@ -104,7 +108,6 @@ public class CustomWorld {
|
||||
}
|
||||
|
||||
public void loadData() {
|
||||
loadSeason();
|
||||
loadCropCache();
|
||||
loadSprinklerCache();
|
||||
loadFertilizerCache();
|
||||
@@ -163,8 +166,7 @@ public class CustomWorld {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
//bypass
|
||||
catch (FileNotFoundException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,8 +207,7 @@ public class CustomWorld {
|
||||
SeasonUtils.setSeason(world, CCSeason.UNKNOWN);
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
//bypass
|
||||
catch (FileNotFoundException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,8 +242,7 @@ public class CustomWorld {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
//bypass
|
||||
catch (FileNotFoundException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,16 +330,26 @@ public class CustomWorld {
|
||||
YamlConfiguration data = loadData("crops", world.getName());
|
||||
String worldName = world.getName();
|
||||
for (Map.Entry<String, Object> entry : data.getValues(false).entrySet()) {
|
||||
cropData.put(MiscUtils.getSimpleLocation(entry.getKey(), worldName), (String) entry.getValue());
|
||||
String crop = (String) entry.getValue();
|
||||
GrowingCrop growingCrop;
|
||||
if (crop.contains("_")) {
|
||||
String stageStr = crop.substring(crop.indexOf("_stage_") + 7);
|
||||
int stage = Integer.parseInt(stageStr);
|
||||
growingCrop = new GrowingCrop(stage, crop.substring(0, crop.indexOf("_stage_")));
|
||||
}
|
||||
else {
|
||||
growingCrop = new GrowingCrop(1, crop);
|
||||
}
|
||||
cropData.put(MiscUtils.getSimpleLocation(entry.getKey(), worldName), growingCrop);
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadCrop() {
|
||||
YamlConfiguration data = new YamlConfiguration();
|
||||
for (Map.Entry<SimpleLocation, String> en : cropData.entrySet()) {
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> en : cropData.entrySet()) {
|
||||
SimpleLocation location = en.getKey();
|
||||
String loc = location.getX() + "," + location.getY() + "," + location.getZ();
|
||||
data.set(loc, en.getValue());
|
||||
data.set(loc, en.getValue().getType() + "_stage_" + en.getValue().getStage());
|
||||
}
|
||||
try {
|
||||
data.save(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data" + File.separator + "crops.yml"));
|
||||
@@ -352,68 +362,81 @@ public class CustomWorld {
|
||||
|
||||
public void growWire(int cropTime, int sprinklerTime, int dryTime, boolean compensation, boolean force) {
|
||||
if (cropData == null) return;
|
||||
|
||||
Random randomGenerator = new Random();
|
||||
if (force) {
|
||||
cropData.keySet().forEach(key -> growSingleWire(key, randomGenerator.nextInt(cropTime)));
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
growSingleWire(entry.getKey(), entry.getValue(), randomGenerator.nextInt(cropTime));
|
||||
}
|
||||
}
|
||||
else if (!compensation) {
|
||||
route(sprinklerTime);
|
||||
potDryJudge(sprinklerTime + randomGenerator.nextInt(dryTime));
|
||||
cropData.keySet().forEach(key -> growSingleWire(key, sprinklerTime + dryTime + randomGenerator.nextInt(cropTime)));
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
growSingleWire(entry.getKey(), entry.getValue(), sprinklerTime + dryTime + randomGenerator.nextInt(cropTime));
|
||||
}
|
||||
}
|
||||
else {
|
||||
int delay = (int)(24000 - world.getTime());
|
||||
int delay = (int) (24000 - world.getTime());
|
||||
double chance = (double) (24000 - world.getTime()) / 24000;
|
||||
cropData.keySet().forEach(key -> {
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
if (Math.random() < chance) {
|
||||
growSingleWire(key, randomGenerator.nextInt(delay));
|
||||
growSingleWire(entry.getKey(), entry.getValue(), randomGenerator.nextInt(delay));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void growSingleWire(SimpleLocation simpleLocation, long delay) {
|
||||
private void growSingleWire(SimpleLocation simpleLocation, GrowingCrop growingCrop, long delay) {
|
||||
bukkitScheduler.runTaskLaterAsynchronously(CustomCrops.plugin, () -> {
|
||||
Location location = MiscUtils.getLocation(simpleLocation);
|
||||
if (cropMode.growJudge(location)) {
|
||||
if (cropManager.wireGrowJudge(location, growingCrop)) {
|
||||
cropData.remove(simpleLocation);
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
public void growFrame(int cropTime, int sprinklerTime, int dryTime, boolean compensation, boolean force) {
|
||||
if (cropData == null) return;
|
||||
Random randomGenerator = new Random();
|
||||
if (force) {
|
||||
cropData.keySet().forEach(key -> growSingleFrame(key, randomGenerator.nextInt(cropTime)));
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
growSingleFrame(entry.getKey(), entry.getValue(), randomGenerator.nextInt(cropTime));
|
||||
}
|
||||
}
|
||||
else if (!compensation) {
|
||||
route(sprinklerTime);
|
||||
potDryJudge(sprinklerTime + randomGenerator.nextInt(dryTime));
|
||||
cropData.keySet().forEach(key -> growSingleFrame(key, sprinklerTime + dryTime + randomGenerator.nextInt(cropTime)));
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
growSingleFrame(entry.getKey(), entry.getValue(), sprinklerTime + dryTime + randomGenerator.nextInt(cropTime));
|
||||
}
|
||||
}
|
||||
else {
|
||||
int delay = (int) (24000 - world.getTime());
|
||||
double chance = (double) (24000 - world.getTime()) / 24000;
|
||||
cropData.keySet().forEach(key -> {
|
||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||
if (Math.random() < chance) {
|
||||
growSingleFrame(key, randomGenerator.nextInt(delay));
|
||||
growSingleFrame(entry.getKey(), entry.getValue(), randomGenerator.nextInt(delay));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void growSingleFrame(SimpleLocation simpleLocation, long delay) {
|
||||
Location location = MiscUtils.getLocation(simpleLocation);
|
||||
if (location == null) return;
|
||||
bukkitScheduler.runTaskLater(CustomCrops.plugin, () -> cropMode.loadChunk(location), delay);
|
||||
private void growSingleFrame(SimpleLocation simpleLocation, GrowingCrop growingCrop, long delay) {
|
||||
bukkitScheduler.runTaskLater(CustomCrops.plugin, () -> {
|
||||
if (cropMode.growJudge(location)) {
|
||||
Location location = MiscUtils.getLocation(simpleLocation);
|
||||
if (location == null) return;
|
||||
location.getChunk().load();
|
||||
}, delay);
|
||||
bukkitScheduler.runTaskLater(CustomCrops.plugin, () -> {
|
||||
Location location = MiscUtils.getLocation(simpleLocation);
|
||||
if (location == null) return;
|
||||
if (cropManager.itemFrameGrowJudge(location, growingCrop)) {
|
||||
cropData.remove(simpleLocation);
|
||||
}
|
||||
}, delay + 5);
|
||||
}
|
||||
|
||||
|
||||
private void route(int sprinklerTime) {
|
||||
|
||||
tempWatered = new HashSet<>(watered);
|
||||
@@ -424,21 +447,13 @@ public class CustomWorld {
|
||||
|
||||
Random randomGenerator = new Random();
|
||||
for (Map.Entry<SimpleLocation, Sprinkler> sprinklerEntry : sprinklerCache.entrySet()) {
|
||||
|
||||
bukkitScheduler.runTaskLaterAsynchronously(CustomCrops.plugin, () -> {
|
||||
sprinklerWork(sprinklerEntry.getKey(), sprinklerEntry.getValue());
|
||||
}, randomGenerator.nextInt(sprinklerTime));
|
||||
|
||||
bukkitScheduler.runTaskLaterAsynchronously(CustomCrops.plugin, () -> sprinklerWork(sprinklerEntry.getKey(), sprinklerEntry.getValue()), randomGenerator.nextInt(sprinklerTime));
|
||||
}
|
||||
|
||||
for (Map.Entry<SimpleLocation, Fertilizer> fertilizerEntry : fertilizerCache.entrySet()) {
|
||||
Fertilizer fertilizer = fertilizerEntry.getValue();
|
||||
if (fertilizer.getTimes() > 1) {
|
||||
fertilizer.setTimes(fertilizer.getTimes() - 1);
|
||||
}
|
||||
else {
|
||||
fertilizerCache.remove(fertilizerEntry.getKey());
|
||||
}
|
||||
if (fertilizer.getTimes() > 1) fertilizer.setTimes(fertilizer.getTimes() - 1);
|
||||
else fertilizerCache.remove(fertilizerEntry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,10 +461,6 @@ public class CustomWorld {
|
||||
return ConfigUtil.readData(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + worldName + File.separator + "customcrops_data" + File.separator + data +".yml"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprinkler Work
|
||||
* @param location sprinkler location
|
||||
*/
|
||||
public void sprinklerWork(SimpleLocation location, Sprinkler sprinkler) {
|
||||
if (sprinkler.getWater() < 1) {
|
||||
sprinklerCache.remove(location);
|
||||
@@ -457,15 +468,16 @@ public class CustomWorld {
|
||||
}
|
||||
Location sprinklerLoc = MiscUtils.getLocation(location);
|
||||
if (sprinklerLoc == null) return;
|
||||
|
||||
if (MainConfig.enableAnimations) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
for (Player player : sprinklerLoc.getNearbyPlayers(48)) {
|
||||
cropManager.getArmorStandUtil().playWaterAnimation(player, sprinklerLoc.clone().add(0.5, 0.3, 0.5));
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : sprinklerLoc.getNearbyPlayers(48)) {
|
||||
cropManager.getArmorStandUtil().playWaterAnimation(player, sprinklerLoc.clone().add(0.5, 0.3, 0.5));
|
||||
}
|
||||
}
|
||||
});
|
||||
}.runTask(CustomCrops.plugin);
|
||||
}
|
||||
|
||||
sprinkler.setWater(sprinkler.getWater() - 1);
|
||||
int range = sprinkler.getRange();
|
||||
for(int i = -range; i <= range; i++){
|
||||
@@ -478,85 +490,116 @@ public class CustomWorld {
|
||||
}
|
||||
|
||||
private void potDryJudge(int time) {
|
||||
bukkitScheduler.runTaskLater(CustomCrops.plugin, () -> {
|
||||
tempWatered.removeAll(watered);
|
||||
for (SimpleLocation simpleLocation : tempWatered) {
|
||||
Location dryLoc = MiscUtils.getLocation(simpleLocation);
|
||||
if (dryLoc == null) return;
|
||||
cropManager.potDryJudge(dryLoc);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tempWatered.removeAll(watered);
|
||||
for (SimpleLocation simpleLocation : tempWatered) {
|
||||
Location potLoc = MiscUtils.getLocation(simpleLocation);
|
||||
if (potLoc == null) return;
|
||||
if (!isPotWet(potLoc)) {
|
||||
cropManager.makePotDry(potLoc);
|
||||
continue;
|
||||
}
|
||||
Fertilizer fertilizer = getFertilizerCache(potLoc);
|
||||
if (!(fertilizer instanceof RetainingSoil retainingSoil && Math.random() < retainingSoil.getChance())) {
|
||||
cropManager.makePotDry(potLoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, time);
|
||||
}.runTaskLaterAsynchronously(CustomCrops.plugin, time);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 肥料缓存
|
||||
*
|
||||
*/
|
||||
@Nullable
|
||||
public Fertilizer getFertilizer(Location potLoc) {
|
||||
public Fertilizer getFertilizerCache(Location potLoc) {
|
||||
return fertilizerCache.get(MiscUtils.getSimpleLocation(potLoc));
|
||||
}
|
||||
|
||||
public boolean isPotWet(Location potLoc) {
|
||||
return watered.contains(MiscUtils.getSimpleLocation(potLoc));
|
||||
}
|
||||
|
||||
public void removeFertilizer(Location potLoc) {
|
||||
public void removeFertilizerCache(Location potLoc) {
|
||||
fertilizerCache.remove(MiscUtils.getSimpleLocation(potLoc));
|
||||
}
|
||||
|
||||
public void removeWatered(Location potLoc) {
|
||||
watered.remove(MiscUtils.getSimpleLocation(potLoc));
|
||||
}
|
||||
|
||||
public void addFertilizer(Location potLoc, Fertilizer fertilizer) {
|
||||
public void addFertilizerCache(Location potLoc, Fertilizer fertilizer) {
|
||||
fertilizerCache.put(MiscUtils.getSimpleLocation(potLoc), fertilizer);
|
||||
}
|
||||
|
||||
public void removeCrop(Location cropLoc) {
|
||||
|
||||
/**
|
||||
*
|
||||
* 农作物缓存
|
||||
*
|
||||
*/
|
||||
public void removeCropCache(Location cropLoc) {
|
||||
cropData.remove(MiscUtils.getSimpleLocation(cropLoc));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Sprinkler getSprinkler(Location location) {
|
||||
return sprinklerCache.get(MiscUtils.getSimpleLocation(location));
|
||||
}
|
||||
|
||||
public void addCrop(Location cropLoc, String crop) {
|
||||
public void addCropCache(Location cropLoc, String crop, int stage) {
|
||||
SimpleLocation simpleLocation = MiscUtils.getSimpleLocation(cropLoc);
|
||||
cropData.put(simpleLocation, crop);
|
||||
if (MainConfig.enableCompensation && !plantedToday.contains(simpleLocation) && world.getTime() > 1500) {
|
||||
int delay = (int)(24000 - world.getTime());
|
||||
GrowingCrop growingCrop = new GrowingCrop(stage, crop);
|
||||
cropData.put(simpleLocation, growingCrop);
|
||||
if (MainConfig.autoGrow && !plantedToday.contains(simpleLocation) && world.getTime() > 1000) {
|
||||
int delay = (int) (24000 - world.getTime());
|
||||
double chance = (double) (24000 - world.getTime()) / 24000;
|
||||
plantedToday.add(simpleLocation);
|
||||
if (Math.random() > chance) return;
|
||||
if (MainConfig.cropMode) {
|
||||
growSingleWire(simpleLocation, new Random().nextInt(delay));
|
||||
}
|
||||
else {
|
||||
growSingleFrame(simpleLocation, new Random().nextInt(delay));
|
||||
}
|
||||
if (MainConfig.cropMode) growSingleWire(simpleLocation, growingCrop, new Random().nextInt(delay));
|
||||
else growSingleFrame(simpleLocation, growingCrop, new Random().nextInt(delay));
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSprinkler(Location location) {
|
||||
sprinklerCache.remove(MiscUtils.getSimpleLocation(location));
|
||||
@Nullable
|
||||
public GrowingCrop getCropCache(Location cropLoc) {
|
||||
return cropData.get(MiscUtils.getSimpleLocation(cropLoc));
|
||||
}
|
||||
|
||||
public void addSprinkler(Location location, Sprinkler sprinkler) {
|
||||
|
||||
/**
|
||||
*
|
||||
* 洒水器缓存
|
||||
*
|
||||
*/
|
||||
@Nullable
|
||||
public Sprinkler getSprinklerCache(Location location) {
|
||||
return sprinklerCache.get(MiscUtils.getSimpleLocation(location));
|
||||
}
|
||||
public void removeSprinklerCache(Location location) {
|
||||
sprinklerCache.remove(MiscUtils.getSimpleLocation(location));
|
||||
}
|
||||
public void addSprinklerCache(Location location, Sprinkler sprinkler) {
|
||||
sprinklerCache.put(MiscUtils.getSimpleLocation(location), sprinkler);
|
||||
}
|
||||
|
||||
public void setPotWet(Location location) {
|
||||
watered.add(MiscUtils.getSimpleLocation(location));
|
||||
|
||||
/**
|
||||
*
|
||||
* 种植盆状态缓存
|
||||
*
|
||||
*/
|
||||
public void setPotWet(Location potLoc) {
|
||||
watered.add(MiscUtils.getSimpleLocation(potLoc));
|
||||
}
|
||||
public boolean isPotWet(Location potLoc) {
|
||||
return watered.contains(MiscUtils.getSimpleLocation(potLoc));
|
||||
}
|
||||
public void removePotFromWatered(Location potLoc) {
|
||||
watered.remove(MiscUtils.getSimpleLocation(potLoc));
|
||||
}
|
||||
public void setPlayerWatered(Location potLoc) {
|
||||
playerWatered.add(MiscUtils.getSimpleLocation(potLoc));
|
||||
}
|
||||
|
||||
public void setPlayerWatered(Location location) {
|
||||
playerWatered.add(MiscUtils.getSimpleLocation(location));
|
||||
}
|
||||
|
||||
public boolean hasScarecrow(Location location) {
|
||||
/**
|
||||
*
|
||||
* 稻草人缓存
|
||||
*
|
||||
*/
|
||||
public boolean hasScarecrowCache(Location location) {
|
||||
Chunk chunk = location.getChunk();
|
||||
return scarecrowCache.containsKey(chunk.getX() + "," + chunk.getZ());
|
||||
}
|
||||
|
||||
public void addScarecrow(Location location) {
|
||||
public void addScarecrowCache(Location location) {
|
||||
Chunk chunk = location.getChunk();
|
||||
HashSet<SimpleLocation> old = scarecrowCache.get(chunk.getX() + "," + chunk.getZ());
|
||||
if (old == null) {
|
||||
@@ -568,8 +611,7 @@ public class CustomWorld {
|
||||
old.add(new SimpleLocation(world.getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
}
|
||||
}
|
||||
|
||||
public void removeScarecrow(Location location) {
|
||||
public void removeScarecrowCache(Location location) {
|
||||
Chunk chunk = location.getChunk();
|
||||
HashSet<SimpleLocation> old = scarecrowCache.get(chunk.getX() + "," + chunk.getZ());
|
||||
if (old == null) return;
|
||||
|
||||
@@ -12,7 +12,6 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.config.WaterCanConfig;
|
||||
import net.momirealms.customcrops.integrations.customplugin.CustomInterface;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.objects.WaterCan;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -24,11 +23,11 @@ import java.util.List;
|
||||
|
||||
public class ContainerListener extends PacketAdapter {
|
||||
|
||||
private final CustomInterface customInterface;
|
||||
private CropManager cropManager;
|
||||
|
||||
public ContainerListener(CropManager cropManager) {
|
||||
super(CustomCrops.plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.WINDOW_ITEMS);
|
||||
this.customInterface = cropManager.getCustomInterface();
|
||||
this.cropManager = cropManager;
|
||||
}
|
||||
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
@@ -42,7 +41,7 @@ public class ContainerListener extends PacketAdapter {
|
||||
ItemStack fake = itemStack.clone();
|
||||
itemStacksClone.add(fake);
|
||||
if (fake.getType() == Material.AIR) continue;
|
||||
String id = customInterface.getItemID(fake);
|
||||
String id = cropManager.getCustomInterface().getItemID(fake);
|
||||
WaterCan config = WaterCanConfig.CANS.get(id);
|
||||
if (config == null) continue;
|
||||
NBTItem nbtItem = new NBTItem(fake);
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package net.momirealms.customcrops.managers.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.integrations.customplugin.HandlerP;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerContainerListener extends PacketAdapter {
|
||||
|
||||
private final HandlerP handlerP;
|
||||
|
||||
public PlayerContainerListener(HandlerP handlerP) {
|
||||
super(CustomCrops.plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.WINDOW_CLICK);
|
||||
this.handlerP = handlerP;
|
||||
}
|
||||
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (handlerP.coolDownJudge(player)) {
|
||||
// player.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class CrowTask extends BukkitRunnable {
|
||||
this.player = player;
|
||||
this.armorStandUtil = armorStandUtil;
|
||||
this.entityID = new Random().nextInt(10000000);
|
||||
yaw = new Random().nextInt(361) - 180;
|
||||
this.yaw = new Random().nextInt(361) - 180;
|
||||
this.from = crop.clone().add(10 * Math.sin((Math.PI * yaw)/180), 10, - 10 * Math.cos((Math.PI * yaw)/180));
|
||||
Location relative = crop.clone().subtract(from);
|
||||
this.vectorDown = new Vector(relative.getX() / 100, -0.1, relative.getZ() / 100);
|
||||
@@ -55,8 +55,7 @@ public class CrowTask extends BukkitRunnable {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getMetaPacket(entityID));
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getEquipPacket(entityID, armorStandUtil.getCropManager().getCustomInterface().getItemStack(BasicItemConfig.crowFly)));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
catch (InvocationTargetException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,34 +74,30 @@ public class CrowTask extends BukkitRunnable {
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getEquipPacket(entityID, armorStandUtil.getCropManager().getCustomInterface().getItemStack(BasicItemConfig.crowLand)));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
catch (InvocationTargetException ignore) {
|
||||
}
|
||||
}
|
||||
else if (timer == 150) {
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getEquipPacket(entityID, armorStandUtil.getCropManager().getCustomInterface().getItemStack(BasicItemConfig.crowFly)));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
catch (InvocationTargetException ignore) {
|
||||
}
|
||||
}
|
||||
else if (timer > 150) {
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getTeleportPacket(entityID, from.add(vectorUp), yaw));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
catch (InvocationTargetException ignore) {
|
||||
}
|
||||
}
|
||||
if (timer > 300) {
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getDestroyPacket(entityID));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
catch (InvocationTargetException ignore) {
|
||||
}
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class TimerTask extends BukkitRunnable {
|
||||
if (!MainConfig.autoGrow) return;
|
||||
for (World world : MainConfig.getWorldsList()) {
|
||||
long time = world.getTime();
|
||||
if (time > 950 && time < 1051) {
|
||||
if (time > 900 && time < 1001) {
|
||||
cropManager.grow(world, MainConfig.timeToGrow, MainConfig.timeToWork, MainConfig.timeToDry, false, false);
|
||||
}
|
||||
if (time > 0 && time < 101) {
|
||||
|
||||
@@ -33,9 +33,11 @@ public class CCCrop implements Crop {
|
||||
private ActionInterface[] actions;
|
||||
private final String key;
|
||||
private boolean rotation;
|
||||
private final int max_stage;
|
||||
|
||||
public CCCrop(String key) {
|
||||
public CCCrop(String key, int max_stage) {
|
||||
this.key = key;
|
||||
this.max_stage = max_stage;
|
||||
}
|
||||
|
||||
public QualityLoot getQualityLoot() {
|
||||
@@ -105,4 +107,8 @@ public class CCCrop implements Crop {
|
||||
public void setCanRotate(boolean rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public int getMax_stage() {
|
||||
return max_stage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.momirealms.customcrops.objects;
|
||||
|
||||
public class GrowingCrop {
|
||||
|
||||
private int stage;
|
||||
|
||||
private final String type;
|
||||
|
||||
public GrowingCrop(int stage, String type) {
|
||||
this.stage = stage;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setStage(int stage) {
|
||||
this.stage = stage;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,10 @@ public class MiscUtils {
|
||||
return new SimpleLocation(location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
|
||||
public static Location getItemFrameBlockLocation(Location frameLoc) {
|
||||
return new Location(frameLoc.getWorld(), frameLoc.getBlockX(), frameLoc.getBlockY(), frameLoc.getBlockZ());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Location getLocation(SimpleLocation location) {
|
||||
World world = Bukkit.getWorld(location.getWorldName());
|
||||
|
||||
Reference in New Issue
Block a user