Skip to content

Commit

Permalink
Move to new packages
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Jun 8, 2024
1 parent 73545ba commit 2059ebe
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,17 @@ public void onEnable() {
logger.info("No PilotTool setting, using default of stick");
}

String packageName = getServer().getClass().getPackage().getName();
String version = packageName.substring(packageName.lastIndexOf('.') + 1);
if (version.equals("craftbukkit")) {
// We must be running Paper without relocation
version = "v1_20";
}

getLogger().info("Loading support for " + version);
String minecraftVersion = getServer().getMinecraftVersion();
getLogger().info("Loading support for " + minecraftVersion);
try {
final Class<?> worldHandlerClazz = Class.forName("net.countercraft.movecraft.compat." + version + ".IWorldHandler");
final Class<?> worldHandlerClazz = Class.forName("net.countercraft.movecraft.compat." + WorldHandler.getPackageName(minecraftVersion) + ".IWorldHandler");
// Check if we have a NMSHandler class at that location.
if (WorldHandler.class.isAssignableFrom(worldHandlerClazz)) { // Make sure it actually implements NMS
worldHandler = (WorldHandler) worldHandlerClazz.getConstructor().newInstance(); // Set our handler

// Try to setup the smooth teleport handler
try {
final Class<?> smoothTeleportClazz = Class.forName("net.countercraft.movecraft.support." + version + ".ISmoothTeleport");
final Class<?> smoothTeleportClazz = Class.forName("net.countercraft.movecraft.support." + WorldHandler.getPackageName(minecraftVersion) + ".ISmoothTeleport");
if (SmoothTeleport.class.isAssignableFrom(smoothTeleportClazz)) {
smoothTeleport = (SmoothTeleport) smoothTeleportClazz.getConstructor().newInstance();
}
Expand Down Expand Up @@ -212,22 +206,11 @@ public void onEnable() {
}
}

Settings.DisableShadowBlocks = EnumSet.noneOf(Material.class); //REMOVE FOR PUBLIC VERSION
// for(String s : getConfig().getStringList("DisableShadowBlocks")){
// Settings.DisableShadowBlocks.add(Material.valueOf(s));
// }

Settings.ForbiddenRemoteSigns = new HashSet<>();

for(String s : getConfig().getStringList("ForbiddenRemoteSigns")) {
Settings.ForbiddenRemoteSigns.add(s.toLowerCase());
}

if(!Settings.CompatibilityMode) {
for(Material typ : Settings.DisableShadowBlocks) {
worldHandler.disableShadow(typ);
}
}
adventure = BukkitAudiences.create(this);

if(shuttingDown && Settings.IGNORE_RESET) {
Expand All @@ -237,7 +220,6 @@ public void onEnable() {
return;
}


// Startup procedure
boolean datapackInitialized = initializeDatapack();
asyncManager = new AsyncManager();
Expand All @@ -247,7 +229,6 @@ public void onEnable() {
CraftManager.initialize(datapackInitialized);
Bukkit.getScheduler().runTaskTimer(this, WorldManager.INSTANCE::run, 0,1);


getServer().getPluginManager().registerEvents(new InteractListener(), this);

getCommand("movecraft").setExecutor(new MovecraftCommand());
Expand Down
1 change: 0 additions & 1 deletion modules/Movecraft/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ ForbiddenRemoteSigns: # These strings will be ignored when searching for signs t
- "Mounted"
- "Denied"
- "[private]"
CompatibilityMode: false
GeneratedDatapack: false # Set to false to re-generate datapack on startup
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public abstract class WorldHandler {
public abstract void translateCraft(@NotNull Craft craft, @NotNull MovecraftLocation newLocation, @NotNull World world);
public abstract void setBlockFast(@NotNull Location location, @NotNull BlockData data);
public abstract void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data);
public abstract void disableShadow(@NotNull Material type);
public abstract @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView);
public abstract void setAccessLocation(@NotNull InventoryView inventoryView, @NotNull Location location);

public static @NotNull String getPackageName(@NotNull String minecraftVersion) {
return "v1_" + minecraftVersion.substring(minecraftVersion.indexOf('.') + 1, minecraftVersion.lastIndexOf('.'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ public class Settings {
public static boolean IGNORE_RESET = false;
public static boolean Debug = false;
public static boolean DisableNMSCompatibilityCheck = false;
public static int THREAD_POOL_SIZE = 5;
public static List<Integer> DATA_BLOCKS;
public static String LOCALE;
public static Material PilotTool = Material.STICK;
public static int SilhouetteViewDistance = 200;
public static int SilhouetteBlockCount = 20;
public static boolean CompatibilityMode = false;
public static boolean DelayColorChanges = false;
public static double SinkRateTicks = 20.0;
public static double SinkCheckTicks = 100.0;
public static boolean ProtectPilotedCrafts = false;
public static boolean DisableSpillProtection = false;
Expand All @@ -52,7 +47,5 @@ public class Settings {
public static double ManOverboardDistSquared = 1000000;
public static int MaxRemoteSigns = -1;
public static boolean CraftsUseNetherPortals = false;

public static EnumSet<Material> DisableShadowBlocks;
public static HashSet<String> ForbiddenRemoteSigns;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.countercraft.movecraft.support;

import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.WorldHandler;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
Expand All @@ -15,17 +16,15 @@ public abstract class AsyncChunk<T extends Chunk> {

private static final Constructor<?> constructor;
static {
String packageName = Bukkit.getServer().getClass().getPackage().getName();
String version = packageName.substring(packageName.lastIndexOf('.') + 1);
Constructor<?> temp = null;
try {
Class.forName("net.countercraft.movecraft.support.v1_18.IAsyncChunk");
final Class<?> clazz = Class.forName("net.countercraft.movecraft.support." + version + ".IAsyncChunk");
final Class<?> clazz = Class.forName("net.countercraft.movecraft.support." + WorldHandler.getPackageName(Bukkit.getServer().getMinecraftVersion()) + ".IAsyncChunk");
if (AsyncChunk.class.isAssignableFrom(clazz)) {
temp = clazz.getConstructor(Chunk.class);
}
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException exception) {
Bukkit.getLogger().severe(String.format("Error in registering Chunk accessor for version %s from the classpath.", version));
Bukkit.getLogger().severe(String.format("Error in registering Chunk accessor for version %s from the classpath.", Bukkit.getServer().getMinecraftVersion()));
exception.printStackTrace();
}
constructor = temp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,6 @@ public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation
setBlockFast(world, BlockPos, blockData);
}

@Override
public void disableShadow(@NotNull Material type) {
// Disabled
}

@Override
public @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView) {
AbstractContainerMenu menu = ((CraftInventoryView) inventoryView).getHandle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,6 @@ public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation
setBlockFast(world, BlockPos, blockData);
}

@Override
public void disableShadow(@NotNull Material type) {
// Disabled
}

@Override
public @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView) {
AbstractContainerMenu menu = ((CraftInventoryView) inventoryView).getHandle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,6 @@ public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation
setBlockFast(world, BlockPos, blockData);
}

@Override
public void disableShadow(@NotNull Material type) {
// Disabled
}

@Override
public @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView) {
AbstractContainerMenu menu = ((CraftInventoryView) inventoryView).getHandle();
Expand Down

0 comments on commit 2059ebe

Please sign in to comment.