mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 17:18:37 +01:00
Merge branch '1.13' into 1.13-items
This commit is contained in:
commit
102cb6d949
@ -1,5 +1,6 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.GameMode;
|
||||
@ -31,12 +32,7 @@ public class EssentialsBlockListener implements Listener {
|
||||
if (is == null) {
|
||||
return;
|
||||
}
|
||||
Material MOB_SPAWNER;
|
||||
try {
|
||||
MOB_SPAWNER = Material.SPAWNER;
|
||||
} catch (Exception e) {
|
||||
MOB_SPAWNER = Material.valueOf("MOB_SPAWNER");
|
||||
}
|
||||
Material MOB_SPAWNER = EnumUtil.getMaterial("SPAWNER", "MOB_SPAWNER");
|
||||
|
||||
if (is.getType() == MOB_SPAWNER && event.getItemInHand() != null && event.getPlayer() != null && event.getItemInHand().getType() == MOB_SPAWNER) {
|
||||
final BlockState blockState = event.getBlockPlaced().getState();
|
||||
|
@ -6,6 +6,7 @@ import com.earth2me.essentials.textreader.TextInput;
|
||||
import com.earth2me.essentials.textreader.TextPager;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
|
||||
@ -592,7 +593,7 @@ public class EssentialsPlayerListener implements Listener {
|
||||
public void onPlayerInteract(final PlayerInteractEvent event) {
|
||||
switch (event.getAction()) {
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
if (!event.isCancelled() && event.getClickedBlock().getType() == Material.LEGACY_BED && ess.getSettings().getUpdateBedAtDaytime()) {
|
||||
if (!event.isCancelled() && MaterialUtil.isBed(event.getClickedBlock().getType()) && ess.getSettings().getUpdateBedAtDaytime()) {
|
||||
User player = ess.getUser(event.getPlayer());
|
||||
if (player.isAuthorized("essentials.sethome.bed")) {
|
||||
player.getBase().setBedSpawnLocation(event.getClickedBlock().getLocation());
|
||||
|
@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.Mob;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
@ -28,12 +29,8 @@ public class Commandspawner extends EssentialsCommand {
|
||||
}
|
||||
|
||||
final Location target = LocationUtil.getTarget(user.getBase());
|
||||
Material MOB_SPAWNER;
|
||||
try {
|
||||
MOB_SPAWNER = Material.SPAWNER;
|
||||
} catch (Exception e) {
|
||||
MOB_SPAWNER = Material.valueOf("MOB_SPAWNER");
|
||||
}
|
||||
Material MOB_SPAWNER = EnumUtil.getMaterial("SPAWNER", "MOB_SPAWNER");
|
||||
|
||||
if (target == null || target.getBlock().getType() != MOB_SPAWNER) {
|
||||
throw new Exception(tl("mobSpawnTarget"));
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.craftbukkit.SetExpFix;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Statistic;
|
||||
@ -16,17 +17,13 @@ import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
|
||||
public class Commandwhois extends EssentialsCommand {
|
||||
private Statistic playOneTick;
|
||||
private final Statistic playOneTick;
|
||||
|
||||
public Commandwhois() {
|
||||
super("whois");
|
||||
try {
|
||||
// For some reason, in 1.13 PLAY_ONE_MINUTE = ticks played
|
||||
// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/b848d8ce633871b52115247b089029749c02f579
|
||||
playOneTick = Statistic.valueOf("PLAY_ONE_MINUTE");
|
||||
} catch (IllegalArgumentException e) {
|
||||
playOneTick = Statistic.valueOf("PLAY_ONE_TICK");
|
||||
}
|
||||
// For some reason, in 1.13 PLAY_ONE_MINUTE = ticks played
|
||||
// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/b848d8ce633871b52115247b089029749c02f579
|
||||
playOneTick = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
35
Essentials/src/com/earth2me/essentials/utils/EnumUtil.java
Normal file
35
Essentials/src/com/earth2me/essentials/utils/EnumUtil.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.earth2me.essentials.utils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class EnumUtil {
|
||||
|
||||
/**
|
||||
* Looks up enum fields by checking multiple names.
|
||||
*/
|
||||
public static <T extends Enum> T valueOf(Class<T> enumClass, String... names) {
|
||||
for (String name : names) {
|
||||
try {
|
||||
Field enumField = enumClass.getDeclaredField(name);
|
||||
|
||||
if (enumField.isEnumConstant()) {
|
||||
return (T) enumField.get(null);
|
||||
}
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Material getMaterial(String... names) {
|
||||
return valueOf(Material.class, names);
|
||||
}
|
||||
|
||||
public static Statistic getStatistic(String... names) {
|
||||
return valueOf(Statistic.class, names);
|
||||
}
|
||||
|
||||
}
|
@ -113,36 +113,22 @@ public class LocationUtil {
|
||||
switch (below.getType()) {
|
||||
case LAVA:
|
||||
case FIRE:
|
||||
case BLACK_BED:
|
||||
case BLUE_BED:
|
||||
case BROWN_BED:
|
||||
case CYAN_BED:
|
||||
case GRAY_BED:
|
||||
case GREEN_BED:
|
||||
case LIGHT_BLUE_BED:
|
||||
case LIGHT_GRAY_BED:
|
||||
case LIME_BED:
|
||||
case MAGENTA_BED:
|
||||
case ORANGE_BED:
|
||||
case PINK_BED:
|
||||
case PURPLE_BED:
|
||||
case RED_BED:
|
||||
case WHITE_BED:
|
||||
case YELLOW_BED:
|
||||
return true;
|
||||
}
|
||||
|
||||
if (MaterialUtil.isBed(below.getType())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (below.getType() == Material.valueOf("FLOWING_LAVA")) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception ignored) { // 1.13 LAVA uses Levelled
|
||||
}
|
||||
Material PORTAL;
|
||||
try {
|
||||
PORTAL = Material.NETHER_PORTAL;
|
||||
} catch (Exception ignored) {
|
||||
PORTAL = Material.valueOf("PORTAL");
|
||||
}
|
||||
|
||||
Material PORTAL = EnumUtil.getMaterial("NETHER_PORTAL", "PORTAL");
|
||||
|
||||
if (world.getBlockAt(x, y, z).getType() == PORTAL) {
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.earth2me.essentials.utils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.earth2me.essentials.utils.EnumUtil.getMaterial;
|
||||
|
||||
public class MaterialUtil {
|
||||
|
||||
private static final Set<Material> BEDS = new HashSet<>();
|
||||
|
||||
static {
|
||||
// Adds WHITE_BED if 1.13+, otherwise BED
|
||||
BEDS.add(getMaterial("WHITE_BED", "BED"));
|
||||
|
||||
// Don't keep looking up and adding BED if we're not on 1.13+
|
||||
if (BEDS.add(getMaterial("ORANGE_BED", "BED"))) {
|
||||
BEDS.add(getMaterial("MAGENTA_BED", "BED"));
|
||||
BEDS.add(getMaterial("LIGHT_BLUE_BED", "BED"));
|
||||
BEDS.add(getMaterial("YELLOW_BED", "BED"));
|
||||
BEDS.add(getMaterial("LIME_BED", "BED"));
|
||||
BEDS.add(getMaterial("PINK_BED", "BED"));
|
||||
BEDS.add(getMaterial("GRAY_BED", "BED"));
|
||||
BEDS.add(getMaterial("LIGHT_GRAY_BED", "BED"));
|
||||
BEDS.add(getMaterial("CYAN_BED", "BED"));
|
||||
BEDS.add(getMaterial("PURPLE_BED", "BED"));
|
||||
BEDS.add(getMaterial("BLUE_BED", "BED"));
|
||||
BEDS.add(getMaterial("BROWN_BED", "BED"));
|
||||
BEDS.add(getMaterial("GREEN_BED", "BED"));
|
||||
BEDS.add(getMaterial("RED_BED", "BED"));
|
||||
BEDS.add(getMaterial("BLACK_BED", "BED"));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBed(Material material) {
|
||||
return BEDS.contains(material);
|
||||
}
|
||||
|
||||
}
|
@ -24,6 +24,7 @@ public class ReflUtil {
|
||||
public static final NMSVersion V1_11_R1 = NMSVersion.fromString("v1_11_R1");
|
||||
public static final NMSVersion V1_12_R1 = NMSVersion.fromString("v1_12_R1");
|
||||
public static final NMSVersion V1_13_R1 = NMSVersion.fromString("v1_13_R1");
|
||||
public static final NMSVersion V1_13_R2 = NMSVersion.fromString("v1_13_R2");
|
||||
private static NMSVersion nmsVersionObject;
|
||||
private static String nmsVersion;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user