mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 05:05:18 +01:00
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:
parent
bb7f124066
commit
063fa97cf3
@ -23,7 +23,6 @@ import world.bentobox.bentobox.database.DatabaseSetup;
|
||||
import world.bentobox.bentobox.hooks.DynmapHook;
|
||||
import world.bentobox.bentobox.hooks.MultiverseCoreHook;
|
||||
import world.bentobox.bentobox.hooks.VaultHook;
|
||||
import world.bentobox.bentobox.hooks.WorldEditHook;
|
||||
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook;
|
||||
import world.bentobox.bentobox.listeners.BannedCommands;
|
||||
import world.bentobox.bentobox.listeners.BlockEndDragon;
|
||||
@ -227,7 +226,6 @@ public class BentoBox extends JavaPlugin {
|
||||
|
||||
// Register additional hooks
|
||||
hooksManager.registerHook(new DynmapHook());
|
||||
hooksManager.registerHook(new WorldEditHook());
|
||||
// TODO: re-enable after rework
|
||||
//hooksManager.registerHook(new LangUtilsHook());
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user