Skip to content

Commit

Permalink
Merge pull request #111 from HibiscusMC/multi_wardrobe
Browse files Browse the repository at this point in the history
Wardrobe Improvements (2.4.0)
  • Loading branch information
LoJoSho authored May 25, 2023
2 parents f087933 + 0528ebf commit b00c79f
Show file tree
Hide file tree
Showing 21 changed files with 405 additions and 208 deletions.
6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.hibiscusmc"
version = "2.3.2-DEV"
version = "2.4.0"

allprojects {
apply(plugin = "java")
Expand Down Expand Up @@ -100,6 +100,7 @@ dependencies {
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
implementation("com.ticxo:PlayerAnimator:R1.2.6")
implementation("com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT")
//implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5")
}

Expand Down Expand Up @@ -141,6 +142,7 @@ tasks {
relocate("com.jeff_media.updatechecker", "com.hisbiscusmc.hmccosmetics.updatechecker")
relocate("com.owen1212055.particlehelper", "com.hisbiscusmc.hmccosmetics.particlehelper")
relocate("com.ticxo.playeranimator", "com.hisbiscusmc.hmccosmetics.playeranimator")
relocate("com.bgsoftware", "com.hisbiscusmc.hmccosmetics.configupdater")
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")

dependencies {
Expand Down Expand Up @@ -210,7 +212,7 @@ bukkit {
register("hmccosmetics.cmd.emote.other") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("hmccosmetics.cmd.setlocation") {
register("hmccosmetics.cmd.setwardrobesetting") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("hmccosmetics.cmd.dataclear") {
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
implementation("com.ticxo:PlayerAnimator:R1.2.6")
implementation("com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT")
//implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hibiscusmc.hmccosmetics;

import com.bgsoftware.common.config.CommentedConfiguration;
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticSetupEvent;
import com.hibiscusmc.hmccosmetics.command.CosmeticCommand;
import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete;
Expand All @@ -12,6 +13,7 @@
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.database.Database;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGHook;
Expand Down Expand Up @@ -86,20 +88,29 @@ public void onEnable() {
.checkNow();
onLatestVersion = checker.isUsingLatestVersion();
// File setup
if (!getDataFolder().exists()) {
saveDefaultConfig();
//saveResource("translations.yml", false);
saveResource("messages.yml", false);
saveResource("cosmetics/defaultcosmetics.yml", false);
saveResource("menus/defaultmenu.yml", false);
}
saveDefaultConfig();
//saveResource("translations.yml", false);
if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false);
if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false);
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) saveResource("menus/defaultmenu.yml", false);

// Emote folder setup
File emoteFile = new File(getDataFolder().getPath() + "/emotes");
if (!emoteFile.exists()) emoteFile.mkdir();

// Player Animator
PlayerAnimatorImpl.initialize(this);

// Configuration Sync
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
final File messageFile = Path.of(getInstance().getDataFolder().getPath(), "messages.yml").toFile();
try {
CommentedConfiguration.loadConfiguration(configFile).syncWithConfig(configFile, getInstance().getResource("config.yml"),
"database-settings", "debug-mode", "wardrobe.viewer-location", "wardrobe.npc-location", "wardrobe.wardrobe-location", "wardrobe.leave-location");
CommentedConfiguration.loadConfiguration(messageFile).syncWithConfig(messageFile, getInstance().getResource("messages.yml"));
} catch (Exception e) {}

// Setup
setup();

// Commands
Expand Down Expand Up @@ -170,7 +181,7 @@ public static void setup() {
WardrobeSettings.load(loader.load().node("wardrobe"));
DatabaseSettings.load(loader.load().node("database-settings"));
configLoader = loader;
} catch (ConfigurateException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}

Expand Down Expand Up @@ -236,12 +247,19 @@ public static void setup() {
getInstance().getServer().getPluginManager().addPermission(new Permission(cosmetic.getPermission()));
}
}
for (Menu menu : Menus.values()) {
if (menu.getPermissionNode() != null) {
if (getInstance().getServer().getPluginManager().getPermission(menu.getPermissionNode()) != null) continue;
getInstance().getServer().getPluginManager().addPermission(new Permission(menu.getPermissionNode()));
}
}

EmoteManager.loadEmotes();

getInstance().getLogger().info("Successfully Enabled HMCCosmetics");
getInstance().getLogger().info(Cosmetics.values().size() + " Cosmetics Successfully Setup");
getInstance().getLogger().info(Menus.getMenuNames().size() + " Menus Successfully Setup");
getInstance().getLogger().info(WardrobeSettings.getWardrobes().size() + " Wardrobes Successfully Setup");
getInstance().getLogger().info("Data storage is set to " + DatabaseSettings.getDatabaseType());

Bukkit.getPluginManager().callEvent(new HMCCosmeticSetupEvent());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hibiscusmc.hmccosmetics.api;

import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeLocation;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
Expand All @@ -12,11 +13,11 @@
public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private WardrobeLocation wardrobeLocation;
private Wardrobe wardrobe;

public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull WardrobeLocation wardrobeLocation) {
public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull Wardrobe wardrobe) {
super(who);
this.wardrobeLocation = wardrobeLocation;
this.wardrobe = wardrobe;
}

@Override
Expand Down Expand Up @@ -49,11 +50,11 @@ public static HandlerList getHandlerList() {
return handlers;
}

public void setWardrobeLocation(WardrobeLocation wardrobeLocation) {
this.wardrobeLocation = wardrobeLocation;
public void setWardrobe(Wardrobe wardrobe) {
this.wardrobe = wardrobe;
}

public WardrobeLocation getWardrobeLocation() {
return wardrobeLocation;
public Wardrobe getWardrobe() {
return wardrobe;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeLocation;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
Expand Down Expand Up @@ -194,8 +196,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
case ("wardrobe") -> {
if (sender instanceof Player) player = ((Player) sender).getPlayer();

if (args.length == 1) {
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
return true;
}

if (sender.hasPermission("hmccosmetics.cmd.wardrobe.other")) {
if (args.length >= 2) player = Bukkit.getPlayer(args[1]);
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
}

if (!sender.hasPermission("hmccosmetics.cmd.wardrobe")) {
Expand All @@ -208,9 +216,19 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return true;
}

if (!WardrobeSettings.getWardrobeNames().contains(args[1])) {
if (!silent) MessagesUtil.sendMessage(sender, "no-wardrobes");
return true;
}
Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]);

CosmeticUser user = CosmeticUsers.getUser(player);

user.toggleWardrobe();
if (user.isInWardrobe()) {
user.leaveWardrobe();
} else {
user.enterWardrobe(false, wardrobe);
}
return true;
}
// cosmetic menu exampleMenu playerName
Expand Down Expand Up @@ -289,36 +307,56 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
DyeMenu.openMenu(user, cosmetic);
}
}
case ("setlocation") -> {
if (!sender.hasPermission("hmccosmetics.cmd.setlocation")) {
case ("setwardrobesetting") -> {
if (!sender.hasPermission("hmccosmetics.cmd.setwardrobesetting")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
return true;
}

if (player == null) return true;

if (args.length < 2) {
if (args.length < 3) {
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
return true;
}
Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]);
if (wardrobe == null) {
wardrobe = new Wardrobe(args[1], new WardrobeLocation(null, null, null), null, -1);
WardrobeSettings.addWardrobe(wardrobe);
//MessagesUtil.sendMessage(player, "no-wardrobes");
//return true;
}

if (args[1].equalsIgnoreCase("wardrobelocation")) {
WardrobeSettings.setNPCLocation(player.getLocation());
if (args[2].equalsIgnoreCase("npclocation")) {
WardrobeSettings.setNPCLocation(wardrobe, player.getLocation());
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-location");
return true;
}

if (args[1].equalsIgnoreCase("viewerlocation")) {
WardrobeSettings.setViewerLocation(player.getLocation());
if (args[2].equalsIgnoreCase("viewerlocation")) {
WardrobeSettings.setViewerLocation(wardrobe, player.getLocation());
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-viewing");
return true;
}

if (args[1].equalsIgnoreCase("leavelocation")) {
WardrobeSettings.setLeaveLocation(player.getLocation());
if (args[2].equalsIgnoreCase("leavelocation")) {
WardrobeSettings.setLeaveLocation(wardrobe, player.getLocation());
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-leaving");
return true;
}

if (args.length >= 4) {
if (args[2].equalsIgnoreCase("permission")) {
WardrobeSettings.setWardrobePermission(wardrobe, args[3]);
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-permission");
return true;
}
if (args[2].equalsIgnoreCase("distance")) {
WardrobeSettings.setWardrobeDistance(wardrobe, Integer.valueOf(args[3]));
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-distance");
return true;
}
}
}
case ("dump") -> {
if (player == null) return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hibiscusmc.hmccosmetics.command;

import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
Expand Down Expand Up @@ -36,7 +38,7 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
if (hasPermission(sender, "hmccosmetics.cmd.wardrobe")) completions.add("wardrobe");
if (hasPermission(sender, "hmccosmetics.cmd.dataclear")) completions.add("dataclear");
if (hasPermission(sender, "hmccosmetics.cmd.dye")) completions.add("dye");
if (hasPermission(sender, "hmccosmetics.cmd.setlocation")) completions.add("setlocation");
if (hasPermission(sender, "hmccosmetics.cmd.setwardrobesetting")) completions.add("setwardrobesetting");
if (hasPermission(sender, "hmccosmetics.cmd.hide")) completions.add("hide");
if (hasPermission(sender, "hmccosmetics.cmd.show")) completions.add("show");
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
Expand Down Expand Up @@ -66,20 +68,29 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
if (menu.canOpen(user.getPlayer())) completions.add(menu.getId());
}
}
case "dataclear", "wardrobe", "hide", "show", "emote" -> {
case "dataclear", "hide", "show", "emote" -> {
for (Player player : Bukkit.getOnlinePlayers()) {
completions.add(player.getName());
}
}
case "wardrobe" -> {
for (Wardrobe wardrobe : WardrobeSettings.getWardrobes()) {
if (wardrobe.hasPermission()) {
if (user.getPlayer().hasPermission(wardrobe.getPermission())) completions.add(wardrobe.getId());
} else {
completions.add(wardrobe.getId());
}
}
}
case "dye" -> {
for (CosmeticSlot slot : user.getDyeableSlots()) {
completions.add(slot.name());
}
}
case "setlocation" -> {
completions.add("wardrobelocation");
completions.add("viewerlocation");
completions.add("leavelocation");
case "setwardrobesetting" -> {
for (Wardrobe wardrobe : WardrobeSettings.getWardrobes()) {
completions.add(wardrobe.getId());
}
}
case "playemote" -> completions.addAll(EmoteManager.getAllNames());
}
Expand All @@ -91,11 +102,18 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
case "dye" -> {
completions.add("#FFFFFF");
}
case "menu", "apply", "unapply", "playemote" -> {
case "menu", "wardrobe", "apply", "unapply", "playemote" -> {
for (Player player : Bukkit.getOnlinePlayers()) {
completions.add(player.getName());
}
}
case "setwardrobesetting" -> {
completions.add("npclocation");
completions.add("viewerlocation");
completions.add("leavelocation");
completions.add("permission");
completions.add("distance");
}
}
StringUtil.copyPartialMatches(args[2], completions, finalCompletions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Settings {
private static final String HOOK_WG_MOVE_CHECK_PATH = "player-move-check";
private static final String HOOK_WG_MOVE_CHECK_PATH_LEGACY = "player_move_check";
private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
private static final String COSMETIC_EMOTE_AIR_CHECK_PATH = "emote-air-check";
private static final String COSMETIC_EMOTE_DAMAGE_PATH = "emote-damage-leave";
private static final String COSMETIC_EMOTE_INVINCIBLE_PATH = "emote-invincible";
private static final String COSMETIC_ADD_ENCHANTS_HELMET_PATH = "helmet-add-enchantments";
Expand Down Expand Up @@ -70,6 +71,7 @@ public class Settings {
private static boolean addChestplateEnchants;
private static boolean addLeggingEnchants;
private static boolean addBootsEnchants;
private static boolean emoteAirCheck;
private static boolean emoteDamageLeave;
private static boolean emoteInvincible;
private static boolean destroyLooseCosmetics;
Expand Down Expand Up @@ -105,6 +107,7 @@ public static void load(ConfigurationNode source) {
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_CHECK_PATH).getBoolean(true);
emoteAirCheck = cosmeticSettings.node(COSMETIC_EMOTE_AIR_CHECK_PATH).getBoolean(true);
emoteDamageLeave = cosmeticSettings.node(COSMETIC_EMOTE_DAMAGE_PATH).getBoolean(false);
emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false);
destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false);
Expand Down Expand Up @@ -263,6 +266,10 @@ public static boolean getCosmeticEmoteBlockCheck() {
return cosmeticEmoteBlockCheck;
}

public static boolean getEmoteAirCheck() {
return emoteAirCheck;
}

public static boolean isEmoteDamageLeave() {
return emoteDamageLeave;
}
Expand Down
Loading

0 comments on commit b00c79f

Please sign in to comment.