Skip to content

Commit

Permalink
1.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
BenceX100 committed Jan 1, 2025
1 parent 4509ad8 commit 2c9b541
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.artillexstudios</groupId>
<artifactId>AxGraves</artifactId>
<version>1.17.0</version>
<version>1.17.1</version>
<packaging>jar</packaging>

<name>AxGraves</name>
Expand Down
37 changes: 14 additions & 23 deletions src/main/java/com/artillexstudios/axgraves/grave/Grave.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,24 @@ public class Grave {
private final String playerName;
private final StorageGui gui;
private int storedXP;
private PacketEntity entity;
private Hologram hologram;
private final PacketEntity entity;
private final Hologram hologram;
private boolean removed = false;

public Grave(Location loc, @NotNull OfflinePlayer offlinePlayer, @NotNull ItemStack[] itemsAr, int storedXP, long date) {
this.location = LocationUtils.getCenterOf(loc, true);
Player pl = offlinePlayer instanceof Player p ? p : null;
if (pl != null && MESSAGES.getBoolean("death-message.enabled", false)) {
MESSAGEUTILS.sendLang(pl, "death-message.message", Map.of("%world%", loc.getWorld().getName(), "%x%", "" + loc.getBlockX(), "%y%", "" + loc.getBlockY(), "%z%", "" + loc.getBlockZ()));
MESSAGEUTILS.sendLang(pl, "death-message.message", Map.of("%world%", location.getWorld().getName(), "%x%", "" + location.getBlockX(), "%y%", "" + location.getBlockY(), "%z%", "" + location.getBlockZ()));
}

if (loc.getWorld().getEnvironment().equals(World.Environment.NETHER) || loc.getWorld().getEnvironment().equals(World.Environment.THE_END)) {
loc.setY(Math.max(loc.getY(), CONFIG.getDouble("spawn-height-limits." + loc.getWorld().getName() + ".min", 0)));
if (location.getWorld().getEnvironment().equals(World.Environment.NETHER) || location.getWorld().getEnvironment().equals(World.Environment.THE_END)) {
location.setY(Math.max(location.getY(), CONFIG.getDouble("spawn-height-limits." + location.getWorld().getName() + ".min", 0)));
} else {
loc.setY(Math.max(loc.getY(), CONFIG.getDouble("spawn-height-limits." + loc.getWorld().getName() + ".min", -64)));
location.setY(Math.max(location.getY(), CONFIG.getDouble("spawn-height-limits." + location.getWorld().getName() + ".min", -64)));
}
loc.setY(Math.min(loc.getY(), CONFIG.getDouble("spawn-height-limits." + loc.getWorld().getName() + ".max", 319)));
location.setY(Math.min(location.getY(), CONFIG.getDouble("spawn-height-limits." + location.getWorld().getName() + ".max", 319)));

this.location = LocationUtils.getCenterOf(loc, true);
this.player = offlinePlayer;
this.playerName = offlinePlayer.getName() == null ? MESSAGES.getString("unknown-player", "???") : offlinePlayer.getName();

Expand All @@ -91,18 +91,7 @@ public Grave(Location loc, @NotNull OfflinePlayer offlinePlayer, @NotNull ItemSt
gui.addItem(it);
}

int itemsAm = countItems();

int time = CONFIG.getInt("despawn-time-seconds", 180);
boolean outOfTime = time * 1_000L <= (System.currentTimeMillis() - spawned);
boolean despawn = CONFIG.getBoolean("despawn-when-empty", true);
boolean empty = itemsAm == 0 && storedXP == 0;
if ((time != -1 && outOfTime) || (despawn && empty)) {
remove();
return;
}

entity = NMSHandlers.getNmsHandler().createEntity(EntityType.ARMOR_STAND, location.clone().add(0, CONFIG.getFloat("head-height", -1.2f), 0));
entity = NMSHandlers.getNmsHandler().createEntity(EntityType.ARMOR_STAND, location.clone().add(0, 1 + CONFIG.getFloat("head-height", -1.2f), 0));
entity.setItem(EquipmentSlot.HELMET, WrappedItemStack.wrap(Utils.getPlayerHead(offlinePlayer)));
final ArmorStandMeta meta = (ArmorStandMeta) entity.meta();
meta.small(true);
Expand All @@ -111,17 +100,18 @@ public Grave(Location loc, @NotNull OfflinePlayer offlinePlayer, @NotNull ItemSt
entity.spawn();

if (CONFIG.getBoolean("rotate-head-360", true)) {
entity.location().setYaw(loc.getYaw());
entity.location().setYaw(location.getYaw());
entity.teleport(entity.location());
} else {
entity.location().setYaw(LocationUtils.getNearestDirection(loc.getYaw()));
entity.location().setYaw(LocationUtils.getNearestDirection(location.getYaw()));
entity.teleport(entity.location());
}

entity.onInteract(event -> Scheduler.get().run(task -> interact(event.getPlayer(), event.getHand())));

hologram = new Hologram(location.clone().add(0, CONFIG.getFloat("hologram-height", 1.2f), 0), Serializers.LOCATION.serialize(location), 0.3);
hologram = new Hologram(location.clone().add(0, 1 + CONFIG.getFloat("hologram-height", 1.2f), 0), Serializers.LOCATION.serialize(location), 0.3);

int time = CONFIG.getInt("despawn-time-seconds", 180);
hologram.addPlaceholder(new Placeholder((player1, string) -> {
string = string.replace("%player%", playerName);
string = string.replace("%xp%", "" + storedXP);
Expand Down Expand Up @@ -153,6 +143,7 @@ public void update() {
entity.teleport(entity.location());
}
}

public void interact(@NotNull Player opener, org.bukkit.inventory.EquipmentSlot slot) {
if (CONFIG.getBoolean("interact-only-own", false) && !opener.getUniqueId().equals(player.getUniqueId()) && !opener.hasPermission("axgraves.admin")) {
MESSAGEUTILS.sendLang(opener, "interact.not-your-grave");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.artillexstudios.axgraves.grave.SpawnedGraves;
import com.artillexstudios.axgraves.utils.ExperienceUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -18,7 +19,7 @@

public class DeathListener implements Listener {

@EventHandler(priority = EventPriority.MONITOR)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDeath(@NotNull PlayerDeathEvent event) {
if (CONFIG.getStringList("disabled-worlds") != null && CONFIG.getStringList("disabled-worlds").contains(event.getEntity().getWorld().getName())) return;
if (!CONFIG.getBoolean("override-keep-inventory", true) && event.getKeepInventory()) return;
Expand All @@ -34,10 +35,12 @@ public void onDeath(@NotNull PlayerDeathEvent event) {
if (CONFIG.getBoolean("store-xp", true))
xp = Math.round(ExperienceUtils.getExp(player) * CONFIG.getFloat("xp-keep-percentage", 1f));

Location location = player.getLocation();
location.add(0, -0.5, 0);
if (!event.getKeepInventory()) {
grave = new Grave(player.getLocation(), player, event.getDrops().toArray(new ItemStack[0]), xp, System.currentTimeMillis());
grave = new Grave(location, player, event.getDrops().toArray(new ItemStack[0]), xp, System.currentTimeMillis());
} else if (CONFIG.getBoolean("override-keep-inventory", true)) {
grave = new Grave(player.getLocation(), player, player.getInventory().getContents(), xp, System.currentTimeMillis());
grave = new Grave(location, player, player.getInventory().getContents(), xp, System.currentTimeMillis());
if (CONFIG.getBoolean("store-xp", true)) {
player.setLevel(0);
player.setTotalExperience(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class LocationUtils {

@NotNull
public static Location getCenterOf(@NotNull Location location, boolean keepPitchYaw) {
location.setY(Math.round(location.getY()));
final Location loc = location.getBlock().getLocation().add(0.5, 0.5, 0.5);
if (keepPitchYaw) {
loc.setPitch(location.getPitch());
Expand Down

0 comments on commit 2c9b541

Please sign in to comment.