Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions Essentials/src/main/java/com/earth2me/essentials/MobCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.bukkit.entity.Axolotl;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Camel;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fox;
Expand All @@ -18,22 +20,39 @@
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Panda;
import org.bukkit.entity.Parrot;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
import org.bukkit.entity.Salmon;
import org.bukkit.entity.TropicalFish;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Wolf;
import org.bukkit.inventory.ItemStack;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;

import static com.earth2me.essentials.utils.EnumUtil.getEntityType;

public final class MobCompat {

// Constants for mob interfaces added in later versions
@SuppressWarnings("rawtypes")
public static final Class RAIDER = ReflUtil.getClassCached("org.bukkit.entity.Raider");
public static final Class<?> RAIDER = ReflUtil.getClassCached("org.bukkit.entity.Raider");

// Stupid hacks to avoid Commodore rewrites.
private static final Class<?> COW = ReflUtil.getClassCached("org.bukkit.entity.Cow");
private static final Class<?> COW_VARIANT = ReflUtil.getClassCached("org.bukkit.entity.Cow$Variant");
private static final MethodHandle COW_VARIANT_HANDLE;

static {
MethodHandle handle = null;
try {
handle = MethodHandles.lookup().findVirtual(COW, "setVariant", MethodType.methodType(void.class, COW_VARIANT));
} catch (NoSuchMethodException | IllegalAccessException ignored) {
}
COW_VARIANT_HANDLE = handle;
}

// Constants for mobs added in later versions
public static final EntityType LLAMA = getEntityType("LLAMA");
Expand Down Expand Up @@ -250,6 +269,41 @@ public static void setSalmonSize(Entity spawned, String s) {
}
}

public static void setCowVariant(final Entity spawned, final String variant) {
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_5_R01) || COW_VARIANT_HANDLE == null) {
return;
}

if (spawned instanceof Cow) {
try {
COW_VARIANT_HANDLE.invoke(spawned, RegistryUtil.valueOf(COW_VARIANT, variant));
} catch (Throwable ignored) {
}
}
}

public static void setChickenVariant(final Entity spawned, final String variant) {
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_5_R01)) {
return;
}

if (spawned instanceof Chicken) {
//noinspection DataFlowIssue
((Chicken) spawned).setVariant(RegistryUtil.valueOf(Chicken.Variant.class, variant));
}
}

public static void setPigVariant(final Entity spawned, final String variant) {
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_5_R01)) {
return;
}

if (spawned instanceof Pig) {
//noinspection DataFlowIssue
((Pig) spawned).setVariant(RegistryUtil.valueOf(Pig.Variant.class, variant));
}
}

