Skip to content

Commit

Permalink
Merge branch '2.x' into fix-respawn-anchor-spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
gibsonpil authored Jul 7, 2024
2 parents 2cdc8a2 + fcf6e64 commit af7f6eb
Show file tree
Hide file tree
Showing 21 changed files with 4,003 additions and 27 deletions.
29 changes: 29 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Enchantments.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,24 @@ public final class Enchantments {
} catch (final IllegalArgumentException ignored) {
}

try { // 1.21
final Enchantment breach = Enchantment.getByName("BREACH");
if (breach != null) {
ENCHANTMENTS.put("breach", breach);
}
final Enchantment density = Enchantment.getByName("DENSITY");
if (density != null) {
ENCHANTMENTS.put("density", density);
}
final Enchantment windBurst = Enchantment.getByName("WIND_BURST");
if (breach != null) {
ENCHANTMENTS.put("windburst", windBurst);
ALIASENCHANTMENTS.put("wind", windBurst);
ALIASENCHANTMENTS.put("burst", windBurst);
}
} catch (final IllegalArgumentException ignored) {
}

try {
final Class<?> namespacedKeyClass = Class.forName("org.bukkit.NamespacedKey");
final Class<?> enchantmentClass = Class.forName("org.bukkit.enchantments.Enchantment");
Expand All @@ -316,6 +334,17 @@ public final class Enchantments {
private Enchantments() {
}

public static String getRealName(final Enchantment enchantment) {
if (enchantment == null) {
return null;
}

if (isFlat) { // 1.13+ only
return enchantment.getKey().getKey();
}
return enchantment.getName().toLowerCase(Locale.ENGLISH);
}

public static Enchantment getByName(final String name) {
if (name == null || name.isEmpty()) {
return null;
Expand Down
24 changes: 21 additions & 3 deletions Essentials/src/main/java/com/earth2me/essentials/Essentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import net.ess3.provider.ContainerProvider;
import net.ess3.provider.DamageEventProvider;
import net.ess3.provider.FormattedCommandAliasProvider;
import net.ess3.provider.InventoryViewProvider;
import net.ess3.provider.ItemUnbreakableProvider;
import net.ess3.provider.KnownCommandsProvider;
import net.ess3.provider.MaterialTagProvider;
Expand All @@ -80,6 +81,7 @@
import net.ess3.provider.SyncCommandsProvider;
import net.ess3.provider.WorldInfoProvider;
import net.ess3.provider.providers.BaseBannerDataProvider;
import net.ess3.provider.providers.BaseInventoryViewProvider;
import net.ess3.provider.providers.BaseLoggerProvider;
import net.ess3.provider.providers.BlockMetaSpawnerItemProvider;
import net.ess3.provider.providers.BukkitMaterialTagProvider;
Expand All @@ -88,6 +90,7 @@
import net.ess3.provider.providers.FlatSpawnEggProvider;
import net.ess3.provider.providers.LegacyBannerDataProvider;
import net.ess3.provider.providers.LegacyDamageEventProvider;
import net.ess3.provider.providers.LegacyInventoryViewProvider;
import net.ess3.provider.providers.LegacyItemUnbreakableProvider;
import net.ess3.provider.providers.LegacyPlayerLocaleProvider;
import net.ess3.provider.providers.LegacyPotionMetaProvider;
Expand Down Expand Up @@ -130,6 +133,7 @@
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.plugin.InvalidDescriptionException;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
Expand Down Expand Up @@ -206,6 +210,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
private transient SignDataProvider signDataProvider;
private transient DamageEventProvider damageEventProvider;
private transient BiomeKeyProvider biomeKeyProvider;
private transient InventoryViewProvider inventoryViewProvider;
private transient Kits kits;
private transient RandomTeleport randomTeleport;
private transient UpdateChecker updateChecker;
Expand Down Expand Up @@ -504,6 +509,12 @@ public void onEnable() {
damageEventProvider = new LegacyDamageEventProvider();
}

if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_21_R01)) {
inventoryViewProvider = new BaseInventoryViewProvider();
} else {
inventoryViewProvider = new LegacyInventoryViewProvider();
}

if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_19_4_R01)) {
biomeKeyProvider = new PaperBiomeKeyProvider();
}
Expand Down Expand Up @@ -928,12 +939,14 @@ private boolean isEssentialsPlugin(Plugin plugin) {
public void cleanupOpenInventories() {
for (final User user : getOnlineUsers()) {
if (user.isRecipeSee()) {
user.getBase().getOpenInventory().getTopInventory().clear();
user.getBase().getOpenInventory().close();
final InventoryView view = user.getBase().getOpenInventory();

inventoryViewProvider.getTopInventory(view).clear();
inventoryViewProvider.close(view);
user.setRecipeSee(false);
}
if (user.isInvSee() || user.isEnderSee()) {
user.getBase().getOpenInventory().close();
inventoryViewProvider.close(user.getBase().getOpenInventory());
user.setInvSee(false);
user.setEnderSee(false);
}
Expand Down Expand Up @@ -1385,6 +1398,11 @@ public BannerDataProvider getBannerDataProvider() {
return bannerDataProvider;
}

@Override
public InventoryViewProvider getInventoryViewProvider() {
return inventoryViewProvider;
}

@Override
public CustomItemResolver getCustomItemResolver() {
return customItemResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void onPlayerQuit(final PlayerQuitEvent event) {
}
user.setLogoutLocation();
if (user.isRecipeSee()) {
user.getBase().getOpenInventory().getTopInventory().clear();
ess.getInventoryViewProvider().getTopInventory(user.getBase().getOpenInventory()).clear();
}

final ArrayList<HumanEntity> viewers = new ArrayList<>(user.getBase().getInventory().getViewers());
Expand Down Expand Up @@ -897,14 +897,14 @@ public void run() {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClickEvent(final InventoryClickEvent event) {
Player refreshPlayer = null;
final Inventory top = event.getView().getTopInventory();
final Inventory top = ess.getInventoryViewProvider().getTopInventory(event.getView());
final InventoryType type = top.getType();

final Inventory clickedInventory;
if (event.getRawSlot() < 0) {
clickedInventory = null;
} else {
clickedInventory = event.getRawSlot() < top.getSize() ? top : event.getView().getBottomInventory();
clickedInventory = event.getRawSlot() < top.getSize() ? top : ess.getInventoryViewProvider().getBottomInventory(event.getView());
}

final User user = ess.getUser((Player) event.getWhoClicked());
Expand Down Expand Up @@ -963,7 +963,7 @@ private boolean isPreventBindingHat(User user, PlayerInventory inventory) {
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryCloseEvent(final InventoryCloseEvent event) {
Player refreshPlayer = null;
final Inventory top = event.getView().getTopInventory();
final Inventory top = ess.getInventoryViewProvider().getTopInventory(event.getView());
final InventoryType type = top.getType();
if (type == InventoryType.PLAYER) {
final User user = ess.getUser((Player) event.getPlayer());
Expand All @@ -977,7 +977,7 @@ public void onInventoryCloseEvent(final InventoryCloseEvent event) {
final User user = ess.getUser((Player) event.getPlayer());
if (user.isRecipeSee()) {
user.setRecipeSee(false);
event.getView().getTopInventory().clear();
ess.getInventoryViewProvider().getTopInventory(event.getView()).clear();
refreshPlayer = user.getBase();
}
} else if (type == InventoryType.CHEST && top.getSize() == 9) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.ess3.provider.ContainerProvider;
import net.ess3.provider.DamageEventProvider;
import net.ess3.provider.FormattedCommandAliasProvider;
import net.ess3.provider.InventoryViewProvider;
import net.ess3.provider.ItemUnbreakableProvider;
import net.ess3.provider.KnownCommandsProvider;
import net.ess3.provider.MaterialTagProvider;
Expand Down Expand Up @@ -192,5 +193,7 @@ public interface IEssentials extends Plugin {

BannerDataProvider getBannerDataProvider();

InventoryViewProvider getInventoryViewProvider();

PluginCommand getPluginCommand(String cmd);
}
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ private boolean parseEnchantmentStrings(final CommandSource sender, final boolea
if (enchantment == null) {
return false;
}
if (hasMetaPermission(sender, "enchantments." + enchantment.getName().toLowerCase(Locale.ENGLISH), false, false, ess)) {
if (hasMetaPermission(sender, "enchantments." + Enchantments.getRealName(enchantment), false, false, ess)) {
int level = -1;
if (split.length > 1) {
try {
Expand Down Expand Up @@ -619,7 +619,7 @@ public void addEnchantment(final CommandSource sender, final boolean allowUnsafe
}
}
} catch (final Exception ex) {
throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex);
throw new Exception("Enchantment " + Enchantments.getRealName(enchantment) + ": " + ex.getMessage(), ex);
}
}

Expand All @@ -629,7 +629,7 @@ public Enchantment getEnchantment(final User user, final String name) throws Exc
return null;
}

final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
final String enchantmentName = Enchantments.getRealName(enchantment);

if (!hasMetaPermission(user, "enchantments." + enchantmentName, true, false)) {
throw new TranslatableException("enchantmentPerm", enchantmentName);
Expand Down
2 changes: 2 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Mob.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public enum Mob {
CAMEL("Camel", Enemies.FRIENDLY, "CAMEL"),
SNIFFER("Sniffer", Enemies.FRIENDLY, "SNIFFER"),
ARMADILLO("Armadillo", Enemies.FRIENDLY, "ARMADILLO"),
BREEZE("Breeze", Enemies.ENEMY, "BREEZE"),
BOGGED("Bogged", Enemies.ENEMY, "BOGGED"),
;

private static final Map<String, Mob> hashMap = new HashMap<>();
Expand Down
17 changes: 17 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Potions.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ public final class Potions {
POTIONS.put("unluck", PotionEffectType.UNLUCK);
} catch (final Throwable ignored) {
}

// 1.21
try {
POTIONS.put("infested", PotionEffectType.INFESTED);
ALIASPOTIONS.put("silverfish", PotionEffectType.INFESTED);

POTIONS.put("oozing", PotionEffectType.OOZING);
ALIASPOTIONS.put("ooze", PotionEffectType.OOZING);

POTIONS.put("weaving", PotionEffectType.WEAVING);
ALIASPOTIONS.put("weave", PotionEffectType.WEAVING);

POTIONS.put("windcharged", PotionEffectType.WIND_CHARGED);
ALIASPOTIONS.put("windcharge", PotionEffectType.WIND_CHARGED);
ALIASPOTIONS.put("wind", PotionEffectType.WIND_CHARGED);
} catch (final Throwable ignored) {
}
}

private Potions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
Expand All @@ -35,7 +34,7 @@ protected void run(final Server server, final User user, final String commandLab
if (args.length == 0) {
final Set<String> usableEnchants = new TreeSet<>();
for (final Map.Entry<String, Enchantment> entry : Enchantments.entrySet()) {
final String name = entry.getValue().getName().toLowerCase(Locale.ENGLISH);
final String name = Enchantments.getRealName(entry.getValue());
if (usableEnchants.contains(name) || (user.isAuthorized("essentials.enchantments." + name) && entry.getValue().canEnchantItem(stack))) {
usableEnchants.add(entry.getKey());
}
Expand All @@ -57,7 +56,7 @@ protected void run(final Server server, final User user, final String commandLab
metaStack.addEnchantment(user.getSource(), ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchantments.allowunsafe"), enchantment, level);
stack.setItemMeta(metaStack.getItemStack().getItemMeta());
user.getBase().updateInventory();
final String enchantName = enchantment.getName().toLowerCase(Locale.ENGLISH).replace('_', ' ');
final String enchantName = Enchantments.getRealName(enchantment).replace('_', ' ');
if (level == 0) {
user.sendTl("enchantmentRemoved", enchantName);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void shapedRecipe(final CommandSource sender, final ShapedRecipe recipe,
if (VersionUtil.PRE_FLATTENING && item.getDurability() == Short.MAX_VALUE) {
item.setDurability((short) 0);
}
view.getTopInventory().setItem(j * 3 + k + 1, item);
ess.getInventoryViewProvider().getTopInventory(view).setItem(j * 3 + k + 1, item);
}
}
} else {
Expand Down Expand Up @@ -174,7 +174,7 @@ public void shapelessRecipe(final CommandSource sender, final ShapelessRecipe re
if (VersionUtil.PRE_FLATTENING && item.getDurability() == Short.MAX_VALUE) {
item.setDurability((short) 0);
}
view.setItem(i + 1, item);
ess.getInventoryViewProvider().setItem(view, i + 1, item);
}

} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.earth2me.essentials.items;

import com.earth2me.essentials.Enchantments;
import com.earth2me.essentials.IConf;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.Inventories;
Expand Down Expand Up @@ -218,7 +219,7 @@ public String serialize(final ItemStack is, final boolean useResolvers) {

if (meta.hasEnchants()) {
for (final Enchantment e : meta.getEnchants().keySet()) {
sb.append(e.getName().toLowerCase()).append(":").append(meta.getEnchantLevel(e)).append(" ");
sb.append(Enchantments.getRealName(e)).append(":").append(meta.getEnchantLevel(e)).append(" ");
}
}

Expand Down Expand Up @@ -263,7 +264,7 @@ public String serialize(final ItemStack is, final boolean useResolvers) {
case ENCHANTED_BOOK:
final EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) is.getItemMeta();
for (final Enchantment e : enchantmentStorageMeta.getStoredEnchants().keySet()) {
sb.append(e.getName().toLowerCase()).append(":").append(enchantmentStorageMeta.getStoredEnchantLevel(e)).append(" ");
sb.append(Enchantments.getRealName(e)).append(":").append(enchantmentStorageMeta.getStoredEnchantLevel(e)).append(" ");
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}

final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
final String enchantmentName = Enchantments.getRealName(enchantment);
if (level == 0) {
player.sendTl("enchantmentRemoved", enchantmentName.replace('_', ' '));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final class VersionUtil {
public static final BukkitVersion v1_20_1_R01 = BukkitVersion.fromString("1.20.1-R0.1-SNAPSHOT");
public static final BukkitVersion v1_20_4_R01 = BukkitVersion.fromString("1.20.4-R0.1-SNAPSHOT");
public static final BukkitVersion v1_20_6_R01 = BukkitVersion.fromString("1.20.6-R0.1-SNAPSHOT");
public static final BukkitVersion v1_21_R01 = BukkitVersion.fromString("1.21-R0.1-SNAPSHOT");

private static final Set<BukkitVersion> supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01, v1_14_4_R01, v1_15_2_R01, v1_16_5_R01, v1_17_1_R01, v1_18_2_R01, v1_19_4_R01, v1_20_6_R01);
private static final Set<BukkitVersion> supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01, v1_14_4_R01, v1_15_2_R01, v1_16_5_R01, v1_17_1_R01, v1_18_2_R01, v1_19_4_R01, v1_20_6_R01, v1_21_R01);

public static final boolean PRE_FLATTENING = VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01);

Expand Down
Loading

0 comments on commit af7f6eb

Please sign in to comment.