diff --git a/src/main/java/com/ytdd9527/networksexpansion/utils/WorldUtils.java b/src/main/java/com/ytdd9527/networksexpansion/utils/WorldUtils.java index dad3af1f..1fa65c99 100644 --- a/src/main/java/com/ytdd9527/networksexpansion/utils/WorldUtils.java +++ b/src/main/java/com/ytdd9527/networksexpansion/utils/WorldUtils.java @@ -7,49 +7,50 @@ import java.lang.reflect.Field; +@Deprecated public class WorldUtils { - protected static Class CraftBlockStateClass; - protected static Field IBlockDataField; - protected static Field BlockPositionField; - protected static Field WorldField; - protected static Field WeakWorldField; - protected static boolean invokeBlockStateSuccess = false; + protected static Class craftBlockStateClass; + protected static Field interfaceBlockDataField; + protected static Field blockPositionField; + protected static Field worldField; + protected static Field weakWorldField; + protected static boolean success = false; static { try { World sampleWorld = Bukkit.getWorlds().get(0); BlockState blockstate = sampleWorld.getBlockAt(0, 0, 0).getState(); var result = ReflectionUtil.getDeclaredFieldsRecursively(blockstate.getClass(), "data"); - IBlockDataField = result.getFirstValue(); - IBlockDataField.setAccessible(true); - CraftBlockStateClass = result.getSecondValue(); - BlockPositionField = ReflectionUtil.getDeclaredFieldsRecursively(CraftBlockStateClass, "position").getFirstValue(); - BlockPositionField.setAccessible(true); - WorldField = ReflectionUtil.getDeclaredFieldsRecursively(CraftBlockStateClass, "world").getFirstValue(); - WorldField.setAccessible(true); - WeakWorldField = ReflectionUtil.getDeclaredFieldsRecursively(CraftBlockStateClass, "weakWorld").getFirstValue(); - WeakWorldField.setAccessible(true); - invokeBlockStateSuccess = true; + interfaceBlockDataField = result.getFirstValue(); + interfaceBlockDataField.setAccessible(true); + craftBlockStateClass = result.getSecondValue(); + blockPositionField = ReflectionUtil.getDeclaredFieldsRecursively(craftBlockStateClass, "position").getFirstValue(); + blockPositionField.setAccessible(true); + worldField = ReflectionUtil.getDeclaredFieldsRecursively(craftBlockStateClass, "world").getFirstValue(); + worldField.setAccessible(true); + weakWorldField = ReflectionUtil.getDeclaredFieldsRecursively(craftBlockStateClass, "weakWorld").getFirstValue(); + weakWorldField.setAccessible(true); + success = true; } catch (Throwable ignored) { } } - public static boolean copyBlockState(BlockState stateToSet, Block toBlock) { - if (!invokeBlockStateSuccess) { + public static boolean copyBlockState(BlockState fromBlockState, Block toBlock) { + if (!success) { return false; } - BlockState originalState = toBlock.getState(); - if (!CraftBlockStateClass.isInstance(originalState) || !CraftBlockStateClass.isInstance(stateToSet)) { + BlockState toState = toBlock.getState(); + if (!craftBlockStateClass.isInstance(toState) || !craftBlockStateClass.isInstance(fromBlockState)) { return false; } try { - BlockPositionField.set(stateToSet, BlockPositionField.get(originalState)); - WorldField.set(stateToSet, WorldField.get(originalState)); - WeakWorldField.set(stateToSet, WeakWorldField.get(originalState)); - stateToSet.update(true, false); + blockPositionField.set(fromBlockState, blockPositionField.get(toState)); + worldField.set(fromBlockState, worldField.get(toState)); + weakWorldField.set(fromBlockState, weakWorldField.get(toState)); + fromBlockState.update(true, false); return true; } catch (Throwable ignored) { return false; diff --git a/src/main/java/io/github/sefiraat/networks/commands/NetworksMain.java b/src/main/java/io/github/sefiraat/networks/commands/NetworksMain.java index b8da3bf8..515d05d9 100644 --- a/src/main/java/io/github/sefiraat/networks/commands/NetworksMain.java +++ b/src/main/java/io/github/sefiraat/networks/commands/NetworksMain.java @@ -69,8 +69,11 @@ @SuppressWarnings({"deprecation", "unused"}) public class NetworksMain implements TabExecutor { + @Deprecated private static final Set requesters = new ConcurrentSkipListSet<>(); + @Deprecated private static final Networks javaPlugin = Networks.getInstance(); + @Deprecated private static final Map> SELECTED_POS = new HashMap<>(); public NetworksMain() { @@ -87,6 +90,7 @@ public NetworksMain() { }, 0, Slimefun.getTickerTask().getTickRate()); } + @Deprecated public static Location getPos1(Player p) { if (SELECTED_POS.get(p.getUniqueId()) == null) { return null; @@ -95,6 +99,7 @@ public static Location getPos1(Player p) { return SELECTED_POS.get(p.getUniqueId()).getFirstValue(); } + @Deprecated public static Location getPos2(Player p) { if (SELECTED_POS.get(p.getUniqueId()) == null) { return null; @@ -102,19 +107,23 @@ public static Location getPos2(Player p) { return SELECTED_POS.get(p.getUniqueId()).getSecondValue(); } + @Deprecated public static void setPos1(Player p, Location pos) { SELECTED_POS.put(p.getUniqueId(), new Pair<>(pos, getPos2(p))); } + @Deprecated public static void setPos2(Player p, Location pos) { SELECTED_POS.put(p.getUniqueId(), new Pair<>(getPos1(p), pos)); } + @Deprecated public static void clearPos(Player p) { SELECTED_POS.remove(p.getUniqueId()); p.sendMessage(Networks.getLocalizationService().getString("messages.commands.clear-selected-pos")); } + @Deprecated public static void toggleShowSelectedAreaOutline(Player p) { if (requesters.contains(p.getUniqueId())) { requesters.remove(p.getUniqueId()); @@ -125,6 +134,7 @@ public static void toggleShowSelectedAreaOutline(Player p) { } } + @Deprecated private static void handleSelectedAreaOutlineShowRequest(Player p) { Location pos1 = getPos1(p); Location pos2 = getPos2(p); @@ -135,6 +145,7 @@ private static void handleSelectedAreaOutlineShowRequest(Player p) { javaPlugin.getServer().getScheduler().runTaskLaterAsynchronously(javaPlugin, () -> ParticleUtil.drawRegionOutline(javaPlugin, Particle.WAX_OFF, 0, pos1, pos2), Slimefun.getTickerTask().getTickRate()); } + @Deprecated public static String locationToString(Location l) { if (l == null) { return Networks.getLocalizationService().getString("icons.drawer.location_error.unknown"); @@ -145,6 +156,7 @@ public static String locationToString(Location l) { return l.getWorld().getName() + "," + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ(); } + @Deprecated public static long locationRange(Location pos1, Location pos2) { if (pos1 == null || pos2 == null) { return 0; @@ -159,6 +171,7 @@ public static long locationRange(Location pos1, Location pos2) { return (long) (Math.abs(upX - downX) + 1) * (Math.abs(upY - downY) + 1) * (Math.abs(upZ - downZ) + 1); } + @Deprecated private static void doWorldEdit(Location pos1, Location pos2, Consumer consumer) { if (pos1 == null || pos2 == null) { return; @@ -368,6 +381,7 @@ public static void setContainerId(Player player, int containerId) { } + @Deprecated public static void worldeditPos1(Player player) { Block targetBlock = player.getTargetBlockExact(8, FluidCollisionMode.NEVER); if (targetBlock == null) { @@ -377,6 +391,7 @@ public static void worldeditPos1(Player player) { worldeditPos1(player, targetBlock.getLocation()); } + @Deprecated public static void worldeditPos1(Player player, Location location) { setPos1(player, location); if (getPos2(player) == null) { @@ -386,6 +401,7 @@ public static void worldeditPos1(Player player, Location location) { } } + @Deprecated public static void worldeditPos2(Player player) { Block targetBlock = player.getTargetBlockExact(8, FluidCollisionMode.NEVER); if (targetBlock == null) { @@ -395,6 +411,7 @@ public static void worldeditPos2(Player player) { worldeditPos2(player, targetBlock.getLocation()); } + @Deprecated public static void worldeditPos2(Player player, Location location) { setPos2(player, location); if (getPos1(player) == null) { @@ -404,10 +421,12 @@ public static void worldeditPos2(Player player, Location location) { } } + @Deprecated public static void worldeditClone(Player player) { worldeditClone(player, false); } + @Deprecated public static void worldeditClone(Player player, boolean overrideData) { if (getPos1(player) == null || getPos2(player) == null) { player.sendMessage(Networks.getLocalizationService().getString("messages.commands.worldedit.must-select-range")); @@ -518,14 +537,17 @@ public static void worldeditClone(Player player, boolean overrideData) { }); } + @Deprecated public static void worldeditPaste(Player player, String sfid) { worldeditPaste(player, sfid, false, false); } + @Deprecated public static void worldeditPaste(Player player, String sfid, boolean overrideData) { worldeditPaste(player, sfid, overrideData, false); } + @Deprecated public static void worldeditPaste(Player player, String sfid, boolean overrideData, boolean force) { final SlimefunItem sfItem = SlimefunItem.getById(sfid); @@ -609,6 +631,7 @@ public static void worldeditPaste(Player player, String sfid, boolean overrideDa player.sendMessage(String.format(Networks.getLocalizationService().getString("messages.commands.worldedit.paste-done"), count, System.currentTimeMillis() - currentMillSeconds)); } + @Deprecated public static void worldeditClear(Player player, boolean callHandler, boolean skipVanilla) { if (getPos1(player) == null || getPos2(player) == null) { player.sendMessage(Networks.getLocalizationService().getString("messages.commands.worldedit.must-select-range")); @@ -647,6 +670,7 @@ public static void worldeditClear(Player player, boolean callHandler, boolean sk player.sendMessage(String.format(Networks.getLocalizationService().getString("messages.commands.worldedit.clear-done"), count, System.currentTimeMillis() - currentMillSeconds)); } + @Deprecated public static void worldeditBlockMenuSetSlot(Player player, int slot) { if (getPos1(player) == null || getPos2(player) == null) { player.sendMessage(Networks.getLocalizationService().getString("messages.commands.worldedit.must-select-range")); @@ -681,6 +705,7 @@ public static void worldeditBlockMenuSetSlot(Player player, int slot) { player.sendMessage(String.format(Networks.getLocalizationService().getString("messages.commands.worldedit.set-slot-done"), slot, itemName, System.currentTimeMillis() - currentMillSeconds)); } + @Deprecated public static void worldeditBlockInfoAdd(Player player, String key, String value) { if (getPos1(player) == null || getPos2(player) == null) { player.sendMessage(Networks.getLocalizationService().getString("messages.commands.worldedit.must-select-range")); @@ -706,6 +731,7 @@ public static void worldeditBlockInfoAdd(Player player, String key, String value player.sendMessage(String.format(Networks.getLocalizationService().getString("messages.commands.worldedit.set-info-done"), key, value, System.currentTimeMillis() - currentMillSeconds)); } + @Deprecated public static void worldeditBlockInfoRemove(Player player, String key) { if (getPos1(player) == null || getPos2(player) == null) { player.sendMessage(Networks.getLocalizationService().getString("messages.commands.worldedit.must-select-range"));