mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-07 16:26:14 +00:00
Repackage utils
This commit is contained in:
30
src/main/java/com/volmit/iris/util/io/Converter.java
Normal file
30
src/main/java/com/volmit/iris/util/io/Converter.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface Converter {
|
||||
String getInExtension();
|
||||
|
||||
@SuppressWarnings("SameReturnValue")
|
||||
String getOutExtension();
|
||||
|
||||
void convert(File in, File out);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class CustomOutputStream extends GZIPOutputStream {
|
||||
public CustomOutputStream(OutputStream out, int level) throws IOException {
|
||||
super(out);
|
||||
def.setLevel(level);
|
||||
}
|
||||
}
|
||||
52
src/main/java/com/volmit/iris/util/io/FileWatcher.java
Normal file
52
src/main/java/com/volmit/iris/util/io/FileWatcher.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FileWatcher {
|
||||
protected final File file;
|
||||
private boolean exists;
|
||||
private long lastModified;
|
||||
private long size;
|
||||
|
||||
public FileWatcher(File file) {
|
||||
this.file = file;
|
||||
readProperties();
|
||||
}
|
||||
|
||||
protected void readProperties() {
|
||||
exists = file.exists();
|
||||
lastModified = exists ? file.lastModified() : -1;
|
||||
size = exists ? file.isDirectory() ? -2 : file.length() : -1;
|
||||
}
|
||||
|
||||
public boolean checkModified() {
|
||||
long m = lastModified;
|
||||
long g = size;
|
||||
boolean mod = false;
|
||||
readProperties();
|
||||
|
||||
if (lastModified != m || g != size) {
|
||||
mod = true;
|
||||
}
|
||||
|
||||
return mod;
|
||||
}
|
||||
}
|
||||
113
src/main/java/com/volmit/iris/util/io/FolderWatcher.java
Normal file
113
src/main/java/com/volmit/iris/util/io/FolderWatcher.java
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FolderWatcher extends FileWatcher {
|
||||
private KMap<File, FolderWatcher> watchers;
|
||||
private KList<File> changed;
|
||||
private KList<File> created;
|
||||
private KList<File> deleted;
|
||||
|
||||
public FolderWatcher(File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
protected void readProperties() {
|
||||
if (watchers == null) {
|
||||
watchers = new KMap<>();
|
||||
changed = new KList<>();
|
||||
created = new KList<>();
|
||||
deleted = new KList<>();
|
||||
}
|
||||
|
||||
if (file.isDirectory()) {
|
||||
for (File i : file.listFiles()) {
|
||||
if (!watchers.containsKey(i)) {
|
||||
watchers.put(i, new FolderWatcher(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (watchers == null) {
|
||||
System.out.print("wtf");
|
||||
}
|
||||
|
||||
for (File i : watchers.k()) {
|
||||
if (!i.exists()) {
|
||||
watchers.remove(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.readProperties();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkModified() {
|
||||
changed.clear();
|
||||
created.clear();
|
||||
deleted.clear();
|
||||
|
||||
if (file.isDirectory()) {
|
||||
KMap<File, FolderWatcher> w = watchers.copy();
|
||||
readProperties();
|
||||
|
||||
for (File i : w.k()) {
|
||||
if (!watchers.containsKey(i)) {
|
||||
deleted.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (File i : watchers.k()) {
|
||||
if (!w.containsKey(i)) {
|
||||
created.add(i);
|
||||
} else {
|
||||
FolderWatcher fw = watchers.get(i);
|
||||
if (fw.checkModified()) {
|
||||
changed.add(fw.file);
|
||||
}
|
||||
|
||||
changed.addAll(fw.getChanged());
|
||||
created.addAll(fw.getCreated());
|
||||
deleted.addAll(fw.getDeleted());
|
||||
}
|
||||
}
|
||||
|
||||
return !changed.isEmpty() || !created.isEmpty() || !deleted.isEmpty();
|
||||
}
|
||||
|
||||
return super.checkModified();
|
||||
}
|
||||
|
||||
public KMap<File, FolderWatcher> getWatchers() {
|
||||
return watchers;
|
||||
}
|
||||
|
||||
public KList<File> getChanged() {
|
||||
return changed;
|
||||
}
|
||||
|
||||
public KList<File> getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public KList<File> getDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
1525
src/main/java/com/volmit/iris/util/io/IO.java
Normal file
1525
src/main/java/com/volmit/iris/util/io/IO.java
Normal file
File diff suppressed because it is too large
Load Diff
25
src/main/java/com/volmit/iris/util/io/IORunnable.java
Normal file
25
src/main/java/com/volmit/iris/util/io/IORunnable.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IORunnable {
|
||||
void run() throws IOException;
|
||||
}
|
||||
96
src/main/java/com/volmit/iris/util/io/JarScanner.java
Normal file
96
src/main/java/com/volmit/iris/util/io/JarScanner.java
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public class JarScanner {
|
||||
private final KSet<Class<?>> classes;
|
||||
private final File jar;
|
||||
private final String superPackage;
|
||||
|
||||
/**
|
||||
* Create a scanner
|
||||
*
|
||||
* @param jar the path to the jar
|
||||
*/
|
||||
public JarScanner(File jar, String superPackage) {
|
||||
this.jar = jar;
|
||||
this.classes = new KSet<>();
|
||||
this.superPackage = superPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the jar
|
||||
*
|
||||
* @throws IOException bad things happen
|
||||
*/
|
||||
public void scan() throws IOException {
|
||||
classes.clear();
|
||||
FileInputStream fin = new FileInputStream(jar);
|
||||
ZipInputStream zip = new ZipInputStream(fin);
|
||||
|
||||
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {
|
||||
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
|
||||
if (entry.getName().contains("$")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String c = entry.getName().replaceAll("/", ".").replace(".class", "");
|
||||
|
||||
if (c.startsWith(superPackage)) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(c);
|
||||
classes.add(clazz);
|
||||
} catch (ClassNotFoundException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zip.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scanned clases
|
||||
*
|
||||
* @return a gset of classes
|
||||
*/
|
||||
public KSet<Class<?>> getClasses() {
|
||||
return classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file object for the jar
|
||||
*
|
||||
* @return a file object representing the jar
|
||||
*/
|
||||
public File getJar() {
|
||||
return jar;
|
||||
}
|
||||
}
|
||||
78
src/main/java/com/volmit/iris/util/io/ReactiveFolder.java
Normal file
78
src/main/java/com/volmit/iris/util/io/ReactiveFolder.java
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import com.volmit.iris.util.function.Consumer3;
|
||||
import com.volmit.iris.util.io.FolderWatcher;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ReactiveFolder {
|
||||
private final File folder;
|
||||
private final Consumer3<KList<File>, KList<File>, KList<File>> hotload;
|
||||
private FolderWatcher fw;
|
||||
|
||||
public ReactiveFolder(File folder, Consumer3<KList<File>, KList<File>, KList<File>> hotload) {
|
||||
this.folder = folder;
|
||||
this.hotload = hotload;
|
||||
this.fw = new FolderWatcher(folder);
|
||||
fw.checkModified();
|
||||
}
|
||||
|
||||
public void checkIgnore() {
|
||||
fw = new FolderWatcher(folder);
|
||||
}
|
||||
|
||||
public void check() {
|
||||
boolean modified = false;
|
||||
|
||||
if (fw.checkModified()) {
|
||||
for (File i : fw.getCreated()) {
|
||||
if (i.getName().endsWith(".iob") || i.getName().endsWith(".json")) {
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!modified) {
|
||||
for (File i : fw.getChanged()) {
|
||||
if (i.getName().endsWith(".iob") || i.getName().endsWith(".json")) {
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!modified) {
|
||||
for (File i : fw.getDeleted()) {
|
||||
if (i.getName().endsWith(".iob") || i.getName().endsWith(".json")) {
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
hotload.accept(fw.getCreated(), fw.getChanged(), fw.getDeleted());
|
||||
}
|
||||
|
||||
fw.checkModified();
|
||||
}
|
||||
}
|
||||
56
src/main/java/com/volmit/iris/util/io/SKConversion.java
Normal file
56
src/main/java/com/volmit/iris/util/io/SKConversion.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
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.math.BlockVector3;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.IrisObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SKConversion {
|
||||
public static void convertSchematic(File in, File out) {
|
||||
ClipboardFormat format = ClipboardFormats.findByFile(in);
|
||||
try (ClipboardReader reader = format.getReader(new FileInputStream(in))) {
|
||||
Clipboard clipboard = reader.read();
|
||||
BlockVector3 size = clipboard.getMaximumPoint().subtract(clipboard.getMinimumPoint());
|
||||
IrisObject o = new IrisObject(size.getBlockX() + 1, size.getBlockY() + 1, size.getBlockZ() + 1);
|
||||
|
||||
for (int i = clipboard.getMinimumPoint().getBlockX(); i <= clipboard.getMaximumPoint().getBlockX(); i++) {
|
||||
for (int j = clipboard.getMinimumPoint().getBlockY(); j <= clipboard.getMaximumPoint().getBlockY(); j++) {
|
||||
for (int k = clipboard.getMinimumPoint().getBlockZ(); k <= clipboard.getMaximumPoint().getBlockZ(); k++) {
|
||||
o.setUnsigned(i - clipboard.getMinimumPoint().getBlockX(), j - clipboard.getMinimumPoint().getBlockY(), k - clipboard.getMinimumPoint().getBlockZ(), BukkitAdapter.adapt(clipboard.getFullBlock(BlockVector3.at(i, j, k))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
o.write(out);
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/main/java/com/volmit/iris/util/io/VoidOutputStream.java
Normal file
28
src/main/java/com/volmit/iris/util/io/VoidOutputStream.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class VoidOutputStream extends OutputStream {
|
||||
@Override
|
||||
public void write(int b) {
|
||||
// poof
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user