diff --git a/bedwars-api/src/main/java/com/andrei1058/bedwars/api/arena/generator/IGenHolo.java b/bedwars-api/src/main/java/com/andrei1058/bedwars/api/arena/generator/IGenHolo.java index e0a429f37..3e79d848a 100644 --- a/bedwars-api/src/main/java/com/andrei1058/bedwars/api/arena/generator/IGenHolo.java +++ b/bedwars-api/src/main/java/com/andrei1058/bedwars/api/arena/generator/IGenHolo.java @@ -22,6 +22,8 @@ import org.bukkit.entity.Player; +@Deprecated(forRemoval = true) + public interface IGenHolo { /** diff --git a/bedwars-plugin/pom.xml b/bedwars-plugin/pom.xml index fbee4f1db..d9e36de97 100644 --- a/bedwars-plugin/pom.xml +++ b/bedwars-plugin/pom.xml @@ -356,6 +356,21 @@ compile + + + + com.andrei1058.hologramapi + hologram-api + 1.0-SNAPSHOT + compile + + + com.andrei1058.hologramapi + hologram_common + 1.0-SNAPSHOT + compile + + @@ -374,6 +389,8 @@ maven-shade-plugin 3.5.0 + + /home/andrei/servers/SERVERS/bedwars/1202/plugins/bedwars-shaded.jar org.bstats diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java index eb16abb87..6e0893dd2 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java @@ -80,6 +80,7 @@ import com.andrei1058.bedwars.support.vipfeatures.VipFeatures; import com.andrei1058.bedwars.support.vipfeatures.VipListeners; import com.andrei1058.handyorbs.core.version.OrbEntityFactory; +import com.andrei1058.hologramapi.HologramAPI; import com.andrei1058.vipfeatures.api.IVipFeatures; import com.andrei1058.vipfeatures.api.MiniGameAlreadyRegistered; import org.bukkit.Bukkit; @@ -135,6 +136,7 @@ public class BedWars extends JavaPlugin { private boolean serverSoftwareSupport = true; private static com.andrei1058.bedwars.api.BedWars api; + private static HologramAPI hologramAPI; @Override public void onLoad() { @@ -524,6 +526,12 @@ public void onEnable() { // init orb factory for generators OrbEntityFactory.init(); + + try { + hologramAPI = new HologramAPI(this); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } } /** diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/generator/OreGenerator.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/generator/OreGenerator.java index 19768915a..48d667f66 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/generator/OreGenerator.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/generator/OreGenerator.java @@ -35,6 +35,9 @@ import com.andrei1058.handyorbs.core.version.OrbActivity; import com.andrei1058.handyorbs.core.version.OrbEntity; import com.andrei1058.handyorbs.core.version.OrbEntityFactory; +import com.andrei1058.hologramapi.Hologram; +import com.andrei1058.hologramapi.HologramPage; +import com.andrei1058.hologramapi.content.LineTextContent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -42,12 +45,15 @@ import org.bukkit.entity.*; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.concurrent.ConcurrentLinkedDeque; +import java.util.concurrent.atomic.AtomicInteger; import static com.andrei1058.bedwars.BedWars.*; @@ -61,23 +67,17 @@ public class OreGenerator implements IGenerator { private GeneratorType type; private int rotate = 0, dropID = 0; private ITeam bwt; - boolean up = true; - /** - * Generator holograms per language - */ - private HashMap armorStands = new HashMap<>(); - -// private ArmorStand item; public boolean stack = getGeneratorsCfg().getBoolean(ConfigPath.GENERATOR_STACK_ITEMS); private static final ConcurrentLinkedDeque rotation = new ConcurrentLinkedDeque<>(); private OrbEntity orbEntity; + private Hologram hologram; public OreGenerator(Location location, IArena arena, GeneratorType type, ITeam bwt) { if (type == GeneratorType.EMERALD || type == GeneratorType.DIAMOND) { - this.location = new Location(location.getWorld(), location.getBlockX() + 0.5, location.getBlockY() + 1.9, location.getBlockZ() + 0.5); + this.location = new Location(location.getWorld(), location.getBlockX() + 0.5, location.getBlockY() + 1.35, location.getBlockZ() + 0.5); } else { this.location = location.add(0, 1.3, 0); } @@ -98,8 +98,12 @@ public OreGenerator(Location location, IArena arena, GeneratorType type, ITeam b new ItemStack(type == GeneratorType.DIAMOND ? Material.DIAMOND_BLOCK : Material.EMERALD_BLOCK) ); orbEntity.setCustomNameVisible(false); + + // disable collisions + ((ArmorStand)orbEntity.getBukkitEntity()).setMarker(true); + OrbActivity floating = orbEntity.getOrbActivity(); - ((ArmorStand)orbEntity.getBukkitEntity()).setSmall(false); + ((ArmorStand) orbEntity.getBukkitEntity()).setSmall(false); orbEntity.setOrbActivity(() -> { floating.doTick(); rotate(); @@ -128,10 +132,10 @@ public void upgrade() { "Default." + ConfigPath.GENERATOR_DIAMOND_TIER_III_SPAWN_LIMIT : arena.getGroup() + "." + ConfigPath.GENERATOR_DIAMOND_TIER_III_SPAWN_LIMIT); } ore = new ItemStack(Material.DIAMOND); - for (IGenHolo e : armorStands.values()) { - e.setTierName(Language.getLang(e.getIso()).m(Messages.GENERATOR_HOLOGRAM_TIER).replace("{tier}", Language.getLang(e.getIso()) - .m(upgradeStage == 2 ? Messages.FORMATTING_GENERATOR_TIER2 : Messages.FORMATTING_GENERATOR_TIER3))); - } +// for (IGenHolo e : armorStands.values()) { +// e.setTierName(Language.getLang(e.getIso()).m(Messages.GENERATOR_HOLOGRAM_TIER).replace("{tier}", Language.getLang(e.getIso()) +// .m(upgradeStage == 2 ? Messages.FORMATTING_GENERATOR_TIER2 : Messages.FORMATTING_GENERATOR_TIER3))); +// } break; case EMERALD: upgradeStage++; @@ -151,10 +155,10 @@ public void upgrade() { "Default." + ConfigPath.GENERATOR_EMERALD_TIER_III_SPAWN_LIMIT : arena.getGroup() + "." + ConfigPath.GENERATOR_EMERALD_TIER_III_SPAWN_LIMIT); } ore = new ItemStack(Material.EMERALD); - for (IGenHolo e : armorStands.values()) { - e.setTierName(Language.getLang(e.getIso()).m(Messages.GENERATOR_HOLOGRAM_TIER).replace("{tier}", - Language.getLang(e.getIso()).m(upgradeStage == 2 ? Messages.FORMATTING_GENERATOR_TIER2 : Messages.FORMATTING_GENERATOR_TIER3))); - } +// for (IGenHolo e : armorStands.values()) { +// e.setTierName(Language.getLang(e.getIso()).m(Messages.GENERATOR_HOLOGRAM_TIER).replace("{tier}", +// Language.getLang(e.getIso()).m(upgradeStage == 2 ? Messages.FORMATTING_GENERATOR_TIER2 : Messages.FORMATTING_GENERATOR_TIER3))); +// } break; } Bukkit.getPluginManager().callEvent(new GeneratorUpgradeEvent(this)); @@ -162,7 +166,7 @@ public void upgrade() { @Override public void spawn() { - if (arena.getStatus() != GameState.playing){ + if (arena.getStatus() != GameState.playing) { return; } @@ -215,9 +219,9 @@ public void spawn() { } } lastSpawn--; - for (IGenHolo e : armorStands.values()) { - e.setTimerName(Language.getLang(e.getIso()).m(Messages.GENERATOR_HOLOGRAM_TIMER).replace("{seconds}", String.valueOf(lastSpawn))); - } +// for (IGenHolo e : armorStands.values()) { +// e.setTimerName(Language.getLang(e.getIso()).m(Messages.GENERATOR_HOLOGRAM_TIMER).replace("{seconds}", String.valueOf(lastSpawn))); +// } } private void dropItem(Location location, int amount) { @@ -258,11 +262,13 @@ public static ConcurrentLinkedDeque getRotation() { return rotation; } + @Deprecated(forRemoval = true) @Override public HashMap getLanguageHolograms() { - return armorStands; + return new HashMap<>(); } + @Deprecated(forRemoval = true) @SuppressWarnings("WeakerAccess") public class HoloGram implements IGenHolo { String iso; @@ -323,7 +329,7 @@ public void destroy() { } private static ArmorStand createArmorStand(String name, Location l) { - ArmorStand a = (ArmorStand) l.getWorld().spawnEntity(l.clone().add(0,0.35,0), EntityType.ARMOR_STAND); + ArmorStand a = (ArmorStand) l.getWorld().spawnEntity(l.clone().add(0, 0.35, 0), EntityType.ARMOR_STAND); a.setGravity(false); if (name != null) { a.setCustomName(name); @@ -341,19 +347,7 @@ private static ArmorStand createArmorStand(String name, Location l) { @Override public void rotate() { ArmorStand item = (ArmorStand) orbEntity.getBukkitEntity(); -// if (up) { -// if (rotate >= 540) { -// up = false; -// this.orbEntity.setAnimationUp(false); -// } - item.setHeadPose(new EulerAngle(0, Math.toRadians(rotate += 5), 0)); -// } else { -// if (rotate <= 0) { -// up = true; -// this.orbEntity.setAnimationUp(true); -// } -// item.setHeadPose(new EulerAngle(0, Math.toRadians(rotate -= 8), 0)); -// } + item.setHeadPose(new EulerAngle(0, Math.toRadians(rotate += 5), 0)); } @Override @@ -378,34 +372,59 @@ public ItemStack getOre() { @Override public void disable() { + // todo this is deprecated if (getOre().getType() == Material.EMERALD || getOre().getType() == Material.DIAMOND) { rotation.remove(this); - for (IGenHolo a : armorStands.values()) { - a.destroy(); - } } - armorStands.clear(); } + @Deprecated @Override public void updateHolograms(Player p, String iso) { - for (IGenHolo h : armorStands.values()) { - h.updateForPlayer(p, iso); - } + // todo I think this is deprecated +// for (IGenHolo h : armorStands.values()) { +// h.updateForPlayer(p, iso); +// } } @Override public void enableRotation() { - rotation.add(this); - for (Language lan : Language.getLanguages()) { - IGenHolo h = armorStands.get(lan.getIso()); - if (h == null) { - armorStands.put(lan.getIso(), new HoloGram(lan.getIso())); - } - } - for (IGenHolo hg : armorStands.values()) { - hg.updateForAll(); - } +// rotation.add(this); +// for (Language lan : Language.getLanguages()) { +// IGenHolo h = armorStands.get(lan.getIso()); +// if (h == null) { +// armorStands.put(lan.getIso(), new HoloGram(lan.getIso())); +// } +// } +// for (IGenHolo hg : armorStands.values()) { +// hg.updateForAll(); +// } + + hologram = new Hologram( + location.clone().add(0, 3.5, 0), + 3 + ); + + HologramPage page1 = hologram.getPage(0); + assert page1 != null; + page1.setLineContent(0, new LineTextContent(player -> Language.getPlayerLanguage(player).m(Messages.GENERATOR_HOLOGRAM_TIER) + .replace("{tier}", Language.getPlayerLanguage(player).m(Messages.FORMATTING_GENERATOR_TIER1)))); + page1.setLineContent(1, new LineTextContent( + player -> Language.getPlayerLanguage(player).m(getOre().getType() == Material.DIAMOND ? Messages.GENERATOR_HOLOGRAM_TYPE_DIAMOND + : Messages.GENERATOR_HOLOGRAM_TYPE_EMERALD) + )); + // setting second line content (a refreshable line) + page1.setLineContent(2, new LineTextContent( + (player) -> Language.getPlayerLanguage(player).m(Messages.GENERATOR_HOLOGRAM_TIMER) + .replace("{seconds}", String.valueOf(lastSpawn)) + )); + + // todo refreshed on lib side for now with entity#tick +// BukkitTask taskToCancelLater = Bukkit.getScheduler().runTaskTimer(plugin, () -> { +// hologram.refreshLine(2); +// }, 1L, 10L); + // setting third line content + hologram.allowCollisions(false); } @Override @@ -517,7 +536,6 @@ public void destroyData() { arena = null; ore = null; bwt = null; - armorStands = null; // item = null; } } diff --git a/versionsupport_1_12_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_12_R1/v1_12_R1.java b/versionsupport_1_12_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_12_R1/v1_12_R1.java index 86bec8d55..ff7ec9dec 100644 --- a/versionsupport_1_12_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_12_R1/v1_12_R1.java +++ b/versionsupport_1_12_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_12_R1/v1_12_R1.java @@ -52,7 +52,6 @@ import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.Plugin; import org.bukkit.potion.PotionEffectType; -import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import java.lang.reflect.Field; diff --git a/versionsupport_v1_20_R2/pom.xml b/versionsupport_v1_20_R2/pom.xml index 0234fddb7..a56faa095 100644 --- a/versionsupport_v1_20_R2/pom.xml +++ b/versionsupport_v1_20_R2/pom.xml @@ -18,6 +18,12 @@ + + com.andrei1058.hologramapi + hologram_v1_20_R2 + 1.0-SNAPSHOT + compile + com.andrei1058.handyorbs handyorbs-v1_20_R2