public enum CatType {
// These are (loosely) Mojang names for the cats
SIAMESE("SIAMESE", "SIAMESE_CAT"),
Expand Down
19 changes: 19 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/MobData.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Boat;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -221,6 +222,15 @@ public enum MobData {
SMALL_SALMON("small", MobCompat.SALMON, "salmon:SMALL", true),
MEDIUM_SALMON("medium", MobCompat.SALMON, "salmon:MEDIUM", true),
LARGE_SALMON("large", MobCompat.SALMON, "salmon:LARGE", true),
TEMPERATE_COW("temperate", EntityType.COW.getEntityClass(), "cow:TEMPERATE", true),
WARM_COW("warm", EntityType.COW.getEntityClass(), "cow:WARM", true),
COLD_COW("cold", EntityType.COW.getEntityClass(), "cow:COLD", true),
TEMPERATE_CHICKEN("temperate", Chicken.class, "chicken:TEMPERATE", true),
WARM_CHICKEN("warm", Chicken.class, "chicken:WARM", true),
COLD_CHICKEN("cold", Chicken.class, "chicken:COLD", true),
TEMPERATE_PIG("temperate", Pig.class, "pig:TEMPERATE", true),
WARM_PIG("warm", Pig.class, "pig:WARM", true),
COLD_PIG("cold", Pig.class, "pig:COLD", true),
;

final private String nickname;
Expand Down Expand Up @@ -442,6 +452,15 @@ public void setData(final Entity spawned, final Player target, final String rawD
case "salmon":
MobCompat.setSalmonSize(spawned, split[1]);
break;
case "cow":
MobCompat.setCowVariant(spawned, split[1]);
break;
case "chicken":
MobCompat.setChickenVariant(spawned, split[1]);
break;
case "pig":
MobCompat.setPigVariant(spawned, split[1]);
break;
}
} else {
Essentials.getWrappedLogger().warning("Unknown mob data type: " + this.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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 com.google.common.collect.Lists;
import net.essentialsx.api.v2.services.BalanceTop;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -121,9 +122,14 @@ public void run() {
final User user = ess.getUser(entry.getKey());

final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
final boolean offlineStatisticSupported = VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_2_R01);
final long playtime;
if (user.getBase() == null || !user.getBase().isOnline()) {
playtime = Bukkit.getServer().getOfflinePlayer(entry.getKey()).getStatistic(PLAY_ONE_TICK);
if (offlineStatisticSupported) {
playtime = Bukkit.getServer().getOfflinePlayer(entry.getKey()).getStatistic(PLAY_ONE_TICK);
} else {
playtime = -1;
}
} else {
playtime = user.getBase().getStatistic(PLAY_ONE_TICK);
}
Expand All @@ -133,7 +139,8 @@ public void run() {
// Checking if player meets the requirements of minimum balance and minimum playtime to be listed in baltop list
if ((ess.getSettings().showZeroBaltop() || balance.compareTo(BigDecimal.ZERO) > 0)
&& balance.compareTo(ess.getSettings().getBaltopMinBalance()) >= 0 &&
playTimeSecs >= ess.getSettings().getBaltopMinPlaytime()) {
// Skip playtime check for offline players on versions below 1.15.2
(playtime == -1 || playTimeSecs >= ess.getSettings().getBaltopMinPlaytime())) {
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(balance, ess)))));
}
pos++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class AdventureUtil {
final LegacyComponentSerializer.Builder builder = LegacyComponentSerializer.builder()
.flattener(ComponentFlattener.basic())
.extractUrls(AbstractChatEvent.URL_PATTERN)
.hexColors()
.useUnusualXRepeatedCharacterHexFormat();
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_16_1_R01)) {
builder.hexColors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ public final class VersionUtil {
public static final BukkitVersion v1_19_R01 = BukkitVersion.fromString("1.19-R0.1-SNAPSHOT");
public static final BukkitVersion v1_19_4_R01 = BukkitVersion.fromString("1.19.4-R0.1-SNAPSHOT");
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");
public static final BukkitVersion v1_21_3_R01 = BukkitVersion.fromString("1.21.3-R0.1-SNAPSHOT");
public static final BukkitVersion v1_21_4_R01 = BukkitVersion.fromString("1.21.4-R0.1-SNAPSHOT");
public static final BukkitVersion v1_21_5_R01 = BukkitVersion.fromString("1.21.5-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, v1_21_4_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_5_R01);

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

Expand Down
76 changes: 75 additions & 1 deletion Essentials/src/main/resources/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,11 @@
"bludye": "blue_dye",
"bluedye": "blue_dye",
"minecraft:blue_dye": "blue_dye",
"blue_egg": {
"material": "BLUE_EGG"
},
"blueegg": "blue_egg",
"minecraft:blue_egg": "blue_egg",
"blue_glazed_terracotta": {
"material": "BLUE_GLAZED_TERRACOTTA"
},
Expand Down Expand Up @@ -2322,6 +2327,11 @@
"brodye": "brown_dye",
"browndye": "brown_dye",
"minecraft:brown_dye": "brown_dye",
"brown_egg": {
"material": "BROWN_EGG"
},
"brownegg": "brown_egg",
"minecraft:brown_egg": "brown_egg",
"brown_glazed_terracotta": {
"material": "BROWN_GLAZED_TERRACOTTA"
},
Expand Down Expand Up @@ -2469,12 +2479,28 @@
"burnpotterysherd": "burn_pottery_sherd",
"burnsherd": "burn_pottery_sherd",
"minecraft:burn_pottery_sherd": "burn_pottery_sherd",
"bush": {
"material": "BUSH"
},
"gbush": "bush",
"grassbush": "bush",
"minecraft:bush": "bush",
"cactus": {
"material": "CACTUS"
},
"cacti": "cactus",
"cactuses": "cactus",
"minecraft:cactus": "cactus",
"cactus_flower": {
"material": "CACTUS_FLOWER"
},
"cactiflower": "cactus_flower",
"cactusflower": "cactus_flower",
"cflower": "cactus_flower",
"flowerc": "cactus_flower",
"flowercacti": "cactus_flower",
"flowercactus": "cactus_flower",
"minecraft:cactus_flower": "cactus_flower",
"cake": {
"material": "CAKE"
},
Expand Down Expand Up @@ -5712,7 +5738,6 @@
"dead_bush": {
"material": "DEAD_BUSH"
},
"bush": "dead_bush",
"dbush": "dead_bush",
"deadbush": "dead_bush",
"deadsapling": "dead_bush",
Expand Down Expand Up @@ -7425,6 +7450,13 @@
"firerestarr": "fire_resistance_tipped_arrow",
"firerestarrow": "fire_resistance_tipped_arrow",
"firerestippedarrow": "fire_resistance_tipped_arrow",
"firefly_bush": {
"material": "FIREFLY_BUSH"
},
"ffbush": "firefly_bush",
"firebush": "firefly_bush",
"fireflybush": "firefly_bush",
"minecraft:firefly_bush": "firefly_bush",
"firework_rocket": {
"material": "FIREWORK_ROCKET"
},
Expand Down Expand Up @@ -11428,6 +11460,15 @@
"material": "LEAD"
},
"minecraft:lead": "lead",
"leaf_litter": {
"material": "LEAF_LITTER"
},
"leaflit": "leaf_litter",
"leaflitter": "leaf_litter",
"litter": "leaf_litter",
"llitter": "leaf_litter",
"minecraft:leaf_litter": "leaf_litter",
"spottedleaf": "leaf_litter",
"leaping_lingering_potion": {
"potionData": {
"type": "LEAPING",
Expand Down Expand Up @@ -27238,6 +27279,14 @@
"minecraft:shield": "shield",
"woodenshield": "shield",
"woodshield": "shield",
"short_dry_grass": {
"material": "SHORT_DRY_GRASS"
},
"minecraft:short_dry_grass": "short_dry_grass",
"sdgrass": "short_dry_grass",
"sdrygrass": "short_dry_grass",
"shortdgrass": "short_dry_grass",
"shortdrygrass": "short_dry_grass",
"short_grass": {
"material": "SHORT_GRASS",
"fallbacks": [
Expand Down Expand Up @@ -33146,6 +33195,14 @@
"tadpolemonsterspawner": "tadpole_spawner",
"tadpolemspawner": "tadpole_spawner",
"tadpolespawner": "tadpole_spawner",
"tall_dry_grass": {
"material": "TALL_DRY_GRASS"
},
"minecraft:tall_dry_grass": "tall_dry_grass",
"talldgrass": "tall_dry_grass",
"talldrygrass": "tall_dry_grass",
"tdgrass": "tall_dry_grass",
"tdrygrass": "tall_dry_grass",
"tall_grass": {
"material": "TALL_GRASS"
},
Expand All @@ -33167,6 +33224,16 @@
"material": "TERRACOTTA"
},
"minecraft:terracotta": "terracotta",
"test_block": {
"material": "TEST_BLOCK"
},
"minecraft:test_block": "test_block",
"testblock": "test_block",
"test_instance_block": {
"material": "TEST_INSTANCE_BLOCK"
},
"minecraft:test_instance_block": "test_instance_block",
"testinstanceblock": "test_instance_block",
"thick_lingering_potion": {
"potionData": {
"type": "THICK",
Expand Down Expand Up @@ -46809,6 +46876,13 @@
"minecraft:wild_armor_trim_smithing_template": "wild_armor_trim_smithing_template",
"wildarmortrimsmithingtemplate": "wild_armor_trim_smithing_template",
"wildtrim": "wild_armor_trim_smithing_template",
"wildflowers": {
"material": "WILDFLOWERS"
},
"minecraft:wildflowers": "wildflowers",
"wflower": "wildflowers",
"wflowers": "wildflowers",
"wildflower": "wildflowers",
"wind_charge": {
"material": "WIND_CHARGE"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ protected void handleChatRecipients(AbstractChatEvent event) {

final ChatProcessingCache.Chat chat = cache.getProcessedChat(event.getPlayer());

// If local chat is enabled, handle the recipients here; else we have nothing to do
// If local chat is enabled, handle the recipients here; else we can just fire the chat event and return
if (chat.getRadius() < 1) {
callChatEvent(event, chat.getType(), null);
return;
}
final long radiusSquared = chat.getRadius() * chat.getRadius();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ public void onDiscordMessage(final DiscordMessageEvent event) {
@EventHandler
public void onUserLinkStatusChange(final DiscordLinkStatusChangeEvent event) {
if (event.isLinked() || ess.getSettings().getLinkPolicy() == DiscordLinkSettings.LinkPolicy.NONE) {
event.getUser().setFreeze(false);
if (event.getUser() != null) {
event.getUser().setFreeze(false);
}
return;
}

if (event.getUser() == null || !event.getUser().getBase().isOnline()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ however, have some new requirements:
* **EssentialsX requires CraftBukkit, Spigot or Paper to run.** Other server software may work, but these are not tested
by the team and we may not be able to help with any issues that occur.
* **EssentialsX currently supports Minecraft versions 1.8.8, 1.9.4, 1.10.2, 1.11.2, 1.12.2, 1.13.2, 1.14.4, 1.15.2,
1.16.5, 1.17.1, 1.18.2, 1.19.4, 1.20.6, and 1.21.4.**
1.16.5, 1.17.1, 1.18.2, 1.19.4, 1.20.6, and 1.21.5.**
* **EssentialsX currently requires Java 8 or higher.** We recommend using the latest Java version supported by your
server software.
* **EssentialsX requires [Vault](http://dev.bukkit.org/bukkit-plugins/vault/) to enable using chat prefix/suffixes and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
val baseExtension = extensions.create<EssentialsBaseExtension>("essentials", project)

val checkstyleVersion = "8.36.2"
val spigotVersion = "1.21.4-R0.1-SNAPSHOT"
val spigotVersion = "1.21.5-R0.1-SNAPSHOT"
val junit5Version = "5.10.2"
val mockitoVersion = "3.12.4"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public PaperChatListenerProvider(final boolean formatParsing) {
this.serializer = LegacyComponentSerializer.builder()
.flattener(ComponentFlattener.basic())
.extractUrls(AbstractChatEvent.URL_PATTERN)
.useUnusualXRepeatedCharacterHexFormat().build();
.useUnusualXRepeatedCharacterHexFormat()
.hexColors()
.build();
}

public void onChatLowest(final AbstractChatEvent event) {
Expand Down
Loading