mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-25 18:09:27 +00:00
Made backpacks actually get removed
This commit is contained in:
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
@@ -75,10 +75,12 @@ public class CosmeticGui {
|
||||
String.valueOf(id.equals(armorItem.getId())).
|
||||
toLowerCase(Locale.ROOT));
|
||||
|
||||
final String permission = armorItem.getPermission() == null ? "" : armorItem.getPermission();
|
||||
|
||||
placeholders.put(
|
||||
Placeholder.ALLOWED,
|
||||
String.valueOf(
|
||||
player.hasPermission(armorItem.getPermission())).
|
||||
player.hasPermission(permission)).
|
||||
toUpperCase(Locale.ROOT)
|
||||
);
|
||||
|
||||
@@ -90,11 +92,7 @@ public class CosmeticGui {
|
||||
lorePlaceholders(placeholders).
|
||||
build(),
|
||||
event -> {
|
||||
final String permission = armorItem.getPermission();
|
||||
|
||||
if (permission != null &&
|
||||
!permission.isBlank() &&
|
||||
!player.hasPermission(armorItem.getPermission())) {
|
||||
if (!permission.isBlank() && !player.hasPermission(armorItem.getPermission())) {
|
||||
this.messageHandler.sendMessage(
|
||||
player,
|
||||
Messages.NO_PERMISSION
|
||||
@@ -126,8 +124,8 @@ public class CosmeticGui {
|
||||
final ArmorItem.Type type = armorItem.getType();
|
||||
|
||||
switch (type) {
|
||||
case HAT -> user.setOrUnsetHat(armorItem);
|
||||
case BACKPACK -> user.setOrUnsetBackpack(armorItem);
|
||||
case HAT -> user.setOrUnsetHat(armorItem, this.messageHandler);
|
||||
case BACKPACK -> user.setOrUnsetBackpack(armorItem, this.messageHandler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,9 +145,15 @@ public class CosmeticGui {
|
||||
|
||||
this.gui.setDefaultClickAction(event -> {
|
||||
event.setCancelled(true);
|
||||
this.setItems(user);
|
||||
this.gui.update();
|
||||
Bukkit.getScheduler().runTaskLater(
|
||||
this.plugin,
|
||||
() -> {
|
||||
this.setItems(user);
|
||||
this.gui.update();
|
||||
},
|
||||
1);
|
||||
});
|
||||
|
||||
this.setItems(user);
|
||||
|
||||
this.gui.open(humanEntity);
|
||||
|
||||
@@ -53,12 +53,14 @@ public class CosmeticsMenu {
|
||||
|
||||
if (!file.exists() ||
|
||||
!file.isDirectory()) {
|
||||
this.plugin.getLogger().severe("No directory found");
|
||||
return;
|
||||
}
|
||||
|
||||
final File[] files = file.listFiles();
|
||||
|
||||
if (files == null) {
|
||||
this.plugin.getLogger().severe("Files are null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,7 +81,7 @@ public class CosmeticsMenu {
|
||||
final ConfigurationNode source = loader.load();
|
||||
|
||||
this.guiMap.put(id, source.get(CosmeticGui.class));
|
||||
|
||||
this.plugin.getLogger().severe("Loaded gui: " + id);
|
||||
} catch (final ConfigurateException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package io.github.fisher2911.hmccosmetics.user;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
||||
import io.github.fisher2911.hmccosmetics.message.MessageHandler;
|
||||
import io.github.fisher2911.hmccosmetics.message.Messages;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
@@ -39,7 +41,14 @@ public class User {
|
||||
this.playerArmor.setBackpack(backpack);
|
||||
}
|
||||
|
||||
public void setOrUnsetBackpack(final ArmorItem backpack) {
|
||||
public void setOrUnsetBackpack(final ArmorItem backpack, final MessageHandler messageHandler) {
|
||||
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (backpack.getId().equals(this.playerArmor.getBackpack().getId())) {
|
||||
this.setBackpack(new ArmorItem(
|
||||
new ItemStack(Material.AIR),
|
||||
@@ -47,10 +56,20 @@ public class User {
|
||||
"",
|
||||
ArmorItem.Type.BACKPACK
|
||||
));
|
||||
|
||||
messageHandler.sendMessage(
|
||||
player,
|
||||
Messages.REMOVED_BACKPACK
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.setBackpack(backpack);
|
||||
messageHandler.sendMessage(
|
||||
player,
|
||||
Messages.SET_BACKPACK
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +78,14 @@ public class User {
|
||||
this.getPlayer().getEquipment().setHelmet(this.playerArmor.getHat().getItemStack());
|
||||
}
|
||||
|
||||
public void setOrUnsetHat(final ArmorItem hat) {
|
||||
public void setOrUnsetHat(final ArmorItem hat, final MessageHandler messageHandler) {
|
||||
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hat.getId().equals(this.playerArmor.getHat().getId())) {
|
||||
this.setHat(new ArmorItem(
|
||||
new ItemStack(Material.AIR),
|
||||
@@ -67,10 +93,19 @@ public class User {
|
||||
"",
|
||||
ArmorItem.Type.HAT
|
||||
));
|
||||
|
||||
messageHandler.sendMessage(
|
||||
player,
|
||||
Messages.REMOVED_HAT
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
this.setHat(hat);
|
||||
messageHandler.sendMessage(
|
||||
player,
|
||||
Messages.SET_HAT
|
||||
);
|
||||
}
|
||||
|
||||
public void detach() {
|
||||
@@ -83,12 +118,15 @@ public class User {
|
||||
// todo change to packets
|
||||
public void updateArmorStand() {
|
||||
final ArmorItem backpackArmorItem = this.playerArmor.getBackpack();
|
||||
if (backpackArmorItem == null || backpackArmorItem.getItemStack().getType() == Material.AIR) {
|
||||
if (backpackArmorItem == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack backpackItem = backpackArmorItem.getItemStack();
|
||||
|
||||
if (backpackItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user