diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/DisplayAPI.iml b/.idea/DisplayAPI.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/DisplayAPI.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..c5a4ea7
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..63e9001
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..eeecc00
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..d5a44fd
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DisplayAPI.iml b/DisplayAPI.iml
new file mode 100644
index 0000000..ef0295c
--- /dev/null
+++ b/DisplayAPI.iml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+ SPIGOT
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 3996f62..e6b99ca 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# DisplayAPI
Display API, a library to create holograms on Minecraft servers (1.8.8 ONLY)
-**You must add the API as your project dependencies and add this to plugins folder**
+**You must add the API as your project dependencies and use the scope compile**
## Features:
- For now, only 1.8.8 because i'm using some reflections
@@ -15,7 +15,6 @@ Display API, a library to create holograms on Minecraft servers (1.8.8 ONLY)
- Make it no blinking on client-side
- Make it multi-version
- Add ProtocolLib as dependencies for safe-use
- - Add Gradle/Maven dependences for this project
## Examples:
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..8f93b08
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,65 @@
+
+
+ 4.0.0
+
+ br.com.redelegit
+ DisplayAPI
+ 1.0-SNAPSHOT
+
+ DisplayAPI
+
+
+ 1.8
+ UTF-8
+
+
+
+ clean package
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ ${java.version}
+ ${java.version}
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.2.4
+
+
+ package
+
+ shade
+
+
+ false
+
+
+
+
+
+
+
+ src/main/resources
+ true
+
+
+
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.8.8-R0.1-SNAPSHOT
+ system
+ D:/dependencies/spigot-1.8.8-R0.1-SNAPSHOT-latest.jar
+
+
+
+
\ No newline at end of file
diff --git a/src/fr/watch54/displays/listeners/ChunkUnloadListener.java b/src/fr/watch54/displays/listeners/ChunkUnloadListener.java
deleted file mode 100644
index 9df93e8..0000000
--- a/src/fr/watch54/displays/listeners/ChunkUnloadListener.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package fr.watch54.displays.listeners;
-
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.world.ChunkUnloadEvent;
-
-public class ChunkUnloadListener implements Listener {
-
- @EventHandler
- public void onChunkUnload(ChunkUnloadEvent event){
- event.setCancelled(true);
-
- }
-
-}
diff --git a/src/fr/watch54/displays/listeners/InteractListener.java b/src/fr/watch54/displays/listeners/InteractListener.java
deleted file mode 100644
index d16142b..0000000
--- a/src/fr/watch54/displays/listeners/InteractListener.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package fr.watch54.displays.listeners;
-
-import fr.watch54.displays.holograms.Hologram;
-import fr.watch54.displays.holograms.HologramServer;
-import fr.watch54.displays.interfaces.Action;
-import fr.watch54.displays.managers.HologramManager;
-import org.bukkit.block.Block;
-import org.bukkit.entity.ArmorStand;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.player.PlayerInteractAtEntityEvent;
-
-import java.util.Optional;
-
-public class InteractListener implements Listener {
-
- private HologramManager hologramManager;
-
- public InteractListener(HologramManager hologramManager){
- this.hologramManager = hologramManager;
-
- }
-
- @EventHandler
- public void onInteract(PlayerInteractAtEntityEvent event){
-
- Player player = event.getPlayer();
- Entity entity = event.getRightClicked();
-
- if(entity instanceof ArmorStand){
-
- Block block = entity.getLocation().getBlock();
-
- if(hologramManager.containsHologram(block)){
-
- Optional optionalHologram = hologramManager.getHologram(block);
-
- optionalHologram.ifPresent(hologram -> {
-
- if(hologram instanceof HologramServer){
-
- HologramServer server = (HologramServer) hologram;
- Action action = server.getAction();
-
- if(action != null) action.execute(player);
-
- }
-
- });
-
- }
-
- }
-
- }
-
-}
diff --git a/src/fr/watch54/displays/Plugin.java b/src/main/java/fr/watch54/displays/Plugin.java
similarity index 95%
rename from src/fr/watch54/displays/Plugin.java
rename to src/main/java/fr/watch54/displays/Plugin.java
index 1cdc791..132b819 100644
--- a/src/fr/watch54/displays/Plugin.java
+++ b/src/main/java/fr/watch54/displays/Plugin.java
@@ -1,5 +1,5 @@
-package fr.watch54.displays;
-
-import org.bukkit.plugin.java.JavaPlugin;
-
-public class Plugin extends JavaPlugin {}
+package fr.watch54.displays;
+
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class Plugin extends JavaPlugin {}
diff --git a/src/fr/watch54/displays/holograms/Hologram.java b/src/main/java/fr/watch54/displays/holograms/Hologram.java
similarity index 87%
rename from src/fr/watch54/displays/holograms/Hologram.java
rename to src/main/java/fr/watch54/displays/holograms/Hologram.java
index 3de95c0..def45c3 100644
--- a/src/fr/watch54/displays/holograms/Hologram.java
+++ b/src/main/java/fr/watch54/displays/holograms/Hologram.java
@@ -1,65 +1,65 @@
-package fr.watch54.displays.holograms;
-
-import fr.watch54.displays.interfaces.Action;
-import fr.watch54.displays.interfaces.Text;
-import org.bukkit.Location;
-
-import java.util.List;
-
-public abstract class Hologram {
-
- protected List textList;
- protected Location location;
- protected boolean spawned;
-
- public Hologram(List textList, Location location){
- this.textList = textList;
- this.location = location;
- this.spawned = false;
-
- }
-
- public List getTextList(){
- return textList;
-
- }
-
- public void setTextList(List textList){
- this.textList = textList;
-
- }
-
- public Location getLocation(){
- return location;
-
- }
-
- public void setLocation(Location location){
- this.location = location;
-
- }
-
- public boolean isSpawned(){
- return spawned;
-
- }
-
- public void setSpawned(boolean spawned){
- this.spawned = spawned;
-
- }
-
- public abstract void display();
-
- public abstract void update();
-
- public abstract void remove();
-
- public abstract void interact(Action action);
-
- public void teleport(Location location){
- this.update();
-
- }
-
-}
+package fr.watch54.displays.holograms;
+
+import fr.watch54.displays.interfaces.Action;
+import fr.watch54.displays.interfaces.Text;
+import org.bukkit.Location;
+
+import java.util.List;
+
+public abstract class Hologram {
+
+ protected List textList;
+ protected Location location;
+ protected boolean spawned;
+ protected Action action;
+
+ public Hologram(List textList, Location location){
+ this.textList = textList;
+ this.location = location;
+ this.spawned = false;
+ }
+
+ public List getTextList(){
+ return textList;
+ }
+
+ public void setTextList(List textList){
+ this.textList = textList;
+ }
+
+ public Location getLocation(){
+ return location;
+
+ }
+
+ public void setLocation(Location location){
+ this.location = location;
+ }
+
+ public boolean isSpawned(){
+ return spawned;
+ }
+
+ public void setSpawned(boolean spawned){
+ this.spawned = spawned;
+ }
+
+ public abstract void display();
+
+ public abstract void update();
+
+ public abstract void remove();
+
+ public void interact(Action action) {
+ this.action = action;
+ }
+
+ public void teleport(Location location){
+ this.update();
+ }
+
+ public Action getAction() {
+ return action;
+ }
+
+}
diff --git a/src/fr/watch54/displays/holograms/HologramClient.java b/src/main/java/fr/watch54/displays/holograms/client/HologramClient.java
similarity index 79%
rename from src/fr/watch54/displays/holograms/HologramClient.java
rename to src/main/java/fr/watch54/displays/holograms/client/HologramClient.java
index 4e00f95..2856657 100644
--- a/src/fr/watch54/displays/holograms/HologramClient.java
+++ b/src/main/java/fr/watch54/displays/holograms/client/HologramClient.java
@@ -1,155 +1,134 @@
-package fr.watch54.displays.holograms;
-
-import fr.watch54.displays.interfaces.Action;
-import fr.watch54.displays.interfaces.Text;
-import io.netty.channel.ChannelDuplexHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelPipeline;
-import net.minecraft.server.v1_8_R3.EntityArmorStand;
-import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
-import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
-import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
-import org.bukkit.Location;
-import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
-import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
-import org.bukkit.entity.Player;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class HologramClient extends Hologram {
-
- private Player player;
- private Map entityArmorStandTextMap;
-
- public HologramClient(Player player, List textList, Location location){
- super(textList, location);
- this.player = player;
- this.entityArmorStandTextMap = new HashMap<>();
-
- }
-
- @Override
- public void display(){
-
- if(player == null) throw new NullPointerException("Player cannot be null!");
- if(this.getTextList() == null) throw new NullPointerException("Texts cannot be null!");
- if(this.getLocation() == null) throw new NullPointerException("Location cannot be null!");
-
- Location locationClone = this.getLocation().clone();
-
- CraftPlayer craftPlayer = (CraftPlayer) player;
- CraftWorld craftWorld = (CraftWorld) locationClone.getWorld();
-
- for(Text text : this.getTextList()){
-
- EntityArmorStand armorStand = new EntityArmorStand(craftWorld.getHandle(), locationClone.getX(), locationClone.getY(), locationClone.getZ());
- armorStand.setGravity(false);
- armorStand.setInvisible(true);
- armorStand.setCustomNameVisible(true);
- armorStand.setCustomName(text.getText());
- armorStand.fireTicks = Integer.MAX_VALUE;
-
- entityArmorStandTextMap.put(armorStand, text);
- locationClone.add(0, -0.3D, 0);
-
- PacketPlayOutSpawnEntityLiving entityLiving = new PacketPlayOutSpawnEntityLiving(armorStand);
- craftPlayer.getHandle().playerConnection.sendPacket(entityLiving);
-
- this.setSpawned(true);
-
- }
-
- }
-
- @Override
- public void update(){
- this.remove();
- this.display();
-
- }
-
- @Override
- public void remove(){
-
- CraftPlayer craftPlayer = (CraftPlayer) player;
-
- List armorStandClone = new ArrayList<>(entityArmorStandTextMap.keySet());
- for(EntityArmorStand armorStand : armorStandClone){
-
- PacketPlayOutEntityDestroy entityDestroy = new PacketPlayOutEntityDestroy(armorStand.getId());
- craftPlayer.getHandle().playerConnection.sendPacket(entityDestroy);
- entityArmorStandTextMap.clear();
-
- this.setSpawned(false);
-
- }
- }
-
- @Override
- public void interact(Action action){
-
- final int[] id = {0};
- ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler(){
-
- @Override
- public void channelRead(ChannelHandlerContext channelHandlerContext, Object packet) throws Exception {
-
- if(packet instanceof PacketPlayInUseEntity){
-
- PacketPlayInUseEntity useEntity = (PacketPlayInUseEntity) packet;
-
- if (useEntity.a() == PacketPlayInUseEntity.EnumEntityUseAction.ATTACK) return;
-
- Field entityIDField = useEntity.getClass().getDeclaredField("a");
- entityIDField.setAccessible(true);
-
- for(EntityArmorStand entityArmorStand : entityArmorStandTextMap.keySet()){
-
- if(entityIDField.get(useEntity).equals(entityArmorStand.getId())){
- action.execute(player);
- id[0] = entityArmorStand.getId();
- break;
-
- }
-
- }
-
- }
-
- super.channelRead(channelHandlerContext, packet);
-
- }
-
- };
-
- ChannelPipeline channelPipeline = ((CraftPlayer) player).getHandle().playerConnection.networkManager.channel.pipeline();
- channelPipeline.addBefore("packet_handler", player.getName() + "/" + id[0], channelDuplexHandler);
-
- }
-
- @Override
- public void teleport(Location location){
-
- this.setLocation(location);
- Location locationClone = location.clone();
-
- entityArmorStandTextMap.keySet().forEach(armorStand -> {
- armorStand.setPosition(locationClone.getX(), location.getY(), location.getZ());
- locationClone.add(0, -0.3D, 0);
-
- });
-
- }
-
- @Override
- public void setTextList(List textList){
- this.textList = textList;
- this.update();
-
- }
-
-}
+package fr.watch54.displays.holograms.client;
+
+import fr.watch54.displays.holograms.Hologram;
+import fr.watch54.displays.interfaces.Action;
+import fr.watch54.displays.interfaces.Text;
+import net.minecraft.server.v1_8_R3.EntityArmorStand;
+import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
+import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
+import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+import org.bukkit.util.BlockIterator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class HologramClient extends Hologram {
+
+ private Player player;
+ private Map entityArmorStandTextMap;
+
+ public HologramClient(Player player, List textList, Location location) {
+ super(textList, location);
+ this.player = player;
+ this.entityArmorStandTextMap = new HashMap<>();
+ }
+
+ @Override
+ public void display() {
+ if (player == null) throw new NullPointerException("Player cannot be null!");
+ if (this.getTextList() == null) throw new NullPointerException("Texts cannot be null!");
+ if (this.getLocation() == null) throw new NullPointerException("Location cannot be null!");
+
+ Location locationClone = this.getLocation().clone();
+
+ CraftPlayer craftPlayer = (CraftPlayer) player;
+ CraftWorld craftWorld = (CraftWorld) locationClone.getWorld();
+
+ for (Text text : this.getTextList()) {
+ EntityArmorStand armorStand = new EntityArmorStand(craftWorld.getHandle(), locationClone.getX(), locationClone.getY(), locationClone.getZ());
+ armorStand.setGravity(false);
+ armorStand.setInvisible(true);
+ armorStand.setCustomNameVisible(true);
+ armorStand.setCustomName(text.getText());
+ armorStand.fireTicks = Integer.MAX_VALUE;
+
+ entityArmorStandTextMap.put(armorStand, text);
+ locationClone.add(0, -0.3D, 0);
+
+ PacketPlayOutSpawnEntityLiving entityLiving = new PacketPlayOutSpawnEntityLiving(armorStand);
+ craftPlayer.getHandle().playerConnection.sendPacket(entityLiving);
+
+ this.setSpawned(true);
+ }
+ }
+
+ @Override
+ public void update() {
+ this.remove();
+ this.display();
+ }
+
+ @Override
+ public void remove() {
+ CraftPlayer craftPlayer = (CraftPlayer) player;
+
+ List armorStandClone = new ArrayList<>(entityArmorStandTextMap.keySet());
+ for (EntityArmorStand armorStand : armorStandClone) {
+
+ PacketPlayOutEntityDestroy entityDestroy = new PacketPlayOutEntityDestroy(armorStand.getId());
+ craftPlayer.getHandle().playerConnection.sendPacket(entityDestroy);
+ entityArmorStandTextMap.clear();
+
+ this.setSpawned(false);
+ }
+ }
+
+ /*@Override
+ public void interact(Action action) {
+ final int[] id = {0};
+ ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler(){
+ @Override
+ public void channelRead(ChannelHandlerContext channelHandlerContext, Object packet) throws Exception {
+ if(packet instanceof PacketPlayInUseEntity){
+ PacketPlayInUseEntity useEntity = (PacketPlayInUseEntity) packet;
+
+ if (useEntity.a() == PacketPlayInUseEntity.EnumEntityUseAction.ATTACK) return;
+
+ Field entityIDField = useEntity.getClass().getDeclaredField("a");
+ entityIDField.setAccessible(true);
+
+ for(EntityArmorStand entityArmorStand : entityArmorStandTextMap.keySet()){
+ if(entityIDField.get(useEntity).equals(entityArmorStand.getId())){
+ action.execute(player);
+ id[0] = entityArmorStand.getId();
+ break;
+ }
+ }
+ }
+ super.channelRead(channelHandlerContext, packet);
+ }
+ };
+ ChannelPipeline channelPipeline = ((CraftPlayer) player).getHandle().playerConnection.networkManager.channel.pipeline();
+ channelPipeline.addBefore("packet_handler", player.getName() + "/" + id[0], channelDuplexHandler);
+ }*/
+
+ @Override
+ public void teleport(Location location) {
+ this.setLocation(location);
+ Location locationClone = location.clone();
+
+ entityArmorStandTextMap.keySet().forEach(armorStand -> {
+ armorStand.setPosition(locationClone.getX(), location.getY(), location.getZ());
+ locationClone.add(0, -0.3D, 0);
+ });
+ }
+
+ @Override
+ public void setTextList(List textList) {
+ this.textList = textList;
+ this.update();
+ }
+
+ public Player getPlayer() {
+ return player;
+ }
+
+ public void setPlayer(Player player) {
+ this.player = player;
+ }
+}
diff --git a/src/fr/watch54/displays/holograms/HologramServer.java b/src/main/java/fr/watch54/displays/holograms/server/HologramServer.java
similarity index 71%
rename from src/fr/watch54/displays/holograms/HologramServer.java
rename to src/main/java/fr/watch54/displays/holograms/server/HologramServer.java
index 23c2266..a460fea 100644
--- a/src/fr/watch54/displays/holograms/HologramServer.java
+++ b/src/main/java/fr/watch54/displays/holograms/server/HologramServer.java
@@ -1,99 +1,78 @@
-package fr.watch54.displays.holograms;
-
-import fr.watch54.displays.interfaces.Action;
-import fr.watch54.displays.interfaces.Text;
-import org.bukkit.Location;
-import org.bukkit.World;
-import org.bukkit.entity.ArmorStand;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.EntityType;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class HologramServer extends Hologram {
-
- private Map armorStandTextMap;
- private Action action;
-
- public HologramServer(List textList, Location location){
- super(textList, location);
- this.armorStandTextMap = new HashMap<>();
-
- }
-
- @Override
- public void display(){
-
- if(this.getTextList() == null) throw new NullPointerException("Texts cannot be null!");
- if(this.getLocation() == null) throw new NullPointerException("Location cannot be null!");
-
- Location locationClone = this.getLocation().clone();
- World world = locationClone.getWorld();
-
- for(Text text : this.getTextList()){
-
- ArmorStand armorStand = (ArmorStand) world.spawnEntity(locationClone, EntityType.ARMOR_STAND);
- armorStand.setGravity(false);
- armorStand.setVisible(false);
- armorStand.setCustomNameVisible(true);
- armorStand.setCustomName(text.getText());
-
- armorStandTextMap.put(armorStand, text);
- locationClone.add(0, -0.3D, 0);
-
- this.setSpawned(true);
-
- }
-
- }
-
- @Override
- public void update(){
- armorStandTextMap.keySet().forEach(armorStand -> armorStand.setCustomName(armorStandTextMap.get(armorStand).getText()));
-
- }
-
- @Override
- public void remove(){
- armorStandTextMap.keySet().forEach(Entity::remove);
- armorStandTextMap.clear();
- this.setSpawned(false);
-
- }
-
- @Override
- public void interact(Action action){
- this.action = action;
-
- }
-
- @Override
- public void teleport(Location location){
-
- this.setLocation(location);
- Location locationClone = location.clone();
-
- armorStandTextMap.keySet().forEach(armorStand -> {
- armorStand.teleport(locationClone);
- locationClone.add(0, -0.3D, 0);
-
- });
-
- }
-
- @Override
- public void setTextList(List textList){
- this.textList = textList;
- this.remove();
- this.display();
-
- }
-
- public Action getAction(){
- return action;
-
- }
-
-}
+package fr.watch54.displays.holograms.server;
+
+import fr.watch54.displays.holograms.Hologram;
+import fr.watch54.displays.interfaces.Action;
+import fr.watch54.displays.interfaces.Text;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.ArmorStand;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.EntityType;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class HologramServer extends Hologram {
+
+ private Map armorStandTextMap;
+
+ public HologramServer(List textList, Location location) {
+ super(textList, location);
+ this.armorStandTextMap = new HashMap<>();
+ }
+
+ @Override
+ public void display() {
+
+ if (this.getTextList() == null) throw new NullPointerException("Texts cannot be null!");
+ if (this.getLocation() == null) throw new NullPointerException("Location cannot be null!");
+
+ Location locationClone = this.getLocation().clone();
+ World world = locationClone.getWorld();
+
+ for (Text text : this.getTextList()) {
+ ArmorStand armorStand = (ArmorStand) world.spawnEntity(locationClone, EntityType.ARMOR_STAND);
+ armorStand.setGravity(false);
+ armorStand.setVisible(false);
+ armorStand.setCustomNameVisible(true);
+ armorStand.setCustomName(text.getText());
+
+ armorStandTextMap.put(armorStand, text);
+ locationClone.add(0, -0.3D, 0);
+
+ this.setSpawned(true);
+ }
+ }
+
+ @Override
+ public void update() {
+ armorStandTextMap.keySet().forEach(armorStand -> armorStand.setCustomName(armorStandTextMap.get(armorStand).getText()));
+ }
+
+ @Override
+ public void remove() {
+ armorStandTextMap.keySet().forEach(Entity::remove);
+ armorStandTextMap.clear();
+ this.setSpawned(false);
+ }
+
+ @Override
+ public void teleport(Location location) {
+ this.setLocation(location);
+ Location locationClone = location.clone();
+
+ armorStandTextMap.keySet().forEach(armorStand -> {
+ armorStand.teleport(locationClone);
+ locationClone.add(0, -0.3D, 0);
+ });
+ }
+
+ @Override
+ public void setTextList(List textList) {
+ this.textList = textList;
+ this.remove();
+ this.display();
+ }
+
+}
diff --git a/src/fr/watch54/displays/interfaces/Action.java b/src/main/java/fr/watch54/displays/interfaces/Action.java
similarity index 93%
rename from src/fr/watch54/displays/interfaces/Action.java
rename to src/main/java/fr/watch54/displays/interfaces/Action.java
index 8eafe2e..d70f1cd 100644
--- a/src/fr/watch54/displays/interfaces/Action.java
+++ b/src/main/java/fr/watch54/displays/interfaces/Action.java
@@ -1,9 +1,9 @@
-package fr.watch54.displays.interfaces;
-
-import org.bukkit.entity.Player;
-
-public interface Action {
-
- void execute(Player player);
-
-}
+package fr.watch54.displays.interfaces;
+
+import org.bukkit.entity.Player;
+
+public interface Action {
+
+ void execute(Player player);
+
+}
diff --git a/src/fr/watch54/displays/interfaces/Text.java b/src/main/java/fr/watch54/displays/interfaces/Text.java
similarity index 92%
rename from src/fr/watch54/displays/interfaces/Text.java
rename to src/main/java/fr/watch54/displays/interfaces/Text.java
index 419ec0c..85c424c 100644
--- a/src/fr/watch54/displays/interfaces/Text.java
+++ b/src/main/java/fr/watch54/displays/interfaces/Text.java
@@ -1,7 +1,7 @@
-package fr.watch54.displays.interfaces;
-
-public interface Text {
-
- String getText();
-
-}
+package fr.watch54.displays.interfaces;
+
+public interface Text {
+
+ String getText();
+
+}
diff --git a/src/main/java/fr/watch54/displays/listeners/Listeners.java b/src/main/java/fr/watch54/displays/listeners/Listeners.java
new file mode 100644
index 0000000..de6b07d
--- /dev/null
+++ b/src/main/java/fr/watch54/displays/listeners/Listeners.java
@@ -0,0 +1,91 @@
+package fr.watch54.displays.listeners;
+
+import fr.watch54.displays.holograms.client.HologramClient;
+import fr.watch54.displays.holograms.server.HologramServer;
+import fr.watch54.displays.managers.HologramManager;
+import org.bukkit.Location;
+import org.bukkit.block.Block;
+import org.bukkit.entity.ArmorStand;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerInteractAtEntityEvent;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.event.world.ChunkUnloadEvent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Copyright (C) gameszaum, all rights reserved, unauthorized
+ * utlization or copy of this file, is strictly prohibited and
+ * liable to civil and criminal penalties, the project 'DisplayAPI'
+ * is privated and the re-sale without contact with me (gameszaum) is not allowed.
+ */
+public class Listeners implements Listener {
+
+ private HologramManager hologramManager;
+
+ public Listeners(HologramManager hologramManager) {
+ this.hologramManager = hologramManager;
+ }
+
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void clientSide(PlayerInteractEvent event) {
+ if (hologramManager.getHologramMap().size() > 0 && hologramManager.getHologramMap().values().stream().anyMatch(hologram -> hologram instanceof HologramClient)) {
+ for (Block block : getNearbyBlocks(event.getPlayer(), 4)) {
+ if (hologramManager.containsHologram(block)) {
+ hologramManager.getHologram(block).filter(hologram -> hologram instanceof HologramClient).map(hologram -> (HologramClient) hologram).ifPresent(hologram -> {
+ if (hologram.getPlayer().getName().equals(event.getPlayer().getName())) {
+ if (hologram.getAction() != null) {
+ hologram.getAction().execute(event.getPlayer());
+ }
+ }
+ });
+ return;
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void serverSide(PlayerInteractAtEntityEvent event) {
+ Player player = event.getPlayer();
+ Entity entity = event.getRightClicked();
+
+ if (entity instanceof ArmorStand) {
+ Block block = entity.getLocation().getBlock();
+
+ if (hologramManager.containsHologram(block)) {
+ hologramManager.getHologram(block).filter(hologram -> hologram instanceof HologramServer).map(hologram -> (HologramServer) hologram).ifPresent(hologram -> {
+ if (hologram.getAction() != null) {
+ hologram.getAction().execute(player);
+ }
+ });
+ }
+ }
+ }
+
+ @EventHandler
+ public void onChunkUnload(ChunkUnloadEvent event) {
+ event.setCancelled(true);
+ }
+
+ private List getNearbyBlocks(Player player, int radius) {
+ List blocks = new ArrayList<>();
+ Location location = player.getLocation();
+
+ for (int x = location.getBlockX() - radius; x <= location.getBlockX() + radius; x++) {
+ for (int y = location.getBlockY() - radius; y <= location.getBlockY() + radius; y++) {
+ for (int z = location.getBlockZ() - radius; z <= location.getBlockZ() + radius; z++) {
+ blocks.add(location.getWorld().getBlockAt(x, y, z));
+ }
+ }
+ }
+ return blocks;
+ }
+
+}
diff --git a/src/fr/watch54/displays/managers/HologramManager.java b/src/main/java/fr/watch54/displays/managers/HologramManager.java
similarity index 67%
rename from src/fr/watch54/displays/managers/HologramManager.java
rename to src/main/java/fr/watch54/displays/managers/HologramManager.java
index 5da096b..c83cc39 100644
--- a/src/fr/watch54/displays/managers/HologramManager.java
+++ b/src/main/java/fr/watch54/displays/managers/HologramManager.java
@@ -1,110 +1,103 @@
-package fr.watch54.displays.managers;
-
-import fr.watch54.displays.holograms.Hologram;
-import fr.watch54.displays.holograms.HologramClient;
-import fr.watch54.displays.holograms.HologramServer;
-import fr.watch54.displays.interfaces.Text;
-import fr.watch54.displays.listeners.ChunkUnloadListener;
-import fr.watch54.displays.listeners.InteractListener;
-import fr.watch54.displays.tasks.HologramTask;
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.block.Block;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.Plugin;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-public class HologramManager {
-
- private Plugin plugin;
- private Map hologramMap;
-
- public HologramManager(Plugin plugin){
- this.plugin = plugin;
- this.hologramMap = new HashMap<>();
- Bukkit.getPluginManager().registerEvents(new InteractListener(this), plugin);
- Bukkit.getPluginManager().registerEvents(new ChunkUnloadListener(), plugin);
-
- }
-
- public HologramServer createServer(List textList, Location location, boolean refresh){
-
- Block block = location.getBlock();
- if(this.containsHologram(block)) return (HologramServer) hologramMap.get(block);
-
- HologramServer hologramServer = new HologramServer(textList, location);
- Bukkit.getScheduler().runTaskLater(plugin, hologramServer::display, 20);
-
- hologramMap.put(location.getBlock(), hologramServer);
-
- HologramTask hologramTask = new HologramTask(hologramServer, this, refresh);
- hologramTask.runTaskTimer(plugin, 20, 20);
-
- return hologramServer;
-
- }
-
- public HologramClient createClient(Player player, List textList, Location location, boolean refresh){
-
- HologramClient hologram = new HologramClient(player, textList, location);
- Bukkit.getScheduler().runTaskLater(plugin, hologram::display, 20);
-
- hologramMap.put(location.getBlock(), hologram);
-
- HologramTask hologramTask = new HologramTask(hologram, this, refresh);
- hologramTask.runTaskTimer(plugin, 20, 20);
-
- return hologram;
-
- }
-
- public void teleport(Hologram hologram, Location location){
-
- if(!hologramMap.containsValue(hologram)) return;
-
- hologramMap.entrySet().removeIf(entry -> entry.getValue().equals(hologram));
- hologramMap.put(location.getBlock(), hologram);
- hologram.teleport(location);
-
- }
-
- public boolean containsHologram(Block block){
- return hologramMap.keySet().stream().anyMatch(blockMap -> block.getX() == blockMap.getX() && block.getZ() == blockMap.getZ());
-
- }
-
- public Optional getHologram(Block block){
-
- Optional blockFinal = hologramMap
- .keySet()
- .stream()
- .filter(blockMap -> blockMap.getX() == block.getX() && blockMap.getZ() == block.getZ())
- .findFirst();
-
- Hologram hologram = null;
-
- if(blockFinal.isPresent()) hologram = hologramMap.get(blockFinal.get());
- return Optional.ofNullable(hologram);
-
- }
-
- public void remove(Hologram hologram){
-
- if(!hologramMap.containsValue(hologram)) return;
-
- hologram.remove();
- hologramMap.entrySet().removeIf(entry -> entry.getValue().equals(hologram));
-
- }
-
- public void clear(){
- hologramMap.values().forEach(Hologram::remove);
- hologramMap.clear();
-
- }
-
-}
+package fr.watch54.displays.managers;
+
+import fr.watch54.displays.holograms.Hologram;
+import fr.watch54.displays.holograms.client.HologramClient;
+import fr.watch54.displays.holograms.server.HologramServer;
+import fr.watch54.displays.interfaces.Text;
+import fr.watch54.displays.listeners.Listeners;
+import fr.watch54.displays.tasks.HologramTask;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.block.Block;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class HologramManager {
+
+ private Plugin plugin;
+ private Map hologramMap;
+
+ public HologramManager(Plugin plugin) {
+ this.plugin = plugin;
+ this.hologramMap = new HashMap<>();
+
+ Bukkit.getPluginManager().registerEvents(new Listeners(this), plugin);
+ }
+
+ public HologramServer createServer(List textList, Location location, boolean refresh) {
+ Block block = location.getBlock();
+ if (this.containsHologram(block)) return (HologramServer) hologramMap.get(block);
+
+ HologramServer hologramServer = new HologramServer(textList, location);
+ Bukkit.getScheduler().runTaskLater(plugin, hologramServer::display, 20);
+
+ hologramMap.put(location.getBlock(), hologramServer);
+
+ HologramTask hologramTask = new HologramTask(hologramServer, this, refresh);
+ hologramTask.runTaskTimer(plugin, 20, 20);
+
+ return hologramServer;
+
+ }
+
+ public HologramClient createClient(Player player, List textList, Location location, boolean refresh) {
+ HologramClient hologram = new HologramClient(player, textList, location);
+ Bukkit.getScheduler().runTaskLater(plugin, hologram::display, 20);
+
+ hologramMap.put(location.getBlock(), hologram);
+
+ HologramTask hologramTask = new HologramTask(hologram, this, refresh);
+ hologramTask.runTaskTimer(plugin, 20, 20);
+
+ return hologram;
+
+ }
+
+ public void teleport(Hologram hologram, Location location) {
+ if (!hologramMap.containsValue(hologram)) return;
+
+ hologramMap.entrySet().removeIf(entry -> entry.getValue().equals(hologram));
+ hologramMap.put(location.getBlock(), hologram);
+ hologram.teleport(location);
+ }
+
+ public boolean containsHologram(Block block) {
+ return hologramMap.keySet().stream().anyMatch(blockMap -> block.getX() == blockMap.getX() && block.getZ() == blockMap.getZ());
+ }
+
+ public Optional getHologram(Block block) {
+ Optional blockFinal = hologramMap
+ .keySet()
+ .stream()
+ .filter(blockMap -> blockMap.getX() == block.getX() && blockMap.getZ() == block.getZ())
+ .findFirst();
+
+ Hologram hologram = null;
+
+ if (blockFinal.isPresent()) {
+ hologram = hologramMap.get(blockFinal.get());
+ }
+ return Optional.ofNullable(hologram);
+ }
+
+ public void remove(Hologram hologram) {
+ if (!hologramMap.containsValue(hologram)) return;
+
+ hologram.remove();
+ hologramMap.entrySet().removeIf(entry -> entry.getValue().equals(hologram));
+ }
+
+ public void clear() {
+ hologramMap.values().forEach(Hologram::remove);
+ hologramMap.clear();
+ }
+
+ public Map getHologramMap() {
+ return hologramMap;
+ }
+}
diff --git a/src/fr/watch54/displays/tasks/HologramTask.java b/src/main/java/fr/watch54/displays/tasks/HologramTask.java
similarity index 95%
rename from src/fr/watch54/displays/tasks/HologramTask.java
rename to src/main/java/fr/watch54/displays/tasks/HologramTask.java
index 79d2645..ca728c3 100644
--- a/src/fr/watch54/displays/tasks/HologramTask.java
+++ b/src/main/java/fr/watch54/displays/tasks/HologramTask.java
@@ -1,35 +1,30 @@
-package fr.watch54.displays.tasks;
-
-import fr.watch54.displays.managers.HologramManager;
-import fr.watch54.displays.holograms.Hologram;
-import org.bukkit.Bukkit;
-import org.bukkit.scheduler.BukkitRunnable;
-
-public class HologramTask extends BukkitRunnable {
-
- private Hologram hologram;
- private HologramManager hologramManager;
- private boolean refresh;
-
- public HologramTask(Hologram hologram, HologramManager hologramManager, boolean refresh){
- this.hologram = hologram;
- this.hologramManager = hologramManager;
- this.refresh = refresh;
-
- }
-
- @Override
- public void run(){
-
- if(Bukkit.getOnlinePlayers().size() < 1 && hologram.isSpawned()){
- cancel();
- hologramManager.remove(hologram);
- return;
-
- }
-
- if(refresh) hologram.update();
-
- }
-
-}
+package fr.watch54.displays.tasks;
+
+import fr.watch54.displays.managers.HologramManager;
+import fr.watch54.displays.holograms.Hologram;
+import org.bukkit.Bukkit;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class HologramTask extends BukkitRunnable {
+
+ private Hologram hologram;
+ private HologramManager hologramManager;
+ private boolean refresh;
+
+ public HologramTask(Hologram hologram, HologramManager hologramManager, boolean refresh){
+ this.hologram = hologram;
+ this.hologramManager = hologramManager;
+ this.refresh = refresh;
+ }
+
+ @Override
+ public void run(){
+ if(Bukkit.getOnlinePlayers().size() < 1 && hologram.isSpawned()){
+ cancel();
+ hologramManager.remove(hologram);
+ return;
+ }
+ if(refresh) hologram.update();
+ }
+
+}
diff --git a/resources/plugin.yml b/src/main/java/resources/plugin.yml
similarity index 70%
rename from resources/plugin.yml
rename to src/main/java/resources/plugin.yml
index 67f73e3..1f2ee22 100644
--- a/resources/plugin.yml
+++ b/src/main/java/resources/plugin.yml
@@ -1,4 +1,4 @@
-name: HologramDisplays
-author: Watch54
-main: fr.watch54.displays.Plugin
+name: HologramDisplays
+authors: [Watch54, gameszaum]
+main: fr.watch54.displays.Plugin
version: 1.0.0
\ No newline at end of file