diff --git a/LICENSE b/LICENSE deleted file mode 100644 index a7847dc..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 Stijn Bannink - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/pom.xml b/pom.xml index 0eee4e2..224235a 100644 --- a/pom.xml +++ b/pom.xml @@ -110,21 +110,9 @@ org.spigotmc spigot-api - 1.18.1-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT provided - - org.inventivetalent - apimanager - 1.0.5-SNAPSHOT - compile - - - org.jetbrains - annotations - 22.0.0 - compile - fr.minuskube.inv smart-invs @@ -134,18 +122,24 @@ com.github.cryptomorin XSeries - 8.6.1 + 8.8.0 com.github.fierioziy.particlenativeapi ParticleNativeAPI-plugin - 3.2.0 + 3.2.1 compile co.aikar acf-paper - 0.5.0-SNAPSHOT + 0.5.1-SNAPSHOT + compile + + + io.github.skytasul + guardianbeam + 2.3.0 compile diff --git a/src/main/java/nl/sbdeveloper/showapi/ShowAPI.java b/src/main/java/nl/sbdeveloper/showapi/ShowAPI.java deleted file mode 100644 index ea6725e..0000000 --- a/src/main/java/nl/sbdeveloper/showapi/ShowAPI.java +++ /dev/null @@ -1,367 +0,0 @@ -package nl.sbdeveloper.showapi; - -import nl.sbdeveloper.showapi.utils.Laser; -import nl.sbdeveloper.showapi.utils.VersionUtil; -import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.Location; -import org.bukkit.entity.EnderCrystal; -import org.bukkit.entity.EntityType; -import org.bukkit.event.Listener; -import org.bukkit.inventory.meta.FireworkMeta; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; -import org.inventivetalent.apihelper.API; -import org.inventivetalent.apihelper.APIManager; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Logger; - -public class ShowAPI implements API, Listener { - Logger logger = Logger.getLogger("ShowAPI"); - - //This gets called either by #registerAPI above, or by the API manager if another plugin requires this API - @Override - public void load() { - - } - - //This gets called either by #initAPI above or #initAPI in one of the requiring plugins - @Override - public void init(Plugin plugin) { - if (VersionUtil.getVersion() < 9 || VersionUtil.getVersion() > 17) { - logger.severe("Deze API werkt alleen tussen 1.9.x en 1.17.x."); - disable(plugin); - return; - } - - APIManager.registerEvents(this, this); - } - - //This gets called either by #disableAPI above or #disableAPI in one of the requiring plugins - @Override - public void disable(Plugin plugin) { - - } - - public static class Fireworks { - public static void spawn(@NotNull Firework fw, Location baseLoc) { - fw.spawn(baseLoc); - } - - public static class Firework { - private final FireworkEffect.Builder effectBuilder; - private int power; - - public Firework() { - effectBuilder = FireworkEffect.builder(); - } - - public Firework addFlicker() { - effectBuilder.flicker(true); - return this; - } - - public Firework addTrail() { - effectBuilder.trail(true); - return this; - } - - public Firework addColor(Color color) { - effectBuilder.withColor(color); - return this; - } - - public Firework addFade(Color color) { - effectBuilder.withFade(color); - return this; - } - - public Firework setType(FireworkEffect.Type type) { - effectBuilder.with(type); - return this; - } - - public Firework setPower(int power) { - this.power = power; - return this; - } - - private void spawn(@NotNull Location loc) { - org.bukkit.entity.Firework fw = (org.bukkit.entity.Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); - FireworkMeta fwm = fw.getFireworkMeta(); - fwm.addEffect(effectBuilder.build()); - fwm.setPower(power); - fw.setFireworkMeta(fwm); - } - } - } - - //SPOTS -> End Crystals - public static class Spots { - private static final Map spots = new HashMap<>(); - - /** - * Check if a spot exists - * - * @param name The name of the spot - * @return true if it exists, false if not - */ - public static boolean exists(String name) { - return spots.containsKey(name); - } - - /** - * Spawn a new spot, and start it - * - * @param name The name of the spot - * @param baseLoc The start location - */ - public static void start(String name, Location baseLoc) { - spots.put(name, new SpotRunnable(name, baseLoc)); - spots.get(name).runTaskTimer(ShowAPIPlugin.getInstance(), 0, 1); - } - - /** - * Move a spot to a location - * - * @param name The name of the spot - * @param posLoc The new location - * - * @return true if done, false if it doesn't exists - */ - public static boolean move(String name, Location posLoc) { - if (!spots.containsKey(name)) return false; - SpotRunnable spot = spots.get(name); - - new BukkitRunnable() { - boolean fired = false; - Location oldLoc = spot.posLoc; - - @Override - public void run() { - if (oldLoc.getBlockX() != posLoc.getBlockX()) { - if (oldLoc.getX() > posLoc.getX()) { //De x gaat omhoog - oldLoc = oldLoc.add(0.01, 0, 0); - } else { - oldLoc = oldLoc.add(-0.01, 0, 0); - } - fired = true; - } else { - fired = false; - } - - if (oldLoc.getBlockY() != posLoc.getBlockY()) { - if (oldLoc.getY() > posLoc.getY()) { //De y gaat omhoog - oldLoc = oldLoc.add(0, 0.01, 0); - } else { - oldLoc = oldLoc.add(0, -0.01, 0); - } - fired = true; - } else { - fired = false; - } - - if (oldLoc.getBlockZ() != posLoc.getBlockZ()) { - if (oldLoc.getZ() > posLoc.getZ()) { //De z gaat omhoog - oldLoc = oldLoc.add(0, 0, 0.01); - } else { - oldLoc = oldLoc.add(0, 0, -0.01); - } - fired = true; - } else { - fired = false; - } - - if (!fired) { - cancel(); - return; - } - - spot.changePositionLocation(oldLoc); - } - }.runTaskTimer(ShowAPIPlugin.getInstance(), 0L, 1L); - return true; - } - - public static void remove(String name) { - if (!spots.containsKey(name)) return; - - spots.get(name).cancel(); - } - - private static class SpotRunnable extends BukkitRunnable { - private final EnderCrystal crystal; - private final String name; - - private Location posLoc; - - public SpotRunnable(String name, Location baseLoc) { - this.name = name; - - this.crystal = (EnderCrystal) baseLoc.getWorld().spawnEntity(baseLoc, EntityType.ENDER_CRYSTAL); - this.crystal.setCustomName(name); - this.crystal.setShowingBottom(false); - this.crystal.setCustomNameVisible(false); - this.crystal.setBeamTarget(baseLoc.clone().add(0, 5, 0)); - } - - @Override - public void run() { - if (posLoc == null) return; - this.crystal.setBeamTarget(posLoc); - } - - public void changePositionLocation(Location posLoc) { - this.posLoc = posLoc; - } - - public synchronized void cancel() throws IllegalStateException { - crystal.remove(); - spots.remove(name); - super.cancel(); - } - } - } - - //LASERS -> Guardian beams - public static class Lasers { - private static final Map lasers = new HashMap<>(); - - /** - * Check if a laser exists - * - * @param name The name of the laser - * @return true if it exists, false if not - */ - public static boolean exists(String name) { - return lasers.containsKey(name); - } - - /** - * Spawn a new laser, and start it - * - * @param name The name of the laser - * @param baseLoc The start location - * - * @return true if done, false if an exception - */ - public static boolean start(String name, Location baseLoc) { - try { - lasers.put(name, new LaserRunnable(name, baseLoc)); - lasers.get(name).runTaskTimer(ShowAPIPlugin.getInstance(), 0, 1); - return true; - } catch (ReflectiveOperationException e) { - e.printStackTrace(); - } - return false; - } - - /** - * Move a laser to a location - * @param name The name of the laser - * @param posLoc The new location - * - * @return true if done, false if it doesn't exists - */ - public static boolean move(String name, Location posLoc) { - if (!lasers.containsKey(name)) return false; - LaserRunnable laser = lasers.get(name); - - new BukkitRunnable() { - boolean fired = false; - Location oldLoc = laser.posLoc; - - @Override - public void run() { - if (oldLoc.getBlockX() != posLoc.getBlockX()) { - if (oldLoc.getX() > posLoc.getX()) { //De x gaat omhoog - oldLoc = oldLoc.add(0.01, 0, 0); - } else { - oldLoc = oldLoc.add(-0.01, 0, 0); - } - fired = true; - } else { - fired = false; - } - - if (oldLoc.getBlockY() != posLoc.getBlockY()) { - if (oldLoc.getY() > posLoc.getY()) { //De y gaat omhoog - oldLoc = oldLoc.add(0, 0.01, 0); - } else { - oldLoc = oldLoc.add(0, -0.01, 0); - } - fired = true; - } else { - fired = false; - } - - if (oldLoc.getBlockZ() != posLoc.getBlockZ()) { - if (oldLoc.getZ() > posLoc.getZ()) { //De z gaat omhoog - oldLoc = oldLoc.add(0, 0, 0.01); - } else { - oldLoc = oldLoc.add(0, 0, -0.01); - } - fired = true; - } else { - fired = false; - } - - if (!fired) { - cancel(); - return; - } - - laser.changePositionLocation(oldLoc); - } - }.runTaskTimer(ShowAPIPlugin.getInstance(), 0L, 1L); - return true; - } - - public static void remove(String name) { - if (!lasers.containsKey(name)) return; - - lasers.get(name).cancel(); - lasers.remove(name); - } - - private static class LaserRunnable extends BukkitRunnable { - private final Laser laser; - private final String name; - private final Location baseLoc; - - private Location posLoc; - - public LaserRunnable(String name, Location baseLoc) throws ReflectiveOperationException { - this.name = name; - this.baseLoc = baseLoc; - this.laser = new Laser(baseLoc, baseLoc.add(0, 5, 0), -1, 50); - this.laser.start(ShowAPIPlugin.getInstance()); - } - - @Override - public void run() { - if (posLoc == null) return; - - try { - laser.moveStart(baseLoc); - laser.moveEnd(posLoc); - } catch (ReflectiveOperationException e) { - e.printStackTrace(); - } - } - - public void changePositionLocation(Location posLoc) { - this.posLoc = posLoc; - } - - public synchronized void cancel() throws IllegalStateException { - laser.stop(); - lasers.remove(name); - super.cancel(); - } - } - } -} diff --git a/src/main/java/nl/sbdeveloper/showapi/ShowAPIPlugin.java b/src/main/java/nl/sbdeveloper/showapi/ShowAPIPlugin.java index 3513ffb..5661048 100644 --- a/src/main/java/nl/sbdeveloper/showapi/ShowAPIPlugin.java +++ b/src/main/java/nl/sbdeveloper/showapi/ShowAPIPlugin.java @@ -12,32 +12,23 @@ import nl.sbdeveloper.showapi.data.Shows; import nl.sbdeveloper.showapi.utils.Inventory; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; -import org.inventivetalent.apihelper.APIManager; import java.util.Arrays; import java.util.stream.Collectors; public final class ShowAPIPlugin extends JavaPlugin { private static ShowAPIPlugin instance; - private final ShowAPI showAPI = new ShowAPI(); private static PaperCommandManager commandManager; private static ParticleNativeAPI particleAPI; - @Override - public void onLoad() { - APIManager.registerAPI(showAPI, this); - } - @Override public void onEnable() { instance = this; DataConversion.handle(); - APIManager.initAPI(ShowAPI.class); - commandManager = new PaperCommandManager(this); commandManager.enableUnstableAPI("help"); @@ -66,8 +57,6 @@ public final class ShowAPIPlugin extends JavaPlugin { DataSaving.save(); Shows.getShowsMap().values().forEach(show -> show.forEach(showCue -> showCue.getTask().remove())); - - APIManager.disableAPI(ShowAPI.class); } public static ShowAPIPlugin getInstance() { diff --git a/src/main/java/nl/sbdeveloper/showapi/api/triggers/FireworkTrigger.java b/src/main/java/nl/sbdeveloper/showapi/api/triggers/FireworkTrigger.java index 8d0c511..deb4cee 100644 --- a/src/main/java/nl/sbdeveloper/showapi/api/triggers/FireworkTrigger.java +++ b/src/main/java/nl/sbdeveloper/showapi/api/triggers/FireworkTrigger.java @@ -1,8 +1,8 @@ package nl.sbdeveloper.showapi.api.triggers; -import nl.sbdeveloper.showapi.ShowAPI; import nl.sbdeveloper.showapi.api.TriggerTask; import nl.sbdeveloper.showapi.api.TriggerType; +import nl.sbdeveloper.showapi.elements.Fireworks; import nl.sbdeveloper.showapi.utils.Color; import org.bukkit.Bukkit; import org.bukkit.FireworkEffect; @@ -10,7 +10,7 @@ import org.bukkit.Location; import org.bukkit.World; public class FireworkTrigger extends TriggerTask { - private ShowAPI.Fireworks.Firework fw; + private Fireworks.Firework fw; private Location spawnLoc; public FireworkTrigger(String[] data) { @@ -36,7 +36,7 @@ public class FireworkTrigger extends TriggerTask { this.spawnLoc = new Location(w, x, y, z); - ShowAPI.Fireworks.Firework firework = new ShowAPI.Fireworks.Firework(); + Fireworks.Firework firework = new Fireworks.Firework(); for (int i = 4; i < data.length; i++) { if (data[i].split(":").length != 2) continue; @@ -71,6 +71,6 @@ public class FireworkTrigger extends TriggerTask { @Override public void trigger() { - ShowAPI.Fireworks.spawn(fw, spawnLoc); + Fireworks.spawn(fw, spawnLoc); } } diff --git a/src/main/java/nl/sbdeveloper/showapi/api/triggers/LaserTrigger.java b/src/main/java/nl/sbdeveloper/showapi/api/triggers/LaserTrigger.java index e4a709e..9ef77a3 100644 --- a/src/main/java/nl/sbdeveloper/showapi/api/triggers/LaserTrigger.java +++ b/src/main/java/nl/sbdeveloper/showapi/api/triggers/LaserTrigger.java @@ -1,8 +1,8 @@ package nl.sbdeveloper.showapi.api.triggers; -import nl.sbdeveloper.showapi.ShowAPI; import nl.sbdeveloper.showapi.api.TriggerTask; import nl.sbdeveloper.showapi.api.TriggerType; +import nl.sbdeveloper.showapi.elements.Lasers; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -37,8 +37,8 @@ public class LaserTrigger extends TriggerTask { this.newLocation = new Location(w, x, y, z); - if (!ShowAPI.Lasers.exists(name)) { - ShowAPI.Lasers.start(name, newLocation); + if (!Lasers.exists(name)) { + Lasers.start(name, newLocation); } } @@ -50,6 +50,6 @@ public class LaserTrigger extends TriggerTask { @Override public void remove() { - ShowAPI.Lasers.remove(name); + Lasers.remove(name); } } diff --git a/src/main/java/nl/sbdeveloper/showapi/api/triggers/SpotTrigger.java b/src/main/java/nl/sbdeveloper/showapi/api/triggers/SpotTrigger.java index cee58ef..d74d643 100644 --- a/src/main/java/nl/sbdeveloper/showapi/api/triggers/SpotTrigger.java +++ b/src/main/java/nl/sbdeveloper/showapi/api/triggers/SpotTrigger.java @@ -1,8 +1,8 @@ package nl.sbdeveloper.showapi.api.triggers; -import nl.sbdeveloper.showapi.ShowAPI; import nl.sbdeveloper.showapi.api.TriggerTask; import nl.sbdeveloper.showapi.api.TriggerType; +import nl.sbdeveloper.showapi.elements.Spots; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -36,8 +36,8 @@ public class SpotTrigger extends TriggerTask { this.newLocation = new Location(w, x, y, z); - if (!ShowAPI.Spots.exists(name)) { - ShowAPI.Spots.start(name, newLocation); + if (!Spots.exists(name)) { + Spots.start(name, newLocation); } } @@ -49,6 +49,6 @@ public class SpotTrigger extends TriggerTask { @Override public void remove() { - ShowAPI.Spots.remove(name); + Spots.remove(name); } } diff --git a/src/main/java/nl/sbdeveloper/showapi/elements/Fireworks.java b/src/main/java/nl/sbdeveloper/showapi/elements/Fireworks.java new file mode 100644 index 0000000..c6c0f81 --- /dev/null +++ b/src/main/java/nl/sbdeveloper/showapi/elements/Fireworks.java @@ -0,0 +1,60 @@ +package nl.sbdeveloper.showapi.elements; + +import org.bukkit.Color; +import org.bukkit.FireworkEffect; +import org.bukkit.Location; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.meta.FireworkMeta; + +public class Fireworks { + public static void spawn(Firework fw, Location baseLoc) { + fw.spawn(baseLoc); + } + + public static class Firework { + private final FireworkEffect.Builder effectBuilder; + private int power; + + public Firework() { + effectBuilder = FireworkEffect.builder(); + } + + public Firework addFlicker() { + effectBuilder.flicker(true); + return this; + } + + public Firework addTrail() { + effectBuilder.trail(true); + return this; + } + + public Firework addColor(Color color) { + effectBuilder.withColor(color); + return this; + } + + public Firework addFade(Color color) { + effectBuilder.withFade(color); + return this; + } + + public Firework setType(FireworkEffect.Type type) { + effectBuilder.with(type); + return this; + } + + public Firework setPower(int power) { + this.power = power; + return this; + } + + private void spawn(Location loc) { + org.bukkit.entity.Firework fw = (org.bukkit.entity.Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); + FireworkMeta fwm = fw.getFireworkMeta(); + fwm.addEffect(effectBuilder.build()); + fwm.setPower(power); + fw.setFireworkMeta(fwm); + } + } +} \ No newline at end of file diff --git a/src/main/java/nl/sbdeveloper/showapi/elements/Lasers.java b/src/main/java/nl/sbdeveloper/showapi/elements/Lasers.java new file mode 100644 index 0000000..55430d6 --- /dev/null +++ b/src/main/java/nl/sbdeveloper/showapi/elements/Lasers.java @@ -0,0 +1,147 @@ +package nl.sbdeveloper.showapi.elements; + +import fr.skytasul.guardianbeam.Laser; +import nl.sbdeveloper.showapi.ShowAPIPlugin; +import org.bukkit.Location; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.HashMap; +import java.util.Map; + +public class Lasers { + private static final Map lasers = new HashMap<>(); + + /** + * Check if a laser exists + * + * @param name The name of the laser + * @return true if it exists, false if not + */ + public static boolean exists(String name) { + return lasers.containsKey(name); + } + + /** + * Spawn a new laser, and start it + * + * @param name The name of the laser + * @param baseLoc The start location + * + * @return true if done, false if an exception + */ + public static boolean start(String name, Location baseLoc) { + try { + lasers.put(name, new LaserRunnable(name, baseLoc)); + lasers.get(name).runTaskTimer(ShowAPIPlugin.getInstance(), 0, 1); + return true; + } catch (ReflectiveOperationException e) { + e.printStackTrace(); + } + return false; + } + + /** + * Move a laser to a location + * @param name The name of the laser + * @param posLoc The new location + * + * @return true if done, false if it doesn't exists + */ + public static boolean move(String name, Location posLoc) { + if (!lasers.containsKey(name)) return false; + LaserRunnable laser = lasers.get(name); + + new BukkitRunnable() { + boolean fired = false; + Location oldLoc = laser.posLoc; + + @Override + public void run() { + if (oldLoc.getBlockX() != posLoc.getBlockX()) { + if (oldLoc.getX() > posLoc.getX()) { //De x gaat omhoog + oldLoc = oldLoc.add(0.01, 0, 0); + } else { + oldLoc = oldLoc.add(-0.01, 0, 0); + } + fired = true; + } else { + fired = false; + } + + if (oldLoc.getBlockY() != posLoc.getBlockY()) { + if (oldLoc.getY() > posLoc.getY()) { //De y gaat omhoog + oldLoc = oldLoc.add(0, 0.01, 0); + } else { + oldLoc = oldLoc.add(0, -0.01, 0); + } + fired = true; + } else { + fired = false; + } + + if (oldLoc.getBlockZ() != posLoc.getBlockZ()) { + if (oldLoc.getZ() > posLoc.getZ()) { //De z gaat omhoog + oldLoc = oldLoc.add(0, 0, 0.01); + } else { + oldLoc = oldLoc.add(0, 0, -0.01); + } + fired = true; + } else { + fired = false; + } + + if (!fired) { + cancel(); + return; + } + + laser.changePositionLocation(oldLoc); + } + }.runTaskTimer(ShowAPIPlugin.getInstance(), 0L, 1L); + return true; + } + + public static void remove(String name) { + if (!lasers.containsKey(name)) return; + + lasers.get(name).cancel(); + lasers.remove(name); + } + + private static class LaserRunnable extends BukkitRunnable { + private final Laser laser; + private final String name; + private final Location baseLoc; + + private Location posLoc; + + public LaserRunnable(String name, Location baseLoc) throws ReflectiveOperationException { + this.name = name; + this.baseLoc = baseLoc; + this.laser = new Laser.GuardianLaser(baseLoc, baseLoc.add(0, 5, 0), -1, 50); + this.laser.start(ShowAPIPlugin.getInstance()); + } + + @Override + public void run() { + if (posLoc == null) return; + + try { + laser.moveStart(baseLoc); + laser.moveEnd(posLoc); + } catch (ReflectiveOperationException e) { + e.printStackTrace(); + } + } + + public void changePositionLocation(Location posLoc) { + this.posLoc = posLoc; + } + + public synchronized void cancel() throws IllegalStateException { + laser.stop(); + lasers.remove(name); + super.cancel(); + } + } +} diff --git a/src/main/java/nl/sbdeveloper/showapi/elements/Spots.java b/src/main/java/nl/sbdeveloper/showapi/elements/Spots.java new file mode 100644 index 0000000..5ee0be6 --- /dev/null +++ b/src/main/java/nl/sbdeveloper/showapi/elements/Spots.java @@ -0,0 +1,147 @@ +package nl.sbdeveloper.showapi.elements; + +import fr.skytasul.guardianbeam.Laser; +import nl.sbdeveloper.showapi.ShowAPIPlugin; +import org.bukkit.Location; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.HashMap; +import java.util.Map; + +public class Spots { + private static final Map spots = new HashMap<>(); + + /** + * Check if a spot exists + * + * @param name The name of the spot + * @return true if it exists, false if not + */ + public static boolean exists(String name) { + return spots.containsKey(name); + } + + /** + * Spawn a new spot, and start it + * + * @param name The name of the spot + * @param baseLoc The start location + * + * @return true if done, false if an exception + */ + public static boolean start(String name, Location baseLoc) { + try { + spots.put(name, new SpotRunnable(name, baseLoc)); + spots.get(name).runTaskTimer(ShowAPIPlugin.getInstance(), 0, 1); + return true; + } catch (ReflectiveOperationException e) { + e.printStackTrace(); + } + return false; + } + + /** + * Move a spot to a location + * @param name The name of the spot + * @param posLoc The new location + * + * @return true if done, false if it doesn't exists + */ + public static boolean move(String name, Location posLoc) { + if (!spots.containsKey(name)) return false; + SpotRunnable laser = spots.get(name); + + new BukkitRunnable() { + boolean fired = false; + Location oldLoc = laser.posLoc; + + @Override + public void run() { + if (oldLoc.getBlockX() != posLoc.getBlockX()) { + if (oldLoc.getX() > posLoc.getX()) { //De x gaat omhoog + oldLoc = oldLoc.add(0.01, 0, 0); + } else { + oldLoc = oldLoc.add(-0.01, 0, 0); + } + fired = true; + } else { + fired = false; + } + + if (oldLoc.getBlockY() != posLoc.getBlockY()) { + if (oldLoc.getY() > posLoc.getY()) { //De y gaat omhoog + oldLoc = oldLoc.add(0, 0.01, 0); + } else { + oldLoc = oldLoc.add(0, -0.01, 0); + } + fired = true; + } else { + fired = false; + } + + if (oldLoc.getBlockZ() != posLoc.getBlockZ()) { + if (oldLoc.getZ() > posLoc.getZ()) { //De z gaat omhoog + oldLoc = oldLoc.add(0, 0, 0.01); + } else { + oldLoc = oldLoc.add(0, 0, -0.01); + } + fired = true; + } else { + fired = false; + } + + if (!fired) { + cancel(); + return; + } + + laser.changePositionLocation(oldLoc); + } + }.runTaskTimer(ShowAPIPlugin.getInstance(), 0L, 1L); + return true; + } + + public static void remove(String name) { + if (!spots.containsKey(name)) return; + + spots.get(name).cancel(); + spots.remove(name); + } + + private static class SpotRunnable extends BukkitRunnable { + private final Laser spot; + private final String name; + private final Location baseLoc; + + private Location posLoc; + + public SpotRunnable(String name, Location baseLoc) throws ReflectiveOperationException { + this.name = name; + this.baseLoc = baseLoc; + this.spot = new Laser.CrystalLaser(baseLoc, baseLoc.add(0, 5, 0), -1, 50); + this.spot.start(ShowAPIPlugin.getInstance()); + } + + @Override + public void run() { + if (posLoc == null) return; + + try { + spot.moveStart(baseLoc); + spot.moveEnd(posLoc); + } catch (ReflectiveOperationException e) { + e.printStackTrace(); + } + } + + public void changePositionLocation(Location posLoc) { + this.posLoc = posLoc; + } + + public synchronized void cancel() throws IllegalStateException { + spot.stop(); + spots.remove(name); + super.cancel(); + } + } +} diff --git a/src/main/java/nl/sbdeveloper/showapi/utils/Laser.java b/src/main/java/nl/sbdeveloper/showapi/utils/Laser.java deleted file mode 100644 index 46a7b23..0000000 --- a/src/main/java/nl/sbdeveloper/showapi/utils/Laser.java +++ /dev/null @@ -1,345 +0,0 @@ -package nl.sbdeveloper.showapi.utils; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.HashSet; -import java.util.UUID; -import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * A whole class to create Guardian Beams by reflection
- * Inspired by the API GuardianBeamAPI
- * 1.9 -> 1.16 - * - * @see GitHub page - * @author SkytAsul - */ -public class Laser { - private final int duration; - private final int distanceSquared; - private Location start; - private Location end; - private final Object createGuardianPacket; - private final Object createSquidPacket; - private final Object teamAddPacket; - private final Object destroyPacket; - private final Object metadataPacketGuardian; - private final Object metadataPacketSquid; - private final Object fakeGuardianDataWatcher; - private final int squid; - private final UUID squidUUID; - private final int guardian; - private final UUID guardianUUID; - private BukkitRunnable run; - private HashSet show = new HashSet<>(); - /** - * Create a Laser instance - * @param start Location where laser will starts - * @param end Location where laser will ends - * @param duration Duration of laser in seconds (-1 if infinite) - * @param distance Distance where laser will be visible - */ - public Laser(Location start, Location end, int duration, int distance) throws ReflectiveOperationException { - this.start = start; - this.end = end; - this.duration = duration; - distanceSquared = distance * distance; - createSquidPacket = Packets.createPacketSquidSpawn(end); - squid = (int) Packets.getField(Packets.packetSpawn, "a", createSquidPacket); - squidUUID = (UUID) Packets.getField(Packets.packetSpawn, "b", createSquidPacket); - metadataPacketSquid = Packets.createPacketMetadata(squid, Packets.fakeSquidWatcher); - Packets.setDirtyWatcher(Packets.fakeSquidWatcher); - fakeGuardianDataWatcher = Packets.createFakeDataWatcher(); - createGuardianPacket = Packets.createPacketGuardianSpawn(start, fakeGuardianDataWatcher, squid); - guardian = (int) Packets.getField(Packets.packetSpawn, "a", createGuardianPacket); - guardianUUID = (UUID) Packets.getField(Packets.packetSpawn, "b", createGuardianPacket); - metadataPacketGuardian = Packets.createPacketMetadata(guardian, fakeGuardianDataWatcher); - teamAddPacket = Packets.createPacketTeamAddEntities(squidUUID, guardianUUID); - destroyPacket = Packets.createPacketRemoveEntities(squid, guardian); - } - public void start(Plugin plugin) { - Validate.isTrue(run == null, "Task already started"); - run = new BukkitRunnable() { - int time = duration; - @Override - public void run() { - try { - if (time == 0) { - cancel(); - return; - } - for (Player p : start.getWorld().getPlayers()) { - if (isCloseEnough(p.getLocation())) { - if (!show.contains(p)) { - sendStartPackets(p); - show.add(p); - } - }else if (show.contains(p)) { - Packets.sendPacket(p, destroyPacket); - show.remove(p); - } - } - if (time != -1) time--; - }catch (ReflectiveOperationException e) { - e.printStackTrace(); - } - } - @Override - public synchronized void cancel() throws IllegalStateException { - super.cancel(); - try { - for (Player p : show) { - Packets.sendPacket(p, destroyPacket); - } - }catch (ReflectiveOperationException e) { - e.printStackTrace(); - } - run = null; - } - }; - run.runTaskTimerAsynchronously(plugin, 0L, 20L); - } - public void stop() { - Validate.isTrue(run != null, "Task not started"); - run.cancel(); - } - public void moveStart(Location location) throws ReflectiveOperationException { - this.start = location; - Object packet = Packets.createPacketMoveEntity(start, guardian); - for (Player p : show) { - Packets.sendPacket(p, packet); - } - } - public Location getStart() { - return start; - } - public void moveEnd(Location location) throws ReflectiveOperationException { - this.end = location; - Object packet = Packets.createPacketMoveEntity(end, squid); - for (Player p : show) { - Packets.sendPacket(p, packet); - } - } - public Location getEnd() { - return end; - } - public void callColorChange() throws ReflectiveOperationException{ - for (Player p : show) { - Packets.sendPacket(p, metadataPacketGuardian); - } - } - public boolean isStarted() { - return run != null; - } - private void sendStartPackets(Player p) throws ReflectiveOperationException { - Packets.sendPacket(p, createSquidPacket); - Packets.sendPacket(p, createGuardianPacket); - if (Packets.version > 14) { - Packets.sendPacket(p, metadataPacketSquid); - Packets.sendPacket(p, metadataPacketGuardian); - } - Packets.sendPacket(p, Packets.packetTeamCreate); - Packets.sendPacket(p, teamAddPacket); - } - private boolean isCloseEnough(Location location) { - return start.distanceSquared(location) <= distanceSquared || - end.distanceSquared(location) <= distanceSquared; - } - private static class Packets { - private static int lastIssuedEID = 2000000000; - static int generateEID() { - return lastIssuedEID++; - } - private static String nmsVersion = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; - private static int version = Integer.parseInt(Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3].substring(1).split("_")[1]); - private static String npack = "net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + "."; - private static String cpack = Bukkit.getServer().getClass().getPackage().getName() + "."; - private static Object packetTeamCreate; - private static Constructor watcherConstructor; - private static Method watcherSet; - private static Method watcherRegister; - private static Method watcherDirty; - private static Class packetSpawn; - private static Class packetRemove; - private static Class packetTeleport; - private static Class packetTeam; - private static Class packetMetadata; - private static Object watcherObject1; // invisilibity - private static Object watcherObject2; // spikes - private static Object watcherObject3; // attack id - private static int squidID; - private static int guardianID; - private static Object fakeSquid; - private static Object fakeSquidWatcher; - static { - try { - String watcherName1 = null, watcherName2 = null, watcherName3 = null; - if (version < 13) { - watcherName1 = "Z"; - watcherName2 = "bA"; - watcherName3 = "bB"; - squidID = 94; - guardianID = 68; - }else if (version == 13) { - watcherName1 = "ac"; - watcherName2 = "bF"; - watcherName3 = "bG"; - squidID = 70; - guardianID = 28; - }else if (version == 14) { - watcherName1 = "W"; - watcherName2 = "b"; - watcherName3 = "bD"; - squidID = 73; - guardianID = 30; - }else if (version == 15) { - watcherName1 = "T"; - watcherName2 = "b"; - watcherName3 = "bA"; - squidID = 74; - guardianID = 31; - }else if (version == 16) { - if (nmsVersion.equals("v1_16_R3")) { - watcherName1 = "S"; - } else { - watcherName1 = "T"; - } - - watcherName2 = "b"; - watcherName3 = "d"; - squidID = 74; - guardianID = 31; - } - watcherObject1 = getField(Class.forName(npack + "Entity"), watcherName1, null); - watcherObject2 = getField(Class.forName(npack + "EntityGuardian"), watcherName2, null); - watcherObject3 = getField(Class.forName(npack + "EntityGuardian"), watcherName3, null); - watcherConstructor = Class.forName(npack + "DataWatcher").getDeclaredConstructor(Class.forName(npack + "Entity")); - watcherSet = getMethod(Class.forName(npack + "DataWatcher"), "set"); - watcherRegister = getMethod(Class.forName(npack + "DataWatcher"), "register"); - if (version >= 15) watcherDirty = getMethod(Class.forName(npack + "DataWatcher"), "markDirty"); - packetSpawn = Class.forName(npack + "PacketPlayOutSpawnEntityLiving"); - packetRemove = Class.forName(npack + "PacketPlayOutEntityDestroy"); - packetTeleport = Class.forName(npack + "PacketPlayOutEntityTeleport"); - packetTeam = Class.forName(npack + "PacketPlayOutScoreboardTeam"); - packetMetadata = Class.forName(npack + "PacketPlayOutEntityMetadata"); - packetTeamCreate = packetTeam.newInstance(); - setField(packetTeamCreate, "a", "noclip"); - setField(packetTeamCreate, "i", 0); - setField(packetTeamCreate, "f", "never"); - Object world = Class.forName(cpack + "CraftWorld").getDeclaredMethod("getHandle").invoke(Bukkit.getWorlds().get(0)); - Object[] entityConstructorParams = version < 14 ? new Object[] { world } : new Object[] { Class.forName(npack + "EntityTypes").getDeclaredField("SQUID").get(null), world }; - fakeSquid = getMethod(Class.forName(cpack + "entity.CraftSquid"), "getHandle").invoke(Class.forName(cpack + "entity.CraftSquid").getDeclaredConstructors()[0].newInstance( - null, Class.forName(npack + "EntitySquid").getDeclaredConstructors()[0].newInstance( - entityConstructorParams))); - fakeSquidWatcher = createFakeDataWatcher(); - tryWatcherSet(fakeSquidWatcher, watcherObject1, (byte) 32); - }catch (ReflectiveOperationException e) { - e.printStackTrace(); - } - } - public static void sendPacket(Player p, Object packet) throws ReflectiveOperationException { - Object entityPlayer = Class.forName(cpack + "entity.CraftPlayer").getDeclaredMethod("getHandle").invoke(p); - Object playerConnection = entityPlayer.getClass().getDeclaredField("playerConnection").get(entityPlayer); - playerConnection.getClass().getDeclaredMethod("sendPacket", Class.forName(npack + "Packet")).invoke(playerConnection, packet); - } - public static Object createFakeDataWatcher() throws ReflectiveOperationException { - Object watcher = watcherConstructor.newInstance(fakeSquid); - if (version > 13) setField(watcher, "registrationLocked", false); - return watcher; - } - public static void setDirtyWatcher(Object watcher) throws ReflectiveOperationException { - if (version >= 15) watcherDirty.invoke(watcher, watcherObject1); - } - public static Object createPacketSquidSpawn(Location location) throws ReflectiveOperationException { - Object packet = packetSpawn.newInstance(); - setField(packet, "a", generateEID()); - setField(packet, "b", UUID.randomUUID()); - setField(packet, "c", squidID); - setField(packet, "d", location.getX()); - setField(packet, "e", location.getY()); - setField(packet, "f", location.getZ()); - setField(packet, "j", (byte) (location.getYaw() * 256.0F / 360.0F)); - setField(packet, "k", (byte) (location.getPitch() * 256.0F / 360.0F)); - if (version <= 14) setField(packet, "m", fakeSquidWatcher); - return packet; - } - public static Object createPacketGuardianSpawn(Location location, Object watcher, int squidId) throws ReflectiveOperationException { - Object packet = packetSpawn.newInstance(); - setField(packet, "a", generateEID()); - setField(packet, "b", UUID.randomUUID()); - setField(packet, "c", guardianID); - setField(packet, "d", location.getX()); - setField(packet, "e", location.getY()); - setField(packet, "f", location.getZ()); - setField(packet, "j", (byte) (location.getYaw() * 256.0F / 360.0F)); - setField(packet, "k", (byte) (location.getPitch() * 256.0F / 360.0F)); - tryWatcherSet(watcher, watcherObject1, (byte) 32); - tryWatcherSet(watcher, watcherObject2, false); - tryWatcherSet(watcher, watcherObject3, squidId); - if (version <= 14) setField(packet, "m", watcher); - return packet; - } - public static Object createPacketRemoveEntities(int squidId, int guardianId) throws ReflectiveOperationException { - Object packet = packetRemove.newInstance(); - setField(packet, "a", new int[] { squidId, guardianId }); - return packet; - } - public static Object createPacketMoveEntity(Location location, int entityId) throws ReflectiveOperationException { - Object packet = packetTeleport.newInstance(); - setField(packet, "a", entityId); - setField(packet, "b", location.getX()); - setField(packet, "c", location.getY()); - setField(packet, "d", location.getZ()); - setField(packet, "e", (byte) (location.getYaw() * 256.0F / 360.0F)); - setField(packet, "f", (byte) (location.getPitch() * 256.0F / 360.0F)); - setField(packet, "g", true); - return packet; - } - public static Object createPacketTeamAddEntities(UUID squidUUID, UUID guardianUUID) throws ReflectiveOperationException { - Object packet = packetTeam.newInstance(); - setField(packet, "a", "noclip"); - setField(packet, "i", 3); - Collection players = (Collection) getField(packetTeam, "h", packet); - players.add(squidUUID.toString()); - players.add(guardianUUID.toString()); - return packet; - } - private static Object createPacketMetadata(int entityId, Object watcher) throws ReflectiveOperationException { - return packetMetadata.getConstructor(int.class, watcher.getClass(), boolean.class).newInstance(entityId, watcher, false); - } - private static void tryWatcherSet(Object watcher, Object watcherObject, Object watcherData) throws ReflectiveOperationException { - try { - watcherSet.invoke(watcher, watcherObject, watcherData); - }catch (InvocationTargetException ex) { - watcherRegister.invoke(watcher, watcherObject, watcherData); - if (version >= 15) watcherDirty.invoke(watcher, watcherObject); - } - } - /* Reflection utils */ - private static Method getMethod(Class clazz, String name) { - for (Method m : clazz.getDeclaredMethods()) { - if (m.getName().equals(name)) return m; - } - return null; - } - private static void setField(Object instance, String name, Object value) throws ReflectiveOperationException { - Validate.notNull(instance); - Field field = instance.getClass().getDeclaredField(name); - field.setAccessible(true); - field.set(instance, value); - } - private static Object getField(Class clazz, String name, Object instance) throws ReflectiveOperationException { - Field field = clazz.getDeclaredField(name); - field.setAccessible(true); - return field.get(instance); - } - } -} \ No newline at end of file diff --git a/src/main/java/nl/sbdeveloper/showapi/utils/MainUtil.java b/src/main/java/nl/sbdeveloper/showapi/utils/MainUtil.java index a5d31f2..0baef75 100644 --- a/src/main/java/nl/sbdeveloper/showapi/utils/MainUtil.java +++ b/src/main/java/nl/sbdeveloper/showapi/utils/MainUtil.java @@ -3,7 +3,6 @@ package nl.sbdeveloper.showapi.utils; import nl.sbdeveloper.showapi.api.ShowCue; import nl.sbdeveloper.showapi.api.TriggerTask; import nl.sbdeveloper.showapi.api.TriggerType; -import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -25,7 +24,7 @@ public class MainUtil { builder.setName(ChatColor.ITALIC + "TimeCode: " + TimeUtil.makeReadable(point.getTime())); List lores = new ArrayList<>(); - lores.add(ChatColor.GREEN + "Type: " + ChatColor.AQUA + StringUtils.capitalize(point.getTask().getType().name())); + lores.add(ChatColor.GREEN + "Type: " + ChatColor.AQUA + capitalize(point.getTask().getType().name())); lores.add(ChatColor.GREEN + "Data:"); for (String str : ChatPaginator.paginate(point.getTask().getDataString(), 20).getLines()) { lores.add(ChatColor.AQUA + ChatColor.stripColor(str)); @@ -56,4 +55,8 @@ public class MainUtil { return null; } } + + public static String capitalize(String str) { + return str.substring(0, 1).toUpperCase() + str.substring(1); + } } diff --git a/src/main/java/nl/sbdeveloper/showapi/utils/VersionUtil.java b/src/main/java/nl/sbdeveloper/showapi/utils/VersionUtil.java index 02993ba..70b00ab 100644 --- a/src/main/java/nl/sbdeveloper/showapi/utils/VersionUtil.java +++ b/src/main/java/nl/sbdeveloper/showapi/utils/VersionUtil.java @@ -1,16 +1,11 @@ package nl.sbdeveloper.showapi.utils; -import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; public class VersionUtil { private static final int VERSION = Integer.parseInt(getMajorVersion(Bukkit.getVersion()).substring(2)); - @NotNull private static String getMajorVersion(String version) { - Validate.notEmpty(version, "Cannot get major Minecraft version from null or empty string"); - // getVersion() int index = version.lastIndexOf("MC:"); if (index != -1) {