mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
Added static wardrobe
This commit is contained in:
2
.idea/modules/1.18/HMCCosmetics.1.18.main.iml
generated
2
.idea/modules/1.18/HMCCosmetics.1.18.main.iml
generated
@@ -4,8 +4,8 @@
|
|||||||
<facet type="minecraft" name="Minecraft">
|
<facet type="minecraft" name="Minecraft">
|
||||||
<configuration>
|
<configuration>
|
||||||
<autoDetectTypes>
|
<autoDetectTypes>
|
||||||
<platformType>MCP</platformType>
|
|
||||||
<platformType>SPIGOT</platformType>
|
<platformType>SPIGOT</platformType>
|
||||||
|
<platformType>MCP</platformType>
|
||||||
</autoDetectTypes>
|
</autoDetectTypes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</facet>
|
</facet>
|
||||||
|
|||||||
@@ -106,6 +106,10 @@ bukkit {
|
|||||||
default = BukkitPluginDescription.Permission.Default.OP
|
default = BukkitPluginDescription.Permission.Default.OP
|
||||||
description = "Permission to set other users' cosmetics."
|
description = "Permission to set other users' cosmetics."
|
||||||
}
|
}
|
||||||
|
register("hmccosmetics.cmd.wardrobe.portable") {
|
||||||
|
default = BukkitPluginDescription.Permission.Default.OP
|
||||||
|
description = "Permission to use a portable wardrobe"
|
||||||
|
}
|
||||||
register("hmccosmetics.cmd.wardrobe") {
|
register("hmccosmetics.cmd.wardrobe") {
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
default = BukkitPluginDescription.Permission.Default.OP
|
||||||
description = "Permission to view the wardrobe"
|
description = "Permission to view the wardrobe"
|
||||||
|
|||||||
@@ -141,14 +141,14 @@ public class HMCCosmetics extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this,
|
Bukkit.getScheduler().runTaskLaterAsynchronously(this,
|
||||||
() -> {
|
() -> {
|
||||||
this.settings.load();
|
this.settings.load();
|
||||||
this.messageHandler.load();
|
this.messageHandler.load();
|
||||||
this.cosmeticsMenu.load();
|
this.cosmeticsMenu.load();
|
||||||
Translation.getInstance().load();
|
Translation.getInstance().load();
|
||||||
this.database.load();
|
this.database.load();
|
||||||
});
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package io.github.fisher2911.hmccosmetics.command;
|
package io.github.fisher2911.hmccosmetics.command;
|
||||||
|
|
||||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||||
|
import io.github.fisher2911.hmccosmetics.config.Settings;
|
||||||
|
import io.github.fisher2911.hmccosmetics.config.WardrobeSettings;
|
||||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||||
import io.github.fisher2911.hmccosmetics.gui.CosmeticsMenu;
|
import io.github.fisher2911.hmccosmetics.gui.CosmeticsMenu;
|
||||||
import io.github.fisher2911.hmccosmetics.message.Message;
|
import io.github.fisher2911.hmccosmetics.message.Message;
|
||||||
@@ -33,17 +35,35 @@ public class CosmeticsCommand extends CommandBase {
|
|||||||
private final UserManager userManager;
|
private final UserManager userManager;
|
||||||
private final MessageHandler messageHandler;
|
private final MessageHandler messageHandler;
|
||||||
private final CosmeticsMenu cosmeticsMenu;
|
private final CosmeticsMenu cosmeticsMenu;
|
||||||
|
private final Settings settings;
|
||||||
|
|
||||||
public CosmeticsCommand(final HMCCosmetics plugin) {
|
public CosmeticsCommand(final HMCCosmetics plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.userManager = this.plugin.getUserManager();
|
this.userManager = this.plugin.getUserManager();
|
||||||
this.messageHandler = this.plugin.getMessageHandler();
|
this.messageHandler = this.plugin.getMessageHandler();
|
||||||
this.cosmeticsMenu = this.plugin.getCosmeticsMenu();
|
this.cosmeticsMenu = this.plugin.getCosmeticsMenu();
|
||||||
|
this.settings = this.plugin.getSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Default
|
@Default
|
||||||
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.DEFAULT_COMMAND)
|
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.DEFAULT_COMMAND)
|
||||||
public void defaultCommand(final Player player) {
|
public void defaultCommand(final Player player) {
|
||||||
|
final Optional<User> optionalUser = this.userManager.get(player.getUniqueId());
|
||||||
|
if (optionalUser.isEmpty()) {
|
||||||
|
this.cosmeticsMenu.openDefault(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final User user = optionalUser.get();
|
||||||
|
final Wardrobe wardrobe = user.getWardrobe();
|
||||||
|
if (wardrobe.isActive() &&
|
||||||
|
!this.settings.getWardrobeSettings().inDistanceOfWardrobe(wardrobe.getCurrentLocation(), player.getLocation())) {
|
||||||
|
wardrobe.setActive(false);
|
||||||
|
wardrobe.despawnFakePlayer(player);
|
||||||
|
this.messageHandler.sendMessage(
|
||||||
|
player,
|
||||||
|
Messages.CLOSED_WARDROBE
|
||||||
|
);
|
||||||
|
}
|
||||||
this.cosmeticsMenu.openDefault(player);
|
this.cosmeticsMenu.openDefault(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +213,7 @@ public class CosmeticsCommand extends CommandBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SubCommand("wardrobe")
|
@SubCommand("wardrobe")
|
||||||
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.VIEW_WARDROBE)
|
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.WARDROBE)
|
||||||
public void openWardrobe(final Player player) {
|
public void openWardrobe(final Player player) {
|
||||||
final Optional<User> optionalUser = this.plugin.getUserManager().get(player.getUniqueId());
|
final Optional<User> optionalUser = this.plugin.getUserManager().get(player.getUniqueId());
|
||||||
if (optionalUser.isEmpty()) return;
|
if (optionalUser.isEmpty()) return;
|
||||||
@@ -209,11 +229,36 @@ public class CosmeticsCommand extends CommandBase {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final WardrobeSettings settings = this.settings.getWardrobeSettings();
|
||||||
|
|
||||||
|
final boolean inDistanceOfStatic = settings.inDistanceOfStatic(player.getLocation());
|
||||||
|
|
||||||
|
if (!settings.isPortable() && !inDistanceOfStatic) {
|
||||||
|
this.messageHandler.sendMessage(
|
||||||
|
player,
|
||||||
|
Messages.NOT_NEAR_WARDROBE
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.isPortable() && !inDistanceOfStatic) {
|
||||||
|
if (!player.hasPermission(io.github.fisher2911.hmccosmetics.message.Permission.PORTABLE_WARDROBE)) {
|
||||||
|
this.messageHandler.sendMessage(
|
||||||
|
player,
|
||||||
|
Messages.CANNOT_USE_PORTABLE_WARDROBE
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wardrobe.setCurrentLocation(null);
|
||||||
|
}
|
||||||
|
|
||||||
wardrobe.setActive(true);
|
wardrobe.setActive(true);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(
|
Bukkit.getScheduler().runTaskAsynchronously(
|
||||||
this.plugin,
|
this.plugin,
|
||||||
() -> wardrobe.spawnFakePlayer(player, this.plugin)
|
() -> wardrobe.spawnFakePlayer(player)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.cosmeticsMenu.openDefault(player);
|
this.cosmeticsMenu.openDefault(player);
|
||||||
this.messageHandler.sendMessage(
|
this.messageHandler.sendMessage(
|
||||||
player,
|
player,
|
||||||
|
|||||||
@@ -5,21 +5,27 @@ import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
|||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
private final HMCCosmetics plugin;
|
private final HMCCosmetics plugin;
|
||||||
private final CosmeticSettings settings;
|
private final CosmeticSettings cosmeticSettings;
|
||||||
|
private final WardrobeSettings wardrobeSettings;
|
||||||
|
|
||||||
public Settings(final HMCCosmetics plugin) {
|
public Settings(final HMCCosmetics plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.settings = new CosmeticSettings();
|
this.cosmeticSettings = new CosmeticSettings();
|
||||||
|
this.wardrobeSettings = new WardrobeSettings(this.plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
this.plugin.saveDefaultConfig();
|
this.plugin.saveDefaultConfig();
|
||||||
this.plugin.reloadConfig();
|
this.plugin.reloadConfig();
|
||||||
this.settings.load(this.plugin.getConfig());
|
this.cosmeticSettings.load(this.plugin.getConfig());
|
||||||
|
this.wardrobeSettings.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticSettings getCosmeticSettings() {
|
public CosmeticSettings getCosmeticSettings() {
|
||||||
return settings;
|
return cosmeticSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WardrobeSettings getWardrobeSettings() {
|
||||||
|
return wardrobeSettings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package io.github.fisher2911.hmccosmetics.config;
|
||||||
|
|
||||||
|
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.checkerframework.checker.units.qual.A;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class WardrobeSettings {
|
||||||
|
|
||||||
|
private static final String WARDROBE_PATH = "wardrobe";
|
||||||
|
private static final String DISABLE_ON_DAMAGE_PATH = WARDROBE_PATH + ".disable-on-damage";
|
||||||
|
private static final String DISPLAY_RADIUS_PATH = WARDROBE_PATH + ".display-radius";
|
||||||
|
private static final String PORTABLE_PATH = WARDROBE_PATH + ".portable";
|
||||||
|
private static final String ALWAYS_DISPLAY_PATH = WARDROBE_PATH + ".always-display";
|
||||||
|
private static final String STATIC_RADIUS_PATH = WARDROBE_PATH + ".static-radius";
|
||||||
|
private static final String STATIC_LOCATION_PATH = WARDROBE_PATH + ".wardrobe-location";
|
||||||
|
private static final String WORLD_PATH = "world";
|
||||||
|
private static final String X_PATH = "x";
|
||||||
|
private static final String Y_PATH = "y";
|
||||||
|
private static final String Z_PATH = "z";
|
||||||
|
private static final String YAW_PATH = "yaw";
|
||||||
|
private static final String PITCH_PATH = "pitch";
|
||||||
|
|
||||||
|
|
||||||
|
private final HMCCosmetics plugin;
|
||||||
|
|
||||||
|
private boolean disableOnDamage;
|
||||||
|
private int displayRadius;
|
||||||
|
private boolean portable;
|
||||||
|
private boolean alwaysDisplay;
|
||||||
|
private int staticRadius;
|
||||||
|
private Location location;
|
||||||
|
|
||||||
|
public WardrobeSettings(final HMCCosmetics plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
final FileConfiguration config = this.plugin.getConfig();
|
||||||
|
this.disableOnDamage = config.getBoolean(DISABLE_ON_DAMAGE_PATH);
|
||||||
|
this.displayRadius = config.getInt(DISPLAY_RADIUS_PATH);
|
||||||
|
this.portable = config.getBoolean(PORTABLE_PATH);
|
||||||
|
this.staticRadius = config.getInt(STATIC_RADIUS_PATH);
|
||||||
|
this.alwaysDisplay = config.getBoolean(ALWAYS_DISPLAY_PATH);
|
||||||
|
final ConfigurationSection locationSection = config.getConfigurationSection(STATIC_LOCATION_PATH);
|
||||||
|
if (locationSection == null) return;
|
||||||
|
this.location = this.loadLocation(locationSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Location loadLocation(final ConfigurationSection section) {
|
||||||
|
final String worldName = section.getString(WORLD_PATH);
|
||||||
|
final int x = section.getInt(X_PATH);
|
||||||
|
final int y = section.getInt(Y_PATH);
|
||||||
|
final int z = section.getInt(Z_PATH);
|
||||||
|
final float yaw = (float) section.getDouble(YAW_PATH);
|
||||||
|
final float pitch = (float) section.getDouble(PITCH_PATH);
|
||||||
|
|
||||||
|
if (worldName == null || worldName.isBlank()) return null;
|
||||||
|
final World world = Bukkit.getWorld(worldName);
|
||||||
|
if (world == null) return null;
|
||||||
|
return new Location(world, x, y, z, yaw, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDisableOnDamage() {
|
||||||
|
return disableOnDamage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDisplayRadius() {
|
||||||
|
return displayRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPortable() {
|
||||||
|
return portable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAlwaysDisplay() {
|
||||||
|
return alwaysDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStaticRadius() {
|
||||||
|
return staticRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean inDistanceOfWardrobe(final Location wardrobeLocation, final Location playerLocation) {
|
||||||
|
if (this.displayRadius == -1) return true;
|
||||||
|
return playerLocation.distanceSquared(wardrobeLocation) <= this.displayRadius * this.displayRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean inDistanceOfStatic(final Location location) {
|
||||||
|
if (this.location == null) return false;
|
||||||
|
if (this.staticRadius == -1) return false;
|
||||||
|
return this.location.distanceSquared(location) <= this.staticRadius * this.staticRadius;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -106,7 +106,6 @@ public class Database {
|
|||||||
final User user = new User(uuid, PlayerArmor.empty(), wardrobe, armorStandId);
|
final User user = new User(uuid, PlayerArmor.empty(), wardrobe, armorStandId);
|
||||||
this.plugin.getUserManager().add(user);
|
this.plugin.getUserManager().add(user);
|
||||||
onComplete.accept(user);
|
onComplete.accept(user);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveUser(final User user) {
|
public void saveUser(final User user) {
|
||||||
@@ -158,6 +157,7 @@ public class Database {
|
|||||||
|
|
||||||
public Wardrobe createNewWardrobe(final UUID ownerUUID) {
|
public Wardrobe createNewWardrobe(final UUID ownerUUID) {
|
||||||
return new Wardrobe(
|
return new Wardrobe(
|
||||||
|
this.plugin,
|
||||||
UUID.randomUUID(),
|
UUID.randomUUID(),
|
||||||
ownerUUID,
|
ownerUUID,
|
||||||
PlayerArmor.empty(),
|
PlayerArmor.empty(),
|
||||||
|
|||||||
@@ -107,12 +107,10 @@ public class CosmeticGui {
|
|||||||
this.gui.updateItem(slot, guiItem);
|
this.gui.updateItem(slot, guiItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open(final User user) {
|
public void open(final User user, final Player player) {
|
||||||
final Player player = user.getPlayer();
|
|
||||||
if (player == null) return;
|
|
||||||
this.gui = Gui.gui().
|
this.gui = Gui.gui().
|
||||||
title(Adventure.MINI_MESSAGE.deserialize(
|
title(Adventure.MINI_MESSAGE.deserialize(
|
||||||
Placeholder.applyPapiPlaceholders(user.getPlayer(), this.title))).
|
Placeholder.applyPapiPlaceholders(player, this.title))).
|
||||||
rows(this.rows).
|
rows(this.rows).
|
||||||
create();
|
create();
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class CosmeticsMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void openMenu(final String id, final HumanEntity humanEntity) {
|
public void openMenu(final String id, final HumanEntity humanEntity) {
|
||||||
|
if (!(humanEntity instanceof final Player player)) return;
|
||||||
final CosmeticGui cosmeticGui = this.getGui(id);
|
final CosmeticGui cosmeticGui = this.getGui(id);
|
||||||
|
|
||||||
final Optional<User> optionalUser = this.plugin.getUserManager().get(humanEntity.getUniqueId());
|
final Optional<User> optionalUser = this.plugin.getUserManager().get(humanEntity.getUniqueId());
|
||||||
@@ -59,9 +60,7 @@ public class CosmeticsMenu {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cosmeticGui != null) {
|
if (cosmeticGui != null) cosmeticGui.open(user, player);
|
||||||
cosmeticGui.open(user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openDefault(final HumanEntity humanEntity) {
|
public void openDefault(final HumanEntity humanEntity) {
|
||||||
|
|||||||
@@ -176,9 +176,7 @@ public class DyeSelectorGui extends CosmeticGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open(final User user) {
|
public void open(final User user, final Player player) {
|
||||||
final Player player = user.getPlayer();
|
|
||||||
if (player == null) return;
|
|
||||||
this.getGui(user, user.getLastSetItem().getType()).open(player);
|
this.getGui(user, user.getLastSetItem().getType()).open(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,21 +61,21 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
|||||||
if (parts.length < 2) return null;
|
if (parts.length < 2) return null;
|
||||||
final String id = this.getId(parts, 1);
|
final String id = this.getId(parts, 1);
|
||||||
for (final ArmorItem item : user.getPlayerArmor().getArmorItems()) {
|
for (final ArmorItem item : user.getPlayerArmor().getArmorItems()) {
|
||||||
if (item.getId().equals(id)) return Translation.translate("true");
|
if (item.getId().equals(id)) return Translation.translate(Translation.TRUE);
|
||||||
}
|
}
|
||||||
return Translation.translate("false");
|
return Translation.translate(Translation.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// %hmccosmetics_current_type%
|
// %hmccosmetics_current_type%
|
||||||
if (parts[0].equals("current")) {
|
if (parts[0].equals("current")) {
|
||||||
if (parts.length < 2) {
|
if (parts.length >= 2) {
|
||||||
final String typeStr = parts[1];
|
final String typeStr = getId(parts, 1);
|
||||||
try {
|
try {
|
||||||
final ArmorItem.Type type = ArmorItem.Type.valueOf(typeStr);
|
final ArmorItem.Type type = ArmorItem.Type.valueOf(typeStr.toUpperCase());
|
||||||
for (final ArmorItem item : user.getPlayerArmor().getArmorItems()) {
|
for (final ArmorItem item : user.getPlayerArmor().getArmorItems()) {
|
||||||
if (item.getType().equals(type)) return item.getId();
|
if (item.getType().equals(type)) return item.getId();
|
||||||
}
|
}
|
||||||
return null;
|
return Translation.translate(Translation.NONE);
|
||||||
} catch (final IllegalArgumentException exception) {
|
} catch (final IllegalArgumentException exception) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -86,9 +86,10 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getId(final String[] parts, final int fromIndex) {
|
private String getId(final String[] parts, final int fromIndex) {
|
||||||
final StringBuilder builder = new StringBuilder(parts[fromIndex]);
|
final StringBuilder builder = new StringBuilder();
|
||||||
for (int i = fromIndex + 1; i < parts.length; i++) {
|
for (int i = fromIndex; i < parts.length; i++) {
|
||||||
builder.append(parts[i]);
|
builder.append(parts[i]);
|
||||||
|
if (i < parts.length - 1) builder.append("_");
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
|
|||||||
@@ -62,4 +62,10 @@ public class PlayerArmor {
|
|||||||
return new PlayerArmor(new HashMap<>(this.armorItems));
|
return new PlayerArmor(new HashMap<>(this.armorItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
for (final ArmorItem.Type type : ArmorItem.Type.values()) {
|
||||||
|
this.setItem(ArmorItem.empty(type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ public class CosmeticFixListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onRightClick(final PlayerInteractEvent event) {
|
public void onRightClick(final PlayerInteractEvent event) {
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||||
&& event.getHand() != EquipmentSlot.OFF_HAND) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.github.fisher2911.hmccosmetics.listener;
|
package io.github.fisher2911.hmccosmetics.listener;
|
||||||
|
|
||||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||||
|
import io.github.fisher2911.hmccosmetics.config.WardrobeSettings;
|
||||||
import io.github.fisher2911.hmccosmetics.database.Database;
|
import io.github.fisher2911.hmccosmetics.database.Database;
|
||||||
import io.github.fisher2911.hmccosmetics.user.User;
|
import io.github.fisher2911.hmccosmetics.user.User;
|
||||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||||
@@ -31,7 +32,15 @@ public class JoinListener implements Listener {
|
|||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
this.database.loadUser(player.getUniqueId(),
|
this.database.loadUser(player.getUniqueId(),
|
||||||
user -> Bukkit.getScheduler().runTaskAsynchronously(this.plugin,
|
user -> Bukkit.getScheduler().runTaskAsynchronously(this.plugin,
|
||||||
() -> this.userManager.resendCosmetics(player)));
|
() -> {
|
||||||
|
this.userManager.resendCosmetics(player);
|
||||||
|
final WardrobeSettings settings = this.plugin.getSettings().getWardrobeSettings();
|
||||||
|
if (settings.isAlwaysDisplay() && settings.getLocation() != null) {
|
||||||
|
final Wardrobe wardrobe = user.getWardrobe();
|
||||||
|
wardrobe.setCurrentLocation(settings.getLocation());
|
||||||
|
wardrobe.spawnFakePlayer(player);
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ public class Messages {
|
|||||||
new Message("closed-wardrobe", ChatColor.GREEN + "Closing wardrobe!");
|
new Message("closed-wardrobe", ChatColor.GREEN + "Closing wardrobe!");
|
||||||
public static final Message WARDROBE_ALREADY_OPEN =
|
public static final Message WARDROBE_ALREADY_OPEN =
|
||||||
new Message("wardrobe-already-open", ChatColor.RED + "The wardrobe is already open!");
|
new Message("wardrobe-already-open", ChatColor.RED + "The wardrobe is already open!");
|
||||||
|
public static final Message NOT_NEAR_WARDROBE =
|
||||||
|
new Message("not-near-wardrobe", ChatColor.RED + "You are not near the wardrobe!");
|
||||||
|
public static final Message CANNOT_USE_PORTABLE_WARDROBE =
|
||||||
|
new Message("cannot-use-portable-wardrobe", ChatColor.RED + "You cannot use the portable wardrobe!");
|
||||||
|
|
||||||
public static final Message SET_OTHER_BACKPACK = new Message(
|
public static final Message SET_OTHER_BACKPACK = new Message(
|
||||||
"set-other-backpack", ChatColor.GREEN + "You have set the backpack of " +
|
"set-other-backpack", ChatColor.GREEN + "You have set the backpack of " +
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public class Permission {
|
|||||||
public static final String RELOAD_COMMAND = "hmccosmetics.cmd.reload";
|
public static final String RELOAD_COMMAND = "hmccosmetics.cmd.reload";
|
||||||
public static final String HELP_COMMAND = "hmccosmetics.cmd.help";
|
public static final String HELP_COMMAND = "hmccosmetics.cmd.help";
|
||||||
public static final String SET_COSMETIC_COMMAND = "hmccosmetics.cmd.set";
|
public static final String SET_COSMETIC_COMMAND = "hmccosmetics.cmd.set";
|
||||||
public static final String VIEW_WARDROBE = "hmccosmetics.cmd.wardrobe";
|
public static final String PORTABLE_WARDROBE = "hmccosmetics.cmd.wardrobe.portable";
|
||||||
|
public static final String WARDROBE = "hmccosmetics.cmd.wardrobe";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
|
|
||||||
public class Translation {
|
public class Translation {
|
||||||
|
|
||||||
|
public static final String TRUE = "true";
|
||||||
|
public static final String FALSE = "false";
|
||||||
|
public static final String NONE = "none";
|
||||||
|
|
||||||
private static final Translation INSTANCE;
|
private static final Translation INSTANCE;
|
||||||
private static final String FILE_NAME = "translations.yml";
|
private static final String FILE_NAME = "translations.yml";
|
||||||
private static final String TRANSLATION_PATH = "translations";
|
private static final String TRANSLATION_PATH = "translations";
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
|||||||
import io.github.fisher2911.hmccosmetics.message.Message;
|
import io.github.fisher2911.hmccosmetics.message.Message;
|
||||||
import io.github.fisher2911.hmccosmetics.message.MessageHandler;
|
import io.github.fisher2911.hmccosmetics.message.MessageHandler;
|
||||||
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||||
|
import io.github.fisher2911.hmccosmetics.message.Translation;
|
||||||
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
|
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
|
||||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -167,8 +168,8 @@ public class UserManager {
|
|||||||
if (hidden) return new ItemStack(Material.AIR);
|
if (hidden) return new ItemStack(Material.AIR);
|
||||||
final CosmeticSettings cosmeticSettings = this.settings.getCosmeticSettings();
|
final CosmeticSettings cosmeticSettings = this.settings.getCosmeticSettings();
|
||||||
|
|
||||||
final Map<String, String> placeholders = Map.of(Placeholder.ALLOWED, "true",
|
final Map<String, String> placeholders = Map.of(Placeholder.ALLOWED, Translation.TRUE,
|
||||||
Placeholder.ENABLED, "true");
|
Placeholder.ENABLED, Translation.TRUE);
|
||||||
|
|
||||||
ItemStack itemStack = ItemBuilder.from(armorItem.getColored()).
|
ItemStack itemStack = ItemBuilder.from(armorItem.getColored()).
|
||||||
namePlaceholders(placeholders).
|
namePlaceholders(placeholders).
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package io.github.fisher2911.hmccosmetics.user;
|
|||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||||
import io.github.fisher2911.hmccosmetics.config.Settings;
|
import io.github.fisher2911.hmccosmetics.config.Settings;
|
||||||
|
import io.github.fisher2911.hmccosmetics.config.WardrobeSettings;
|
||||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||||
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
||||||
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
|
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
|
||||||
@@ -11,17 +12,22 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Wardrobe extends User {
|
public class Wardrobe extends User {
|
||||||
|
|
||||||
|
private final HMCCosmetics plugin;
|
||||||
private final UUID ownerUUID;
|
private final UUID ownerUUID;
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private boolean active;
|
private boolean active;
|
||||||
|
|
||||||
|
private boolean spawned;
|
||||||
|
|
||||||
private Location currentLocation;
|
private Location currentLocation;
|
||||||
|
|
||||||
public Wardrobe(
|
public Wardrobe(
|
||||||
|
final HMCCosmetics plugin,
|
||||||
final UUID uuid,
|
final UUID uuid,
|
||||||
final UUID ownerUUID,
|
final UUID ownerUUID,
|
||||||
final PlayerArmor playerArmor,
|
final PlayerArmor playerArmor,
|
||||||
@@ -29,16 +35,25 @@ public class Wardrobe extends User {
|
|||||||
final int entityId,
|
final int entityId,
|
||||||
final boolean active) {
|
final boolean active) {
|
||||||
super(uuid, playerArmor, armorStandId);
|
super(uuid, playerArmor, armorStandId);
|
||||||
|
this.plugin = plugin;
|
||||||
this.ownerUUID = ownerUUID;
|
this.ownerUUID = ownerUUID;
|
||||||
this.entityId = entityId;
|
this.entityId = entityId;
|
||||||
this.active = active;
|
this.active = active;
|
||||||
this.wardrobe = this;
|
this.wardrobe = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawnFakePlayer(final Player viewer, final HMCCosmetics plugin) {
|
public void spawnFakePlayer(final Player viewer) {
|
||||||
|
final WardrobeSettings settings = this.plugin.getSettings().getWardrobeSettings();
|
||||||
|
if (settings.inDistanceOfStatic(viewer.getLocation())) {
|
||||||
|
this.currentLocation = settings.getLocation();
|
||||||
|
} else if (this.currentLocation == null) {
|
||||||
this.currentLocation = viewer.getLocation().clone();
|
this.currentLocation = viewer.getLocation().clone();
|
||||||
this.currentLocation.setPitch(0);
|
this.currentLocation.setPitch(0);
|
||||||
this.currentLocation.setYaw(0);
|
this.currentLocation.setYaw(0);
|
||||||
|
} else if (this.spawned) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final PacketContainer playerSpawnPacket = PacketManager.getFakePlayerSpawnPacket(
|
final PacketContainer playerSpawnPacket = PacketManager.getFakePlayerSpawnPacket(
|
||||||
this.currentLocation,
|
this.currentLocation,
|
||||||
this.getUuid(),
|
this.getUuid(),
|
||||||
@@ -51,6 +66,7 @@ public class Wardrobe extends User {
|
|||||||
PacketManager.sendPacket(viewer, playerInfoPacket, playerSpawnPacket);
|
PacketManager.sendPacket(viewer, playerInfoPacket, playerSpawnPacket);
|
||||||
this.spawnArmorStand(viewer);
|
this.spawnArmorStand(viewer);
|
||||||
this.updateArmorStand(viewer, plugin.getSettings(), this.currentLocation);
|
this.updateArmorStand(viewer, plugin.getSettings(), this.currentLocation);
|
||||||
|
this.spawned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -59,9 +75,19 @@ public class Wardrobe extends User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void despawnFakePlayer(final Player viewer) {
|
public void despawnFakePlayer(final Player viewer) {
|
||||||
|
final WardrobeSettings settings = this.plugin.getSettings().getWardrobeSettings();
|
||||||
PacketManager.sendPacket(viewer, PacketManager.getEntityDestroyPacket(this.getEntityId()));
|
PacketManager.sendPacket(viewer, PacketManager.getEntityDestroyPacket(this.getEntityId()));
|
||||||
this.despawnAttached();
|
this.despawnAttached();
|
||||||
this.active = false;
|
this.active = false;
|
||||||
|
this.spawned = false;
|
||||||
|
this.currentLocation = null;
|
||||||
|
this.getPlayerArmor().clear();
|
||||||
|
|
||||||
|
if (settings.isAlwaysDisplay()) {
|
||||||
|
this.currentLocation = settings.getLocation();
|
||||||
|
if (this.currentLocation == null) return;
|
||||||
|
this.spawnFakePlayer(viewer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -82,10 +108,19 @@ public class Wardrobe extends User {
|
|||||||
this.active = active;
|
this.active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCurrentLocation(final Location currentLocation) {
|
||||||
|
this.currentLocation = currentLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Location getCurrentLocation() {
|
||||||
|
return currentLocation;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return null;
|
return Bukkit.getPlayer(this.ownerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,3 +4,22 @@ cosmetic-settings:
|
|||||||
# The pitch the player must look down for the backpack to be removed
|
# The pitch the player must look down for the backpack to be removed
|
||||||
# Set to -1 for no removal
|
# Set to -1 for no removal
|
||||||
look-down-backpack-remove: 70
|
look-down-backpack-remove: 70
|
||||||
|
wardrobe:
|
||||||
|
# if true, the wardrobe will be removed when the player is damaged
|
||||||
|
disable-on-damage: true
|
||||||
|
# removed if player leaves this radius, set to -1 for infinite radius
|
||||||
|
display-radius: -1
|
||||||
|
# if the player can use the wardrobe in other locations
|
||||||
|
portable: false
|
||||||
|
# if the wardrobe should always be displayed in the location below
|
||||||
|
always-display: false
|
||||||
|
# spawn static wardrobe if in this radius of wardrobe-location
|
||||||
|
static-radius: 10
|
||||||
|
# location of static wardrobe, remove for none
|
||||||
|
wardrobe-location:
|
||||||
|
world: "World"
|
||||||
|
x: 0
|
||||||
|
y: 0
|
||||||
|
z: 0
|
||||||
|
yaw: 0
|
||||||
|
pitch: 0
|
||||||
@@ -17,6 +17,8 @@ set-other-off-hand: "%prefix% <gradient:#6D9DC5:#45CDE9>You have set the off han
|
|||||||
opened-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9>Viewing wardrobe!"
|
opened-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9>Viewing wardrobe!"
|
||||||
closed-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9>Closed wardrobe!"
|
closed-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9>Closed wardrobe!"
|
||||||
wardrobe-already-open: "%prefix% <gradient:#6D9DC5:#45CDE9><red>The wardrobe is already open!"
|
wardrobe-already-open: "%prefix% <gradient:#6D9DC5:#45CDE9><red>The wardrobe is already open!"
|
||||||
|
not-near-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9><red>You are not near the wardrobe!"
|
||||||
|
cannot-use-portable-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9><red>You cannot use the portable wardrobe!"
|
||||||
help-command: "<#6D9DC5><st> </st> %prefix% <gradient:#40B7D6:#6D9DC5>HMCCosmetics - Help</gradient> %prefix% <#6D9DC5> <st> </st>
|
help-command: "<#6D9DC5><st> </st> %prefix% <gradient:#40B7D6:#6D9DC5>HMCCosmetics - Help</gradient> %prefix% <#6D9DC5> <st> </st>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user