9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-26 18:39:17 +00:00
This commit is contained in:
Xiao-MoMi
2023-05-17 17:29:53 +08:00
parent 5041662a60
commit 2994689bcf
12 changed files with 316 additions and 148 deletions

View File

@@ -59,12 +59,12 @@ public abstract class Handler extends Function implements Listener {
@EventHandler
public void onBreak(BlockBreakEvent event) {
platformManager.onBreakVanilla(event);
platformManager.onBreakVanillaBlock(event);
}
@EventHandler
public void onPlace(BlockPlaceEvent event) {
platformManager.onPlaceVanilla(event);
platformManager.onPlaceVanillaBlock(event);
}
@EventHandler

View File

@@ -34,47 +34,127 @@ import java.util.Collection;
public interface PlatformInterface {
/**
* This method is used for removing custom blocks
* @param location location
* @return false if it is not a custom one
*/
boolean removeCustomBlock(Location location);
/**
* This method is used for removing any block
* @param location location
* @return false if there's no block
*/
default boolean removeAnyBlock(Location location) {
String id = getCustomBlockID(location);
if (id != null) {
return removeCustomBlock(location);
}
Block block = location.getBlock();
if (block.getType() == Material.AIR) {
return false;
} else {
block.setType(Material.AIR);
return true;
}
if (!removeCustomBlock(location)) {
block.setType(Material.AIR);
}
return true;
}
default boolean removeAnyBlock(Block block) {
if (block.getType() == Material.AIR) {
return false;
}
if (!removeCustomBlock(block.getLocation())) {
block.setType(Material.AIR);
}
return true;
}
/**
* Get custom block id at a certain location
* @param location location
* @return block id
*/
@Nullable
String getCustomBlockID(Location location);
/**
* Get item by id
* @param id id
* @return itemStack
*/
@Nullable
ItemStack getItemStack(String id);
/**
* Place an item frame at the specified location
* Would remove the entity if it is not item frame
* @param location location
* @param id id
* @return item frame
*/
@Nullable
ItemFrame placeItemFrame(Location location, String id);
/**
* Place an item display at the specified location
* Would remove the entity if it is not item display
* @param location location
* @param id id
* @return item display
*/
@Nullable
ItemDisplay placeItemDisplay(Location location, String id);
/**
* Place custom note block at a specified location
* @param location location
* @param id id
*/
void placeNoteBlock(Location location, String id);
/**
* Place custom string block at a specified location
* @param location location
* @param id id
*/
void placeTripWire(Location location, String id);
/**
* Place custom chorus plant at a specified location
* @param location location
* @param id id
*/
void placeChorus(Location location, String id);
/**
* Get the block id
* (Examples)
* Vanilla stone -> STONE
* ItemsAdder pot -> customcrops:pot
* Oraxen pot -> pot
* @param block block
* @return id
*/
@NotNull
String getBlockID(Block block);
/**
* If an item exists in item library
* @param id id
* @return exists or not
*/
boolean doesItemExist(String id);
/**
* Drop the block's loot
* @param block block
*/
void dropBlockLoot(Block block);
void placeChorus(Location location, String id);
/**
* Get the custom stuff at a specified location
* It might be a block or an entity
* @param location location
* @return id
*/
@NotNull
default String getAnyItemIDAt(Location location) {
String block = getBlockID(location.getBlock());
@@ -94,14 +174,29 @@ public interface PlatformInterface {
return "AIR";
}
/**
* Remove all the custom stuff at a specified location
* @param location location
*/
default void removeCustomItemAt(Location location) {
removeCustomBlock(location);
removeItemFrame(location);
}
/**
* Get itemStack's internal id
* @param itemStack itemStack
* @return id
*/
@NotNull
String getItemStackID(@NotNull ItemStack itemStack);
/**
* Get item display at a specified location
* This method would also remove overlapped entities
* @param location location
* @return id
*/
@Nullable
default String getItemDisplayIDAt(Location location) {
ItemDisplay itemDisplay = getItemDisplayAt(location);
@@ -109,6 +204,12 @@ public interface PlatformInterface {
return getItemDisplayID(itemDisplay);
}
/**
* Get item frame at a specified location
* This method would also remove overlapped entities
* @param location location
* @return id
*/
@Nullable
default String getItemFrameIDAt(Location location) {
ItemFrame itemFrame = getItemFrameAt(location);
@@ -116,12 +217,28 @@ public interface PlatformInterface {
return getItemFrameID(itemFrame);
}
/**
* Get custom furniture's id
* @param itemDisplay itemDisplay
* @return id
*/
@Nullable
String getItemDisplayID(ItemDisplay itemDisplay);
/**
* Get custom furniture's id
* @param itemFrame itemFrame
* @return id
*/
@Nullable
String getItemFrameID(ItemFrame itemFrame);
/**
* Get item frame at a specified location
* This method would also remove overlapped entities
* @param location location
* @return id
*/
@Nullable
default ItemFrame getItemFrameAt(Location location) {
Collection<ItemFrame> itemFrames = location.clone().add(0.5,0.5,0.5).getNearbyEntitiesByType(ItemFrame.class, 0.4, 0.5, 0.4);
@@ -137,6 +254,12 @@ public interface PlatformInterface {
return null;
}
/**
* Get item display at a specified location
* This method would also remove overlapped entities
* @param location location
* @return id
*/
@Nullable
default ItemDisplay getItemDisplayAt(Location location) {
Collection<ItemDisplay> itemDisplays = location.clone().add(0.5,0.25,0.5).getNearbyEntitiesByType(ItemDisplay.class, 0.4, 0.5, 0.4);
@@ -152,6 +275,11 @@ public interface PlatformInterface {
return null;
}
/**
* Remove item frames at a specified location
* @param location location
* @return success or not
*/
default boolean removeItemFrame(Location location) {
ItemFrame itemFrame = getItemFrameAt(location);
if (itemFrame != null) {
@@ -162,10 +290,11 @@ public interface PlatformInterface {
return false;
}
default void removeInteractions(Location location) {
location.clone().add(0.5,0.5,0.5).getNearbyEntitiesByType(Interaction.class, 0.4, 0.5, 0.4).forEach(Entity::remove);
}
/**
* Remove item display entities at a specified location
* @param location location
* @return success or not
*/
default boolean removeItemDisplay(Location location) {
ItemDisplay itemDisplay = getItemDisplayAt(location);
if (itemDisplay != null) {
@@ -176,6 +305,24 @@ public interface PlatformInterface {
return false;
}
/**
* Remove interaction entities at a specified location
* @param location location
* @return success or not
*/
default boolean removeInteractions(Location location) {
Collection<Interaction> interactions = location.clone().add(0.5,0.5,0.5).getNearbyEntitiesByType(Interaction.class, 0.4, 0.5, 0.4);
for (Interaction interaction : interactions) {
interaction.remove();
}
return interactions.size() != 0;
}
/**
* If there's any custom stuff at a specified location
* @param location location
* @return has custom stuff or not
*/
default boolean detectAnyThing(Location location) {
Block block = location.getBlock();
if (block.getType() != Material.AIR) return true;
@@ -183,27 +330,21 @@ public interface PlatformInterface {
return entities.size() != 0 || (CustomCrops.getInstance().getVersionHelper().isVersionNewerThan1_19_R3() && detectItemDisplay(location));
}
/**
* If there's any item display entity at a specified location
* @param location location
* @return has item display or not
*/
default boolean detectItemDisplay(Location location) {
Collection<Entity> entities = location.clone().add(0.5,0,0.5).getNearbyEntitiesByType(ItemDisplay.class, 0.4, 0.5, 0.4);
return entities.size() != 0;
}
default boolean removeCustomItem(Location location, ItemMode itemMode) {
if (itemMode == ItemMode.TRIPWIRE || itemMode == ItemMode.CHORUS)
return removeCustomBlock(location);
else if (itemMode == ItemMode.ITEM_FRAME)
return removeItemFrame(location);
else if (itemMode == ItemMode.ITEM_DISPLAY)
return removeItemDisplay(location);
return false;
}
default void removeAnyThingAt(Location location) {
removeAnyBlock(location);
removeItemFrame(location);
if (CustomCrops.getInstance().getVersionHelper().isVersionNewerThan1_19_R3()) removeItemDisplay(location);
}
/**
* Place custom stuff according to its mode
* @param location location
* @param itemMode itemMode
*/
default void placeCustomItem(Location location, String id, ItemMode itemMode) {
if (itemMode == ItemMode.TRIPWIRE)
placeTripWire(location, id);
@@ -214,4 +355,30 @@ public interface PlatformInterface {
else if (itemMode == ItemMode.CHORUS)
placeChorus(location, id);
}
/**
* Remove custom stuff according to its mode
* @param location location
* @param itemMode itemMode
* @return success or not
*/
default boolean removeCustomItem(Location location, ItemMode itemMode) {
if (itemMode == ItemMode.TRIPWIRE || itemMode == ItemMode.CHORUS)
return removeCustomBlock(location);
else if (itemMode == ItemMode.ITEM_FRAME)
return removeItemFrame(location);
else if (itemMode == ItemMode.ITEM_DISPLAY)
return removeItemDisplay(location);
return false;
}
/**
* Remove anything
* @param location location
*/
default void removeAnyThingAt(Location location) {
removeAnyBlock(location);
removeItemFrame(location);
if (CustomCrops.getInstance().getVersionHelper().isVersionNewerThan1_19_R3()) removeItemDisplay(location);
}
}

View File

@@ -17,7 +17,6 @@
package net.momirealms.customcrops.api.customplugin;
import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent;
import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.api.customplugin.itemsadder.ItemsAdderHandler;
import net.momirealms.customcrops.api.customplugin.oraxen.OraxenHandler;
@@ -87,52 +86,41 @@ public class PlatformManager extends Function {
this.handler.unload();
}
public void onBreakVanilla(BlockBreakEvent event) {
public void onPlaceVanillaBlock(BlockPlaceEvent event) {
if (event.isCancelled()) return;
Block block = event.getBlock();
if (block.getType() == Material.NOTE_BLOCK) plugin.getWorldDataManager().removeCorrupted(SimpleLocation.getByBukkitLocation(block.getLocation()));
onBreakSomething(event.getPlayer(), block.getLocation(), block.getType().name(), event);
onPlaceVanilla(event.getPlayer(), block.getLocation(), block.getType().name(), event);
}
public void onPlaceVanilla(BlockPlaceEvent event) {
public void onBreakVanillaBlock(BlockBreakEvent event) {
if (event.isCancelled()) return;
Block block = event.getBlock();
onPlaceSomething(event.getPlayer(), block.getLocation(), block.getType().name(), event);
}
public void onBreakTripWire(Player player, Block block, String id, Cancellable event) {
if (event.isCancelled()) return;
onBreakSomething(player, block.getLocation(), id, event);
}
public void onBreakChorus(Player player, Block block, String id, CustomBlockBreakEvent event) {
if (event.isCancelled()) return;
onBreakSomething(player, block.getLocation(), id, event);
}
public void onBreakNoteBlock(Player player, Block block, String id, Cancellable event) {
if (event.isCancelled()) return;
onBreakSomething(player, block.getLocation(), id, event);
}
public void onBreakItemDisplay(Player player, Entity entity, String id, Cancellable event) {
if (event.isCancelled()) return;
onBreakSomething(player, entity.getLocation().getBlock().getLocation(), id, event);
}
public void onBreakItemFrame(Player player, Entity entity, String id, Cancellable event) {
if (event.isCancelled()) return;
onBreakSomething(player, entity.getLocation().getBlock().getLocation(), id, event);
if (block.getType() == Material.NOTE_BLOCK) {
SimpleLocation potLoc = SimpleLocation.getByBukkitLocation(block.getLocation());
plugin.getWorldDataManager().removeCorrupted(potLoc);
plugin.getWorldDataManager().removePotData(potLoc);
}
onBreakVanilla(event.getPlayer(), block.getLocation(), block.getType().name(), event);
}
public void onPlaceFurniture(Player player, Location location, String id, Cancellable event) {
if (event != null && event.isCancelled()) return;
onPlaceSomething(player, location, id, event);
onPlaceCustom(player, location, id, event);
}
public void onPlaceBlock(Player player, Location location, String id, Cancellable event) {
public void onBreakFurniture(Player player, Entity entity, String id, Cancellable event) {
if (event.isCancelled()) return;
onPlaceSomething(player, location, id, event);
onBreakCustom(player, entity.getLocation().getBlock().getLocation(), id, event);
}
public void onPlaceCustomBlock(Player player, Location location, String id, Cancellable event) {
if (event.isCancelled()) return;
onPlaceCustom(player, location, id, event);
}
public void onBreakCustomBlock(Player player, Location location, String id, Cancellable event) {
if (event.isCancelled()) return;
onBreakCustom(player, location, id, event);
}
public void onInteractBlock(PlayerInteractEvent event) {
@@ -144,6 +132,9 @@ public class PlatformManager extends Function {
Block block = event.getClickedBlock();
String id = plugin.getPlatformInterface().getBlockID(block);
assert block != null;
if (ConfigManager.enableCorruptionFixer && onInteractBrokenPot(id, block.getLocation())) {
return;
}
onInteractSomething(event.getPlayer(), block.getLocation(), id, event.getBlockFace(), event);
}
}
@@ -156,13 +147,10 @@ public class PlatformManager extends Function {
public void onInteractAir(Player player) {
ItemStack item_in_hand = player.getInventory().getItemInMainHand();
String id = plugin.getPlatformInterface().getItemStackID(item_in_hand);
if (onInteractWithWateringCan(player, id, item_in_hand, null, null)) {
return;
}
onInteractWithWateringCan(player, id, item_in_hand, null, null);
}
public void onBreakSomething(Player player, Location location, String id, Cancellable event) {
public void onBreakCustom(Player player, Location location, String id, Cancellable event) {
if (onBreakGlass(player, id, location, event)) {
return;
@@ -185,7 +173,18 @@ public class PlatformManager extends Function {
}
}
public void onPlaceSomething(Player player, Location location, String id, @Nullable Cancellable event) {
public void onBreakVanilla(Player player, Location location, String id, Cancellable event) {
if (onBreakGlass(player, id, location, event)) {
return;
}
if (onBreakPot(player, id, location, event)) {
return;
}
}
public void onPlaceCustom(Player player, Location location, String id, @Nullable Cancellable event) {
if (onPlaceGlass(player, id, location, event)) {
return;
@@ -200,6 +199,17 @@ public class PlatformManager extends Function {
}
}
public void onPlaceVanilla(Player player, Location location, String id, @Nullable Cancellable event) {
if (onPlaceGlass(player, id, location, event)) {
return;
}
if (onPlacePot(player, id, location, event)) {
return;
}
}
void onInteractSomething(Player player, Location location, String id, @Nullable BlockFace blockFace, Cancellable event) {
if (!plugin.getWorldDataManager().isWorldAllowed(location.getWorld())) {
@@ -228,16 +238,15 @@ public class PlatformManager extends Function {
return;
}
if (onInteractBrokenPot(id, location)) {
return;
}
if (onInteractWithWateringCan(player, item_in_hand_id, item_in_hand, id, location)) {
return;
}
}
}
/**
* Fix a pot if CustomCrops detected the location seems to be corrupted
*/
private boolean onInteractBrokenPot(String id, Location location) {
if (!id.equals("NOTE_BLOCK")) {
return false;
@@ -263,6 +272,10 @@ public class PlatformManager extends Function {
return true;
}
/**
* Fix the pots according to the range
* The scope of detection is to some extent determined by the scope of corruption
*/
public void furtherFix(Location location, int range) {
if (range >= ConfigManager.fixRange) return;
List<Location> locations = new ArrayList<>();
@@ -453,7 +466,6 @@ public class PlatformManager extends Function {
}
Sprinkler sprinkler = plugin.getWorldDataManager().getSprinklerData(SimpleLocation.getByBukkitLocation(location));
WaterAmountHologram waterAmountHologram = sprinklerConfig.getSprinklerHologram();
if (waterAmountHologram != null) {
String content;
@@ -923,19 +935,18 @@ public class PlatformManager extends Function {
CropConfig cropConfig = plugin.getCropManager().getCropConfigByStage(id);
if (cropConfig == null) return false;
// The entity might be other creatures when the pot is FARMLAND
// because of vanilla farmland mechanics
if (entity instanceof Player player) {
if (!canBreak(player, cropConfig, location)) {
event.setCancelled(true);
return true;
}
CropBreakEvent cropBreakEvent = new CropBreakEvent(entity, cropConfig, id, location);
Bukkit.getPluginManager().callEvent(cropBreakEvent);
if (cropBreakEvent.isCancelled()) {
return true;
}
if (player.getGameMode() != GameMode.CREATIVE) {
StageConfig stageConfig = plugin.getCropManager().getStageConfig(id);
if (stageConfig != null) {
@@ -948,13 +959,11 @@ public class PlatformManager extends Function {
}
}
} else {
CropBreakEvent cropBreakEvent = new CropBreakEvent(entity, cropConfig, id, location);
Bukkit.getPluginManager().callEvent(cropBreakEvent);
if (cropBreakEvent.isCancelled()) {
return true;
}
StageConfig stageConfig = plugin.getCropManager().getStageConfig(id);
if (stageConfig != null) {
Action[] breakActions = stageConfig.getBreakActions();
@@ -965,7 +974,6 @@ public class PlatformManager extends Function {
}
}
}
plugin.getWorldDataManager().removeCropData(SimpleLocation.getByBukkitLocation(location));
return true;
}

View File

@@ -20,8 +20,6 @@ package net.momirealms.customcrops.api.customplugin.itemsadder;
import dev.lone.itemsadder.api.Events.*;
import net.momirealms.customcrops.api.customplugin.Handler;
import net.momirealms.customcrops.api.customplugin.PlatformManager;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
public class ItemsAdderHandler extends Handler {
@@ -32,21 +30,12 @@ public class ItemsAdderHandler extends Handler {
@EventHandler
public void onBreakCustomBlock(CustomBlockBreakEvent event) {
Block block = event.getBlock();
switch (block.getType()) {
case NOTE_BLOCK -> platformManager.onBreakNoteBlock(event.getPlayer(), event.getBlock(), event.getNamespacedID(), event);
case TRIPWIRE -> platformManager.onBreakTripWire(event.getPlayer(), event.getBlock(), event.getNamespacedID(), event);
case CHORUS_PLANT -> platformManager.onBreakChorus(event.getPlayer(), event.getBlock(), event.getNamespacedID(), event);
}
platformManager.onBreakCustomBlock(event.getPlayer(), event.getBlock().getLocation(), event.getNamespacedID(), event);
}
@EventHandler
public void onBreakFurniture(FurnitureBreakEvent event) {
Entity entity = event.getBukkitEntity();
switch (entity.getType()) {
case ITEM_FRAME -> platformManager.onBreakItemFrame(event.getPlayer(), entity, event.getNamespacedID(), event);
case ITEM_DISPLAY -> platformManager.onBreakItemDisplay(event.getPlayer(), entity, event.getNamespacedID(), event);
}
platformManager.onBreakFurniture(event.getPlayer(), event.getBukkitEntity(), event.getNamespacedID(), event);
}
@EventHandler
@@ -56,7 +45,7 @@ public class ItemsAdderHandler extends Handler {
@EventHandler
public void onPlaceCustomBlock(CustomBlockPlaceEvent event) {
platformManager.onPlaceBlock(event.getPlayer(), event.getBlock().getLocation(), event.getNamespacedID(), event);
platformManager.onPlaceCustomBlock(event.getPlayer(), event.getBlock().getLocation(), event.getNamespacedID(), event);
}
@EventHandler

View File

@@ -34,22 +34,20 @@ public class OraxenHandler extends Handler {
@EventHandler
public void onBreakNoteBlock(OraxenNoteBlockBreakEvent event) {
platformManager.onBreakNoteBlock(event.getPlayer(), event.getBlock(), event.getMechanic().getItemID(), event);
platformManager.onBreakCustomBlock(event.getPlayer(), event.getBlock().getLocation(), event.getMechanic().getItemID(), event);
}
@EventHandler
public void onBreakStringBlock(OraxenStringBlockBreakEvent event) {
platformManager.onBreakTripWire(event.getPlayer(), event.getBlock(), event.getMechanic().getItemID(), event);
platformManager.onBreakCustomBlock(event.getPlayer(), event.getBlock().getLocation(), event.getMechanic().getItemID(), event);
}
@EventHandler
public void onBreakFurniture(OraxenFurnitureBreakEvent event) {
Entity entity = event.getBaseEntity();
// TODO Why entity would sometimes be null
if (entity == null) return;
switch (entity.getType()) {
case ITEM_FRAME -> platformManager.onBreakItemFrame(event.getPlayer(), entity, event.getMechanic().getItemID(), event);
case ITEM_DISPLAY -> platformManager.onBreakItemDisplay(event.getPlayer(), entity, event.getMechanic().getItemID(), event);
}
platformManager.onBreakFurniture(event.getPlayer(), entity, event.getMechanic().getItemID(), event);
}
@EventHandler
@@ -63,14 +61,15 @@ public class OraxenHandler extends Handler {
public void onPlaceStringBlock(OraxenStringBlockPlaceEvent event) {
StringBlockMechanic mechanic = event.getMechanic();
if (mechanic == null) return;
platformManager.onPlaceBlock(event.getPlayer(), event.getBlock().getLocation(), mechanic.getItemID(), event);
platformManager.onPlaceCustomBlock(event.getPlayer(), event.getBlock().getLocation(), mechanic.getItemID(), event);
}
@EventHandler
public void onPlaceNoteBlock(OraxenNoteBlockPlaceEvent event) {
NoteBlockMechanic mechanic = event.getMechanic();
// TODO Why mechanic would sometimes be null
if (mechanic == null) return;
platformManager.onPlaceBlock(event.getPlayer(), event.getBlock().getLocation(), mechanic.getItemID(), event);
platformManager.onPlaceCustomBlock(event.getPlayer(), event.getBlock().getLocation(), mechanic.getItemID(), event);
}
@EventHandler

View File

@@ -79,6 +79,7 @@ public class OraxenPluginImpl implements PlatformInterface {
return itemFrame;
else {
AdventureUtils.consoleMessage("<red>[CustomCrops] ItemFrame not exists: " + id);
// use oraxen method to remove sub entities
OraxenFurniture.remove(entity, null);
return null;
}
@@ -97,6 +98,7 @@ public class OraxenPluginImpl implements PlatformInterface {
return itemDisplay;
else {
AdventureUtils.consoleMessage("<red>[CustomCrops] ItemDisplay not exists: " + id);
// use oraxen method to remove sub entities
OraxenFurniture.remove(entity, null);
return null;
}

View File

@@ -41,7 +41,8 @@ public class ConfigManager extends Function {
public static boolean whiteListWorlds;
public static HashSet<String> worldList;
public static String worldFolderPath;
public static boolean debug;
public static boolean debugScheduler;
public static boolean debugCorruption;
public static String greenhouseBlock;
public static String scarecrow;
public static boolean enableGreenhouse;
@@ -66,6 +67,7 @@ public class ConfigManager extends Function {
public static boolean disableMoistureMechanic;
public static boolean preventTrampling;
public static boolean onlyInLoadedChunks;
public static boolean enableCorruptionFixer;
private final HashMap<String, Integer> cropPerWorld;
private final CustomCrops plugin;
@@ -92,7 +94,8 @@ public class ConfigManager extends Function {
YamlConfiguration config = ConfigUtils.getConfig("config.yml");
enableBStats = config.getBoolean("metrics");
lang = config.getString("lang");
debug = config.getBoolean("debug");
debugScheduler = config.getBoolean("debug.log-scheduler", false);
debugCorruption = config.getBoolean("debug.log-corruption-fixer", false);
loadWorlds(Objects.requireNonNull(config.getConfigurationSection("worlds")));
loadOptimization(Objects.requireNonNull(config.getConfigurationSection("optimization")));
loadScheduleSystem(Objects.requireNonNull(config.getConfigurationSection("schedule-system")));
@@ -149,6 +152,7 @@ public class ConfigManager extends Function {
private void loadOtherSetting(ConfigurationSection section) {
enableSkillBonus = section.getBoolean("skill-bonus.enable", false);
bonusFormula = section.getString("skill-bonus.formula");
enableCorruptionFixer = section.getBoolean("enable-corruption-fixer", true);
fixRange = section.getInt("corrupt-fix-range", 4);
}

View File

@@ -233,7 +233,7 @@ public class CCWorld extends Function {
this.timerTask = plugin.getScheduler().runTaskTimerAsync(() -> {
World current = world.get();
if (current != null) {
if (ConfigManager.debug) {
if (ConfigManager.debugScheduler) {
Log.info("Queue size: " + schedule.getQueue().size() + " Completed: " + schedule.getCompletedTaskCount());
}
long day = current.getFullTime() / 24000;
@@ -259,7 +259,7 @@ public class CCWorld extends Function {
if (ConfigManager.cacheSaveInterval != -1) {
cacheTimer--;
if (cacheTimer <= 0) {
if (ConfigManager.debug) Log.info("== Save cache ==");
if (ConfigManager.debugScheduler) Log.info("== Save cache ==");
cacheTimer = ConfigManager.cacheSaveInterval;
schedule.execute(this::saveDateData);
schedule.execute(this::saveCorruptedPots);
@@ -278,12 +278,12 @@ public class CCWorld extends Function {
public void onReachPoint() {
if (ConfigManager.enableScheduleSystem) {
if (ConfigManager.debug) Log.info("== Grow point ==");
if (ConfigManager.debugScheduler) Log.info("== Grow point ==");
plantInPoint.clear();
int size = schedule.getQueue().size();
if (size != 0) {
schedule.getQueue().clear();
if (ConfigManager.debug) Log.info("== Clear queue ==");
if (ConfigManager.debugScheduler) Log.info("== Clear queue ==");
}
for (CCChunk chunk : chunkMap.values()) {
chunk.scheduleGrowTask(this, -1);
@@ -296,12 +296,12 @@ public class CCWorld extends Function {
}
if (consumeCounter == 0) {
consumeCounter = ConfigManager.intervalConsume;
if (ConfigManager.debug) Log.info("== Consume time ==");
if (ConfigManager.debugScheduler) Log.info("== Consume time ==");
scheduleConsumeTask(-1);
}
if (workCounter == 0) {
workCounter = ConfigManager.intervalWork;
if (ConfigManager.debug) Log.info("== Work time ==");
if (ConfigManager.debugScheduler) Log.info("== Work time ==");
scheduleSprinklerWork(-1);
}
}
@@ -443,13 +443,26 @@ public class CCWorld extends Function {
CompletableFuture<Chunk> asyncGetChunk = location.getWorld().getChunkAtAsync(location.getBlockX() >> 4, location.getBlockZ() >> 4);
asyncGetChunk.whenComplete((result, throwable) ->
plugin.getScheduler().runTask(() -> {
if (!plugin.getPlatformInterface().removeAnyBlock(location)) {
plugin.getWorldDataManager().removePotData(simpleLocation);
Block block = location.getBlock();
if (block.getType() == Material.AIR) {
removePotData(simpleLocation);
return;
}
String replacer = wet ? potConfig.getWetPot(fertilizer) : potConfig.getDryPot(fertilizer);
String id = plugin.getPlatformInterface().getBlockID(block);
if (ConfigManager.enableCorruptionFixer && id.equals("NOTE_BLOCK")) {
plugin.getPlatformInterface().placeNoteBlock(location, replacer);
return;
}
String potKey = plugin.getPotManager().getPotKeyByBlockID(id);
if (potKey == null) {
removePotData(simpleLocation);
return;
}
if (potKey.equals(pot.getPotKey())) {
return;
}
if (ConfigUtils.isVanillaItem(replacer)) {
Block block = location.getBlock();
block.setType(Material.valueOf(replacer));
if (block.getBlockData() instanceof Farmland farmland && ConfigManager.disableMoistureMechanic) {
farmland.setMoisture(wet ? farmland.getMaximumMoisture() : 0);
@@ -546,15 +559,12 @@ public class CCWorld extends Function {
} else {
addWaterToPot(simpleLocation, amount, potKey);
}
} else if (blockID.equals("NOTE_BLOCK")) {
} else if (ConfigManager.enableCorruptionFixer && blockID.equals("NOTE_BLOCK")) {
// Only ItemsAdder can go to this step
Pot pot = getPotData(simpleLocation);
if (pot != null) {
// mark it as glitched
// mark it as corrupted
potKey = pot.getPotKey();
corruptedPot.put(simpleLocation, potKey);
if (ConfigManager.debug) AdventureUtils.consoleMessage("[CustomCrops] Trying to fix corrupted pot found at: " + simpleLocation);
if (whitelist == null) {
pot.addWater(amount);
} else {
@@ -565,21 +575,12 @@ public class CCWorld extends Function {
}
}
}
corruptedPot.put(simpleLocation, potKey);
if (ConfigManager.debugCorruption) AdventureUtils.consoleMessage("[CustomCrops] Trying to fix corrupted pot found at: " + simpleLocation);
// only custom blocks would corrupt
String replacer = pot.getConfig().getWetPot(pot.getFertilizer());
// so it's not necessary to check if the pot is a vanilla block
String replacer = pot.isWet() ? pot.getConfig().getWetPot(pot.getFertilizer()) : pot.getConfig().getDryPot(pot.getFertilizer());
plugin.getPlatformInterface().placeNoteBlock(location, replacer);
} else {
potKey = corruptedPot.get(simpleLocation);
if (potKey != null) {
PotConfig potConfig = plugin.getPotManager().getPotConfig(potKey);
if (potConfig != null) {
String replacer = potConfig.getDryPot(null);
plugin.getPlatformInterface().placeNoteBlock(location, replacer);
} else {
corruptedPot.remove(simpleLocation);
}
}
}
}
}
@@ -627,7 +628,7 @@ public class CCWorld extends Function {
}
int points = 1;
Pot pot = plugin.getWorldDataManager().getPotData(simpleLocation.add(0,-1,0));
Pot pot = getPotData(simpleLocation.add(0,-1,0));
if (pot != null) {
FertilizerConfig fertilizerConfig = plugin.getFertilizerManager().getConfigByFertilizer(pot.getFertilizer());
if (fertilizerConfig instanceof SpeedGrow speedGrow) {

View File

@@ -24,19 +24,13 @@ import org.bukkit.entity.Player;
public class EcoSkillsImpl implements SkillInterface {
public EcoSkillsAPI ecoSkillsAPI;
public EcoSkillsImpl() {
ecoSkillsAPI = EcoSkillsAPI.getInstance();
}
@Override
public void addXp(Player player, double amount) {
ecoSkillsAPI.giveSkillExperience(player, Skills.FARMING, amount);
EcoSkillsAPI.giveSkillXP(player, Skills.INSTANCE.getByID("farming"), amount);
}
@Override
public int getLevel(Player player) {
return ecoSkillsAPI.getSkillLevel(player, Skills.FISHING);
return EcoSkillsAPI.getSkillLevel(player, Skills.INSTANCE.getByID("farming"));
}
}

View File

@@ -1,11 +1,13 @@
# Don't change
config-version: '31'
config-version: '32'
# BStats
metrics: true
# Language: english / spanish / chinese / turkish
lang: english
# debug
debug: false
debug:
log-scheduler: false
log-corruption-fixer: false
worlds:
# This is designed for servers that using a separate folder for worlds
@@ -114,5 +116,7 @@ other-settings:
# MMOCore profession name
# MMOCore职业名
MMOCore-profession-name: 'farmer'
# Enable corruption fixer
enable-corruption-fixer: true
# Fixed corrupted pots when interacting
corrupt-fix-range: 4