mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-09 18:07:37 +01:00
Use enum methods throughout plugin for cross-version enum lookups
This commit is contained in:
parent
acbc96fd55
commit
6c9c9ad42a
@ -1,5 +1,6 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.utils.EnumUtil;
|
||||||
import com.earth2me.essentials.utils.LocationUtil;
|
import com.earth2me.essentials.utils.LocationUtil;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -31,12 +32,7 @@ public class EssentialsBlockListener implements Listener {
|
|||||||
if (is == null) {
|
if (is == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Material MOB_SPAWNER;
|
Material MOB_SPAWNER = EnumUtil.getMaterial("SPAWNER", "MOB_SPAWNER");
|
||||||
try {
|
|
||||||
MOB_SPAWNER = Material.SPAWNER;
|
|
||||||
} catch (Exception e) {
|
|
||||||
MOB_SPAWNER = Material.valueOf("MOB_SPAWNER");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is.getType() == MOB_SPAWNER && event.getItemInHand() != null && event.getPlayer() != null && event.getItemInHand().getType() == MOB_SPAWNER) {
|
if (is.getType() == MOB_SPAWNER && event.getItemInHand() != null && event.getPlayer() != null && event.getItemInHand().getType() == MOB_SPAWNER) {
|
||||||
final BlockState blockState = event.getBlockPlaced().getState();
|
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.textreader.TextPager;
|
||||||
import com.earth2me.essentials.utils.DateUtil;
|
import com.earth2me.essentials.utils.DateUtil;
|
||||||
import com.earth2me.essentials.utils.LocationUtil;
|
import com.earth2me.essentials.utils.LocationUtil;
|
||||||
|
import com.earth2me.essentials.utils.MaterialUtil;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import net.ess3.nms.refl.ReflUtil;
|
import net.ess3.nms.refl.ReflUtil;
|
||||||
|
|
||||||
@ -592,7 +593,7 @@ public class EssentialsPlayerListener implements Listener {
|
|||||||
public void onPlayerInteract(final PlayerInteractEvent event) {
|
public void onPlayerInteract(final PlayerInteractEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case RIGHT_CLICK_BLOCK:
|
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());
|
User player = ess.getUser(event.getPlayer());
|
||||||
if (player.isAuthorized("essentials.sethome.bed")) {
|
if (player.isAuthorized("essentials.sethome.bed")) {
|
||||||
player.getBase().setBedSpawnLocation(event.getClickedBlock().getLocation());
|
player.getBase().setBedSpawnLocation(event.getClickedBlock().getLocation());
|
||||||
|
@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
|
|||||||
import com.earth2me.essentials.Mob;
|
import com.earth2me.essentials.Mob;
|
||||||
import com.earth2me.essentials.Trade;
|
import com.earth2me.essentials.Trade;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
|
import com.earth2me.essentials.utils.EnumUtil;
|
||||||
import com.earth2me.essentials.utils.LocationUtil;
|
import com.earth2me.essentials.utils.LocationUtil;
|
||||||
import com.earth2me.essentials.utils.NumberUtil;
|
import com.earth2me.essentials.utils.NumberUtil;
|
||||||
import com.earth2me.essentials.utils.StringUtil;
|
import com.earth2me.essentials.utils.StringUtil;
|
||||||
@ -28,12 +29,8 @@ public class Commandspawner extends EssentialsCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Location target = LocationUtil.getTarget(user.getBase());
|
final Location target = LocationUtil.getTarget(user.getBase());
|
||||||
Material MOB_SPAWNER;
|
Material MOB_SPAWNER = EnumUtil.getMaterial("SPAWNER", "MOB_SPAWNER");
|
||||||
try {
|
|
||||||
MOB_SPAWNER = Material.SPAWNER;
|
|
||||||
} catch (Exception e) {
|
|
||||||
MOB_SPAWNER = Material.valueOf("MOB_SPAWNER");
|
|
||||||
}
|
|
||||||
if (target == null || target.getBlock().getType() != MOB_SPAWNER) {
|
if (target == null || target.getBlock().getType() != MOB_SPAWNER) {
|
||||||
throw new Exception(tl("mobSpawnTarget"));
|
throw new Exception(tl("mobSpawnTarget"));
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.CommandSource;
|
|||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.craftbukkit.SetExpFix;
|
import com.earth2me.essentials.craftbukkit.SetExpFix;
|
||||||
import com.earth2me.essentials.utils.DateUtil;
|
import com.earth2me.essentials.utils.DateUtil;
|
||||||
|
import com.earth2me.essentials.utils.EnumUtil;
|
||||||
import com.earth2me.essentials.utils.NumberUtil;
|
import com.earth2me.essentials.utils.NumberUtil;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
@ -16,17 +17,13 @@ import static com.earth2me.essentials.I18n.tl;
|
|||||||
|
|
||||||
|
|
||||||
public class Commandwhois extends EssentialsCommand {
|
public class Commandwhois extends EssentialsCommand {
|
||||||
private Statistic playOneTick;
|
private final Statistic playOneTick;
|
||||||
|
|
||||||
public Commandwhois() {
|
public Commandwhois() {
|
||||||
super("whois");
|
super("whois");
|
||||||
try {
|
// For some reason, in 1.13 PLAY_ONE_MINUTE = ticks played
|
||||||
// For some reason, in 1.13 PLAY_ONE_MINUTE = ticks played
|
// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/b848d8ce633871b52115247b089029749c02f579
|
||||||
// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/b848d8ce633871b52115247b089029749c02f579
|
playOneTick = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
|
||||||
playOneTick = Statistic.valueOf("PLAY_ONE_MINUTE");
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
playOneTick = Statistic.valueOf("PLAY_ONE_TICK");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -113,36 +113,22 @@ public class LocationUtil {
|
|||||||
switch (below.getType()) {
|
switch (below.getType()) {
|
||||||
case LAVA:
|
case LAVA:
|
||||||
case FIRE:
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MaterialUtil.isBed(below.getType())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (below.getType() == Material.valueOf("FLOWING_LAVA")) {
|
if (below.getType() == Material.valueOf("FLOWING_LAVA")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) { // 1.13 LAVA uses Levelled
|
} catch (Exception ignored) { // 1.13 LAVA uses Levelled
|
||||||
}
|
}
|
||||||
Material PORTAL;
|
|
||||||
try {
|
Material PORTAL = EnumUtil.getMaterial("NETHER_PORTAL", "PORTAL");
|
||||||
PORTAL = Material.NETHER_PORTAL;
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
PORTAL = Material.valueOf("PORTAL");
|
|
||||||
}
|
|
||||||
if (world.getBlockAt(x, y, z).getType() == PORTAL) {
|
if (world.getBlockAt(x, y, z).getType() == PORTAL) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user