From c4db0437ac171fa1e9e9a73d9cda030e08774a11 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 15 Jun 2023 15:53:46 +0530 Subject: [PATCH] Fixed "random" for ShopKeeperSkins and some other changes --- pom.xml | 17 +++++- .../java/me/defender/cosmetics/Cosmetics.java | 24 +++----- .../islandtoppers/util/IslandToppersUtil.java | 42 ++++++++++++-- .../shopkeeperskins/ShopKeeperHandler.java | 9 ++- .../items/ShopKeeperItems.java | 11 +++- .../preview/ShopKeeperPreview.java | 21 +++++-- .../utils/ShopKeeperSkinsUtils.java | 51 +++++++++-------- .../cosmetics/api/util/MainMenuUtils.java | 55 ++++++++++--------- .../cosmetics/api/util/StartupUtils.java | 5 ++ .../cosmetics/command/MainCommand.java | 41 +++++++++++++- .../cosmetics/database/sqlite/SQLite.java | 2 +- .../defender/cosmetics/menu/CategoryMenu.java | 1 + 12 files changed, 196 insertions(+), 83 deletions(-) diff --git a/pom.xml b/pom.xml index bf19c95d..3de8e643 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.defender BW1058-Cosmetics - 1.4.2 + 1.4.4 jar Cosmetics @@ -45,6 +45,18 @@ me.defender.cosmetics.support.hcore + + + *:* + + com/cryptomorin/xseries/XBiome* + com/cryptomorin/xseries/NMSExtras* + com/cryptomorin/xseries/NoteBlockMusic* + com/cryptomorin/xseries/SkullCacheListener* + com/hakan/core/scoreboard + + + @@ -83,6 +95,7 @@ enginehub-maven https://maven.enginehub.org/repo/ + @@ -96,7 +109,7 @@ org.projectlombok lombok 1.18.26 - compile + provided com.sk89q.worldedit diff --git a/src/main/java/me/defender/cosmetics/Cosmetics.java b/src/main/java/me/defender/cosmetics/Cosmetics.java index e5978dcc..41e0b349 100644 --- a/src/main/java/me/defender/cosmetics/Cosmetics.java +++ b/src/main/java/me/defender/cosmetics/Cosmetics.java @@ -34,19 +34,9 @@ public class Cosmetics extends JavaPlugin public static HikariDataSource db; @Getter public static Connection dbConnection; - public boolean forcedDisable = false; + public boolean dependenciesMissing = false; static boolean placeholderAPI; - @Override - public void onEnable() { - loadOnEnable(); - } - - - public void onDisable() { - unloadOnDisable(); - } - public static void downloadFile(URL url, String filePath) { try { ReadableByteChannel rbc = Channels.newChannel(url.openStream()); @@ -59,11 +49,12 @@ public static void downloadFile(URL url, String filePath) { } } - private void loadOnEnable() { + @Override + public void onEnable() { if(!StartupUtils.checkDependencies()){ getLogger().severe("Cosmetics addon will now disable, make sure you have all dependencies installed!"); getServer().getPluginManager().disablePlugin(this); - forcedDisable = true; + dependenciesMissing = true; return; } @@ -121,11 +112,14 @@ private void loadOnEnable() { getLogger().info("Loading cosmetics..."); StartupUtils.loadCosmetics(); getLogger().info("Addon have been loaded and enabled!"); + // This is a check to make sure victory dance config doesn't have any issues. VictoryDance.getDefault(null); + } - private void unloadOnDisable() { - if(forcedDisable){ + @Override + public void onDisable() { + if(dependenciesMissing){ getLogger().severe("Detected forced disable! plugin will not unload anything!"); return; } diff --git a/src/main/java/me/defender/cosmetics/api/category/islandtoppers/util/IslandToppersUtil.java b/src/main/java/me/defender/cosmetics/api/category/islandtoppers/util/IslandToppersUtil.java index ed8f0760..acee5a04 100644 --- a/src/main/java/me/defender/cosmetics/api/category/islandtoppers/util/IslandToppersUtil.java +++ b/src/main/java/me/defender/cosmetics/api/category/islandtoppers/util/IslandToppersUtil.java @@ -2,14 +2,20 @@ package me.defender.cosmetics.api.category.islandtoppers.util; +import com.andrei1058.bedwars.api.arena.IArena; import com.sk89q.worldedit.*; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.schematic.SchematicFormat; +import me.defender.cosmetics.api.BwcAPI; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; +import org.bukkit.material.Bed; +import org.bukkit.material.Directional; import java.io.File; import java.io.IOException; @@ -26,14 +32,40 @@ public static void sendIslandTopper(World world, Location loc, Player p, File fi Bukkit.getLogger().severe("Schematic format is null! most probably file is invalid! (" + file.getName() + ")"); return; } - CuboidClipboard clipboard = schematicFormat.load(file); - // Move the schematic to the target location - clipboard.setOrigin(new Vector(loc.getX(), loc.getY() + clipboard.getHeight() + 1, loc.getZ())); - // Paste the schematic - clipboard.paste(editSession, new Vector(loc.getX(), loc.getY() + clipboard.getHeight() + 1, loc.getZ()), true); + IArena arena = new BwcAPI().getBwAPI().getArenaUtil().getArenaByPlayer(p); + if(arena != null) { + Block block = arena.getTeam(p).getBed().getBlock(); + if(block.getState() instanceof Bed && block.getState().getData() instanceof Directional){ + Directional directional = (Directional) block.getState().getData(); + CuboidClipboard clipboard = schematicFormat.load(file); + clipboard = flipDirection(clipboard, directional.getFacing()); + // Move the schematic to the target location + clipboard.setOrigin(new Vector(loc.getX(), loc.getY() + clipboard.getHeight() + 1, loc.getZ())); + // Paste the schematic + clipboard.paste(editSession, new Vector(loc.getX(), loc.getY() + clipboard.getHeight() + 1, loc.getZ()), true); + + } + } } catch (Exception e) { e.printStackTrace(); } } + + + private static CuboidClipboard flipDirection(CuboidClipboard clipboard, BlockFace direction) { + switch (direction) { + case NORTH: + clipboard.rotate2D(180); + return clipboard; + case EAST: + clipboard.rotate2D(270); + return clipboard; + case WEST: + clipboard.rotate2D(90); + return clipboard; + default: + return clipboard; + } + } } diff --git a/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/ShopKeeperHandler.java b/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/ShopKeeperHandler.java index 6a182688..68d0dcb4 100644 --- a/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/ShopKeeperHandler.java +++ b/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/ShopKeeperHandler.java @@ -14,14 +14,17 @@ import me.defender.cosmetics.api.util.DebugUtil; import me.defender.cosmetics.api.util.Utility; import net.citizensnpcs.api.CitizensAPI; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.Debug; import java.util.HashMap; import java.util.List; @@ -50,16 +53,16 @@ public void run() { Location shopLocation = team.getShop(); Location upgradeLocation = team.getTeamUpgrades(); World world = shopLocation.getWorld(); - + DebugUtil.addMessage("Executing ShopKeeper Skins for team " + team.getName()); // Delete existing NPCs world.getEntities().stream() - .filter(e -> (e.getLocation().distance(shopLocation) <= 0.2 || e.getLocation().distance(upgradeLocation) <= 0.2)) + .filter(e -> (e.getLocation().distance(shopLocation) <= 0.2 || e.getLocation().distance(upgradeLocation) <= 0.2 && e instanceof Villager)) .forEach(Entity::remove); // Choose random player from the team Player player = team.getMembers().get(new Random().nextInt(team.getSize())); String skin = new BwcAPI().getSelectedCosmetic(player, CosmeticsType.ShopKeeperSkin); - + DebugUtil.addMessage("Selected skin: " + skin); // Spawn new NPCs for (ShopKeeperSkin skins : StartupUtils.shopKeeperSkinList) { if (skin.equals(skins.getIdentifier())) { diff --git a/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/items/ShopKeeperItems.java b/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/items/ShopKeeperItems.java index 5a5d37d7..63ebfe37 100644 --- a/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/items/ShopKeeperItems.java +++ b/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/items/ShopKeeperItems.java @@ -9,6 +9,7 @@ import me.defender.cosmetics.api.util.StringUtils; import me.defender.cosmetics.api.configuration.ConfigManager; import me.defender.cosmetics.api.category.shopkeeperskins.utils.ShopKeeperSkinsUtils; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -74,8 +75,14 @@ public void execute(Player player, Location shopLocation, Location upgradeLocati shopKeeperSkins.add(shopKeeperSkin); } } - shopKeeperSkins.get(new Random().nextInt(shopKeeperSkins.size())).execute(player, shopLocation, upgradeLocation); - return; + if(shopKeeperSkins.isEmpty()){ + // ShopKeeperSkin#getDefault should not return null! + ShopKeeperSkinsUtils.spawnShopKeeperNPC(player, shopLocation, upgradeLocation, ShopKeeperSkin.getDefault(player).getIdentifier()); + }else{ + ShopKeeperSkin shopKeeperSkin1 = shopKeeperSkins.get(new Random().nextInt(shopKeeperSkins.size())); + ShopKeeperSkinsUtils.spawnShopKeeperNPC(player, shopLocation, upgradeLocation, shopKeeperSkin1.getIdentifier()); + } + return; } ShopKeeperSkinsUtils.spawnShopKeeperNPC(player, shopLocation, upgradeLocation); } diff --git a/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/preview/ShopKeeperPreview.java b/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/preview/ShopKeeperPreview.java index e4396a08..365dd0d9 100644 --- a/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/preview/ShopKeeperPreview.java +++ b/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/preview/ShopKeeperPreview.java @@ -2,6 +2,7 @@ import com.hakan.core.HCore; import com.hakan.core.ui.inventory.InventoryGui; +import com.hakan.core.utils.ColorUtil; import me.defender.cosmetics.api.category.shopkeeperskins.ShopKeeperSkin; import me.defender.cosmetics.api.category.shopkeeperskins.utils.ShopKeeperSkinsUtils; import me.defender.cosmetics.api.enums.FieldsType; @@ -26,13 +27,23 @@ public void sendPreviewShopKeeperSkin(Player player, String selected, InventoryG Location beforeLocation = player.getLocation(); float walkSpeed = player.getWalkSpeed(); player.closeInventory(); + Location cosmeticLocation = null, playerLocation = null; - Location cosmeticLocation = getCosmeticLocation(); - Location playerLocation = getPlayerLocation(); + try { + cosmeticLocation = getCosmeticLocation(); + playerLocation = getPlayerLocation(); + }catch (Exception exception){ + exception.printStackTrace(); + player.sendMessage(ColorUtil.colored("&cEither Preview location or Player location is not set! Contact the admin.")); + } + + if(cosmeticLocation == null || playerLocation == null) return; - HCore.asyncScheduler().run(() -> { - player.teleport(playerLocation); - ShopKeeperSkinsUtils.spawnShopKeeperNPCForPreview(player, cosmeticLocation); + Location finalPlayerLocation = playerLocation; + Location finalCosmeticLocation = cosmeticLocation; + HCore.syncScheduler().run(() -> { + player.teleport(finalPlayerLocation); + ShopKeeperSkinsUtils.spawnShopKeeperNPCForPreview(player, finalCosmeticLocation); player.setWalkSpeed(0); }); diff --git a/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/utils/ShopKeeperSkinsUtils.java b/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/utils/ShopKeeperSkinsUtils.java index 124cd0e6..1ad5312e 100644 --- a/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/utils/ShopKeeperSkinsUtils.java +++ b/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/utils/ShopKeeperSkinsUtils.java @@ -1,5 +1,8 @@ package me.defender.cosmetics.api.category.shopkeeperskins.utils; +import com.hakan.core.HCore; +import com.hakan.core.npc.Npc; +import com.hakan.core.skin.Skin; import me.defender.cosmetics.Cosmetics; import me.defender.cosmetics.api.BwcAPI; import me.defender.cosmetics.api.enums.CosmeticsType; @@ -19,10 +22,7 @@ import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.scheduler.BukkitRunnable; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.UUID; +import java.util.*; import static me.defender.cosmetics.api.util.Utility.plugin; @@ -76,25 +76,8 @@ private static void createShopKeeperNPC(Player p, Location loc, Location loc1, S value = values.get(0); sign = values.get(1); } - NPCRegistry registry = CitizensAPI.createAnonymousNPCRegistry(new MemoryNPCDataStore()); - // Shop NPC - NPC npc = registry.createNPC(EntityType.PLAYER, ""); - npc.setName("&r"); - npc.getTrait(SkinTrait.class).setSkinPersistent(UUID.randomUUID().toString(), sign, value); - npc.getTrait(SkinTrait.class).setTexture(value, sign); - npc.getTrait(LookClose.class).lookClose(true); - npc.getOrAddTrait(HologramTrait.class).clear(); - npc.spawn(loc); - npc.getEntity().setMetadata("NPC2", new FixedMetadataValue(plugin(), "")); - // Upgrade NPC - NPC npc1 = registry.createNPC(EntityType.PLAYER, ""); - npc1.setName("&r"); - npc1.getTrait(SkinTrait.class).setSkinPersistent(UUID.randomUUID().toString(), sign, value); - npc1.getTrait(SkinTrait.class).setTexture(value, sign); - npc1.getTrait(LookClose.class).lookClose(true); - npc.data().setPersistent(NPC.Metadata.NAMEPLATE_VISIBLE, false); - npc1.spawn(loc1); - npc1.getEntity().setMetadata("NPC2", new FixedMetadataValue(plugin(), "")); + Npc npc = HCore.npcBuilder(new Random().nextInt() + "ID").skin(new Skin(value, sign)).showEveryone(true).target(Npc.LookTarget.NEAREST).lines(Collections.emptyList()).location(loc).build(); + Npc npc1 = HCore.npcBuilder(new Random().nextInt() + "ID").skin(new Skin(value, sign)).showEveryone(true).target(Npc.LookTarget.NEAREST).lines(Collections.emptyList()).location(loc1).build(); } /** @@ -114,7 +97,7 @@ private static void createShopKeeperNPC(Player p, Location loc, String value, St npc.setName("&r"); npc.getTrait(SkinTrait.class).setSkinPersistent(UUID.randomUUID().toString(), sign, value); npc.getTrait(SkinTrait.class).setTexture(value, sign); -// npc.getTrait(LookClose.class).lookClose(true); + npc.getTrait(LookClose.class).lookClose(true); npc.getOrAddTrait(HologramTrait.class).clear(); npc.spawn(loc); npc.getEntity().setMetadata("NPC2", new FixedMetadataValue(plugin(), "")); @@ -164,6 +147,26 @@ public static void spawnShopKeeperNPC(Player p, Location loc, Location loc1) { } } + public static void spawnShopKeeperNPC(Player p, Location loc, Location loc1, String skin) { + ConfigManager config = ConfigUtils.getShopKeeperSkins(); + String key = CosmeticsType.ShopKeeperSkin.getSectionKey(); + String skinvalue = config.getString(key + "." + skin + ".skin-value"); + String skinsign = config.getString(key + "." + skin + ".skin-sign"); + String etype = config.getString(key + "." + skin + ".entity-type"); + boolean mirror = config.getBoolean(key + "." + skin + ".mirror"); + + if(mirror){ + createShopKeeperNPC(p, loc, loc1, skinvalue, skinsign, true); + return; + } + if(etype != null) { + createEntityNPC(EntityType.valueOf(etype), loc1); + createEntityNPC(EntityType.valueOf(etype), loc); + }else if(skinvalue != null && skinsign != null) { + createShopKeeperNPC(p, loc, loc1, skinvalue, skinsign, false); + } + } + public static void spawnShopKeeperNPCForPreview(Player p, Location loc) { Cosmetics plugin = plugin(); String skin = new BwcAPI().getSelectedCosmetic(p, CosmeticsType.ShopKeeperSkin); diff --git a/src/main/java/me/defender/cosmetics/api/util/MainMenuUtils.java b/src/main/java/me/defender/cosmetics/api/util/MainMenuUtils.java index 406215e5..4ab4e4e6 100644 --- a/src/main/java/me/defender/cosmetics/api/util/MainMenuUtils.java +++ b/src/main/java/me/defender/cosmetics/api/util/MainMenuUtils.java @@ -73,31 +73,36 @@ public static List formatLore(List lores, Player p){ BwcAPI api = new BwcAPI(); PlayerOwnedData ownedData = Utility.playerOwnedDataList.get(p.getUniqueId()); - lores = lores.stream() - .map(s -> s.replace("{islandtopper}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.IslandTopper)))) - .map(s -> s.replace("{spray}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.Sprays)))) - .map(s -> s.replace("{killmsg}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.KillMessage)))) - .map(s -> s.replace("{shopkeeper}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.ShopKeeperSkin)))) - .map(s -> s.replace("{woodskin}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.WoodSkins)))) - .map(s -> s.replace("{victory}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.VictoryDances)))) - .map(s -> s.replace("{deathcries}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.DeathCries)))) - .map(s -> s.replace("{glyphs}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.Glyphs)))) - .map(s -> s.replace("{bedbreak}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.BedBreakEffects)))) - .map(s -> s.replace("{projectile}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.ProjectileTrails)))) - .map(s -> s.replace("{finalkill}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.FinalKillEffects)))) - .map(s -> s.replace("{islandtopper}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.IslandTopper)))) - .map(s -> s.replace("{ownedSpray}", "&a" + ownedData.getSpray() + "/" + StartupUtils.sprayList.size() + " &8(" + ((ownedData.getSpray() / StartupUtils.sprayList.size()) * 100) + "%)" )) - .map(s -> s.replace("{ownedpt}", "&a" + ownedData.getProjectileTrail() + "/" + StartupUtils.projectileTrailList.size() + " &8(" + ((ownedData.getProjectileTrail() / StartupUtils.projectileTrailList.size()) * 100) + "%)" )) - .map(s -> s.replace("{ownedfinalkill}", "&a" + ownedData.getFinalKillEffect() + "/" + StartupUtils.finalKillList.size() + " &8(" + ((ownedData.getFinalKillEffect() / StartupUtils.finalKillList.size()) * 100) + "%)" )) - .map(s -> s.replace("{ownedkm}", "&a" + ownedData.getKillMessage() + "/" + StartupUtils.killMessageList.size() + " &8(" + ((ownedData.getKillMessage() / StartupUtils.killMessageList.size()) * 100) + "%)" )) - .map(s -> s.replace("{ownedgly}", "&a" + ownedData.getGlyph() + "/" + StartupUtils.glyphsList.size() + " &8(" + ((ownedData.getGlyph() / StartupUtils.glyphsList.size()) * 100) + "%)" )) - .map(s -> s.replace("{ownedbbe}", "&a" + ownedData.getBedDestroy() + "/" + StartupUtils.bedDestroyList.size() + " &8(" + ((ownedData.getBedDestroy() / StartupUtils.bedDestroyList.size()) * 100) + "%)" )) - .map(s -> s.replace("{ownedws}", "&a" + ownedData.getWoodSkin() + "/" + StartupUtils.woodSkinsList.size() + " &8(" + ((ownedData.getWoodSkin() / StartupUtils.woodSkinsList.size()) * 100) + "%)" )) - .map(s -> s.replace("{ownedvd}", "&a" + ownedData.getVictoryDance() + "/" + StartupUtils.victoryDancesList.size() + " &8(" + ((ownedData.getVictoryDance() / StartupUtils.victoryDancesList.size()) * 100) + "%)" )) - .map(s -> s.replace("{ownedit}", "&a" + ownedData.getIslandTopper() + "/" + StartupUtils.islandTopperList.size() + " &8(" + ((ownedData.getIslandTopper() / StartupUtils.islandTopperList.size()) * 100) + "%)" )) - .map(s -> s.replace("{ownedshopkeeper}", "&a" + ownedData.getShopkeeperSkin() + "/" + StartupUtils.shopKeeperSkinList.size() + " &8(" + ((ownedData.getShopkeeperSkin() / StartupUtils.shopKeeperSkinList.size()) * 100) + "%)" )) - .map(s -> s.replace("{owneddc}", "&a" + ownedData.getDeathCry() + "/" + StartupUtils.deathCryList.size() + " &8(" + ((ownedData.getDeathCry() / StartupUtils.deathCryList.size()) * 100) + "%)" )) - .collect(Collectors.toList()); + try { + lores = lores.stream() + .map(s -> s.replace("{islandtopper}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.IslandTopper)))) + .map(s -> s.replace("{spray}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.Sprays)))) + .map(s -> s.replace("{killmsg}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.KillMessage)))) + .map(s -> s.replace("{shopkeeper}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.ShopKeeperSkin)))) + .map(s -> s.replace("{woodskin}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.WoodSkins)))) + .map(s -> s.replace("{victory}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.VictoryDances)))) + .map(s -> s.replace("{deathcries}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.DeathCries)))) + .map(s -> s.replace("{glyphs}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.Glyphs)))) + .map(s -> s.replace("{bedbreak}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.BedBreakEffects)))) + .map(s -> s.replace("{projectile}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.ProjectileTrails)))) + .map(s -> s.replace("{finalkill}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.FinalKillEffects)))) + .map(s -> s.replace("{islandtopper}", "&a" + StringUtils.replaceHyphensAndCaptalizeFirstLetter(api.getSelectedCosmetic(p, CosmeticsType.IslandTopper)))) + .map(s -> s.replace("{ownedSpray}", "&a" + ownedData.getSpray() + "/" + StartupUtils.sprayList.size() + " &8(" + ((ownedData.getSpray() / StartupUtils.sprayList.size()) * 100) + "%)")) + .map(s -> s.replace("{ownedpt}", "&a" + ownedData.getProjectileTrail() + "/" + StartupUtils.projectileTrailList.size() + " &8(" + ((ownedData.getProjectileTrail() / StartupUtils.projectileTrailList.size()) * 100) + "%)")) + .map(s -> s.replace("{ownedfinalkill}", "&a" + ownedData.getFinalKillEffect() + "/" + StartupUtils.finalKillList.size() + " &8(" + ((ownedData.getFinalKillEffect() / StartupUtils.finalKillList.size()) * 100) + "%)")) + .map(s -> s.replace("{ownedkm}", "&a" + ownedData.getKillMessage() + "/" + StartupUtils.killMessageList.size() + " &8(" + ((ownedData.getKillMessage() / StartupUtils.killMessageList.size()) * 100) + "%)")) + .map(s -> s.replace("{ownedgly}", "&a" + ownedData.getGlyph() + "/" + StartupUtils.glyphsList.size() + " &8(" + ((ownedData.getGlyph() / StartupUtils.glyphsList.size()) * 100) + "%)")) + .map(s -> s.replace("{ownedbbe}", "&a" + ownedData.getBedDestroy() + "/" + StartupUtils.bedDestroyList.size() + " &8(" + ((ownedData.getBedDestroy() / StartupUtils.bedDestroyList.size()) * 100) + "%)")) + .map(s -> s.replace("{ownedws}", "&a" + ownedData.getWoodSkin() + "/" + StartupUtils.woodSkinsList.size() + " &8(" + ((ownedData.getWoodSkin() / StartupUtils.woodSkinsList.size()) * 100) + "%)")) + .map(s -> s.replace("{ownedvd}", "&a" + ownedData.getVictoryDance() + "/" + StartupUtils.victoryDancesList.size() + " &8(" + ((ownedData.getVictoryDance() / StartupUtils.victoryDancesList.size()) * 100) + "%)")) + .map(s -> s.replace("{ownedit}", "&a" + ownedData.getIslandTopper() + "/" + StartupUtils.islandTopperList.size() + " &8(" + ((ownedData.getIslandTopper() / StartupUtils.islandTopperList.size()) * 100) + "%)")) + .map(s -> s.replace("{ownedshopkeeper}", "&a" + ownedData.getShopkeeperSkin() + "/" + StartupUtils.shopKeeperSkinList.size() + " &8(" + ((ownedData.getShopkeeperSkin() / StartupUtils.shopKeeperSkinList.size()) * 100) + "%)")) + .map(s -> s.replace("{owneddc}", "&a" + ownedData.getDeathCry() + "/" + StartupUtils.deathCryList.size() + " &8(" + ((ownedData.getDeathCry() / StartupUtils.deathCryList.size()) * 100) + "%)")) + .collect(Collectors.toList()); + }catch (Exception ignored){ + // Cuz I guess only IslandTopper have this issue + Bukkit.getLogger().severe("Please install world edit, without world edit plugin will not work!"); + } return lores; } diff --git a/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java b/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java index c0fff05b..31cf29ab 100644 --- a/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java +++ b/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java @@ -184,6 +184,11 @@ public static boolean checkDependencies(){ log.severe("Cosmetics addon requires Vault to work properly!"); return false; } + if(!isPluginEnabled("WorldEdit") && !isPluginEnabled("FastAsyncWorldEdit")){ + log.severe("Cosmetics addon requires WorldEdit to work!"); + return false; + } + if(isPluginEnabled("PlaceholderAPI")){ log.info("Found PlaceholderAPI, loading placeholders!"); new Placeholders(Utility.plugin()).register(); diff --git a/src/main/java/me/defender/cosmetics/command/MainCommand.java b/src/main/java/me/defender/cosmetics/command/MainCommand.java index 123e9d04..9d1876a1 100644 --- a/src/main/java/me/defender/cosmetics/command/MainCommand.java +++ b/src/main/java/me/defender/cosmetics/command/MainCommand.java @@ -12,6 +12,7 @@ import com.hakan.core.utils.ColorUtil; import me.clip.placeholderapi.PlaceholderAPI; import me.defender.cosmetics.Cosmetics; +import me.defender.cosmetics.api.configuration.ConfigManager; import me.defender.cosmetics.api.enums.ConfigType; import me.defender.cosmetics.api.enums.CosmeticsType; import me.defender.cosmetics.api.util.StartupUtils; @@ -23,9 +24,11 @@ import me.defender.cosmetics.menu.CategoryMenu; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.metadata.FixedMetadataValue; @@ -67,6 +70,9 @@ public void helpCommand(CommandSender sender, String[] args) { p.spigot().sendMessage(Utility.hoverablemsg("&6-> &7/bwc vd &8- &eclick for details", "Opens the Victory Dance GUI")); p.spigot().sendMessage(Utility.hoverablemsg("&6-> &7/bwc ws &8- &eclick for details", "Opens the Wood Skins GUI")); p.spigot().sendMessage(Utility.hoverablemsg("&6-> &7/bwc it &8- &eclick for details", "Opens the Island Toppers GUI")); + p.spigot().sendMessage(Utility.hoverablemsg("&6-> &7/bwc setupIslandTopper &8- &eclick for details", "Set the island topper location for an team in an arena")); + p.spigot().sendMessage(Utility.hoverablemsg("&6-> &7/bwc setupPlayerLocation &8- &eclick for details", "Set the player location for preview")); + p.spigot().sendMessage(Utility.hoverablemsg("&6-> &7/bwc setupPreviewLocation &8- &eclick for details", "Set the preview location")); } else { sender.sendMessage(ChatColor.RED + "You need to be in-game!"); } @@ -423,7 +429,40 @@ public void setPreviewLocation(CommandSender sender, String[] args){ sender.sendMessage(ChatColor.RED + "Sorry but you need to be in-game to do that!"); return; } + Player player = (Player) sender; + Location location = player.getLocation(); + ConfigManager config = ConfigUtils.getMainConfig(); + config.set("cosmetic-preview.cosmetic-location.world", location.getWorld().getName()); + config.set("cosmetic-preview.cosmetic-location.x", location.getX()); + config.set("cosmetic-preview.cosmetic-location.y", location.getY()); + config.set("cosmetic-preview.cosmetic-location.z", location.getZ()); + config.set("cosmetic-preview.cosmetic-location.yaw", location.getYaw()); + config.set("cosmetic-preview.cosmetic-location.pitch", location.getPitch()); + config.save(); + config.reload(); + player.sendMessage(ChatColor.GREEN + "Done! saved your current location as preview location."); + } - //TODO check how /setIslandTopper works and use it that way + @SubCommand( + args = "setupPlayerLocation", + permission = "bwcosmetics.admin" + ) + public void setPlayerLocation(CommandSender sender, String[] args){ + if (!(sender instanceof Player)){ + sender.sendMessage(ChatColor.RED + "Sorry but you need to be in-game to do that!"); + return; + } + Player player = (Player) sender; + Location location = player.getLocation(); + ConfigManager config = ConfigUtils.getMainConfig(); + config.set("cosmetic-preview.player-location.world", location.getWorld().getName()); + config.set("cosmetic-preview.player-location.x", location.getX()); + config.set("cosmetic-preview.player-location.y", location.getY()); + config.set("cosmetic-preview.player-location.z", location.getZ()); + config.set("cosmetic-preview.player-location.yaw", location.getYaw()); + config.set("cosmetic-preview.player-location.pitch", location.getPitch()); + config.save(); + config.reload(); + player.sendMessage(ChatColor.GREEN + "Done! saved your current location as player location for preview."); } } \ No newline at end of file diff --git a/src/main/java/me/defender/cosmetics/database/sqlite/SQLite.java b/src/main/java/me/defender/cosmetics/database/sqlite/SQLite.java index 044a31d3..02b8a2dd 100644 --- a/src/main/java/me/defender/cosmetics/database/sqlite/SQLite.java +++ b/src/main/java/me/defender/cosmetics/database/sqlite/SQLite.java @@ -34,7 +34,7 @@ public void connect(){ config.setUsername(""); config.setPassword(""); config.setConnectionTestQuery("SELECT 1"); - config.setConnectionTimeout(5000); + config.setConnectionTimeout(500000); config.setMaximumPoolSize(100); config.setPoolName("COSMETICS-SQLITE"); dataSource = new HikariDataSource(config); diff --git a/src/main/java/me/defender/cosmetics/menu/CategoryMenu.java b/src/main/java/me/defender/cosmetics/menu/CategoryMenu.java index 8332319d..f429bc90 100644 --- a/src/main/java/me/defender/cosmetics/menu/CategoryMenu.java +++ b/src/main/java/me/defender/cosmetics/menu/CategoryMenu.java @@ -294,6 +294,7 @@ public void previewClick(Player player, CosmeticsType type, String id, int price break; case ShopKeeperSkin: new ShopKeeperPreview().sendPreviewShopKeeperSkin(player, id, this); + break; default: onClick(player,type, price, id, false); break;