Skip to content

Commit

Permalink
remove non-module dependency on nms
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 6, 2019
1 parent e787f6b commit ea22f2b
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 18 deletions.
Expand Up @@ -73,6 +73,8 @@ public boolean isCorrectMappingsCode() {
return true;
}

public abstract void disableAsyncCatcher();

public abstract Sidebar createSidebar(Player player);

public abstract BlockLight createBlockLight(Location location, int lightLevel, long ticks);
Expand Down
7 changes: 0 additions & 7 deletions plugin/pom.xml
Expand Up @@ -22,13 +22,6 @@
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>${craftbukkit.version}</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.aufdemrand</groupId>
<artifactId>denizen-nmshandler</artifactId>
Expand Down
9 changes: 5 additions & 4 deletions plugin/src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -358,10 +358,11 @@ public void onEnable() {
}

try {
org.spigotmc.AsyncCatcher.enabled = false;
NMSHandler.getInstance().disableAsyncCatcher();
}
catch (Throwable e) {
dB.echoError("Running not-Spigot?!");
catch (Throwable ex) {
dB.echoError("Running not-Spigot?! AsyncCatcher disable failed!");
dB.echoError(ex);
}

try {
Expand Down Expand Up @@ -1707,7 +1708,7 @@ public boolean allowedToWebget() {
@Override
public void preTagExecute() {
try {
org.spigotmc.AsyncCatcher.enabled = false;
NMSHandler.getInstance().disableAsyncCatcher();
}
catch (Throwable e) {
dB.echoError("Running not-Spigot?!");
Expand Down
@@ -1,14 +1,14 @@
package net.aufdemrand.denizen.objects;

import net.aufdemrand.denizen.Settings;
import net.aufdemrand.denizen.utilities.Utilities;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.apache.commons.io.FileUtils;
import org.bukkit.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -1044,7 +1044,7 @@ public void adjust(Mechanism mechanism) {
File folder = new File(getWorld().getName());
Bukkit.getServer().unloadWorld(getWorld(), false);
try {
FileUtils.deleteDirectory(folder);
Utilities.deleteDirectory(folder);
}
catch (Exception ex) {
dB.echoError(ex);
Expand Down
Expand Up @@ -10,9 +10,9 @@
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.nio.file.Files;

public class FileCopyCommand extends AbstractCommand {

Expand Down Expand Up @@ -103,10 +103,10 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
d.mkdirs();
}
if (o.isDirectory()) {
FileUtils.copyDirectory(o, d);
Utilities.copyDirectory(o, d);
}
else {
FileUtils.copyFile(o, d);
Files.copy(o.toPath(), (disdir ? d.toPath().resolve(o.toPath().getFileName()) : d.toPath()));
}
scriptEntry.addObject("success", new Element("true"));
}
Expand Down
@@ -1,13 +1,13 @@
package net.aufdemrand.denizen.scripts.commands.world;

import net.aufdemrand.denizen.utilities.Utilities;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
Expand Down Expand Up @@ -100,7 +100,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dB.echoError(scriptEntry.getResidingQueue(), "Invalid copy from world folder - does not exist!");
return;
}
FileUtils.copyDirectory(folder, newFolder);
Utilities.copyDirectory(folder, newFolder);
File file = new File(worldName.asString() + "/uid.dat");
if (file.exists()) {
file.delete();
Expand Down
Expand Up @@ -26,6 +26,11 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand All @@ -37,6 +42,38 @@ public class Utilities {

public static final TagContext noDebugContext = new BukkitTagContext(null, null, false, null, false, null);

public static void deleteDirectory(File directory) throws IOException {
Files.walkFileTree(directory.toPath(),
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
});
}

public static void copyDirectory(File source, File destination) throws IOException {
copyDirectory(source.toPath(), destination.toPath());
}

public static void copyDirectory(Path source, Path destination) throws IOException {
Files.walk(source).forEach(file -> {
try {
Files.copy(file, destination.resolve(source.relativize(file)));
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
});
}

public static boolean canReadFile(File f) {
if (Settings.allowStupids()) {
return true;
Expand Down
Expand Up @@ -49,6 +49,11 @@ public class Handler_v1_10_R1 extends NMSHandler {

private final ProfileEditor profileEditor = new ProfileEditor_v1_10_R1();

@Override
public void disableAsyncCatcher() {
org.spigotmc.AsyncCatcher.enabled = false;
}

@Override
public Thread getMainThread() {
return ((CraftServer) Bukkit.getServer()).getServer().primaryThread;
Expand Down
Expand Up @@ -49,6 +49,11 @@ public class Handler_v1_11_R1 extends NMSHandler {

private final ProfileEditor profileEditor = new ProfileEditor_v1_11_R1();

@Override
public void disableAsyncCatcher() {
org.spigotmc.AsyncCatcher.enabled = false;
}

@Override
public Thread getMainThread() {
return ((CraftServer) Bukkit.getServer()).getServer().primaryThread;
Expand Down
Expand Up @@ -55,6 +55,11 @@ public class Handler_v1_12_R1 extends NMSHandler {

private final ProfileEditor profileEditor = new ProfileEditor_v1_12_R1();

@Override
public void disableAsyncCatcher() {
org.spigotmc.AsyncCatcher.enabled = false;
}

@Override
public Thread getMainThread() {
return ((CraftServer) Bukkit.getServer()).getServer().primaryThread;
Expand Down
Expand Up @@ -59,6 +59,11 @@ public class Handler_v1_13_R2 extends NMSHandler {

private final ProfileEditor profileEditor = new ProfileEditor_v1_13_R2();

@Override
public void disableAsyncCatcher() {
org.spigotmc.AsyncCatcher.enabled = false;
}

@Override
public boolean isCorrectMappingsCode() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals("00ed8e5c39debc3ed194ad7c5645cc45");
Expand Down
Expand Up @@ -49,6 +49,11 @@ public class Handler_v1_8_R3 extends NMSHandler {

private final ProfileEditor profileEditor = new ProfileEditor_v1_8_R3();

@Override
public void disableAsyncCatcher() {
org.spigotmc.AsyncCatcher.enabled = false;
}

@Override
public Thread getMainThread() {
return ((CraftServer) Bukkit.getServer()).getServer().primaryThread;
Expand Down
Expand Up @@ -49,6 +49,11 @@ public class Handler_v1_9_R2 extends NMSHandler {

private final ProfileEditor profileEditor = new ProfileEditor_v1_9_R2();

@Override
public void disableAsyncCatcher() {
org.spigotmc.AsyncCatcher.enabled = false;
}

@Override
public int getPort() {
return ((CraftServer) Bukkit.getServer()).getServer().P();
Expand Down

0 comments on commit ea22f2b

Please sign in to comment.