mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-12-26 02:17:38 +01:00
Added HolographicDisplays
This commit is contained in:
parent
22214e8749
commit
2dec87fbeb
@ -1,15 +0,0 @@
|
||||
Hey loves,
|
||||
|
||||
Thanks for downloading our plugin ^_^ If you
|
||||
want hologram support you have to download
|
||||
the plugin below.
|
||||
|
||||
Link to download:
|
||||
https://gitlab.com/Songoda/Arconix/-/jobs/artifacts/master/download?job=build
|
||||
|
||||
If you need help you can always join our
|
||||
discord in which is listed at the bottom of all of
|
||||
our plugin pages.
|
||||
|
||||
Enjoy <3
|
||||
Brianna & The Songoda Team.
|
6
pom.xml
6
pom.xml
@ -47,6 +47,12 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
|
||||
<artifactId>holographicdisplays</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
|
@ -4,7 +4,9 @@ import com.songoda.ultimatestacker.command.CommandManager;
|
||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
||||
import com.songoda.ultimatestacker.events.*;
|
||||
import com.songoda.ultimatestacker.handlers.HologramHandler;
|
||||
import com.songoda.ultimatestacker.hologram.Hologram;
|
||||
import com.songoda.ultimatestacker.hologram.HologramArconix;
|
||||
import com.songoda.ultimatestacker.hologram.HologramHolographicDisplays;
|
||||
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
||||
import com.songoda.ultimatestacker.spawner.SpawnerStackManager;
|
||||
import com.songoda.ultimatestacker.storage.Storage;
|
||||
@ -22,6 +24,7 @@ import org.bukkit.*;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@ -48,7 +51,7 @@ public class UltimateStacker extends JavaPlugin {
|
||||
private SpawnerStackManager spawnerStackManager;
|
||||
private CommandManager commandManager;
|
||||
private StackingTask stackingTask;
|
||||
private HologramHandler hologramHandler;
|
||||
private Hologram hologram;
|
||||
|
||||
private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
|
||||
private Storage storage;
|
||||
@ -60,6 +63,8 @@ public class UltimateStacker extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
this.saveToFile();
|
||||
this.storage.closeConnection();
|
||||
if (hologram != null)
|
||||
this.hologram.unloadHolograms();
|
||||
|
||||
ConsoleCommandSender console = Bukkit.getConsoleSender();
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
@ -167,12 +172,6 @@ public class UltimateStacker extends JavaPlugin {
|
||||
try {
|
||||
Location location = Methods.unserializeLocation(row.getKey());
|
||||
|
||||
if (location.getWorld() == null || !location.getBlock().getType().name().contains("SPAWNER")) {
|
||||
if (location.getWorld() != null && !location.getBlock().getType().name().contains("SPAWNER")) {
|
||||
this.hologramHandler.despawn(location.getBlock());
|
||||
}
|
||||
}
|
||||
|
||||
SpawnerStack stack = new SpawnerStack(
|
||||
location,
|
||||
row.get("amount").asInt());
|
||||
@ -191,11 +190,10 @@ public class UltimateStacker extends JavaPlugin {
|
||||
}
|
||||
// Save data initially so that if the person reloads again fast they don't lose all their data.
|
||||
this.saveToFile();
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Arconix")) {
|
||||
this.hologramHandler = new HologramHandler(this);
|
||||
}
|
||||
if (hologram != null)
|
||||
hologram.loadHolograms();
|
||||
}, 10);
|
||||
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
if (isServerVersionAtLeast(ServerVersion.V1_10))
|
||||
Bukkit.getPluginManager().registerEvents(new BreedListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new SpawnerListeners(this), this);
|
||||
@ -206,6 +204,9 @@ public class UltimateStacker extends JavaPlugin {
|
||||
Bukkit.getPluginManager().registerEvents(new InventoryListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new EntityListeners(this), this);
|
||||
|
||||
// Register Hologram Plugin
|
||||
if (pluginManager.isPluginEnabled("Arconix")) hologram = new HologramArconix(this);
|
||||
else if (pluginManager.isPluginEnabled("HolographicDisplays")) hologram = new HologramHolographicDisplays(this);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
|
||||
|
||||
@ -297,6 +298,8 @@ public class UltimateStacker extends JavaPlugin {
|
||||
return this.getConfig().getBoolean("Main.Stack Spawners");
|
||||
}
|
||||
|
||||
public Hologram getHologram() { return hologram; }
|
||||
|
||||
public ServerVersion getServerVersion() {
|
||||
return serverVersion;
|
||||
}
|
||||
@ -313,10 +316,6 @@ public class UltimateStacker extends JavaPlugin {
|
||||
return serverVersion.ordinal() >= version.ordinal();
|
||||
}
|
||||
|
||||
public HologramHandler getHologramHandler() {
|
||||
return hologramHandler;
|
||||
}
|
||||
|
||||
public References getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
@ -71,14 +71,14 @@ public class BlockListeners implements Listener {
|
||||
}
|
||||
|
||||
stack.setAmount(stack.getAmount() + itemAmount);
|
||||
if (instance.getHologramHandler() != null)
|
||||
instance.getHologramHandler().updateHologram(stack);
|
||||
if (instance.getHologram() != null)
|
||||
instance.getHologram().update(stack);
|
||||
Methods.takeItem(player, itemAmount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> instance.getHologramHandler().processChange(block), 10L);
|
||||
if (instance.getHologram() != null)
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> instance.getHologram().processChange(block), 10L);
|
||||
|
||||
}
|
||||
|
||||
@ -99,10 +99,12 @@ public class BlockListeners implements Listener {
|
||||
cs.setSpawnedType(cs2.getSpawnedType());
|
||||
cs.update();
|
||||
|
||||
instance.getHologramHandler().updateHologram(stack);
|
||||
if (instance.getHologram() != null)
|
||||
instance.getHologram().add(stack);
|
||||
}
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> instance.getHologramHandler().processChange(block), 1L);
|
||||
if (instance.getHologram() != null)
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> instance.getHologram().processChange(block), 1L);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@ -128,18 +130,19 @@ public class BlockListeners implements Listener {
|
||||
if (player.isSneaking()) {
|
||||
event.setCancelled(false);
|
||||
amt = stack.getAmount();
|
||||
instance.getHologramHandler().despawn(block);
|
||||
if (instance.getHologram() != null)
|
||||
instance.getHologram().remove(stack);
|
||||
instance.getSpawnerStackManager().removeSpawner(block.getLocation());
|
||||
} else {
|
||||
if (stack.getAmount() <= 1) {
|
||||
event.setCancelled(false);
|
||||
if (instance.getHologramHandler() != null)
|
||||
instance.getHologramHandler().despawn(block);
|
||||
instance.getSpawnerStackManager().removeSpawner(block.getLocation());
|
||||
if (instance.getHologram() != null)
|
||||
instance.getHologram().remove(stack);
|
||||
} else {
|
||||
stack.setAmount(stack.getAmount() - 1);
|
||||
if (instance.getHologramHandler() != null)
|
||||
instance.getHologramHandler().updateHologram(stack);
|
||||
if (instance.getHologram() != null)
|
||||
instance.getHologram().update(stack);
|
||||
}
|
||||
}
|
||||
if (player.hasPermission("ultimatestacker.spawner.nosilkdrop") || item != null && item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && player.hasPermission("ultimatestacker.spawner.silktouch"))
|
||||
|
@ -41,7 +41,7 @@ public class EntityListeners implements Listener {
|
||||
ItemStack item = Methods.getSpawnerItem(((CreatureSpawner) block.getState()).getSpawnedType(), stack.getAmount());
|
||||
spawnerLocation.getWorld().dropItemNaturally(spawnerLocation.clone().add(.5, 0, .5), item);
|
||||
|
||||
instance.getHologramHandler().despawn(spawnerLocation.getBlock());
|
||||
instance.getHologram().remove(stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,69 +0,0 @@
|
||||
package com.songoda.ultimatestacker.handlers;
|
||||
|
||||
import com.songoda.arconix.api.hologram.HologramObject;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/12/2017.
|
||||
*/
|
||||
public class HologramHandler {
|
||||
|
||||
private final UltimateStacker instance;
|
||||
|
||||
public HologramHandler(UltimateStacker instance) {
|
||||
this.instance = instance;
|
||||
loadHolograms();
|
||||
}
|
||||
|
||||
private void loadHolograms() {
|
||||
Collection<SpawnerStack> spawners = instance.getSpawnerStackManager().getStacks();
|
||||
if (spawners.size() == 0) return;
|
||||
|
||||
for (SpawnerStack spawner : spawners) {
|
||||
if (spawner.getLocation().getWorld() == null) continue;
|
||||
updateHologram(spawner);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateHologram(SpawnerStack spawner) {
|
||||
if (spawner == null) return;
|
||||
|
||||
Location location = spawner.getLocation().add(0.5, 1, 0.5);
|
||||
|
||||
if (!instance.getConfig().getBoolean("Spawners.Holograms Enabled")) return;
|
||||
|
||||
addHologram(location, spawner);
|
||||
}
|
||||
|
||||
public void despawn(Block b) {
|
||||
Location location = b.getLocation().add(0.5, 1, 0.5);
|
||||
Arconix.pl().getApi().packetLibrary.getHologramManager().removeHologram(location, 1);
|
||||
}
|
||||
|
||||
private void addHologram(Location location, SpawnerStack spawner) {
|
||||
int amount = spawner.getAmount();
|
||||
|
||||
CreatureSpawner creatureSpawner = (CreatureSpawner) spawner.getLocation().getBlock().getState();
|
||||
String name = Methods.compileSpawnerName(creatureSpawner.getSpawnedType(), amount);
|
||||
|
||||
HologramObject hologram = new HologramObject(null, location, name);
|
||||
|
||||
Arconix.pl().getApi().packetLibrary.getHologramManager().addHologram(hologram);
|
||||
}
|
||||
|
||||
public void processChange(Block block) {
|
||||
if (block.getType() != Material.MOB_SPAWNER) return;
|
||||
SpawnerStack spawner = instance.getSpawnerStackManager().getSpawner(block);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> updateHologram(spawner), 1L);
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.songoda.ultimatestacker.hologram;
|
||||
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class Hologram {
|
||||
|
||||
protected final UltimateStacker instance;
|
||||
|
||||
Hologram(UltimateStacker instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void loadHolograms() {
|
||||
Collection<SpawnerStack> spawners = instance.getSpawnerStackManager().getStacks();
|
||||
if (spawners.size() == 0) return;
|
||||
|
||||
for (SpawnerStack spawner : spawners) {
|
||||
if (spawner.getLocation().getWorld() == null) continue;
|
||||
add(spawner);
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadHolograms() {
|
||||
Collection<SpawnerStack> spawners = instance.getSpawnerStackManager().getStacks();
|
||||
if (spawners.size() == 0) return;
|
||||
|
||||
for (SpawnerStack spawner : spawners) {
|
||||
if (spawner.getLocation().getWorld() == null) continue;
|
||||
remove(spawner);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(SpawnerStack spawner) {
|
||||
int amount = spawner.getAmount();
|
||||
if (spawner.getLocation().getBlock().getType() != Material.SPAWNER) return;
|
||||
|
||||
CreatureSpawner creatureSpawner = (CreatureSpawner) spawner.getLocation().getBlock().getState();
|
||||
String name = Methods.compileSpawnerName(creatureSpawner.getSpawnedType(), amount);
|
||||
|
||||
add(spawner.getLocation(), name);
|
||||
}
|
||||
|
||||
public void remove(SpawnerStack spawner) {
|
||||
remove(spawner.getLocation());
|
||||
}
|
||||
|
||||
public void update(SpawnerStack spawner) {
|
||||
int amount = spawner.getAmount();
|
||||
if (spawner.getLocation().getBlock().getType() != Material.SPAWNER) return;
|
||||
|
||||
CreatureSpawner creatureSpawner = (CreatureSpawner) spawner.getLocation().getBlock().getState();
|
||||
String name = Methods.compileSpawnerName(creatureSpawner.getSpawnedType(), amount);
|
||||
|
||||
update(spawner.getLocation(), name);
|
||||
}
|
||||
|
||||
protected abstract void add(Location location, String line);
|
||||
|
||||
protected abstract void remove(Location location);
|
||||
|
||||
protected abstract void update(Location location, String line);
|
||||
|
||||
public void processChange(Block block) {
|
||||
if (block.getType() != Material.MOB_SPAWNER) return;
|
||||
SpawnerStack spawner = instance.getSpawnerStackManager().getSpawner(block);
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () ->
|
||||
update(spawner), 1L);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.songoda.ultimatestacker.hologram;
|
||||
|
||||
import com.songoda.arconix.api.hologram.HologramObject;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class HologramArconix extends Hologram {
|
||||
|
||||
private com.songoda.arconix.api.packets.Hologram hologramManager;
|
||||
|
||||
public HologramArconix(UltimateStacker instance) {
|
||||
super(instance);
|
||||
this.hologramManager = Arconix.pl().getApi().packetLibrary.getHologramManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Location location, String line) {
|
||||
fixLocation(location);
|
||||
HologramObject hologram = new HologramObject(null, location, line);
|
||||
hologramManager.addHologram(hologram);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Location location) {
|
||||
fixLocation(location);
|
||||
hologramManager.removeHologram(location, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Location location, String line) {
|
||||
fixLocation(location);
|
||||
HologramObject hologram = new HologramObject(null, location, line);
|
||||
hologramManager.addHologram(hologram);
|
||||
}
|
||||
|
||||
private void fixLocation(Location location) {
|
||||
location.add(0.5, 1, 0.5);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.songoda.epicspawners.hologram;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
import com.songoda.epicspawners.EpicSpawnersPlugin;
|
||||
import org.bukkit.Location;
|
||||
|
||||
|
||||
public class HologramHolographicDisplays extends Hologram {
|
||||
|
||||
public HologramHolographicDisplays(EpicSpawnersPlugin instance) {
|
||||
super(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Location location, String line) {
|
||||
fixLocation(location);
|
||||
com.gmail.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(instance, location);
|
||||
hologram.appendTextLine(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Location location) {
|
||||
fixLocation(location);
|
||||
for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(instance)) {
|
||||
if (hologram.getX() != location.getX()
|
||||
|| hologram.getY() != location.getY()
|
||||
|| hologram.getZ() != location.getZ()) continue;
|
||||
hologram.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Location location, String line) {
|
||||
fixLocation(location);
|
||||
for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(instance)) {
|
||||
if (hologram.getX() != location.getX()
|
||||
|| hologram.getY() != location.getY()
|
||||
|| hologram.getZ() != location.getZ()) continue;
|
||||
hologram.clearLines();
|
||||
hologram.appendTextLine(line);
|
||||
}
|
||||
}
|
||||
|
||||
private void fixLocation(Location location) {
|
||||
location.add(0.5, 1.52, 0.5);
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import org.bukkit.block.CreatureSpawner;
|
||||
public class SpawnerStack {
|
||||
|
||||
private final Location location;
|
||||
private int amount;
|
||||
private int amount = 1;
|
||||
|
||||
public SpawnerStack(Location location, int amount) {
|
||||
this.location = location;
|
||||
|
@ -13,7 +13,8 @@ public class SpawnerStackManager {
|
||||
private static final Map<Location, SpawnerStack> registeredSpawners = new HashMap<>();
|
||||
|
||||
public SpawnerStack addSpawner(SpawnerStack spawnerStack) {
|
||||
return registeredSpawners.put(roundLocation(spawnerStack.getLocation()), spawnerStack);
|
||||
registeredSpawners.put(roundLocation(spawnerStack.getLocation()), spawnerStack);
|
||||
return spawnerStack;
|
||||
}
|
||||
|
||||
public SpawnerStack removeSpawner(Location location) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: UltimateStacker
|
||||
description: UltimateStacker
|
||||
version: maven-version-number
|
||||
soft-depend: [Arconix]
|
||||
softdepend: [Arconix, HolographicDisplays]
|
||||
main: com.songoda.ultimatestacker.UltimateStacker
|
||||
author: songoda
|
||||
commands:
|
||||
|
Loading…
Reference in New Issue
Block a user