diff --git a/pom.xml b/pom.xml
index 5e2373e..2280415 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
timvandijkhuizen
spigot-utils
- 1.2.2
+ 1.2.3
SpigotUtils
diff --git a/resources/plugin.yml b/resources/plugin.yml
index 2d34de4..bcbb10e 100644
--- a/resources/plugin.yml
+++ b/resources/plugin.yml
@@ -1,7 +1,7 @@
name: SpigotUtils
description: A Spigot plugin to make plugin development easier.
author: Tim van Dijkhuizen
-version: "1.2.2"
+version: "1.2.3"
api-version: 1.13
main: nl.timvandijkhuizen.spigotutils.SpigotUtils
load: STARTUP
\ No newline at end of file
diff --git a/src/nl/timvandijkhuizen/spigotutils/helpers/InventoryHelper.java b/src/nl/timvandijkhuizen/spigotutils/helpers/InventoryHelper.java
deleted file mode 100644
index 685ef59..0000000
--- a/src/nl/timvandijkhuizen/spigotutils/helpers/InventoryHelper.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package nl.timvandijkhuizen.spigotutils.helpers;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.util.io.BukkitObjectInputStream;
-import org.bukkit.util.io.BukkitObjectOutputStream;
-import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
-
-public class InventoryHelper {
-
- public static String serialize(Inventory inventory) throws Exception {
- if(inventory == null) {
- throw new IllegalArgumentException("Inventory can not be null");
- }
-
- // Write the size of the inventory
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
-
- try {
- dataOutput.writeInt(inventory.getSize());
-
- for (int i = 0; i < inventory.getSize(); i++) {
- dataOutput.writeObject(inventory.getItem(i));
- }
- } finally {
- dataOutput.close();
- }
-
- return Base64Coder.encodeLines(outputStream.toByteArray());
- }
-
- public static void deserialize(Inventory inventory, String data) throws Exception {
- if(inventory == null) {
- throw new IllegalArgumentException("Inventory can not be null");
- }
-
- if(data == null) {
- throw new IllegalArgumentException("Data can not be null");
- }
-
- // Read the serialized inventory
- ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
- BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
-
- try {
- int size = dataInput.readInt();
-
- for (int i = 0; i < size; i++) {
- inventory.setItem(i, (ItemStack) dataInput.readObject());
- }
- } finally {
- dataInput.close();
- }
- }
-
-}
diff --git a/src/nl/timvandijkhuizen/spigotutils/music/Instrument.java b/src/nl/timvandijkhuizen/spigotutils/music/Instrument.java
deleted file mode 100644
index fb3aeae..0000000
--- a/src/nl/timvandijkhuizen/spigotutils/music/Instrument.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package nl.timvandijkhuizen.spigotutils.music;
-
-import org.bukkit.Sound;
-
-public class Instrument {
-
- public static Sound getInstrument(byte instrument) {
- switch (instrument) {
- case 0:
- return Sound.BLOCK_NOTE_BLOCK_HARP;
- case 1:
- return Sound.BLOCK_NOTE_BLOCK_BASS;
- case 2:
- return Sound.BLOCK_NOTE_BLOCK_BASEDRUM;
- case 3:
- return Sound.BLOCK_NOTE_BLOCK_SNARE;
- case 4:
- return Sound.BLOCK_NOTE_BLOCK_HAT;
- case 5:
- return Sound.BLOCK_NOTE_BLOCK_PLING;
- default:
- return Sound.BLOCK_NOTE_BLOCK_HARP;
- }
- }
-
- public static org.bukkit.Instrument getBukkitInstrument(byte instrument) {
- switch (instrument) {
- case 0:
- return org.bukkit.Instrument.PIANO;
- case 1:
- return org.bukkit.Instrument.BASS_GUITAR;
- case 2:
- return org.bukkit.Instrument.BASS_DRUM;
- case 3:
- return org.bukkit.Instrument.SNARE_DRUM;
- case 4:
- return org.bukkit.Instrument.STICKS;
-
- default:
- return org.bukkit.Instrument.PIANO;
- }
- }
-
-}
diff --git a/src/nl/timvandijkhuizen/spigotutils/music/Interpolator.java b/src/nl/timvandijkhuizen/spigotutils/music/Interpolator.java
deleted file mode 100644
index 4729f3b..0000000
--- a/src/nl/timvandijkhuizen/spigotutils/music/Interpolator.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package nl.timvandijkhuizen.spigotutils.music;
-
-import java.util.Arrays;
-
-public class Interpolator {
-
- public static double[] interpLinear(double[] x, double[] y, double[] xi) throws IllegalArgumentException {
- if (x.length != y.length) {
- throw new IllegalArgumentException("X and Y must be the same length");
- }
-
- if (x.length == 1) {
- throw new IllegalArgumentException("X must contain more than one value");
- }
-
- double[] dx = new double[x.length - 1];
- double[] dy = new double[x.length - 1];
- double[] slope = new double[x.length - 1];
- double[] intercept = new double[x.length - 1];
-
- // Calculate the line equation (i.e. slope and intercept) between each point
- for (int i = 0; i < x.length - 1; i++) {
- dx[i] = x[i + 1] - x[i];
-
- if (dx[i] == 0) {
- throw new IllegalArgumentException("X must be montotonic. A duplicate " + "x-value was found");
- }
-
- if (dx[i] < 0) {
- throw new IllegalArgumentException("X must be sorted");
- }
-
- dy[i] = y[i + 1] - y[i];
- slope[i] = dy[i] / dx[i];
- intercept[i] = y[i] - x[i] * slope[i];
- }
-
- // Perform the interpolation here
- double[] yi = new double[xi.length];
- for (int i = 0; i < xi.length; i++) {
- if ((xi[i] > x[x.length - 1]) || (xi[i] < x[0])) {
- yi[i] = Double.NaN;
- } else {
- int loc = Arrays.binarySearch(x, xi[i]);
-
- if (loc < -1) {
- loc = -loc - 2;
- yi[i] = slope[loc] * xi[i] + intercept[loc];
- } else {
- yi[i] = y[loc];
- }
- }
- }
-
- return yi;
- }
-
- public static double[] interpLinear(long[] x, double[] y, long[] xi) throws IllegalArgumentException {
- double[] xd = new double[x.length];
- for (int i = 0; i < x.length; i++) {
- xd[i] = (double) x[i];
- }
-
- double[] xid = new double[xi.length];
- for (int i = 0; i < xi.length; i++) {
- xid[i] = (double) xi[i];
- }
-
- return interpLinear(xd, y, xid);
- }
-
- public static double interpLinear(double[] xy, double xx) {
- if (xy.length % 2 != 0) {
- throw new IllegalArgumentException("XY must be divisible by two.");
- }
-
- double[] x = new double[xy.length/2];
- double[] y = new double[x.length];
- for (int i = 0; i < xy.length; i++) {
- if (i % 2 == 0) {
- x[i/2] = xy[i];
- } else {
- y[i/2] = xy[i];
- }
- }
-
- return interpLinear(x, y, new double[] {xx})[0];
- }
-
-}
\ No newline at end of file
diff --git a/src/nl/timvandijkhuizen/spigotutils/music/Layer.java b/src/nl/timvandijkhuizen/spigotutils/music/Layer.java
deleted file mode 100644
index d0b0d9f..0000000
--- a/src/nl/timvandijkhuizen/spigotutils/music/Layer.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package nl.timvandijkhuizen.spigotutils.music;
-
-import java.util.HashMap;
-
-public class Layer {
-
- private HashMap hashMap = new HashMap();
- private byte volume = 100;
- private String name = "";
-
- public HashMap getHashMap() {
- return hashMap;
- }
-
- public void setHashMap(HashMap hashMap) {
- this.hashMap = hashMap;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Note getNote(int tick) {
- return hashMap.get(tick);
- }
-
- public void setNote(int tick, Note note) {
- hashMap.put(tick, note);
- }
-
- public byte getVolume() {
- return volume;
- }
-
- public void setVolume(byte volume) {
- this.volume = volume;
- }
-
-}
diff --git a/src/nl/timvandijkhuizen/spigotutils/music/Note.java b/src/nl/timvandijkhuizen/spigotutils/music/Note.java
deleted file mode 100644
index a32ad2b..0000000
--- a/src/nl/timvandijkhuizen/spigotutils/music/Note.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package nl.timvandijkhuizen.spigotutils.music;
-
-public class Note {
-
- private byte instrument;
- private byte key;
-
- public Note(byte instrument, byte key) {
- this.instrument = instrument;
- this.key = key;
- }
-
- public byte getInstrument() {
- return instrument;
- }
-
- public void setInstrument(byte instrument) {
- this.instrument = instrument;
- }
-
- public byte getKey() {
- return key;
- }
-
- public void setKey(byte key) {
- this.key = key;
- }
-
-}
diff --git a/src/nl/timvandijkhuizen/spigotutils/music/NotePitch.java b/src/nl/timvandijkhuizen/spigotutils/music/NotePitch.java
deleted file mode 100644
index 31511d7..0000000
--- a/src/nl/timvandijkhuizen/spigotutils/music/NotePitch.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package nl.timvandijkhuizen.spigotutils.music;
-
-public enum NotePitch {
-
- NOTE_0(0, 0.5F),
- NOTE_1(1, 0.53F),
- NOTE_2(2, 0.56F),
- NOTE_3(3, 0.6F),
- NOTE_4(4, 0.63F),
- NOTE_5(5, 0.67F),
- NOTE_6(6, 0.7F),
- NOTE_7(7, 0.76F),
- NOTE_8(8, 0.8F),
- NOTE_9(9, 0.84F),
- NOTE_10(10, 0.9F),
- NOTE_11(11, 0.94F),
- NOTE_12(12, 1.0F),
- NOTE_13(13, 1.06F),
- NOTE_14(14, 1.12F),
- NOTE_15(15, 1.18F),
- NOTE_16(16, 1.26F),
- NOTE_17(17, 1.34F),
- NOTE_18(18, 1.42F),
- NOTE_19(19, 1.5F),
- NOTE_20(20, 1.6F),
- NOTE_21(21, 1.68F),
- NOTE_22(22, 1.78F),
- NOTE_23(23, 1.88F),
- NOTE_24(24, 2.0F);
-
- public int note;
- public float pitch;
-
- private NotePitch(int note, float pitch) {
- this.note = note;
- this.pitch = pitch;
- }
-
- public static float getPitch(int note) {
- for (NotePitch notePitch : values()) {
- if (notePitch.note == note) {
- return notePitch.pitch;
- }
- }
-
- return 0.0F;
- }
-
-}
\ No newline at end of file
diff --git a/src/nl/timvandijkhuizen/spigotutils/music/Song.java b/src/nl/timvandijkhuizen/spigotutils/music/Song.java
deleted file mode 100644
index 1107a62..0000000
--- a/src/nl/timvandijkhuizen/spigotutils/music/Song.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package nl.timvandijkhuizen.spigotutils.music;
-
-import java.io.File;
-import java.util.HashMap;
-
-public class Song {
-
- private HashMap layerHashMap = new HashMap();
- private short songHeight;
- private short length;
- private String title;
- private File path;
- private String author;
- private String description;
- private float speed;
- private float delay;
-
- public Song(Song other) {
- this.speed = other.getSpeed();
- delay = 20 / speed;
- this.layerHashMap = other.getLayerHashMap();
- this.songHeight = other.getSongHeight();
- this.length = other.getLength();
- this.title = other.getTitle();
- this.author = other.getAuthor();
- this.description = other.getDescription();
- this.path = other.getPath();
- }
-
- public Song(float speed, HashMap layerHashMap, short songHeight, final short length, String title, String author, String description, File path) {
- this.speed = speed;
- delay = 20 / speed;
- this.layerHashMap = layerHashMap;
- this.songHeight = songHeight;
- this.length = length;
- this.title = title;
- this.author = author;
- this.description = description;
- this.path = path;
- }
-
- public HashMap getLayerHashMap() {
- return layerHashMap;
- }
-
- public short getSongHeight() {
- return songHeight;
- }
-
- public short getLength() {
- return length;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public String getAuthor() {
- return author;
- }
-
- public File getPath() {
- return path;
- }
-
- public String getDescription() {
- return description;
- }
-
- public float getSpeed() {
- return speed;
- }
-
- public float getDelay() {
- return delay;
- }
-
-}
diff --git a/src/nl/timvandijkhuizen/spigotutils/music/SongDecoder.java b/src/nl/timvandijkhuizen/spigotutils/music/SongDecoder.java
deleted file mode 100644
index 01b7469..0000000
--- a/src/nl/timvandijkhuizen/spigotutils/music/SongDecoder.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package nl.timvandijkhuizen.spigotutils.music;
-
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-
-public class SongDecoder {
-
- public static Song parse(File decodeFile) {
- try {
- return parse(new FileInputStream(decodeFile), decodeFile);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
-
- return null;
- }
-
- public static Song parse(InputStream inputStream) {
- return parse(inputStream, null); // Source is unknown -> no file
- }
-
- private static Song parse(InputStream inputStream, File decodeFile) {
- HashMap layerHashMap = new HashMap();
-
- try {
- DataInputStream dis = new DataInputStream(inputStream);
- short length = readShort(dis);
- short songHeight = readShort(dis);
- String title = readString(dis);
- String author = readString(dis);
- readString(dis);
- String description = readString(dis);
- float speed = readShort(dis) / 100f;
- dis.readBoolean(); // auto-save
- dis.readByte(); // auto-save duration
- dis.readByte(); // x/4ths, time signature
- readInt(dis); // minutes spent on project
- readInt(dis); // left clicks (why?)
- readInt(dis); // right clicks (why?)
- readInt(dis); // blocks added
- readInt(dis); // blocks removed
- readString(dis); // .mid/.schematic file name
- short tick = -1;
-
- while (true) {
- short jumpTicks = readShort(dis); // jumps till next tick
-
- if (jumpTicks == 0) {
- break;
- }
-
- tick += jumpTicks;
-
- //System.out.println("Tick: " + tick);
- short layer = -1;
- while (true) {
- short jumpLayers = readShort(dis); // jumps till next layer
-
- if (jumpLayers == 0) {
- break;
- }
-
- layer += jumpLayers;
- setNote(layer, tick, dis.readByte() /* instrument */, dis.readByte() /* note */, layerHashMap);
- }
- }
- for (int i = 0; i < songHeight; i++) {
- Layer l = layerHashMap.get(i);
-
- if (l != null) {
- l.setName(readString(dis));
- l.setVolume(dis.readByte());
- }
- }
-
- return new Song(speed, layerHashMap, songHeight, length, title, author, description, decodeFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- private static void setNote(int layer, int ticks, byte instrument, byte key, HashMap layerHashMap) {
- Layer l = layerHashMap.get(layer);
-
- if (l == null) {
- l = new Layer();
- layerHashMap.put(layer, l);
- }
-
- l.setNote(ticks, new Note(instrument, key));
- }
-
- private static short readShort(DataInputStream dis) throws IOException {
- int byte1 = dis.readUnsignedByte();
- int byte2 = dis.readUnsignedByte();
-
- return (short) (byte1 + (byte2 << 8));
- }
-
- private static int readInt(DataInputStream dis) throws IOException {
- int byte1 = dis.readUnsignedByte();
- int byte2 = dis.readUnsignedByte();
- int byte3 = dis.readUnsignedByte();
- int byte4 = dis.readUnsignedByte();
-
- return (byte1 + (byte2 << 8) + (byte3 << 16) + (byte4 << 24));
- }
-
- private static String readString(DataInputStream dis) throws IOException {
- int length = readInt(dis);
- StringBuilder sb = new StringBuilder(length);
-
- for (; length > 0; --length) {
- char c = (char) dis.readByte();
-
- if (c == (char) 0x0D) {
- c = ' ';
- }
-
- sb.append(c);
- }
-
- return sb.toString();
- }
-
-}
diff --git a/src/nl/timvandijkhuizen/spigotutils/music/SongPlayer.java b/src/nl/timvandijkhuizen/spigotutils/music/SongPlayer.java
deleted file mode 100644
index ffbbae7..0000000
--- a/src/nl/timvandijkhuizen/spigotutils/music/SongPlayer.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package nl.timvandijkhuizen.spigotutils.music;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.function.Consumer;
-
-import org.bukkit.entity.Player;
-
-import nl.timvandijkhuizen.spigotutils.SpigotUtils;
-
-public class SongPlayer {
-
- private Song song;
- private boolean playing = true;
- private short tick = -1;
- private ArrayList playerList = new ArrayList();
- private boolean destroyed = false;
- private Thread playerThread;
- private byte volume = 100;
- protected Consumer endCallback;
-
- public SongPlayer(Song song) {
- this.song = song;
- createThread();
- }
-
- public SongPlayer(Song song, Consumer endCallback) {
- this.song = song;
- this.endCallback = endCallback;
- createThread();
- }
-
- private void createThread() {
- playerThread = new Thread(new Runnable() {
- @Override
- public void run() {
- while (!destroyed) {
- long startTime = System.currentTimeMillis();
-
- synchronized (SongPlayer.this) {
- if (playing) {
- tick++;
-
- if (tick > song.getLength()) {
- destroy();
- if(endCallback != null) endCallback.accept(false);
- return;
- }
-
- for (String s : playerList) {
- Player p = SpigotUtils.getInstance().getServer().getPlayerExact(s);
-
- if (p == null) continue;
-
- playTick(p, tick);
- }
- }
- }
-
- long duration = System.currentTimeMillis() - startTime;
- float delayMillis = song.getDelay() * 50;
- if (duration < delayMillis) {
- try {
- Thread.sleep((long) (delayMillis - duration));
- } catch (InterruptedException e) { /* do nothing */ }
- }
- }
- }
- });
-
- playerThread.setPriority(Thread.MAX_PRIORITY);
- playerThread.start();
- }
-
- public void playTick(Player p, int tick) {
- for (Layer l : song.getLayerHashMap().values()) {
- Note note = l.getNote(tick);
- if (note == null) {
- continue;
- }
-
- p.playSound(p.getLocation(), Instrument.getInstrument(note.getInstrument()), (l.getVolume() * (int) volume * 100) / 1000000f, NotePitch.getPitch(note.getKey() - 33));
- }
- }
-
- private void destroy() {
- synchronized (this) {
- destroyed = true;
- playing = false;
- setTick((short) -1);
- if(endCallback != null) endCallback.accept(true);
- }
- }
-
- /**
- * Public functions
- * These can be used to interact with the SongPlayer
- */
- public List getPlayers() {
- return Collections.unmodifiableList(playerList);
- }
-
- public void addPlayer(Player p) {
- synchronized (this) {
- if (playerList.contains(p.getName())) return;
- playerList.add(p.getName());
- }
- }
-
- public void removePlayer(Player p) {
- synchronized (this) {
- playerList.remove(p.getName());
- }
- }
-
- public boolean isPlaying() {
- return playing;
- }
-
- public void play() {
- this.playing = true;
- }
-
- public void pause() {
- this.playing = false;
- }
-
- public void stop() {
- destroy();
- }
-
- public short getTick() {
- return tick;
- }
-
- public void setTick(short tick) {
- this.tick = tick;
- }
-
- public byte getVolume() {
- return volume;
- }
-
- public void setVolume(byte volume) {
- this.volume = volume;
- }
-
- public Song getSong() {
- return song;
- }
-
-}