First stable commit

This commit is contained in:
Fangoboyo 2022-06-25 18:57:33 -07:00
parent 1d0dd9e23b
commit 362b0da66b
19 changed files with 524 additions and 36 deletions

View File

@ -0,0 +1,9 @@
<component name="ArtifactManager">
<artifact type="jar" name="BossBarAPI:jar">
<output-path>$PROJECT_DIR$/out/artifacts/BossBarAPI_jar</output-path>
<root id="archive" name="BossBarAPI.jar">
<element id="module-output" name="BossBarAPI" />
<element id="library" level="project" name="Maven: com.github.EaglerMaven:PacketWrapper:1.5.2" />
</root>
</artifact>
</component>

7
.idea/encodings.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

View File

@ -6,6 +6,11 @@
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="EaglerMaven-Repo" />
<option name="name" value="EaglerMaven-Repo" />
<option name="url" value="https://github.com/darverdevs/EaglerMavenRepo/raw/main" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
</list>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
@ -8,7 +13,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

12
BossBarAPI.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>BUKKIT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
</module>

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tech.nully</groupId>
<artifactId>BossBarAPI</artifactId>
<version>0.0.1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Built-By />
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<generateUniqueDependencyReducedPom>false</generateUniqueDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<minimizeJar>true</minimizeJar>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>EaglerMaven-Repo</id>
<url>https://github.com/darverdevs/EaglerMavenRepo/raw/main</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.EaglerMaven</groupId>
<artifactId>ProtocolLib</artifactId>
<version>3.6.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.EaglerMaven</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.5.2-R1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

90
pom.xml
View File

@ -4,9 +4,95 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<groupId>tech.nully</groupId>
<artifactId>BossBarAPI</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.0.1</version>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>EaglerMaven-Repo</id>
<url>https://github.com/darverdevs/EaglerMavenRepo/raw/main</url>
</repository>
</repositories>
<dependencies>
<!-- PrimCore dependencies -->
<dependency>
<groupId>com.github.EaglerMaven</groupId>
<artifactId>PacketWrapper</artifactId>
<version>1.5.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.EaglerMaven</groupId>
<artifactId>ProtocolLib</artifactId>
<version>3.6.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.EaglerMaven</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.5.2-R1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Built-By/>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<generateUniqueDependencyReducedPom>false</generateUniqueDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<minimizeJar>true</minimizeJar>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,13 +0,0 @@
package BossBarAPI;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

View File

@ -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();
}
}
}

View File

@ -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;
}
}

View File

@ -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() {
}
}

View File

@ -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);
}
}
}
}
}
}

View File

@ -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: /<command>
description: Displays a bossbar

View File

@ -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 );
}
}

11
target/classes/plugin.yml Normal file
View File

@ -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: /<command>
description: Displays a bossbar

View File

@ -0,0 +1,5 @@
#Generated by Maven
#Fri Jun 24 18:50:10 PDT 2022
groupId=tech.nully
artifactId=BossBarAPI
version=0.0.1

View File

@ -0,0 +1,2 @@
tech\nully\BossBarAPI\FakeWitherCommand$1.class
tech\nully\BossBarAPI\FakeWitherCommand.class

View File

@ -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