Merge branch 'EssentialsX:2.x' into 2.x

This commit is contained in:
Hernán Indíbil de la Cruz Calvo 2024-10-16 20:44:34 +02:00 committed by GitHub
commit 2b75c879ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 78 additions and 15 deletions

View File

@ -812,7 +812,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
if (cSender instanceof Player) {
cSender.sendMessage(tlLocale(I18n.getLocale(getPlayerLocaleProvider().getLocale((Player) cSender)), "internalError"));
getBukkitAudience().sender(cSender).sendMessage(AdventureUtil.miniMessage().deserialize(tlLocale(I18n.getLocale(getPlayerLocaleProvider().getLocale((Player) cSender)), "internalError")));
} else {
cSender.sendMessage(tlLiteral("internalError"));
}

View File

@ -79,7 +79,7 @@ public class Warps implements IConf, net.ess3.api.IWarps {
if (conf == null) {
final File confFile = new File(warpsFolder, filename + ".yml");
if (confFile.exists()) {
throw new Exception(user == null ? tlLiteral("similarWarpExist") : user.playerTl("similarWarpExist"));
throw new TranslatableException("similarWarpExist");
}
conf = new EssentialsConfiguration(confFile);
conf.load();

View File

@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.google.common.collect.Lists;
import net.ess3.api.TranslatableException;
import org.bukkit.Server;
@ -53,7 +54,7 @@ public class Commandbroadcastworld extends EssentialsCommand {
if (message.isEmpty()) {
throw new NotEnoughArgumentsException();
}
ess.broadcastTl(null, u -> !u.getBase().getWorld().equals(world), true, "broadcast", message, AdventureUtil.parsed(AdventureUtil.legacyToMini(name)));
ess.broadcastTl(null, u -> !u.getBase().getWorld().equals(world), true, "broadcast", FormatUtil.replaceFormat(message).replace("\\n", "\n"), AdventureUtil.parsed(AdventureUtil.legacyToMini(name)));
}
@Override

View File

@ -19,6 +19,7 @@ import org.bukkit.entity.Snowball;
import org.bukkit.entity.SplashPotion;
import org.bukkit.entity.ThrownExpBottle;
import org.bukkit.entity.Trident;
import org.bukkit.entity.WindCharge;
import org.bukkit.entity.WitherSkull;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
@ -55,6 +56,10 @@ public class Commandfireball extends EssentialsCommand {
builder.put("trident", Trident.class);
}
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_21_R01)) {
builder.put("windcharge", WindCharge.class);
}
types = builder.build();
}

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Mob;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.RegistryUtil;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Cat;
@ -21,8 +22,12 @@ public class Commandkittycannon extends EssentialsCommand {
private static Ocelot spawnOcelot(final Server server, final User user) throws Mob.MobException {
final Ocelot ocelot = (Ocelot) Mob.OCELOT.spawn(user.getWorld(), server, user.getBase().getEyeLocation());
final int i = random.nextInt(Ocelot.Type.values().length);
ocelot.setCatType(Ocelot.Type.values()[i]);
//noinspection deprecation
final Object[] values = RegistryUtil.values(Ocelot.Type.class);
final int i = random.nextInt(values.length);
//noinspection deprecation
ocelot.setCatType((Ocelot.Type) values[i]);
((Tameable) ocelot).setTamed(true);
ocelot.setBaby();
ocelot.setVelocity(user.getBase().getEyeLocation().getDirection().multiply(2));
@ -31,8 +36,10 @@ public class Commandkittycannon extends EssentialsCommand {
private static Entity spawnCat(final Server server, final User user) throws Mob.MobException {
final Cat cat = (Cat) Mob.CAT.spawn(user.getWorld(), server, user.getBase().getEyeLocation());
final int i = random.nextInt(Cat.Type.values().length);
cat.setCatType(Cat.Type.values()[i]);
final Object[] values = RegistryUtil.values(Cat.Type.class);
final int i = random.nextInt(values.length);
cat.setCatType((Cat.Type) values[i]);
cat.setTamed(true);
cat.setBaby();
cat.setVelocity(user.getBase().getEyeLocation().getDirection().multiply(2));

View File

@ -3,10 +3,12 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.Inventories;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.NumberUtil;
import com.earth2me.essentials.utils.VersionUtil;
import net.ess3.api.TranslatableException;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.FurnaceRecipe;
@ -150,18 +152,28 @@ public class Commandrecipe extends EssentialsCommand {
materials[j][k] = item == null ? null : item.getType();
}
}
sender.sendTl("recipeGrid", colorMap.get(materials[0][0]), colorMap.get(materials[0][1]), colorMap.get(materials[0][2]));
sender.sendTl("recipeGrid", colorMap.get(materials[1][0]), colorMap.get(materials[1][1]), colorMap.get(materials[1][2]));
sender.sendTl("recipeGrid", colorMap.get(materials[2][0]), colorMap.get(materials[2][1]), colorMap.get(materials[2][2]));
sender.sendTl("recipeGrid", colorTag(colorMap, materials, 0, 0), colorTag(colorMap, materials, 0, 1), colorTag(colorMap, materials, 0, 2));
sender.sendTl("recipeGrid", colorTag(colorMap, materials, 1, 0), colorTag(colorMap, materials, 1, 1), colorTag(colorMap, materials, 1, 2));
sender.sendTl("recipeGrid", colorTag(colorMap, materials, 2, 0), colorTag(colorMap, materials, 2, 1), colorTag(colorMap, materials, 2, 2));
final StringBuilder s = new StringBuilder();
for (final Material items : colorMap.keySet().toArray(new Material[0])) {
s.append(sender.tl("recipeGridItem", colorMap.get(items), getMaterialName(sender, items)));
s.append(sender.tl("recipeGridItem", colorMap.get(items), getMaterialName(sender, items))).append(" ");
}
sender.sendTl("recipeWhere", s.toString());
sender.sendTl("recipeWhere", AdventureUtil.parsed(s.toString()));
}
}
private AdventureUtil.ParsedPlaceholder colorTag(final Map<Material, String> colorMap, final Material[][] materials, final int x, final int y) {
final char colorChar = colorMap.get(materials[x][y]).charAt(0);
final NamedTextColor namedTextColor = AdventureUtil.fromChar(colorChar);
if (namedTextColor == null) {
throw new IllegalStateException("Illegal amount of materials in recipe");
}
return AdventureUtil.parsed("<" + namedTextColor + ">" + colorChar);
}
public void shapelessRecipe(final CommandSource sender, final ShapelessRecipe recipe, final boolean showWindow) {
final List<ItemStack> ingredients = recipe.getIngredientList();
if (showWindow) {

View File

@ -3,12 +3,50 @@ package com.earth2me.essentials.utils;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
public final class RegistryUtil {
private static final Table<Class<?>, String, Object> registryCache = HashBasedTable.create();
private RegistryUtil() {
}
public static <T> Object[] values(Class<T> registry) {
if (registry.getEnumConstants() != null) {
return registry.getEnumConstants();
}
//noinspection unchecked
final T[] values = (T[]) registryCache.get(registry, "$values");
if (values != null) {
return values;
}
final List<T> set = new ArrayList<>();
for (final Field field : registry.getDeclaredFields()) {
try {
final Object value = field.get(null);
if (value != null && registry.isAssignableFrom(value.getClass())) {
//noinspection unchecked
set.add((T) value);
}
} catch (NullPointerException | IllegalAccessException ignored) {
}
}
//noinspection unchecked
final T[] array = (T[]) new Object[set.size()];
for (int i = 0; i < set.size(); i++) {
array[i] = set.get(i);
}
registryCache.put(registry, "$values", array);
return array;
}
public static <T> T valueOf(Class<T> registry, String... names) {
for (final String name : names) {
//noinspection unchecked

View File

@ -248,7 +248,7 @@ discordCommandAccountResponseLinkedOther={0}'s account is linked to the Minecraf
discordCommandAccountResponseNotLinked=You do not have a linked Minecraft account.
discordCommandAccountResponseNotLinkedOther={0} does not have a linked Minecraft account.
discordCommandDescription=Sends the discord invite link to the player.
discordCommandLink=<primary>Join our Discord server at <secondary>{0}<primary>\!
discordCommandLink=<primary>Join our Discord server at <secondary><click:open_url:"{0}">{0}</click><primary>\!
discordCommandUsage=/<command>
discordCommandUsage1=/<command>
discordCommandUsage1Description=Sends the discord invite link to the player
@ -1042,7 +1042,7 @@ recipeCommandUsage=/<command> <<item>|hand> [number]
recipeCommandUsage1=/<command> <<item>|hand> [page]
recipeCommandUsage1Description=Displays how to craft the given item
recipeFurnace=<primary>Smelt\: <secondary>{0}<primary>.
recipeGrid=<secondary>{0}X <primary>| §{1}X <primary>| §{2}X
recipeGrid=<secondary>{0}X <primary>| {1}X <primary>| {2}X
recipeGridItem=<secondary>{0}X <primary>is <secondary>{1}
recipeMore=<primary>Type<secondary> /{0} {1} <number><primary> to see other recipes for <secondary>{2}<primary>.
recipeNone=No recipes exist for {0}.

View File

@ -12,7 +12,7 @@ dependencies {
exclude(module: 'okhttp')
}
compileOnly 'org.apache.logging.log4j:log4j-core:2.17.1'
compileOnly 'me.clip:placeholderapi:2.10.9'
compileOnly 'me.clip:placeholderapi:2.11.6'
}
shadowJar {