mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 18:09:28 +00:00
3.0.7
This commit is contained in:
@@ -32,7 +32,7 @@ public class InteractCrop {
|
||||
private final Action[] actions;
|
||||
private final Requirement[] requirements;
|
||||
|
||||
public InteractCrop(@NotNull String id, boolean consume, @Nullable String returned, @Nullable Action[] actions, @Nullable Requirement[] requirements) {
|
||||
public InteractCrop(@Nullable String id, boolean consume, @Nullable String returned, @Nullable Action[] actions, @Nullable Requirement[] requirements) {
|
||||
this.consume = consume;
|
||||
this.id = id;
|
||||
this.returned = returned;
|
||||
@@ -41,6 +41,7 @@ public class InteractCrop {
|
||||
}
|
||||
|
||||
public boolean isRightItem(String item) {
|
||||
if (id == null || id.equals("*")) return true;
|
||||
return item.equals(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,13 @@ package net.momirealms.customcrops.api.object.condition;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.object.ItemMode;
|
||||
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class DeathCondition {
|
||||
|
||||
private final String dead_model;
|
||||
@@ -46,12 +49,32 @@ public class DeathCondition {
|
||||
public void applyDeadModel(SimpleLocation simpleLocation, ItemMode itemMode) {
|
||||
Location location = simpleLocation.getBukkitLocation();
|
||||
if (location == null) return;
|
||||
CustomCrops.getInstance().getScheduler().callSyncMethod(() -> {
|
||||
CustomCrops.getInstance().getPlatformInterface().removeCustomItem(location, itemMode);
|
||||
if (dead_model != null) {
|
||||
CustomCrops.getInstance().getPlatformInterface().placeCustomItem(location, dead_model, itemMode);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
CompletableFuture<Chunk> asyncGetChunk = location.getWorld().getChunkAtAsync(location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
if (itemMode == ItemMode.ITEM_FRAME || itemMode == ItemMode.ITEM_DISPLAY) {
|
||||
CompletableFuture<Boolean> loadEntities = asyncGetChunk.thenApply((chunk) -> {
|
||||
chunk.getEntities();
|
||||
return chunk.isEntitiesLoaded();
|
||||
});
|
||||
loadEntities.whenComplete((result, throwable) ->
|
||||
CustomCrops.getInstance().getScheduler().callSyncMethod(() -> {
|
||||
if (CustomCrops.getInstance().getPlatformInterface().removeCustomItem(location, itemMode)) {
|
||||
if (dead_model != null) {
|
||||
CustomCrops.getInstance().getPlatformInterface().placeCustomItem(location, dead_model, itemMode);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
else {
|
||||
asyncGetChunk.whenComplete((result, throwable) ->
|
||||
CustomCrops.getInstance().getScheduler().callSyncMethod(() -> {
|
||||
if (CustomCrops.getInstance().getPlatformInterface().removeCustomItem(location, itemMode)) {
|
||||
if (dead_model != null) {
|
||||
CustomCrops.getInstance().getPlatformInterface().placeCustomItem(location, dead_model, itemMode);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,43 +134,65 @@ public class AdventureUtils {
|
||||
au.playSound(sound);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace the legacy codes with MiniMessage Format
|
||||
* @param str text
|
||||
* @return MiniMessage format text
|
||||
*/
|
||||
public static String replaceLegacy(String str) {
|
||||
public static String replaceLegacy(String legacy) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
char[] chars = str.replace("&","§").toCharArray();
|
||||
char[] chars = legacy.toCharArray();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
if (chars[i] == '§') {
|
||||
if (isColorCode(chars[i])) {
|
||||
if (i + 1 < chars.length) {
|
||||
switch (chars[i+1]) {
|
||||
case '0' -> {i++;stringBuilder.append("<black>");}
|
||||
case '1' -> {i++;stringBuilder.append("<dark_blue>");}
|
||||
case '2' -> {i++;stringBuilder.append("<dark_green>");}
|
||||
case '3' -> {i++;stringBuilder.append("<dark_aqua>");}
|
||||
case '4' -> {i++;stringBuilder.append("<dark_red>");}
|
||||
case '5' -> {i++;stringBuilder.append("<dark_purple>");}
|
||||
case '6' -> {i++;stringBuilder.append("<gold>");}
|
||||
case '7' -> {i++;stringBuilder.append("<gray>");}
|
||||
case '8' -> {i++;stringBuilder.append("<dark_gray>");}
|
||||
case '9' -> {i++;stringBuilder.append("<blue>");}
|
||||
case 'a' -> {i++;stringBuilder.append("<green>");}
|
||||
case 'b' -> {i++;stringBuilder.append("<aqua>");}
|
||||
case 'c' -> {i++;stringBuilder.append("<red>");}
|
||||
case 'd' -> {i++;stringBuilder.append("<light_purple>");}
|
||||
case 'e' -> {i++;stringBuilder.append("<yellow>");}
|
||||
case 'f' -> {i++;stringBuilder.append("<white>");}
|
||||
case 'r' -> {i++;stringBuilder.append("<reset><!italic>");}
|
||||
case 'l' -> {i++;stringBuilder.append("<bold>");}
|
||||
case 'm' -> {i++;stringBuilder.append("<strikethrough>");}
|
||||
case 'o' -> {i++;stringBuilder.append("<italic>");}
|
||||
case 'n' -> {i++;stringBuilder.append("<underlined>");}
|
||||
case 'k' -> {i++;stringBuilder.append("<obfuscated>");}
|
||||
case 'x' -> {stringBuilder.append("<#").append(chars[i+3]).append(chars[i+5]).append(chars[i+7]).append(chars[i+9]).append(chars[i+11]).append(chars[i+13]).append(">");i += 13;}
|
||||
case '0' -> stringBuilder.append("<black>");
|
||||
case '1' -> stringBuilder.append("<dark_blue>");
|
||||
case '2' -> stringBuilder.append("<dark_green>");
|
||||
case '3' -> stringBuilder.append("<dark_aqua>");
|
||||
case '4' -> stringBuilder.append("<dark_red>");
|
||||
case '5' -> stringBuilder.append("<dark_purple>");
|
||||
case '6' -> stringBuilder.append("<gold>");
|
||||
case '7' -> stringBuilder.append("<gray>");
|
||||
case '8' -> stringBuilder.append("<dark_gray>");
|
||||
case '9' -> stringBuilder.append("<blue>");
|
||||
case 'a' -> stringBuilder.append("<green>");
|
||||
case 'b' -> stringBuilder.append("<aqua>");
|
||||
case 'c' -> stringBuilder.append("<red>");
|
||||
case 'd' -> stringBuilder.append("<light_purple>");
|
||||
case 'e' -> stringBuilder.append("<yellow>");
|
||||
case 'f' -> stringBuilder.append("<white>");
|
||||
case 'r' -> stringBuilder.append("<reset><!italic>");
|
||||
case 'l' -> stringBuilder.append("<bold>");
|
||||
case 'm' -> stringBuilder.append("<strikethrough>");
|
||||
case 'o' -> stringBuilder.append("<italic>");
|
||||
case 'n' -> stringBuilder.append("<underlined>");
|
||||
case 'k' -> stringBuilder.append("<obfuscated>");
|
||||
case 'x' -> {
|
||||
if (i + 13 >= chars.length
|
||||
|| !isColorCode(chars[i+2])
|
||||
|| !isColorCode(chars[i+4])
|
||||
|| !isColorCode(chars[i+6])
|
||||
|| !isColorCode(chars[i+8])
|
||||
|| !isColorCode(chars[i+10])
|
||||
|| !isColorCode(chars[i+12])) {
|
||||
stringBuilder.append(chars[i]);
|
||||
continue;
|
||||
}
|
||||
stringBuilder
|
||||
.append("<#")
|
||||
.append(chars[i+3])
|
||||
.append(chars[i+5])
|
||||
.append(chars[i+7])
|
||||
.append(chars[i+9])
|
||||
.append(chars[i+11])
|
||||
.append(chars[i+13])
|
||||
.append(">");
|
||||
i += 13;
|
||||
}
|
||||
default -> {
|
||||
stringBuilder.append(chars[i]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
stringBuilder.append(chars[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -179,4 +201,8 @@ public class AdventureUtils {
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private static boolean isColorCode(char c) {
|
||||
return c == '§' || c == '&';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,8 +176,14 @@ public class ConfigUtils {
|
||||
switch (type) {
|
||||
case "water_less_than" -> conditions.add(new WaterLessThan(map2.getInt("value")));
|
||||
case "water_more_than" -> conditions.add(new WaterMoreThan(map2.getInt("value")));
|
||||
case "unsuitable_season" -> conditions.add(new WrongSeason(map2.getStringList("value").stream().map(s -> CCSeason.valueOf(s.toUpperCase())).toList().toArray(new CCSeason[0])));
|
||||
case "suitable_season" -> conditions.add(new RightSeason(map2.getStringList("value").stream().map(s -> CCSeason.valueOf(s.toUpperCase())).toList().toArray(new CCSeason[0])));
|
||||
case "unsuitable_season" -> {
|
||||
if (!ConfigManager.enableSeason) return;
|
||||
conditions.add(new WrongSeason(map2.getStringList("value").stream().map(s -> CCSeason.valueOf(s.toUpperCase())).toList().toArray(new CCSeason[0])));
|
||||
}
|
||||
case "suitable_season" -> {
|
||||
if (!ConfigManager.enableSeason) return;
|
||||
conditions.add(new RightSeason(map2.getStringList("value").stream().map(s -> CCSeason.valueOf(s.toUpperCase())).toList().toArray(new CCSeason[0])));
|
||||
}
|
||||
case "crow_attack" -> conditions.add(new CrowAttack(map2.getDouble("value.chance"), map2.getString("value.fly-model"), map2.getString("value.stand-model")));
|
||||
case "random" -> conditions.add(new Random(map2.getDouble("value")));
|
||||
}
|
||||
@@ -201,7 +207,10 @@ public class ConfigUtils {
|
||||
case "biome" -> requirements.add(new BiomeImpl(msg, new HashSet<>(innerSec.getStringList("value"))));
|
||||
case "weather" -> requirements.add(new WeatherImpl(msg, innerSec.getStringList("value")));
|
||||
case "ypos" -> requirements.add(new YPosImpl(msg, innerSec.getStringList("value")));
|
||||
case "season" -> requirements.add(new SeasonImpl(msg, innerSec.getStringList("value").stream().map(str -> CCSeason.valueOf(str.toUpperCase())).collect(Collectors.toList())));
|
||||
case "season" -> {
|
||||
if (!ConfigManager.enableSeason) continue;
|
||||
requirements.add(new SeasonImpl(msg, innerSec.getStringList("value").stream().map(str -> CCSeason.valueOf(str.toUpperCase())).collect(Collectors.toList())));
|
||||
}
|
||||
case "world" -> requirements.add(new WorldImpl(msg, innerSec.getStringList("value")));
|
||||
case "permission" -> requirements.add(new PermissionImpl(msg, innerSec.getString("value")));
|
||||
case "time" -> requirements.add(new TimeImpl(msg, innerSec.getStringList("value")));
|
||||
@@ -439,7 +448,7 @@ public class ConfigUtils {
|
||||
ConfigurationSection innerSec = section.getConfigurationSection(key);
|
||||
if (innerSec == null) continue;
|
||||
InteractCrop interactCrop = new InteractCrop(
|
||||
innerSec.getString("item", "AIR"),
|
||||
innerSec.getString("item"),
|
||||
innerSec.getBoolean("reduce-amount", false),
|
||||
innerSec.getString("return"),
|
||||
getActions(innerSec.getConfigurationSection("actions"), stageModel),
|
||||
|
||||
Reference in New Issue
Block a user