mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 16:39:36 +00:00
1.7-5
This commit is contained in:
@@ -292,6 +292,12 @@ public abstract class HandlerP extends Function {
|
|||||||
return StringUtils.chop(id) + nextStage;
|
return StringUtils.chop(id) + nextStage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void placeScareCrow(Location location) {
|
||||||
|
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||||
|
if (customWorld == null) return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public boolean fillWaterCan(String id, NBTItem nbtItem, ItemStack itemStack, Player player) {
|
public boolean fillWaterCan(String id, NBTItem nbtItem, ItemStack itemStack, Player player) {
|
||||||
WaterCan config = WaterCanConfig.CANS.get(id);
|
WaterCan config = WaterCanConfig.CANS.get(id);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package net.momirealms.customcrops.integrations.customplugin.itemsadder.listener
|
|||||||
|
|
||||||
import dev.lone.itemsadder.api.Events.FurnitureBreakEvent;
|
import dev.lone.itemsadder.api.Events.FurnitureBreakEvent;
|
||||||
import dev.lone.itemsadder.api.Events.FurnitureInteractEvent;
|
import dev.lone.itemsadder.api.Events.FurnitureInteractEvent;
|
||||||
|
import dev.lone.itemsadder.api.Events.FurniturePlaceEvent;
|
||||||
import net.momirealms.customcrops.integrations.customplugin.itemsadder.ItemsAdderHandler;
|
import net.momirealms.customcrops.integrations.customplugin.itemsadder.ItemsAdderHandler;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -40,4 +41,9 @@ public class ItemsAdderFurnitureListener implements Listener {
|
|||||||
public void onBreakFurniture(FurnitureBreakEvent event) {
|
public void onBreakFurniture(FurnitureBreakEvent event) {
|
||||||
handler.onBreakFurniture(event);
|
handler.onBreakFurniture(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlaceFurniture(FurniturePlaceEvent event) {
|
||||||
|
//TODO scarecrow
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,11 @@ public class OraxenFrameHandler extends OraxenHandler {
|
|||||||
super.onBreakSprinkler(event.getBlock().getLocation());
|
super.onBreakSprinkler(event.getBlock().getLocation());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (MainConfig.enableCrow && id.equals(BasicItemConfig.scarecrow)) {
|
||||||
|
super.removeScarecrow(event.getBlock().getLocation());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//TODO check if event.getBlock()
|
||||||
if (id.contains("_stage_")) {
|
if (id.contains("_stage_")) {
|
||||||
if (id.equals(BasicItemConfig.deadCrop)) return;
|
if (id.equals(BasicItemConfig.deadCrop)) return;
|
||||||
if (hasNextStage(id)) {
|
if (hasNextStage(id)) {
|
||||||
|
|||||||
@@ -21,17 +21,16 @@ import de.tr7zw.changeme.nbtapi.NBTCompound;
|
|||||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||||
import io.th0rgal.oraxen.events.*;
|
import io.th0rgal.oraxen.events.*;
|
||||||
import io.th0rgal.oraxen.items.OraxenItems;
|
import io.th0rgal.oraxen.items.OraxenItems;
|
||||||
|
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic;
|
||||||
import net.momirealms.customcrops.CustomCrops;
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
import net.momirealms.customcrops.api.crop.Crop;
|
import net.momirealms.customcrops.api.crop.Crop;
|
||||||
import net.momirealms.customcrops.api.event.WaterEvent;
|
import net.momirealms.customcrops.api.event.WaterEvent;
|
||||||
import net.momirealms.customcrops.config.CropConfig;
|
import net.momirealms.customcrops.config.*;
|
||||||
import net.momirealms.customcrops.config.MainConfig;
|
|
||||||
import net.momirealms.customcrops.config.SoundConfig;
|
|
||||||
import net.momirealms.customcrops.config.WaterCanConfig;
|
|
||||||
import net.momirealms.customcrops.integrations.customplugin.HandlerP;
|
import net.momirealms.customcrops.integrations.customplugin.HandlerP;
|
||||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenBlockListener;
|
import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenBlockListener;
|
||||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenFurnitureListener;
|
import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenFurnitureListener;
|
||||||
import net.momirealms.customcrops.managers.CropManager;
|
import net.momirealms.customcrops.managers.CropManager;
|
||||||
|
import net.momirealms.customcrops.managers.CustomWorld;
|
||||||
import net.momirealms.customcrops.objects.WaterCan;
|
import net.momirealms.customcrops.objects.WaterCan;
|
||||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
@@ -73,6 +72,24 @@ public abstract class OraxenHandler extends HandlerP {
|
|||||||
HandlerList.unregisterAll(this.oraxenFurnitureListener);
|
HandlerList.unregisterAll(this.oraxenFurnitureListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//scarecrow place
|
||||||
|
public void placeScarecrow(OraxenFurniturePlaceEvent event) {
|
||||||
|
if (!MainConfig.enableCrow) return;
|
||||||
|
FurnitureMechanic mechanic = event.getFurnitureMechanic();
|
||||||
|
String id = mechanic.getItemID();
|
||||||
|
if (!id.equals(BasicItemConfig.scarecrow)) return;
|
||||||
|
Location location = event.getItemFrame().getLocation();
|
||||||
|
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||||
|
if (customWorld == null) return;
|
||||||
|
customWorld.addScarecrow(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeScarecrow(Location location) {
|
||||||
|
CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld());
|
||||||
|
if (customWorld == null) return;
|
||||||
|
customWorld.removeScarecrow(location);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) {
|
public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) {
|
||||||
if (itemInHand == null || itemInHand.getType() == Material.AIR) return true;
|
if (itemInHand == null || itemInHand.getType() == Material.AIR) return true;
|
||||||
String id = OraxenItems.getIdByItem(itemInHand);
|
String id = OraxenItems.getIdByItem(itemInHand);
|
||||||
|
|||||||
@@ -138,13 +138,17 @@ public class OraxenWireHandler extends OraxenHandler{
|
|||||||
if (event.isCancelled()) return;
|
if (event.isCancelled()) return;
|
||||||
|
|
||||||
//TODO Check if triggered in res
|
//TODO Check if triggered in res
|
||||||
//System.out.println(1);
|
|
||||||
|
|
||||||
FurnitureMechanic mechanic = event.getFurnitureMechanic();
|
FurnitureMechanic mechanic = event.getFurnitureMechanic();
|
||||||
if (mechanic == null) return;
|
if (mechanic == null) return;
|
||||||
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(mechanic.getItemID());
|
String id = mechanic.getItemID();
|
||||||
|
Sprinkler sprinkler = SprinklerConfig.SPRINKLERS_3D.get(id);
|
||||||
if (sprinkler != null) {
|
if (sprinkler != null) {
|
||||||
super.onBreakSprinkler(event.getBlock().getLocation());
|
super.onBreakSprinkler(event.getBlock().getLocation());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MainConfig.enableCrow && id.equals(BasicItemConfig.scarecrow)) {
|
||||||
|
super.removeScarecrow(event.getBlock().getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,8 +243,6 @@ public class OraxenWireHandler extends OraxenHandler{
|
|||||||
@Override
|
@Override
|
||||||
public void onInteractStringBlock(OraxenStringBlockInteractEvent event) {
|
public void onInteractStringBlock(OraxenStringBlockInteractEvent event) {
|
||||||
if (event.isCancelled()) return;
|
if (event.isCancelled()) return;
|
||||||
|
|
||||||
|
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
@@ -253,7 +255,6 @@ public class OraxenWireHandler extends OraxenHandler{
|
|||||||
if (id.contains("_stage_")) {
|
if (id.contains("_stage_")) {
|
||||||
|
|
||||||
Location seedLoc = block.getLocation();
|
Location seedLoc = block.getLocation();
|
||||||
|
|
||||||
ItemStack itemInHand = event.getItemInHand();
|
ItemStack itemInHand = event.getItemInHand();
|
||||||
//ripe crops
|
//ripe crops
|
||||||
if (!id.equals(BasicItemConfig.deadCrop)) {
|
if (!id.equals(BasicItemConfig.deadCrop)) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package net.momirealms.customcrops.integrations.customplugin.oraxen.listeners;
|
|||||||
|
|
||||||
import io.th0rgal.oraxen.events.OraxenFurnitureBreakEvent;
|
import io.th0rgal.oraxen.events.OraxenFurnitureBreakEvent;
|
||||||
import io.th0rgal.oraxen.events.OraxenFurnitureInteractEvent;
|
import io.th0rgal.oraxen.events.OraxenFurnitureInteractEvent;
|
||||||
|
import io.th0rgal.oraxen.events.OraxenFurniturePlaceEvent;
|
||||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.OraxenHandler;
|
import net.momirealms.customcrops.integrations.customplugin.oraxen.OraxenHandler;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -32,12 +33,17 @@ public class OraxenFurnitureListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInteract(OraxenFurnitureInteractEvent event) {
|
public void onInteractFurniture(OraxenFurnitureInteractEvent event) {
|
||||||
handler.onInteractFurniture(event);
|
handler.onInteractFurniture(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBreak(OraxenFurnitureBreakEvent event) {
|
public void onBreakFurniture(OraxenFurnitureBreakEvent event) {
|
||||||
handler.onBreakFurniture(event);
|
handler.onBreakFurniture(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlaceFurniture(OraxenFurniturePlaceEvent event) {
|
||||||
|
handler.placeScarecrow(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,19 +89,27 @@ public class CropManager extends Function {
|
|||||||
//Custom Plugin
|
//Custom Plugin
|
||||||
if (MainConfig.customPlugin.equals("itemsadder")) {
|
if (MainConfig.customPlugin.equals("itemsadder")) {
|
||||||
customInterface = new ItemsAdderHook();
|
customInterface = new ItemsAdderHook();
|
||||||
if (MainConfig.cropMode) this.handler = new ItemsAdderWireHandler(this);
|
if (MainConfig.cropMode) {
|
||||||
else this.handler = new ItemsAdderFrameHandler(this);
|
this.handler = new ItemsAdderWireHandler(this);
|
||||||
|
this.cropMode = new ItemsAdderWireCropImpl(this);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.handler = new ItemsAdderFrameHandler(this);
|
||||||
|
this.cropMode = new ItemsAdderFrameCropImpl(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (MainConfig.customPlugin.equals("oraxen")){
|
else if (MainConfig.customPlugin.equals("oraxen")){
|
||||||
customInterface = new OraxenHook();
|
customInterface = new OraxenHook();
|
||||||
if (MainConfig.cropMode) this.handler = new OraxenWireHandler(this);
|
if (MainConfig.cropMode) {
|
||||||
else this.handler = new OraxenFrameHandler(this);
|
this.handler = new OraxenWireHandler(this);
|
||||||
|
this.cropMode = new OraxenWireCropImpl(this);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.handler = new OraxenFrameHandler(this);
|
||||||
|
this.cropMode = new OraxenFrameCropImpl(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Crop mode
|
|
||||||
if (MainConfig.cropMode) this.cropMode = new WireCropImpl(this);
|
|
||||||
else this.cropMode = new FrameCropImpl(this);
|
|
||||||
|
|
||||||
//new Time Check task
|
//new Time Check task
|
||||||
this.timerTask = new TimerTask(this);
|
this.timerTask = new TimerTask(this);
|
||||||
this.timerTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1,100);
|
this.timerTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1,100);
|
||||||
@@ -125,14 +133,12 @@ public class CropManager extends Function {
|
|||||||
HandlerList.unregisterAll(this.itemSpawnListener);
|
HandlerList.unregisterAll(this.itemSpawnListener);
|
||||||
HandlerList.unregisterAll(this.worldListener);
|
HandlerList.unregisterAll(this.worldListener);
|
||||||
if (this.handler != null) handler.unload();
|
if (this.handler != null) handler.unload();
|
||||||
this.timerTask.cancel();
|
if (this.timerTask != null) this.timerTask.cancel();
|
||||||
for (CustomWorld customWorld : customWorlds.values()) {
|
for (CustomWorld customWorld : customWorlds.values()) {
|
||||||
customWorld.unload(true);
|
customWorld.unload(true);
|
||||||
}
|
}
|
||||||
customWorlds.clear();
|
customWorlds.clear();
|
||||||
if (this.seasonInterface != null) {
|
if (this.seasonInterface != null) seasonInterface.unload();
|
||||||
seasonInterface.unload();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemSpawn(Item item) {
|
public void onItemSpawn(Item item) {
|
||||||
@@ -148,7 +154,7 @@ public class CropManager extends Function {
|
|||||||
CustomWorld customWorld = new CustomWorld(world, this);
|
CustomWorld customWorld = new CustomWorld(world, this);
|
||||||
customWorlds.put(world, customWorld);
|
customWorlds.put(world, customWorld);
|
||||||
if (MainConfig.autoGrow && MainConfig.enableCompensation) {
|
if (MainConfig.autoGrow && MainConfig.enableCompensation) {
|
||||||
if (world.getTime() < 24000 - MainConfig.timeToWork - MainConfig.timeToDry - 1200 && world.getTime() > 1500) {
|
if (world.getTime() < 24000 - MainConfig.timeToWork - MainConfig.timeToDry - 1200 && world.getTime() > 1200) {
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, () -> grow(world, MainConfig.timeToGrow, MainConfig.timeToWork, MainConfig.timeToDry, true), 100);
|
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, () -> grow(world, MainConfig.timeToGrow, MainConfig.timeToWork, MainConfig.timeToDry, true), 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,15 @@
|
|||||||
|
|
||||||
package net.momirealms.customcrops.managers;
|
package net.momirealms.customcrops.managers;
|
||||||
|
|
||||||
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
public interface CropModeInterface {
|
public interface CropModeInterface {
|
||||||
|
|
||||||
boolean growJudge(Location location);
|
boolean growJudge(Location location);
|
||||||
void loadChunk(Location location);
|
|
||||||
|
|
||||||
}
|
default void loadChunk(Location location) {
|
||||||
|
Chunk chunk = location.getChunk();
|
||||||
|
chunk.load();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ import net.momirealms.customcrops.utils.MiscUtils;
|
|||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@@ -51,6 +52,7 @@ public class CustomWorld {
|
|||||||
private final ConcurrentHashMap<SimpleLocation, String> cropCache;
|
private final ConcurrentHashMap<SimpleLocation, String> cropCache;
|
||||||
private final ConcurrentHashMap<SimpleLocation, Sprinkler> sprinklerCache;
|
private final ConcurrentHashMap<SimpleLocation, Sprinkler> sprinklerCache;
|
||||||
private final ConcurrentHashMap<SimpleLocation, Fertilizer> fertilizerCache;
|
private final ConcurrentHashMap<SimpleLocation, Fertilizer> fertilizerCache;
|
||||||
|
private final ConcurrentHashMap<String, HashSet<SimpleLocation>> scarecrowCache;
|
||||||
private final Set<SimpleLocation> watered;
|
private final Set<SimpleLocation> watered;
|
||||||
private HashSet<SimpleLocation> tempWatered;
|
private HashSet<SimpleLocation> tempWatered;
|
||||||
private final HashSet<SimpleLocation> playerWatered;
|
private final HashSet<SimpleLocation> playerWatered;
|
||||||
@@ -64,17 +66,14 @@ public class CustomWorld {
|
|||||||
this.fertilizerCache = new ConcurrentHashMap<>(2048);
|
this.fertilizerCache = new ConcurrentHashMap<>(2048);
|
||||||
this.sprinklerCache = new ConcurrentHashMap<>(1024);
|
this.sprinklerCache = new ConcurrentHashMap<>(1024);
|
||||||
this.tasksCache = new HashSet<>(4096);
|
this.tasksCache = new HashSet<>(4096);
|
||||||
|
this.scarecrowCache = new ConcurrentHashMap<>(256);
|
||||||
this.cropManager = cropManager;
|
this.cropManager = cropManager;
|
||||||
this.bukkitScheduler = Bukkit.getScheduler();
|
this.bukkitScheduler = Bukkit.getScheduler();
|
||||||
this.watered = Collections.synchronizedSet(new HashSet<>());
|
this.watered = Collections.synchronizedSet(new HashSet<>());
|
||||||
this.playerWatered = new HashSet<>();
|
this.playerWatered = new HashSet<>();
|
||||||
this.tempWatered = new HashSet<>();
|
this.tempWatered = new HashSet<>();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {
|
||||||
loadSeason();
|
loadData();
|
||||||
loadCropCache();
|
|
||||||
loadSprinklerCache();
|
|
||||||
loadFertilizerCache();
|
|
||||||
loadPot();
|
|
||||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||||
CustomWorldEvent customWorldEvent = new CustomWorldEvent(world, WorldState.LOAD);
|
CustomWorldEvent customWorldEvent = new CustomWorldEvent(world, WorldState.LOAD);
|
||||||
Bukkit.getPluginManager().callEvent(customWorldEvent);
|
Bukkit.getPluginManager().callEvent(customWorldEvent);
|
||||||
@@ -84,21 +83,11 @@ public class CustomWorld {
|
|||||||
|
|
||||||
public void unload(boolean disable) {
|
public void unload(boolean disable) {
|
||||||
if (disable) {
|
if (disable) {
|
||||||
unloadSeason();
|
unloadData();
|
||||||
unloadCrop();
|
|
||||||
unloadSprinkler();
|
|
||||||
unloadFertilizer();
|
|
||||||
unloadPot();
|
|
||||||
backUp(world.getName());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {
|
||||||
unloadSeason();
|
unloadData();
|
||||||
unloadCrop();
|
|
||||||
unloadSprinkler();
|
|
||||||
unloadFertilizer();
|
|
||||||
unloadPot();
|
|
||||||
backUp(world.getName());
|
|
||||||
for (BukkitTask task : tasksCache) {
|
for (BukkitTask task : tasksCache) {
|
||||||
task.cancel();
|
task.cancel();
|
||||||
}
|
}
|
||||||
@@ -111,7 +100,27 @@ public class CustomWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadData() {
|
||||||
|
loadSeason();
|
||||||
|
loadCropCache();
|
||||||
|
loadSprinklerCache();
|
||||||
|
loadFertilizerCache();
|
||||||
|
loadPot();
|
||||||
|
loadScarecrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unloadData() {
|
||||||
|
unloadSeason();
|
||||||
|
unloadCrop();
|
||||||
|
unloadSprinkler();
|
||||||
|
unloadFertilizer();
|
||||||
|
unloadPot();
|
||||||
|
unloadScarecrow();
|
||||||
|
backUp(world.getName());
|
||||||
|
}
|
||||||
|
|
||||||
private void backUp(String worldName) {
|
private void backUp(String worldName) {
|
||||||
|
if (!MainConfig.autoBackUp) return;
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
||||||
try {
|
try {
|
||||||
@@ -128,7 +137,53 @@ public class CustomWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadSeason() {
|
private void loadScarecrow() {
|
||||||
|
if (!MainConfig.enableCrow) return;
|
||||||
|
try {
|
||||||
|
JsonParser jsonParser = new JsonParser();
|
||||||
|
JsonElement json= jsonParser.parse(new FileReader(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "scarecrow.json")));
|
||||||
|
if (json.isJsonObject()) {
|
||||||
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
|
for (Map.Entry<String, JsonElement> en : jsonObject.entrySet()) {
|
||||||
|
JsonArray jsonArray = en.getValue().getAsJsonArray();
|
||||||
|
int size = jsonArray.size();
|
||||||
|
HashSet<SimpleLocation> simpleLocations = new HashSet<>();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
simpleLocations.add(MiscUtils.getSimpleLocation(jsonArray.get(i).getAsString(), world.getName()));
|
||||||
|
}
|
||||||
|
scarecrowCache.put(en.getKey(), simpleLocations);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
SeasonUtils.setSeason(world, CCSeason.UNKNOWN);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e) {
|
||||||
|
//bypass
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unloadScarecrow() {
|
||||||
|
if (!MainConfig.enableCrow) return;
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
for (Map.Entry<String, HashSet<SimpleLocation>> entry : scarecrowCache.entrySet()) {
|
||||||
|
HashSet<SimpleLocation> locations = entry.getValue();
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
for (SimpleLocation simpleLocation : locations) {
|
||||||
|
String loc = simpleLocation.getX() + "," + simpleLocation.getY() + "," + simpleLocation.getZ();
|
||||||
|
jsonArray.add(new JsonPrimitive(loc));
|
||||||
|
}
|
||||||
|
jsonObject.add(entry.getKey(), jsonArray);
|
||||||
|
}
|
||||||
|
try (FileWriter fileWriter = new FileWriter(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "scarecrow.json"))){
|
||||||
|
fileWriter.write(jsonObject.toString().replace("\\\\", "\\"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
SeasonUtils.unloadSeason(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadSeason() {
|
||||||
|
if (!SeasonConfig.enable) return;
|
||||||
try {
|
try {
|
||||||
JsonParser jsonParser = new JsonParser();
|
JsonParser jsonParser = new JsonParser();
|
||||||
JsonElement json= jsonParser.parse(new FileReader(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "season.json")));
|
JsonElement json= jsonParser.parse(new FileReader(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "season.json")));
|
||||||
@@ -149,7 +204,8 @@ public class CustomWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unloadSeason() {
|
private void unloadSeason() {
|
||||||
|
if (!SeasonConfig.enable) return;
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
JsonPrimitive jsonPrimitive = new JsonPrimitive(SeasonUtils.getSeason(world).name());
|
JsonPrimitive jsonPrimitive = new JsonPrimitive(SeasonUtils.getSeason(world).name());
|
||||||
jsonObject.add("season", jsonPrimitive);
|
jsonObject.add("season", jsonPrimitive);
|
||||||
@@ -161,7 +217,7 @@ public class CustomWorld {
|
|||||||
SeasonUtils.unloadSeason(world);
|
SeasonUtils.unloadSeason(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadPot() {
|
private void loadPot() {
|
||||||
try {
|
try {
|
||||||
JsonParser jsonParser = new JsonParser();
|
JsonParser jsonParser = new JsonParser();
|
||||||
JsonElement json= jsonParser.parse(new FileReader(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "pot.json")));
|
JsonElement json= jsonParser.parse(new FileReader(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "pot.json")));
|
||||||
@@ -183,7 +239,7 @@ public class CustomWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unloadPot() {
|
private void unloadPot() {
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
JsonArray jsonArray = new JsonArray();
|
JsonArray jsonArray = new JsonArray();
|
||||||
watered.addAll(playerWatered);
|
watered.addAll(playerWatered);
|
||||||
@@ -470,4 +526,30 @@ public class CustomWorld {
|
|||||||
public void setPlayerWatered(Location location) {
|
public void setPlayerWatered(Location location) {
|
||||||
playerWatered.add(MiscUtils.getSimpleLocation(location));
|
playerWatered.add(MiscUtils.getSimpleLocation(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasScarecrow(Location location) {
|
||||||
|
Chunk chunk = location.getChunk();
|
||||||
|
return scarecrowCache.containsKey(chunk.getX() + "," + chunk.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addScarecrow(Location location) {
|
||||||
|
Chunk chunk = location.getChunk();
|
||||||
|
HashSet<SimpleLocation> old = scarecrowCache.get(chunk.getX() + "," + chunk.getZ());
|
||||||
|
if (old == null) {
|
||||||
|
HashSet<SimpleLocation> young = new HashSet<>(4);
|
||||||
|
young.add(new SimpleLocation(world.getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||||
|
scarecrowCache.put(chunk.getX() + "," + chunk.getZ(), young);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
old.add(new SimpleLocation(world.getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeScarecrow(Location location) {
|
||||||
|
Chunk chunk = location.getChunk();
|
||||||
|
HashSet<SimpleLocation> old = scarecrowCache.get(chunk.getX() + "," + chunk.getZ());
|
||||||
|
if (old == null) return;
|
||||||
|
old.remove(new SimpleLocation(world.getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||||
|
if (old.size() == 0) scarecrowCache.remove(chunk.getX() + "," + chunk.getZ());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* 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.managers;
|
||||||
|
|
||||||
|
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.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()) {
|
||||||
|
|
||||||
|
Location cropLoc = location.clone().add(0.5,0.5,0.5);
|
||||||
|
ItemFrame itemFrame = FurnitureUtil.getItemFrame(cropLoc);
|
||||||
|
if (itemFrame == null) return true;
|
||||||
|
String id = customInterface.getItemID(itemFrame.getItem());
|
||||||
|
if (id == null) return true;
|
||||||
|
if (id.equals(BasicItemConfig.deadCrop)) return true;
|
||||||
|
|
||||||
|
String[] cropNameList = StringUtils.split(id,"_");
|
||||||
|
String cropKey = StringUtils.split(cropNameList[0], ":")[1];
|
||||||
|
Crop crop = CropConfig.CROPS.get(cropKey);
|
||||||
|
if (crop == null) return true;
|
||||||
|
if (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) 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 (customInterface.doesExist(temp + nextStage)) {
|
||||||
|
if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance()) {
|
||||||
|
if (customInterface.doesExist(temp + (nextStage+1))) {
|
||||||
|
addStage(itemFrame, temp + (nextStage+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (certainGrow || Math.random() < MainConfig.dryGrowChance) {
|
||||||
|
addStage(itemFrame, temp + nextStage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addStage(ItemFrame itemFrame, String stage) {
|
||||||
|
itemFrame.setItem(customInterface.getItemStack(stage), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,33 +29,25 @@ import net.momirealms.customcrops.objects.fertilizer.Gigantic;
|
|||||||
import net.momirealms.customcrops.objects.fertilizer.SpeedGrow;
|
import net.momirealms.customcrops.objects.fertilizer.SpeedGrow;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
public class WireCropImpl implements CropModeInterface{
|
public class ItemsAdderWireCropImpl implements CropModeInterface{
|
||||||
|
|
||||||
private final CropManager cropManager;
|
private final CropManager cropManager;
|
||||||
private final CustomInterface customInterface;
|
private final CustomInterface customInterface;
|
||||||
|
|
||||||
public WireCropImpl(CropManager cropManager) {
|
public ItemsAdderWireCropImpl(CropManager cropManager) {
|
||||||
this.cropManager = cropManager;
|
this.cropManager = cropManager;
|
||||||
this.customInterface = cropManager.getCustomInterface();
|
this.customInterface = cropManager.getCustomInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadChunk(Location location) {
|
|
||||||
Chunk chunk = location.getChunk();
|
|
||||||
chunk.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean growJudge(Location location) {
|
public boolean growJudge(Location location) {
|
||||||
String blockID = customInterface.getBlockID(location);
|
String blockID = customInterface.getBlockID(location);
|
||||||
if (blockID == null) return true;
|
if (blockID == null) return true;
|
||||||
if (!blockID.contains("_stage_")) return true;
|
if (!blockID.contains("_stage_")) return true;
|
||||||
String[] cropNameList = StringUtils.split(blockID,"_");
|
String[] cropNameList = StringUtils.split(blockID,"_");
|
||||||
String cropKey = cropNameList[0];
|
String cropKey = StringUtils.split(cropNameList[0], ":")[1];
|
||||||
if (cropKey.contains(":")) cropKey = StringUtils.split(cropKey, ":")[1];
|
|
||||||
Crop crop = CropConfig.CROPS.get(cropKey);
|
Crop crop = CropConfig.CROPS.get(cropKey);
|
||||||
if (crop == null) return true;
|
if (crop == null) return true;
|
||||||
if (cropManager.isWrongSeason(location, crop.getSeasons())) {
|
if (cropManager.isWrongSeason(location, crop.getSeasons())) {
|
||||||
@@ -110,7 +102,7 @@ public class WireCropImpl implements CropModeInterface{
|
|||||||
|
|
||||||
private void addStage(Location seedLoc, String stage) {
|
private void addStage(Location seedLoc, String stage) {
|
||||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||||
if (!MainConfig.OraxenHook) customInterface.removeBlock(seedLoc);
|
customInterface.removeBlock(seedLoc);
|
||||||
customInterface.placeWire(seedLoc, stage);
|
customInterface.placeWire(seedLoc, stage);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -36,22 +36,16 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.ItemFrame;
|
import org.bukkit.entity.ItemFrame;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
public class FrameCropImpl implements CropModeInterface {
|
public class OraxenFrameCropImpl implements CropModeInterface {
|
||||||
|
|
||||||
private final CropManager cropManager;
|
private final CropManager cropManager;
|
||||||
private final CustomInterface customInterface;
|
private final CustomInterface customInterface;
|
||||||
|
|
||||||
public FrameCropImpl(CropManager cropManager) {
|
public OraxenFrameCropImpl(CropManager cropManager) {
|
||||||
this.cropManager = cropManager;
|
this.cropManager = cropManager;
|
||||||
this.customInterface = cropManager.getCustomInterface();
|
this.customInterface = cropManager.getCustomInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadChunk(Location location) {
|
|
||||||
Chunk chunk = location.getChunk();
|
|
||||||
chunk.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean growJudge(Location location) {
|
public boolean growJudge(Location location) {
|
||||||
|
|
||||||
@@ -59,10 +53,7 @@ public class FrameCropImpl implements CropModeInterface {
|
|||||||
|
|
||||||
if (chunk.isEntitiesLoaded()) {
|
if (chunk.isEntitiesLoaded()) {
|
||||||
|
|
||||||
Location cropLoc;
|
Location cropLoc = location.clone().add(0.5,0.03125,0.5);
|
||||||
if (MainConfig.OraxenHook) cropLoc = location.clone().add(0.5,0.03125,0.5);
|
|
||||||
else cropLoc = location.clone().add(0.5,0.5,0.5);
|
|
||||||
|
|
||||||
ItemFrame itemFrame = FurnitureUtil.getItemFrame(cropLoc);
|
ItemFrame itemFrame = FurnitureUtil.getItemFrame(cropLoc);
|
||||||
if (itemFrame == null) return true;
|
if (itemFrame == null) return true;
|
||||||
String id = customInterface.getItemID(itemFrame.getItem());
|
String id = customInterface.getItemID(itemFrame.getItem());
|
||||||
@@ -71,12 +62,11 @@ public class FrameCropImpl implements CropModeInterface {
|
|||||||
|
|
||||||
String[] cropNameList = StringUtils.split(id,"_");
|
String[] cropNameList = StringUtils.split(id,"_");
|
||||||
String cropKey = cropNameList[0];
|
String cropKey = cropNameList[0];
|
||||||
if (cropKey.contains(":")) cropKey = StringUtils.split(cropKey, ":")[1];
|
|
||||||
Crop crop = CropConfig.CROPS.get(cropKey);
|
Crop crop = CropConfig.CROPS.get(cropKey);
|
||||||
if (crop == null) return true;
|
if (crop == null) return true;
|
||||||
if (cropManager.isWrongSeason(location, crop.getSeasons())) {
|
if (cropManager.isWrongSeason(location, crop.getSeasons())) {
|
||||||
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop));
|
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false);
|
||||||
if (MainConfig.OraxenHook) itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, BasicItemConfig.deadCrop);
|
itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, BasicItemConfig.deadCrop);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +115,7 @@ public class FrameCropImpl implements CropModeInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addStage(ItemFrame itemFrame, String stage) {
|
private void addStage(ItemFrame itemFrame, String stage) {
|
||||||
itemFrame.setItem(customInterface.getItemStack(stage));
|
itemFrame.setItem(customInterface.getItemStack(stage), false);
|
||||||
if (MainConfig.OraxenHook) itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, stage);
|
itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, stage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* 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.managers;
|
||||||
|
|
||||||
|
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.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) return true;
|
||||||
|
if (!blockID.contains("_stage_")) return true;
|
||||||
|
String[] cropNameList = StringUtils.split(blockID,"_");
|
||||||
|
String cropKey = cropNameList[0];
|
||||||
|
Crop crop = CropConfig.CROPS.get(cropKey);
|
||||||
|
if (crop == null) return true;
|
||||||
|
if (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) return true;
|
||||||
|
|
||||||
|
Fertilizer fertilizer = cropManager.getFertilizer(potLoc);
|
||||||
|
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
|
||||||
|
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||||
|
String temp = StringUtils.chop(blockID);
|
||||||
|
if (customInterface.doesExist(temp + nextStage)) {
|
||||||
|
if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance()) {
|
||||||
|
if (customInterface.doesExist(temp + (nextStage+1))) {
|
||||||
|
addStage(location, temp + (nextStage+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (certainGrow || Math.random() < MainConfig.dryGrowChance) {
|
||||||
|
addStage(location, temp + nextStage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addStage(Location seedLoc, String stage) {
|
||||||
|
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> customInterface.placeWire(seedLoc, stage));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
package net.momirealms.customcrops.utils;
|
package net.momirealms.customcrops.utils;
|
||||||
|
|
||||||
import net.momirealms.customcrops.objects.SimpleLocation;
|
import net.momirealms.customcrops.objects.SimpleLocation;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@@ -35,4 +36,9 @@ public class MiscUtils {
|
|||||||
if (world == null) return null;
|
if (world == null) return null;
|
||||||
return new Location(world, location.getX(), location.getY(), location.getZ());
|
return new Location(world, location.getX(), location.getY(), location.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SimpleLocation getSimpleLocation(String location, String world) {
|
||||||
|
String[] loc = StringUtils.split(location, ",");
|
||||||
|
return new SimpleLocation(world, Integer.parseInt(loc[0]), Integer.parseInt(loc[1]), Integer.parseInt(loc[2]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ dead-crop: customcrops:crop_stage_death
|
|||||||
soil-surveyor: customcrops:soil_surveyor
|
soil-surveyor: customcrops:soil_surveyor
|
||||||
crow-fly: customcrops:crow_fly
|
crow-fly: customcrops:crow_fly
|
||||||
crow-land: customcrops:crow_land
|
crow-land: customcrops:crow_land
|
||||||
scarecow: customcrops:scarecow
|
scarecrow: customcrops:scarecrow
|
||||||
water-effect: customcrops:water_effect
|
water-effect: customcrops:water_effect
|
||||||
@@ -5,5 +5,5 @@ dead-crop: crop_stage_death
|
|||||||
soil-surveyor: soil_surveyor
|
soil-surveyor: soil_surveyor
|
||||||
crow-fly: crow_fly
|
crow-fly: crow_fly
|
||||||
crow-land: crow_land
|
crow-land: crow_land
|
||||||
scarecow: scarecow
|
scarecrow: scarecrow
|
||||||
water-effect: water_effect
|
water-effect: water_effect
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#Don't change
|
#Don't change
|
||||||
config-version: '9'
|
config-version: '10'
|
||||||
|
|
||||||
# lang: english / spanish / chinese
|
# lang: english / spanish / chinese
|
||||||
lang: chinese
|
lang: chinese
|
||||||
@@ -58,7 +58,7 @@ mechanics:
|
|||||||
# For example, the time to start growing is 1000ticks(7am),
|
# For example, the time to start growing is 1000ticks(7am),
|
||||||
# sprinklers would finish their work in a random time between 1000~1300ticks,
|
# sprinklers would finish their work in a random time between 1000~1300ticks,
|
||||||
# Pot would start drying in a random time between 1300~1500ticks
|
# Pot would start drying in a random time between 1300~1500ticks
|
||||||
# and crops would grow in a random time between 1500~21300ticks
|
# and crops would grow in a random time between 1500~21500ticks
|
||||||
sprinkler-work-time: 300
|
sprinkler-work-time: 300
|
||||||
pot-dry-time: 200
|
pot-dry-time: 200
|
||||||
crops-grow-time: 20000
|
crops-grow-time: 20000
|
||||||
|
|||||||
Reference in New Issue
Block a user