Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei1058 committed Jun 4, 2024
1 parent 98088a4 commit c81658e
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import org.bukkit.entity.Player;

@Deprecated(forRemoval = true)

public interface IGenHolo {

/**
Expand Down
17 changes: 17 additions & 0 deletions bedwars-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@
<scope>compile</scope>
</dependency>
<!-- End of Orb dependency-->

<!-- Hologram API -->
<dependency>
<groupId>com.andrei1058.hologramapi</groupId>
<artifactId>hologram-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.hologramapi</groupId>
<artifactId>hologram_common</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- End of Hologram API -->
</dependencies>

<build>
Expand All @@ -374,6 +389,8 @@
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<!-- <outputDirectory>/home/andrei/servers/SERVERS/bedwars/1202/plugins</outputDirectory>-->
<outputFile>/home/andrei/servers/SERVERS/bedwars/1202/plugins/bedwars-shaded.jar</outputFile>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,25 @@
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;
import org.bukkit.Sound;
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.*;

Expand All @@ -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 <iso, holo></iso,>
*/
private HashMap<String, IGenHolo> armorStands = new HashMap<>();

// private ArmorStand item;
public boolean stack = getGeneratorsCfg().getBoolean(ConfigPath.GENERATOR_STACK_ITEMS);

private static final ConcurrentLinkedDeque<OreGenerator> 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);
}
Expand All @@ -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();
Expand Down Expand Up @@ -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++;
Expand All @@ -151,18 +155,18 @@ 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));
}

@Override
public void spawn() {
if (arena.getStatus() != GameState.playing){
if (arena.getStatus() != GameState.playing) {
return;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -258,11 +262,13 @@ public static ConcurrentLinkedDeque<OreGenerator> getRotation() {
return rotation;
}

@Deprecated(forRemoval = true)
@Override
public HashMap<String, IGenHolo> getLanguageHolograms() {
return armorStands;
return new HashMap<>();
}

@Deprecated(forRemoval = true)
@SuppressWarnings("WeakerAccess")
public class HoloGram implements IGenHolo {
String iso;
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -517,7 +536,6 @@ public void destroyData() {
arena = null;
ore = null;
bwt = null;
armorStands = null;
// item = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions versionsupport_v1_20_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
</properties>

<dependencies>
<dependency>
<groupId>com.andrei1058.hologramapi</groupId>
<artifactId>hologram_v1_20_R2</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.handyorbs</groupId>
<artifactId>handyorbs-v1_20_R2</artifactId>
Expand Down

0 comments on commit c81658e

Please sign in to comment.