Skip to content

Commit 7d063fa

Browse files
authored
Merge branch '2.x' into l10n_2.x
2 parents 5f84343 + 8455212 commit 7d063fa

File tree

28 files changed

+376
-46
lines changed

28 files changed

+376
-46
lines changed

.github/ISSUE_TEMPLATE/report-a-bug.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Report bug
22
description: Report a bug in EssentialsX.
33
labels: 'bug: unconfirmed'
4+
type: Bug
45
body:
56
- type: markdown
67
attributes:

.github/ISSUE_TEMPLATE/request-a-feature.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Request a feature
22
description: Suggest a feature you want to see in EssentialsX!
33
labels: 'type: enhancement'
4+
type: Feature
45
body:
56
- type: markdown
67
attributes:

Essentials/src/main/java/com/earth2me/essentials/ISettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ public interface ISettings extends IConf {
424424

425425
boolean showZeroBaltop();
426426

427+
String getNickRegex();
428+
427429
BigDecimal getMultiplier(final User user);
428430

429431
int getMaxItemLore();

Essentials/src/main/java/com/earth2me/essentials/IUser.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ default boolean hasOutstandingTeleportRequest() {
177177

178178
String getFormattedJailTime();
179179

180+
/**
181+
* Returns last activity time.
182+
* <p>
183+
* It is used internally to determine if user's afk status should be set to
184+
* true because of ACTIVITY {@link AfkStatusChangeEvent.Cause}, or the player
185+
* should be kicked for being afk too long.
186+
*
187+
* @return Last activity time (Epoch Milliseconds)
188+
*/
189+
long getLastActivityTime();
190+
180191
@Deprecated
181192
List<String> getMails();
182193

Essentials/src/main/java/com/earth2me/essentials/MobCompat.java

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.bukkit.entity.Axolotl;
1010
import org.bukkit.entity.Boat;
1111
import org.bukkit.entity.Camel;
12+
import org.bukkit.entity.Chicken;
13+
import org.bukkit.entity.Cow;
1214
import org.bukkit.entity.Entity;
1315
import org.bukkit.entity.EntityType;
1416
import org.bukkit.entity.Fox;
@@ -18,22 +20,39 @@
1820
import org.bukkit.entity.Ocelot;
1921
import org.bukkit.entity.Panda;
2022
import org.bukkit.entity.Parrot;
23+
import org.bukkit.entity.Pig;
2124
import org.bukkit.entity.Player;
2225
import org.bukkit.entity.Salmon;
2326
import org.bukkit.entity.TropicalFish;
2427
import org.bukkit.entity.Villager;
2528
import org.bukkit.entity.Wolf;
2629
import org.bukkit.inventory.ItemStack;
2730

31+
import java.lang.invoke.MethodHandle;
32+
import java.lang.invoke.MethodHandles;
33+
import java.lang.invoke.MethodType;
2834
import java.lang.reflect.Method;
2935

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

3238
public final class MobCompat {
3339

3440
// Constants for mob interfaces added in later versions
35-
@SuppressWarnings("rawtypes")
36-
public static final Class RAIDER = ReflUtil.getClassCached("org.bukkit.entity.Raider");
41+
public static final Class<?> RAIDER = ReflUtil.getClassCached("org.bukkit.entity.Raider");
42+
43+
// Stupid hacks to avoid Commodore rewrites.
44+
private static final Class<?> COW = ReflUtil.getClassCached("org.bukkit.entity.Cow");
45+
private static final Class<?> COW_VARIANT = ReflUtil.getClassCached("org.bukkit.entity.Cow$Variant");
46+
private static final MethodHandle COW_VARIANT_HANDLE;
47+
48+
static {
49+
MethodHandle handle = null;
50+
try {
51+
handle = MethodHandles.lookup().findVirtual(COW, "setVariant", MethodType.methodType(void.class, COW_VARIANT));
52+
} catch (final Throwable ignored) {
53+
}
54+
COW_VARIANT_HANDLE = handle;
55+
}
3756

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

272+
public static void setCowVariant(final Entity spawned, final String variant) {
273+
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_5_R01) || COW_VARIANT_HANDLE == null) {
274+
return;
275+
}
276+
277+
if (spawned instanceof Cow) {
278+
try {
279+
COW_VARIANT_HANDLE.invoke(spawned, RegistryUtil.valueOf(COW_VARIANT, variant));
280+
} catch (Throwable ignored) {
281+
}
282+
}
283+
}
284+
285+
public static void setChickenVariant(final Entity spawned, final String variant) {
286+
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_5_R01)) {
287+
return;
288+
}
289+
290+
if (spawned instanceof Chicken) {
291+
//noinspection DataFlowIssue
292+
((Chicken) spawned).setVariant(RegistryUtil.valueOf(Chicken.Variant.class, variant));
293+
}
294+
}
295+
296+
public static void setPigVariant(final Entity spawned, final String variant) {
297+
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_5_R01)) {
298+
return;
299+
}
300+
301+
if (spawned instanceof Pig) {
302+
//noinspection DataFlowIssue
303+
((Pig) spawned).setVariant(RegistryUtil.valueOf(Pig.Variant.class, variant));
304+
}
305+
}
306+
253307
public enum CatType {
254308
// These are (loosely) Mojang names for the cats
255309
SIAMESE("SIAMESE", "SIAMESE_CAT"),

Essentials/src/main/java/com/earth2me/essentials/MobData.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.bukkit.entity.Ageable;
1111
import org.bukkit.entity.Boat;
1212
import org.bukkit.entity.ChestedHorse;
13+
import org.bukkit.entity.Chicken;
1314
import org.bukkit.entity.Creeper;
1415
import org.bukkit.entity.Entity;
1516
import org.bukkit.entity.EntityType;
@@ -221,6 +222,15 @@ public enum MobData {
221222
SMALL_SALMON("small", MobCompat.SALMON, "salmon:SMALL", true),
222223
MEDIUM_SALMON("medium", MobCompat.SALMON, "salmon:MEDIUM", true),
223224
LARGE_SALMON("large", MobCompat.SALMON, "salmon:LARGE", true),
225+
TEMPERATE_COW("temperate", EntityType.COW.getEntityClass(), "cow:TEMPERATE", true),
226+
WARM_COW("warm", EntityType.COW.getEntityClass(), "cow:WARM", true),
227+
COLD_COW("cold", EntityType.COW.getEntityClass(), "cow:COLD", true),
228+
TEMPERATE_CHICKEN("temperate", Chicken.class, "chicken:TEMPERATE", true),
229+
WARM_CHICKEN("warm", Chicken.class, "chicken:WARM", true),
230+
COLD_CHICKEN("cold", Chicken.class, "chicken:COLD", true),
231+
TEMPERATE_PIG("temperate", Pig.class, "pig:TEMPERATE", true),
232+
WARM_PIG("warm", Pig.class, "pig:WARM", true),
233+
COLD_PIG("cold", Pig.class, "pig:COLD", true),
224234
;
225235

226236
final private String nickname;
@@ -442,6 +452,15 @@ public void setData(final Entity spawned, final Player target, final String rawD
442452
case "salmon":
443453
MobCompat.setSalmonSize(spawned, split[1]);
444454
break;
455+
case "cow":
456+
MobCompat.setCowVariant(spawned, split[1]);
457+
break;
458+
case "chicken":
459+
MobCompat.setChickenVariant(spawned, split[1]);
460+
break;
461+
case "pig":
462+
MobCompat.setPigVariant(spawned, split[1]);
463+
break;
445464
}
446465
} else {
447466
Essentials.getWrappedLogger().warning("Unknown mob data type: " + this.toString());

Essentials/src/main/java/com/earth2me/essentials/Settings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,11 @@ public boolean showZeroBaltop() {
21202120
return config.getBoolean("show-zero-baltop", true);
21212121
}
21222122

2123+
@Override
2124+
public String getNickRegex() {
2125+
return config.getString("allowed-nicks-regex", "^[a-zA-Z_0-9§]+$");
2126+
}
2127+
21232128
@Override
21242129
public BigDecimal getMultiplier(final User user) {
21252130
BigDecimal multiplier = defaultMultiplier;

Essentials/src/main/java/com/earth2me/essentials/User.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,11 @@ public boolean checkMuteTimeout(final long currentTime) {
775775
return false;
776776
}
777777

778+
@Override
779+
public long getLastActivityTime() {
780+
return this.lastActivity;
781+
}
782+
778783
@Deprecated
779784
public void updateActivity(final boolean broadcast) {
780785
updateActivity(broadcast, AfkStatusChangeEvent.Cause.UNKNOWN);

Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.earth2me.essentials.utils.AdventureUtil;
88
import com.earth2me.essentials.utils.EnumUtil;
99
import com.earth2me.essentials.utils.NumberUtil;
10+
import com.earth2me.essentials.utils.VersionUtil;
1011
import com.google.common.collect.Lists;
1112
import net.essentialsx.api.v2.services.BalanceTop;
1213
import org.bukkit.Bukkit;
@@ -121,9 +122,14 @@ public void run() {
121122
final User user = ess.getUser(entry.getKey());
122123

123124
final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
125+
final boolean offlineStatisticSupported = VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_2_R01);
124126
final long playtime;
125127
if (user.getBase() == null || !user.getBase().isOnline()) {
126-
playtime = Bukkit.getServer().getOfflinePlayer(entry.getKey()).getStatistic(PLAY_ONE_TICK);
128+
if (offlineStatisticSupported) {
129+
playtime = Bukkit.getServer().getOfflinePlayer(entry.getKey()).getStatistic(PLAY_ONE_TICK);
130+
} else {
131+
playtime = -1;
132+
}
127133
} else {
128134
playtime = user.getBase().getStatistic(PLAY_ONE_TICK);
129135
}
@@ -133,7 +139,8 @@ public void run() {
133139
// Checking if player meets the requirements of minimum balance and minimum playtime to be listed in baltop list
134140
if ((ess.getSettings().showZeroBaltop() || balance.compareTo(BigDecimal.ZERO) > 0)
135141
&& balance.compareTo(ess.getSettings().getBaltopMinBalance()) >= 0 &&
136-
playTimeSecs >= ess.getSettings().getBaltopMinPlaytime()) {
142+
// Skip playtime check for offline players on versions below 1.15.2
143+
(playtime == -1 || playTimeSecs >= ess.getSettings().getBaltopMinPlaytime())) {
137144
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(balance, ess)))));
138145
}
139146
pos++;

Essentials/src/main/java/com/earth2me/essentials/commands/Commandnick.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected void updatePlayer(final Server server, final CommandSource sender, fin
6363

6464
private String formatNickname(final User user, final String nick) throws Exception {
6565
final String newNick = user == null ? FormatUtil.replaceFormat(nick) : FormatUtil.formatString(user, "essentials.nick", nick);
66-
if (!newNick.matches("^[a-zA-Z_0-9" + ChatColor.COLOR_CHAR + "]+$") && user != null && !user.isAuthorized("essentials.nick.allowunsafe")) {
66+
if (!newNick.matches(ess.getSettings().getNickRegex()) && user != null && !user.isAuthorized("essentials.nick.allowunsafe")) {
6767
throw new TranslatableException("nickNamesAlpha");
6868
} else if (getNickLength(newNick) > ess.getSettings().getMaxNickLength()) {
6969
throw new TranslatableException("nickTooLong");

0 commit comments

Comments
 (0)