mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-26 10:29:10 +00:00
3.4.3.1
This commit is contained in:
@@ -24,6 +24,7 @@ import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import net.momirealms.customcrops.api.CustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.common.Initable;
|
||||
import net.momirealms.customcrops.api.integration.SeasonInterface;
|
||||
import net.momirealms.customcrops.api.manager.ConfigManager;
|
||||
import net.momirealms.customcrops.api.manager.MessageManager;
|
||||
import net.momirealms.customcrops.api.mechanic.item.ItemType;
|
||||
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
||||
@@ -186,7 +187,12 @@ public class CommandManager implements Initable {
|
||||
plugin.getAdventure().sendMessageWithPrefix(sender, MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeason(world)));
|
||||
}),
|
||||
new CommandAPICommand("set")
|
||||
.withArguments(new StringArgument("world").replaceSuggestions(ArgumentSuggestions.strings(commandSenderSuggestionInfo -> Bukkit.getWorlds().stream().map(WorldInfo::getName).toList().toArray(new String[0]))))
|
||||
.withArguments(new StringArgument("world").replaceSuggestions(ArgumentSuggestions.strings(commandSenderSuggestionInfo -> {
|
||||
if (ConfigManager.syncSeasons()) {
|
||||
return new String[]{ConfigManager.referenceWorld().getName()};
|
||||
}
|
||||
return Bukkit.getWorlds().stream().map(WorldInfo::getName).toList().toArray(new String[0]);
|
||||
})))
|
||||
.withArguments(new StringArgument("season")
|
||||
.replaceSuggestions(ArgumentSuggestions.stringsWithTooltips(info ->
|
||||
new IStringTooltip[] {
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -74,7 +75,7 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor {
|
||||
public void unload(CustomCropsWorld customCropsWorld) {
|
||||
World world = customCropsWorld.getWorld();
|
||||
if (world != null) {
|
||||
new File(world.getWorldFolder(), "customcrops").mkdir();
|
||||
getWorldFolder(world).mkdir();
|
||||
customCropsWorld.save();
|
||||
}
|
||||
}
|
||||
@@ -88,8 +89,17 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor {
|
||||
return;
|
||||
}
|
||||
|
||||
world.getPersistentDataContainer().set(key, PersistentDataType.STRING,
|
||||
gson.toJson(cWorld.getInfoData()));
|
||||
try {
|
||||
world.getPersistentDataContainer().set(key, PersistentDataType.STRING,
|
||||
gson.toJson(cWorld.getInfoData()));
|
||||
} catch (Exception e) {
|
||||
// handle exceptions for those servers without pdc
|
||||
try (FileWriter file = new FileWriter(new File(getWorldFolder(world), "cworld.dat"))) {
|
||||
gson.toJson(cWorld.getInfoData(), file);
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,10 +120,26 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor {
|
||||
return;
|
||||
}
|
||||
|
||||
// init world basic info
|
||||
String json = world.getPersistentDataContainer().get(key, PersistentDataType.STRING);
|
||||
WorldInfoData data = (json == null || json.equals("null")) ? WorldInfoData.empty() : gson.fromJson(json, WorldInfoData.class);
|
||||
cWorld.setInfoData(data);
|
||||
try {
|
||||
// init world basic info
|
||||
String json = world.getPersistentDataContainer().get(key, PersistentDataType.STRING);
|
||||
WorldInfoData data = (json == null || json.equals("null")) ? WorldInfoData.empty() : gson.fromJson(json, WorldInfoData.class);
|
||||
cWorld.setInfoData(data);
|
||||
} catch (Exception e) {
|
||||
File cWorldFile = new File(getWorldFolder(world), "cworld.dat");
|
||||
if (cWorldFile.exists()) {
|
||||
byte[] fileBytes = new byte[(int) cWorldFile.length()];
|
||||
try (FileInputStream fis = new FileInputStream(cWorldFile)) {
|
||||
fis.read(fileBytes);
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
String jsonContent = new String(fileBytes, StandardCharsets.UTF_8);
|
||||
cWorld.setInfoData(gson.fromJson(jsonContent, WorldInfoData.class));
|
||||
} else {
|
||||
cWorld.setInfoData(WorldInfoData.empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -285,6 +311,14 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor {
|
||||
}
|
||||
}
|
||||
|
||||
private File getWorldFolder(World world) {
|
||||
if (worldFolder.isEmpty()) {
|
||||
return new File(world.getWorldFolder(), "customcrops");
|
||||
} else {
|
||||
return new File(worldFolder, world.getName() + File.separator + "customcrops");
|
||||
}
|
||||
}
|
||||
|
||||
public void setWorldFolder(String folder) {
|
||||
this.worldFolder = folder;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ worlds:
|
||||
mode: RANDOM_TICK
|
||||
tick-interval: 1
|
||||
# Limit the max amount of crops in one chunk
|
||||
max-per-chunk: 150
|
||||
max-per-chunk: 256
|
||||
# Settings for pots
|
||||
pot:
|
||||
# RANDOM_TICK / SCHEDULED_TICK
|
||||
@@ -71,7 +71,7 @@ worlds:
|
||||
mode: SCHEDULED_TICK
|
||||
tick-interval: 2
|
||||
# Limit the max amount of sprinklers in one chunk
|
||||
max-per-chunk: 20
|
||||
max-per-chunk: 64
|
||||
# You can override the default settings for worlds here
|
||||
_WORLDS_:
|
||||
world_nether:
|
||||
|
||||
Reference in New Issue
Block a user