diff --git a/.idea/artifacts/BossBarAPI_jar.xml b/.idea/artifacts/BossBarAPI_jar.xml
new file mode 100644
index 0000000..aed244c
--- /dev/null
+++ b/.idea/artifacts/BossBarAPI_jar.xml
@@ -0,0 +1,9 @@
+
+
+ $PROJECT_DIR$/out/artifacts/BossBarAPI_jar
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 712ab9d..568f651 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -6,6 +6,11 @@
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 2b545b8..bf9e798 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,10 @@
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/BossBarAPI.iml b/BossBarAPI.iml
new file mode 100644
index 0000000..4ec1b0e
--- /dev/null
+++ b/BossBarAPI.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+ BUKKIT
+
+
+
+
+
\ No newline at end of file
diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
new file mode 100644
index 0000000..174e8a0
--- /dev/null
+++ b/dependency-reduced-pom.xml
@@ -0,0 +1,81 @@
+
+
+ 4.0.0
+ tech.nully
+ BossBarAPI
+ 0.0.1
+
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+
+ 1.8
+
+
+
+ maven-jar-plugin
+
+
+
+
+
+
+
+
+
+ maven-shade-plugin
+ 3.2.4
+
+
+ package
+
+ shade
+
+
+
+
+ false
+
+
+ *:*
+
+ META-INF/*.SF
+ META-INF/*.DSA
+ META-INF/*.RSA
+
+
+
+ true
+
+
+
+
+
+
+ EaglerMaven-Repo
+ https://github.com/darverdevs/EaglerMavenRepo/raw/main
+
+
+
+
+ com.github.EaglerMaven
+ ProtocolLib
+ 3.6.4
+ provided
+
+
+ com.github.EaglerMaven
+ craftbukkit
+ 1.5.2-R1.0
+ provided
+
+
+
+ 1.8
+ 1.8
+ 1.8
+ UTF-8
+
+
diff --git a/pom.xml b/pom.xml
index af1832e..c4de976 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,9 +4,95 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- org.example
+ tech.nully
BossBarAPI
- 1.0-SNAPSHOT
+ 0.0.1
+
+ 1.8
+ UTF-8
+ 1.8
+ 1.8
+
+
+
+
+ EaglerMaven-Repo
+ https://github.com/darverdevs/EaglerMavenRepo/raw/main
+
+
+
+
+
+ com.github.EaglerMaven
+ PacketWrapper
+ 1.5.2
+ compile
+
+
+ com.github.EaglerMaven
+ ProtocolLib
+ 3.6.4
+ provided
+
+
+ com.github.EaglerMaven
+ craftbukkit
+ 1.5.2-R1.0
+ provided
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.0
+
+
+ 1.8
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.2.4
+
+
+ package
+
+ shade
+
+
+
+
+ false
+
+
+ *:*
+
+ META-INF/*.SF
+ META-INF/*.DSA
+ META-INF/*.RSA
+
+
+
+ true
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/tech/nully/BossBarAPI/App.java b/src/main/java/tech/nully/BossBarAPI/App.java
deleted file mode 100644
index 122c1a1..0000000
--- a/src/main/java/tech/nully/BossBarAPI/App.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package BossBarAPI;
-
-/**
- * Hello world!
- *
- */
-public class App
-{
- public static void main( String[] args )
- {
- System.out.println( "Hello World!" );
- }
-}
diff --git a/src/main/java/tech/nully/BossBarAPI/BossBar.java b/src/main/java/tech/nully/BossBarAPI/BossBar.java
new file mode 100644
index 0000000..38c6127
--- /dev/null
+++ b/src/main/java/tech/nully/BossBarAPI/BossBar.java
@@ -0,0 +1,62 @@
+package tech.nully.BossBarAPI;
+
+import com.comphenix.protocol.ProtocolLibrary;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitTask;
+
+public class BossBar {
+ private Location dragonLocation;
+ private int bossHealth;
+ private String text;
+
+ private SpawnFakeWither.FakeWither dragon;
+
+ private BukkitTask task;
+
+ public BossBar(Player p) {
+ this.dragonLocation = new Location(p.getWorld(), p.getLocation().getX(), -15, p.getLocation().getZ());
+ }
+
+ public Location getDragonLocation() {
+ return dragonLocation;
+ }
+
+ public int getBarHealth() {
+ return bossHealth;
+ }
+
+ public void setBarHealth(int bossHealth) {
+ this.bossHealth = bossHealth;
+ if (dragon != null) {
+ dragon.setHealth(bossHealth);
+ }
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ if (dragon != null) {
+ dragon.setCustomName(text);
+ }
+ }
+
+ public void spawn() {
+ if (dragon != null) {
+ dragon.destroy();
+ }
+ dragon = new SpawnFakeWither.FakeWither(dragonLocation, ProtocolLibrary.getProtocolManager())
+ dragon.setCustomName(text);
+ dragon.setVisible(false);
+ dragon.create();
+ }
+
+ public void delete() {
+ if (dragon != null) {
+ dragon.destroy();
+ }
+ }
+}
diff --git a/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java b/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java
new file mode 100644
index 0000000..d279d27
--- /dev/null
+++ b/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java
@@ -0,0 +1,42 @@
+package tech.nully.BossBarAPI;
+
+import com.comphenix.protocol.ProtocolLibrary;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitTask;
+
+import static tech.nully.BossBarAPI.SpawnFakeWither.TICKS_PER_SECOND;
+
+public class FakeWitherCommand implements CommandExecutor {
+
+ private BukkitTask task;
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (sender instanceof Player) {
+ Player player = (Player) sender;
+ BossBar bar = new BossBar(player);
+ bar.setText("Countdown");
+
+
+ // Count down
+ task = Bukkit.getServer().getScheduler().runTaskTimer(Main.getInstance(), new Runnable() {
+ @Override
+ public void run() {
+ // Count down
+ bar.setBarHealth(bar.getBarHealth() - 1);
+
+ if (bar.getBarHealth() <= 0) {
+ bar.delete();
+ task.cancel();
+ }
+ }
+ }, TICKS_PER_SECOND / 4, TICKS_PER_SECOND / 4);
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/tech/nully/BossBarAPI/Main.java b/src/main/java/tech/nully/BossBarAPI/Main.java
new file mode 100644
index 0000000..f6812c8
--- /dev/null
+++ b/src/main/java/tech/nully/BossBarAPI/Main.java
@@ -0,0 +1,25 @@
+package tech.nully.BossBarAPI;
+
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class Main extends JavaPlugin {
+
+ private static Plugin instance;
+
+ public static Plugin getInstance() {
+ return instance;
+ }
+ @Override
+ public void onEnable() {
+ instance = this;
+ System.out.println("BossBar is on");
+ getCommand("bossbar").setExecutor(new FakeWitherCommand());
+ }
+
+ // Overrides onDisable
+ @Override
+ public void onDisable() {
+
+ }
+}
diff --git a/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java b/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java
new file mode 100644
index 0000000..72f042e
--- /dev/null
+++ b/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java
@@ -0,0 +1,156 @@
+package tech.nully.BossBarAPI;
+
+import com.comphenix.packetwrapper.Packet18SpawnMob;
+import com.comphenix.packetwrapper.Packet1DDestroyEntity;
+import com.comphenix.packetwrapper.Packet28EntityMetadata;
+import com.comphenix.protocol.ProtocolManager;
+import com.comphenix.protocol.events.PacketContainer;
+import com.comphenix.protocol.wrappers.WrappedDataWatcher;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.logging.Level;
+
+public class SpawnFakeWither extends JavaPlugin {
+ public static final int TICKS_PER_SECOND = 20;
+
+ // You could also use a full-fledged API like RemoteEntities
+ public static class FakeWither {
+ public static final byte INVISIBLE = 0x20;
+ // Just a guess
+ public static final int HEALTH_RANGE = 80 * 80;
+ // Next entity ID
+ public static int NEXT_ID = 6000;
+
+ public static final int METADATA_WITHER_HEALTH = 16; // 1.5.2 -> Change to 16
+
+ // Metadata indices
+ public static final int METADATA_FLAGS = 0;
+ public static final int METADATA_NAME = 5; // 1.5.2 -> Change to 5
+ public static final int METADATA_SHOW_NAME = 6; // 1.5.2 -> Change to 6
+
+ // Unique ID
+ public int id = NEXT_ID++;
+ // Default health
+ public int health = 300;
+
+ public boolean visible;
+ public String customName;
+ public boolean created;
+
+ public Location location;
+ public ProtocolManager manager;
+
+ public FakeWither(Location location, ProtocolManager manager) {
+ this.location = location;
+ this.manager = manager;
+ }
+
+ public int getHealth() {
+ return health;
+ }
+
+ public void setHealth(int health) {
+ // Update the health of the entity
+ if (created) {
+ WrappedDataWatcher watcher = new WrappedDataWatcher();
+
+ watcher.setObject(METADATA_WITHER_HEALTH, (int) health); // 1.5.2 -> Change to (int)
+ sendMetadata(watcher);
+ }
+ this.health = health;
+ }
+
+ public void setVisible(boolean visible) {
+ // Make visible or invisible
+ if (created) {
+ WrappedDataWatcher watcher = new WrappedDataWatcher();
+
+ watcher.setObject(METADATA_FLAGS, visible ? (byte)0 : INVISIBLE);
+ sendMetadata(watcher);
+ }
+ this.visible = visible;
+ }
+
+ public void setCustomName(String name) {
+ if (created) {
+ WrappedDataWatcher watcher = new WrappedDataWatcher();
+
+ if (name != null) {
+ watcher.setObject(METADATA_NAME, name);
+ watcher.setObject(METADATA_SHOW_NAME, (byte) 1);
+ } else {
+ // Hide custom name
+ watcher.setObject(METADATA_SHOW_NAME, (byte) 0);
+ }
+
+ // Only players nearby when this is sent will see this name
+ sendMetadata(watcher);
+ }
+ this.customName = name;
+ }
+
+ public void sendMetadata(WrappedDataWatcher watcher) {
+ Packet28EntityMetadata update = new Packet28EntityMetadata();
+
+ update.setEntityId(id);
+ update.setEntityMetadata(watcher.getWatchableObjects());
+ broadcastPacket(update.getHandle(), true);
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void create() {
+ Packet18SpawnMob spawnMob = new Packet18SpawnMob();
+ WrappedDataWatcher watcher = new WrappedDataWatcher();
+
+ watcher.setObject(METADATA_FLAGS, visible ? (byte)0 : INVISIBLE);
+ watcher.setObject(METADATA_WITHER_HEALTH, (int) health); // 1.5.2 -> Change to (int)
+
+ if (customName != null) {
+ watcher.setObject(METADATA_NAME, customName);
+ watcher.setObject(METADATA_SHOW_NAME, (byte) 1);
+ }
+
+ spawnMob.setEntityID(id);
+ spawnMob.setType(EntityType.ENDER_DRAGON);
+ spawnMob.setX(location.getX());
+ spawnMob.setY(location.getY());
+ spawnMob.setZ(location.getZ());
+ spawnMob.setMetadata(watcher);
+
+ broadcastPacket(spawnMob.getHandle(), true);
+ created = true;
+ }
+
+ public void destroy() {
+ if (!created)
+ throw new IllegalStateException("Cannot kill a killed entity.");
+
+ Packet1DDestroyEntity destroyMe = new Packet1DDestroyEntity();
+ destroyMe.setEntities(new int[] { id });
+
+ broadcastPacket(destroyMe.getHandle(), false);
+ created = false;
+ }
+
+ public void broadcastPacket(PacketContainer packet, boolean onlyNearby) {
+ for (Player player : Bukkit.getServer().getOnlinePlayers()) {
+ // Must be within the range
+ if (!onlyNearby || player.getLocation().distanceSquared(location) < HEALTH_RANGE) {
+ try {
+ manager.sendServerPacket(player, packet);
+ } catch (InvocationTargetException e) {
+ Bukkit.getLogger().log(Level.WARNING, "Cannot send " + packet + " to " + player, e);
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/resouces/plugin.yml b/src/main/resouces/plugin.yml
deleted file mode 100644
index e69de29..0000000
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..4b929f5
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,11 @@
+name: BossBarAPI
+version: 0.0.1
+main: tech.nully.BossBarAPI.Main
+prefix: [BossBarAPI]
+authors: [BongoCat]
+description: An API for eaglercraft to be able to display bossbars
+website: nully.tech
+commands:
+ bossbar:
+ usage: /
+ description: Displays a bossbar
\ No newline at end of file
diff --git a/src/test/java/BossBarAPI/AppTest.java b/src/test/java/BossBarAPI/AppTest.java
deleted file mode 100644
index fdd6627..0000000
--- a/src/test/java/BossBarAPI/AppTest.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package BossBarAPI;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest
-{
- /**
- * Rigorous Test :-)
- */
- @Test
- public void shouldAnswerWithTrue()
- {
- assertTrue( true );
- }
-}
diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml
new file mode 100644
index 0000000..4b929f5
--- /dev/null
+++ b/target/classes/plugin.yml
@@ -0,0 +1,11 @@
+name: BossBarAPI
+version: 0.0.1
+main: tech.nully.BossBarAPI.Main
+prefix: [BossBarAPI]
+authors: [BongoCat]
+description: An API for eaglercraft to be able to display bossbars
+website: nully.tech
+commands:
+ bossbar:
+ usage: /
+ description: Displays a bossbar
\ No newline at end of file
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
new file mode 100644
index 0000000..20902d1
--- /dev/null
+++ b/target/maven-archiver/pom.properties
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Fri Jun 24 18:50:10 PDT 2022
+groupId=tech.nully
+artifactId=BossBarAPI
+version=0.0.1
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
new file mode 100644
index 0000000..0875038
--- /dev/null
+++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -0,0 +1,2 @@
+tech\nully\BossBarAPI\FakeWitherCommand$1.class
+tech\nully\BossBarAPI\FakeWitherCommand.class
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
new file mode 100644
index 0000000..2e3598a
--- /dev/null
+++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
@@ -0,0 +1,2 @@
+C:\Users\PC\Documents\BossBarAPI\src\main\java\tech\nully\BossBarAPI\SpawnFakeWither.java
+C:\Users\PC\Documents\BossBarAPI\src\main\java\tech\nully\BossBarAPI\Main.java