mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-21 16:09:21 +00:00
world settings
This commit is contained in:
@@ -49,7 +49,7 @@ public class ConfigManagerImpl extends ConfigManager {
|
|||||||
private boolean metrics;
|
private boolean metrics;
|
||||||
private boolean legacyColorSupport;
|
private boolean legacyColorSupport;
|
||||||
private boolean protectLore;
|
private boolean protectLore;
|
||||||
private String[] itemDetectionOrder;
|
private String[] itemDetectionOrder = new String[0];
|
||||||
private boolean checkUpdate;
|
private boolean checkUpdate;
|
||||||
private boolean disableMoisture;
|
private boolean disableMoisture;
|
||||||
private boolean preventTrampling;
|
private boolean preventTrampling;
|
||||||
|
|||||||
@@ -450,8 +450,10 @@ public class ActionManagerImpl implements ActionManager {
|
|||||||
private void registerVariationAction() {
|
private void registerVariationAction() {
|
||||||
registerAction("variation", (args, chance) -> {
|
registerAction("variation", (args, chance) -> {
|
||||||
if (args instanceof ConfigurationSection section) {
|
if (args instanceof ConfigurationSection section) {
|
||||||
|
boolean ignore = section.getBoolean("ignore-fertilizer", false);
|
||||||
ArrayList<VariationCrop> variationCrops = new ArrayList<>();
|
ArrayList<VariationCrop> variationCrops = new ArrayList<>();
|
||||||
for (String inner_key : section.getKeys(false)) {
|
for (String inner_key : section.getKeys(false)) {
|
||||||
|
if (inner_key.equals("ignore-fertilizer")) continue;
|
||||||
VariationCrop variationCrop = new VariationCrop(
|
VariationCrop variationCrop = new VariationCrop(
|
||||||
section.getString(inner_key + ".item"),
|
section.getString(inner_key + ".item"),
|
||||||
ItemCarrier.valueOf(section.getString(inner_key + ".type", "TripWire").toUpperCase(Locale.ENGLISH)),
|
ItemCarrier.valueOf(section.getString(inner_key + ".type", "TripWire").toUpperCase(Locale.ENGLISH)),
|
||||||
@@ -463,6 +465,7 @@ public class ActionManagerImpl implements ActionManager {
|
|||||||
return state -> {
|
return state -> {
|
||||||
if (Math.random() > chance) return;
|
if (Math.random() > chance) return;
|
||||||
double bonus = 0;
|
double bonus = 0;
|
||||||
|
if (!ignore) {
|
||||||
Optional<WorldPot> pot = plugin.getWorldManager().getPotAt(SimpleLocation.of(state.getLocation().clone().subtract(0,1,0)));
|
Optional<WorldPot> pot = plugin.getWorldManager().getPotAt(SimpleLocation.of(state.getLocation().clone().subtract(0,1,0)));
|
||||||
if (pot.isPresent()) {
|
if (pot.isPresent()) {
|
||||||
Fertilizer fertilizer = pot.get().getFertilizer();
|
Fertilizer fertilizer = pot.get().getFertilizer();
|
||||||
@@ -470,6 +473,7 @@ public class ActionManagerImpl implements ActionManager {
|
|||||||
bonus += variation.getChanceBonus();
|
bonus += variation.getChanceBonus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (VariationCrop variationCrop : variations) {
|
for (VariationCrop variationCrop : variations) {
|
||||||
if (Math.random() < variationCrop.getChance() + bonus) {
|
if (Math.random() < variationCrop.getChance() + bonus) {
|
||||||
plugin.getItemManager().removeAnythingAt(state.getLocation());
|
plugin.getItemManager().removeAnythingAt(state.getLocation());
|
||||||
@@ -638,11 +642,14 @@ public class ActionManagerImpl implements ActionManager {
|
|||||||
crop.trigger(ActionTrigger.REACH_LIMIT, state);
|
crop.trigger(ActionTrigger.REACH_LIMIT, state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
plugin.getScheduler().runTaskSync(() -> {
|
||||||
// fire event
|
// fire event
|
||||||
|
if (state.getPlayer() != null) {
|
||||||
CropPlantEvent plantEvent = new CropPlantEvent(state.getPlayer(), state.getItemInHand(), location, crop, 0);
|
CropPlantEvent plantEvent = new CropPlantEvent(state.getPlayer(), state.getItemInHand(), location, crop, 0);
|
||||||
if (EventUtils.fireAndCheckCancel(plantEvent)) {
|
if (EventUtils.fireAndCheckCancel(plantEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// place the crop
|
// place the crop
|
||||||
switch (crop.getItemCarrier()) {
|
switch (crop.getItemCarrier()) {
|
||||||
case ITEM_FRAME, ITEM_DISPLAY, TRIPWIRE -> plugin.getItemManager().placeItem(location, crop.getItemCarrier(), crop.getStageItemByPoint(point));
|
case ITEM_FRAME, ITEM_DISPLAY, TRIPWIRE -> plugin.getItemManager().placeItem(location, crop.getItemCarrier(), crop.getStageItemByPoint(point));
|
||||||
@@ -652,6 +659,7 @@ public class ActionManagerImpl implements ActionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
plugin.getWorldManager().addCropAt(new MemoryCrop(SimpleLocation.of(location), crop.getKey(), point), SimpleLocation.of(location));
|
plugin.getWorldManager().addCropAt(new MemoryCrop(SimpleLocation.of(location), crop.getKey(), point), SimpleLocation.of(location));
|
||||||
|
}, state.getLocation());
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
LogUtils.warn("Illegal value format found at action: " + name);
|
LogUtils.warn("Illegal value format found at action: " + name);
|
||||||
@@ -666,6 +674,7 @@ public class ActionManagerImpl implements ActionManager {
|
|||||||
boolean arg = (boolean) (args == null ? true : args);
|
boolean arg = (boolean) (args == null ? true : args);
|
||||||
return state -> {
|
return state -> {
|
||||||
if (Math.random() > chance) return;
|
if (Math.random() > chance) return;
|
||||||
|
plugin.getScheduler().runTaskSync(() -> {
|
||||||
Optional<CustomCropsBlock> removed = plugin.getWorldManager().getBlockAt(SimpleLocation.of(state.getLocation()));
|
Optional<CustomCropsBlock> removed = plugin.getWorldManager().getBlockAt(SimpleLocation.of(state.getLocation()));
|
||||||
if (removed.isPresent()) {
|
if (removed.isPresent()) {
|
||||||
switch (removed.get().getType()) {
|
switch (removed.get().getType()) {
|
||||||
@@ -704,6 +713,7 @@ public class ActionManagerImpl implements ActionManager {
|
|||||||
} else {
|
} else {
|
||||||
plugin.getItemManager().removeAnythingAt(state.getLocation());
|
plugin.getItemManager().removeAnythingAt(state.getLocation());
|
||||||
}
|
}
|
||||||
|
}, state.getLocation());
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,10 +41,7 @@ import org.bukkit.event.world.ChunkLoadEvent;
|
|||||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class WorldManagerImpl implements WorldManager, Listener {
|
public class WorldManagerImpl implements WorldManager, Listener {
|
||||||
@@ -89,6 +86,7 @@ public class WorldManagerImpl implements WorldManager, Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void unload() {
|
public void unload() {
|
||||||
this.unregisterListener();
|
this.unregisterListener();
|
||||||
|
this.worldSettingMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -130,13 +128,21 @@ public class WorldManagerImpl implements WorldManager, Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigurationSection defaultSchedulerSection = settingSection.getConfigurationSection("_DEFAULT_");
|
ConfigurationSection defaultSection = settingSection.getConfigurationSection("_DEFAULT_");
|
||||||
if (defaultSchedulerSection == null) {
|
if (defaultSection == null) {
|
||||||
LogUtils.severe("worlds.settings._DEFAULT_ section should not be null");
|
LogUtils.severe("worlds.settings._DEFAULT_ section should not be null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.defaultWorldSetting = ConfigUtils.getWorldSettingFromSection(defaultSchedulerSection);
|
this.defaultWorldSetting = ConfigUtils.getWorldSettingFromSection(defaultSection);
|
||||||
|
ConfigurationSection worldSection = settingSection.getConfigurationSection("_WORLDS_");
|
||||||
|
if (worldSection != null) {
|
||||||
|
for (Map.Entry<String, Object> entry : worldSection.getValues(false).entrySet()) {
|
||||||
|
if (entry.getValue() instanceof ConfigurationSection inner) {
|
||||||
|
this.worldSettingMap.put(entry.getKey(), ConfigUtils.getWorldSettingFromSection(inner));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerListener() {
|
private void registerListener() {
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ update-checker: true
|
|||||||
# Language
|
# Language
|
||||||
lang: english
|
lang: english
|
||||||
|
|
||||||
# NOTE: This section requires a restart to apply
|
# World settings
|
||||||
# NOTE: This section requires a restart to apply
|
|
||||||
# NOTE: This section requires a restart to apply
|
|
||||||
worlds:
|
worlds:
|
||||||
# This is designed for servers that using an independent folder for worlds
|
# This is designed for servers that using an independent folder for worlds
|
||||||
# Especially for realm systems
|
# Especially for realm systems
|
||||||
@@ -74,16 +72,6 @@ worlds:
|
|||||||
tick-interval: 2
|
tick-interval: 2
|
||||||
# Limit the max amount of sprinklers in one chunk
|
# Limit the max amount of sprinklers in one chunk
|
||||||
max-per-chunk: 20
|
max-per-chunk: 20
|
||||||
# Offline growth is a special mode for crops
|
|
||||||
# Take server performance into account, enabling this option will not load the unloaded chunks
|
|
||||||
# On the contrary, CustomCrops get how long crops have grown by comparing the unload and load timestamps
|
|
||||||
offline-growth:
|
|
||||||
enable: false
|
|
||||||
# Maximum offline time recorded in seconds
|
|
||||||
# Please do not set this option to a value that is too large,
|
|
||||||
# as it may cause chunks that have been unloaded for a long time
|
|
||||||
# to consume too much server performance during loading
|
|
||||||
max-offline-seconds: 1200
|
|
||||||
# You can override the default settings for worlds here
|
# You can override the default settings for worlds here
|
||||||
_WORLDS_:
|
_WORLDS_:
|
||||||
world_nether:
|
world_nether:
|
||||||
|
|||||||
Reference in New Issue
Block a user