mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-28 19:39:14 +00:00
Fixed teleport issue
This commit is contained in:
@@ -7,6 +7,7 @@ import io.github.fisher2911.hmccosmetics.command.CosmeticsCommand;
|
||||
import io.github.fisher2911.hmccosmetics.gui.CosmeticsMenu;
|
||||
import io.github.fisher2911.hmccosmetics.listener.ClickListener;
|
||||
import io.github.fisher2911.hmccosmetics.listener.JoinListener;
|
||||
import io.github.fisher2911.hmccosmetics.listener.TeleportListener;
|
||||
import io.github.fisher2911.hmccosmetics.message.MessageHandler;
|
||||
import io.github.fisher2911.hmccosmetics.message.Messages;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
@@ -46,7 +47,8 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
|
||||
private void registerListeners() {
|
||||
List.of(new JoinListener(this),
|
||||
new ClickListener(this)).
|
||||
new ClickListener(this),
|
||||
new TeleportListener(this)).
|
||||
forEach(listener ->
|
||||
this.getServer().getPluginManager().registerEvents(listener, this)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.github.fisher2911.hmccosmetics.listener;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
public class TeleportListener implements Listener {
|
||||
|
||||
private final HMCCosmetics plugin;
|
||||
private final UserManager userManager;
|
||||
|
||||
public TeleportListener(final HMCCosmetics plugin) {
|
||||
this.plugin = plugin;
|
||||
this.userManager = this.plugin.getUserManager();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(final PlayerTeleportEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
this.userManager.get(player.getUniqueId()).ifPresent(User::despawnAttached);
|
||||
}
|
||||
}
|
||||
@@ -137,18 +137,21 @@ public class User {
|
||||
public void updateArmorStand() {
|
||||
final ArmorItem backpackArmorItem = this.playerArmor.getBackpack();
|
||||
if (backpackArmorItem == null ) {
|
||||
this.despawnAttached();
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack backpackItem = backpackArmorItem.getItemStack();
|
||||
|
||||
if (backpackItem == null) {
|
||||
if (backpackItem == null || backpackItem.getType() == Material.AIR) {
|
||||
this.despawnAttached();
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
this.despawnAttached();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -168,6 +171,11 @@ public class User {
|
||||
|
||||
final EntityEquipment equipment = this.attached.getEquipment();
|
||||
|
||||
if (equipment == null) {
|
||||
this.despawnAttached();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!backpackItem.equals(equipment.getHelmet())) {
|
||||
equipment.setHelmet(backpackItem);
|
||||
}
|
||||
@@ -178,6 +186,15 @@ public class User {
|
||||
player.getLocation().getPitch());
|
||||
}
|
||||
|
||||
public void despawnAttached() {
|
||||
if (this.attached == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.attached.remove();
|
||||
this.attached = null;
|
||||
}
|
||||
|
||||
public ArmorItem getLastSetItem() {
|
||||
return lastSetItem;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user