Removed the unused WorldEdit hook. (#1853)

If someone wants to add it back later they can, but this code does
nothing right now.
This commit is contained in:
tastybento 2021-09-13 19:46:10 -07:00 committed by GitHub
parent bb7f124066
commit 063fa97cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 0 additions and 286 deletions

View File

@ -23,7 +23,6 @@ import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.hooks.DynmapHook; import world.bentobox.bentobox.hooks.DynmapHook;
import world.bentobox.bentobox.hooks.MultiverseCoreHook; import world.bentobox.bentobox.hooks.MultiverseCoreHook;
import world.bentobox.bentobox.hooks.VaultHook; import world.bentobox.bentobox.hooks.VaultHook;
import world.bentobox.bentobox.hooks.WorldEditHook;
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook; import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook;
import world.bentobox.bentobox.listeners.BannedCommands; import world.bentobox.bentobox.listeners.BannedCommands;
import world.bentobox.bentobox.listeners.BlockEndDragon; import world.bentobox.bentobox.listeners.BlockEndDragon;
@ -227,7 +226,6 @@ public class BentoBox extends JavaPlugin {
// Register additional hooks // Register additional hooks
hooksManager.registerHook(new DynmapHook()); hooksManager.registerHook(new DynmapHook());
hooksManager.registerHook(new WorldEditHook());
// TODO: re-enable after rework // TODO: re-enable after rework
//hooksManager.registerHook(new LangUtilsHook()); //hooksManager.registerHook(new LangUtilsHook());

View File

@ -1,136 +0,0 @@
package world.bentobox.bentobox.blueprints.worldedit;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.blueprints.Blueprint;
import world.bentobox.bentobox.database.json.BentoboxTypeAdapterFactory;
/**
* @since 1.6.0
* @author CustomEntity
*/
public class BlueprintClipboardFormat implements ClipboardFormat {
public BlueprintClipboardFormat() {
ClipboardFormats.registerClipboardFormat(this);
}
@Override
public String getName() {
return "Blueprint";
}
@Override
public Set<String> getAliases() {
return Sets.newHashSet("Bp");
}
@Override
public ClipboardReader getReader(InputStream inputStream) {
return new BlueprintClipboardReader(inputStream);
}
@Override
public ClipboardWriter getWriter(OutputStream outputStream) {
return new BlueprintClipboardWriter(outputStream);
}
@Override
public boolean isFormat(File file) {
try {
Gson gson = getGson();
unzip(file.getAbsolutePath());
File unzippedFile = new File(file.getParentFile(), file.getName());
return gsonCheck(gson, unzippedFile);
} catch (IOException e) {
BentoBox.getInstance().logStacktrace(e);
}
return false;
}
private boolean gsonCheck(Gson gson, File unzippedFile) {
try (FileReader fr = new FileReader(unzippedFile)) {
gson.fromJson(fr, Blueprint.class);
return true;
} catch (Exception e) {
return false;
}
}
@Override
public String getPrimaryFileExtension() {
return "blueprint";
}
@Override
public Set<String> getFileExtensions() {
return ImmutableSet.of("blu", "blueprint");
}
private Gson getGson() {
GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().enableComplexMapKeySerialization();
// Disable <>'s escaping etc.
builder.disableHtmlEscaping();
// Register adapter factory
builder.registerTypeAdapterFactory(new BentoboxTypeAdapterFactory(BentoBox.getInstance()));
return builder.create();
}
private void unzip(final String zipFilePath) throws IOException {
Path path = Paths.get(zipFilePath);
if (!(path.toFile().exists())) {
throw new IOException("No file exists!");
}
try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipFilePath))) {
ZipEntry entry = zipInputStream.getNextEntry();
while (entry != null) {
Path filePath = Paths.get(path.getParent().toString(), entry.getName());
if (!entry.isDirectory()) {
unzipFiles(zipInputStream, filePath);
} else {
Files.createDirectories(filePath);
}
zipInputStream.closeEntry();
entry = zipInputStream.getNextEntry();
}
}
}
private void unzipFiles(final ZipInputStream zipInputStream, final Path unzipFilePath) throws IOException {
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(unzipFilePath.toAbsolutePath().toString()))) {
byte[] bytesIn = new byte[1024];
int read;
while ((read = zipInputStream.read(bytesIn)) != -1) {
bos.write(bytesIn, 0, read);
}
}
}
}

View File

@ -1,33 +0,0 @@
package world.bentobox.bentobox.blueprints.worldedit;
import java.io.InputStream;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
/**
* @since 1.6.0
* @author CustomEntity
*/
public class BlueprintClipboardReader implements ClipboardReader {
private final InputStream inputStream;
public BlueprintClipboardReader(InputStream inputStream) {
this.inputStream = inputStream;
}
@Override
public Clipboard read() {
throw new UnsupportedOperationException(); // TODO
}
@Override
public void close() {
throw new UnsupportedOperationException(); // TODO
}
public InputStream getInputStream() {
return inputStream;
}
}

View File

@ -1,32 +0,0 @@
package world.bentobox.bentobox.blueprints.worldedit;
import java.io.OutputStream;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
/**
* @since 1.6.0
* @author CustomEntity
*/
public class BlueprintClipboardWriter implements ClipboardWriter {
private final OutputStream outputStream;
public BlueprintClipboardWriter(OutputStream outputStream) {
this.outputStream = outputStream;
}
@Override
public void write(Clipboard clipboard) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public void close() {
throw new UnsupportedOperationException(); // TODO
}
public OutputStream getOutputStream() {
return outputStream;
}
}

View File

@ -1,42 +0,0 @@
package world.bentobox.bentobox.blueprints.worldedit;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import world.bentobox.bentobox.BentoBox;
/**
* @since 1.6.0
* @author CustomEntity
*/
public class BlueprintSchematicConverter {
private File blueprintFile;
public BlueprintSchematicConverter(File blueprintFile) {
if(BentoBox.getInstance().getHooks().getHook("WorldEdit").isEmpty()) {
BentoBox.getInstance().logError("WorldEdit must be installed to use that class !");
return;
}
this.blueprintFile = blueprintFile;
}
public Clipboard convertBlueprintToSchematic() {
Clipboard clipboard = null;
try {
clipboard = ClipboardFormats.findByFile(blueprintFile).getReader(new FileInputStream(blueprintFile)).read();
} catch (IOException e) {
BentoBox.getInstance().logWarning("Error while trying to convert blueprint format to schematic format.");
BentoBox.getInstance().logStacktrace(e);
}
return clipboard;
}
public File getBlueprintFile() {
return blueprintFile;
}
}

View File

@ -1,41 +0,0 @@
package world.bentobox.bentobox.hooks;
import org.bukkit.Material;
import org.eclipse.jdt.annotation.Nullable;
import com.sk89q.worldedit.WorldEdit;
import world.bentobox.bentobox.api.hooks.Hook;
import world.bentobox.bentobox.blueprints.worldedit.BlueprintClipboardFormat;
/**
* @since 1.6.0
* @author Poslovitch
*/
public class WorldEditHook extends Hook {
public WorldEditHook() {
super("WorldEdit", Material.WOODEN_AXE);
}
@Override
public boolean hook() {
WorldEdit instance;
try {
instance = WorldEdit.getInstance();
new BlueprintClipboardFormat();
} catch (Exception e) {
return false;
}
return instance != null;
}
@Override
@Nullable
public String getFailureCause() {
return null; // The process shouldn't fail
}
}