diff --git a/README.md b/README.md new file mode 100644 index 0000000..555d67f --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Nicko +## The most complete disguising plugin in Minecraft. + +### Commands + +> /nicko + +#### Permissions \ No newline at end of file diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/NickoBukkit.java b/nicko-core/src/main/java/net/artelnatif/nicko/NickoBukkit.java index d365dc4..4e11825 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/NickoBukkit.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/NickoBukkit.java @@ -88,6 +88,7 @@ public class NickoBukkit extends JavaPlugin { public void onDisable() { if (!dataStore.getStorage().isError()) { getLogger().info("Closing persistence..."); + dataStore.removeAllNames(); if (!dataStore.getStorage().getProvider().close()) { getLogger().warning("Failed to close persistence!"); } diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/command/sub/NickoCheckSubCmd.java b/nicko-core/src/main/java/net/artelnatif/nicko/command/sub/NickoCheckSubCmd.java index da93eb6..0651cd1 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/command/sub/NickoCheckSubCmd.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/command/sub/NickoCheckSubCmd.java @@ -27,13 +27,13 @@ public class NickoCheckSubCmd extends NickoSubCmd { } final StringJoiner builder = new StringJoiner("\n"); - builder.add("§c" + NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§f- §6Check for:§f§o" + targetName); + builder.add("§c" + NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§6Check for: §f§o" + targetName); if (!appearanceManager.hasData()) { builder.add("§cThis player has not data."); } else { - builder.add("§7- §fNicked: " + (appearanceManager.isNicked() ? "§a✔" : "§c❌")); - builder.add("§7- §fNickname: §6" + (appearanceManager.getName().equals(targetName) ? "N/A" : appearanceManager.getName())); - builder.add("§7- §fSkin: §6" + (appearanceManager.getSkin().equals(targetName) ? "N/A" : appearanceManager.getSkin())); + builder.add("§7- §fNicked: " + (appearanceManager.hasData() ? "§a✔" : "§c❌")); + builder.add("§7- §fName: §6" + appearanceManager.getName()); + builder.add("§7- §fSkin: §6" + appearanceManager.getSkin()); } sender.sendMessage(builder.toString()); diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/disguise/AppearanceManager.java b/nicko-core/src/main/java/net/artelnatif/nicko/disguise/AppearanceManager.java index 801fec5..b1f4a86 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/disguise/AppearanceManager.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/disguise/AppearanceManager.java @@ -35,10 +35,6 @@ public class AppearanceManager { return !profile.isEmpty(); } - public boolean isNicked() { - return hasData() && !profile.getSkin().equals(player.getName()) || !profile.getName().equals(player.getName()); - } - public void setSkin(String skin) { profile.setSkin(skin); } @@ -65,6 +61,16 @@ public class AppearanceManager { updatePlayer(true); } + public UpdateResult reset() { + final String defaultName = instance.getDataStore().getStoredName(player); + this.profile.setName(defaultName); + this.profile.setSkin(defaultName); + final UpdateResult updateResult = updatePlayer(true); + this.profile.setSkin(null); + this.profile.setName(null); + return updateResult; + } + public UpdateResult updatePlayer(boolean skinChange) { return NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange); } diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/event/PlayerJoinListener.java b/nicko-core/src/main/java/net/artelnatif/nicko/event/PlayerJoinListener.java index 732d7e0..5f2d2bc 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/event/PlayerJoinListener.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/event/PlayerJoinListener.java @@ -15,6 +15,7 @@ public class PlayerJoinListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { final Player player = event.getPlayer(); + NickoBukkit.getInstance().getDataStore().storeName(player); Bukkit.getScheduler().runTaskLater(NickoBukkit.getInstance(), () -> { final AppearanceManager appearanceManager = AppearanceManager.get(player); diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/gui/AdminPanelGUI.java b/nicko-core/src/main/java/net/artelnatif/nicko/gui/AdminPanelGUI.java index eeb0e91..4adae9b 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/gui/AdminPanelGUI.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/gui/AdminPanelGUI.java @@ -5,23 +5,29 @@ import de.studiocode.invui.gui.builder.GUIBuilder; import de.studiocode.invui.gui.builder.guitype.GUIType; import de.studiocode.invui.gui.structure.Structure; import de.studiocode.invui.window.impl.single.SimpleWindow; +import net.artelnatif.nicko.gui.items.common.BackItem; import org.bukkit.entity.Player; public class AdminPanelGUI { private final Player player; private final GUI gui; - private String[] structureIngredients = new String[] - {"# # # # # # # # #", - "# % % M C R % % #", - "E # # # # # # # #"}; public AdminPanelGUI(Player player) { + final Structure structure = new Structure("# # # # # # # # #", + "# % % M C R % % #", + "B # # # # # # # #"); + structure.addIngredient('B', new BackItem(new MainGUI(player).getGUI())); this.gui = new GUIBuilder<>(GUIType.NORMAL) - .setStructure(new Structure(structureIngredients)) + .setStructure(structure) .build(); + this.player = player; } + public GUI getGUI() { + return gui; + } + public void open() { new SimpleWindow(player, "Nicko", gui).show(); } diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/gui/MainGUI.java b/nicko-core/src/main/java/net/artelnatif/nicko/gui/MainGUI.java index f11a211..5587903 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/gui/MainGUI.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/gui/MainGUI.java @@ -12,9 +12,9 @@ public class MainGUI { private final Player player; private final GUI gui; private final String[] structureIngredients = new String[] - {"# # # # # # # # #", + {"# # # # # # # # #", "# % % % % % % % #", - "# % # # B # # % #", + "# % # R B # # % #", "# % # N A S # % #", "# % % % % % % % #", "E # # # # # # # #"}; @@ -31,10 +31,16 @@ public class MainGUI { .addIngredient('S', new ChangeSkinItem()) .addIngredient('A', new AdminPanelAccessItem()) .addIngredient('B', new ChangeNameAndSkinItem()) + .addIngredient('R', new ResetItem()) + // TODO: 11/3/22 Add possibility to reset either skin or name or both .build(); this.player = player; } + public GUI getGUI() { + return gui; + } + public void open() { new SimpleWindow(player, "Nicko", gui).show(); } diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/gui/items/common/BackItem.java b/nicko-core/src/main/java/net/artelnatif/nicko/gui/items/common/BackItem.java new file mode 100644 index 0000000..1b6c589 --- /dev/null +++ b/nicko-core/src/main/java/net/artelnatif/nicko/gui/items/common/BackItem.java @@ -0,0 +1,34 @@ +package net.artelnatif.nicko.gui.items.common; + +import de.studiocode.invui.gui.GUI; +import de.studiocode.invui.item.ItemProvider; +import de.studiocode.invui.item.builder.ItemBuilder; +import de.studiocode.invui.item.impl.BaseItem; +import de.studiocode.invui.window.impl.single.SimpleWindow; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.jetbrains.annotations.NotNull; + +public class BackItem extends BaseItem { + private final GUI gui; + + public BackItem(GUI gui) { + this.gui = gui; + } + + @Override + public ItemProvider getItemProvider() { + final ItemBuilder builder = new ItemBuilder(Material.ARROW); + builder.setDisplayName("Go back"); + builder.addLoreLines("§7Return to the previous window."); + return builder; + } + + @Override + public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { + event.getView().close(); + new SimpleWindow(player, "Nicko", gui).show(); + } +} diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/gui/items/main/AdminPanelAccessItem.java b/nicko-core/src/main/java/net/artelnatif/nicko/gui/items/main/AdminPanelAccessItem.java index cbb3568..7464a19 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/gui/items/main/AdminPanelAccessItem.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/gui/items/main/AdminPanelAccessItem.java @@ -14,7 +14,7 @@ public class AdminPanelAccessItem extends BaseItem { @Override public ItemProvider getItemProvider() { final ItemBuilder builder = new ItemBuilder(Material.PISTON); - builder.setDisplayName("§cAdministration panel"); + builder.setDisplayName("§cAdministration panel..."); builder.addLoreLines("§7Access the administration panel."); return builder; } diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/gui/items/main/ResetItem.java b/nicko-core/src/main/java/net/artelnatif/nicko/gui/items/main/ResetItem.java new file mode 100644 index 0000000..1baf59d --- /dev/null +++ b/nicko-core/src/main/java/net/artelnatif/nicko/gui/items/main/ResetItem.java @@ -0,0 +1,42 @@ +package net.artelnatif.nicko.gui.items.main; + +import de.studiocode.invui.item.ItemProvider; +import de.studiocode.invui.item.builder.ItemBuilder; +import de.studiocode.invui.item.impl.BaseItem; +import net.artelnatif.nicko.disguise.AppearanceManager; +import net.artelnatif.nicko.i18n.I18N; +import net.artelnatif.nicko.i18n.I18NDict; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.jetbrains.annotations.NotNull; + +public class ResetItem extends BaseItem { + @Override + public ItemProvider getItemProvider() { + final ItemBuilder builder = new ItemBuilder(Material.TNT); + builder.setDisplayName("§6Reset"); + builder.addLoreLines("§7Removes your disguise."); + return builder; + } + + @Override + public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { + if (clickType.isLeftClick() || clickType.isRightClick()) { + final AppearanceManager appearanceManager = AppearanceManager.get(player); + + if (!appearanceManager.hasData()) { + player.sendMessage(I18N.translate(player, I18NDict.Event.UNDISGUISE_NOTACTIVE.getKey())); + event.getView().close(); + return; + } + + if (!appearanceManager.reset().isError()) { + player.sendMessage(I18N.translate(player, I18NDict.Event.UNDISGUISE_SUCCESS.getKey())); + } else { + player.sendMessage(I18N.translate(player, I18NDict.Event.UNDISGUISE_FAIL.getKey())); + } + } + } +} diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/i18n/I18NDict.java b/nicko-core/src/main/java/net/artelnatif/nicko/i18n/I18NDict.java index f5377d3..fb5280f 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/i18n/I18NDict.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/i18n/I18NDict.java @@ -2,6 +2,9 @@ package net.artelnatif.nicko.i18n; public class I18NDict { public enum Event { + UNDISGUISE_SUCCESS("undisguise.success"), + UNDISGUISE_FAIL("undisguise.fail"), + UNDISGUISE_NOTACTIVE("undisguise.notactive"), DISGUISE_SUCCESS("disguise.success"), DISGUISE_FAIL("disguise.fail"), PREVIOUS_SKIN_APPLIED("previous_skin_applied.success"), diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/storage/PlayerDataStore.java b/nicko-core/src/main/java/net/artelnatif/nicko/storage/PlayerDataStore.java index a47e028..7e60ea5 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/storage/PlayerDataStore.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/storage/PlayerDataStore.java @@ -14,27 +14,46 @@ import java.util.UUID; public class PlayerDataStore { private final Storage storage; + private final HashMap profiles = new HashMap<>(); + private final HashMap names = new HashMap<>(); public PlayerDataStore(NickoBukkit instance) { this.storage = instance.getNickoConfig().isLocalStorage() ? new JSONStorage() : new SQLStorage(instance); } - public static final HashMap PROFILES = new HashMap<>(); + public void storeName(Player player) { + if(!isNameStored(player)) { + names.put(player.getUniqueId(), player.getName()); + } + } + + public String getStoredName(Player player) { + return names.get(player.getUniqueId()); + } + + private boolean isNameStored(Player player) { + return names.containsKey(player.getUniqueId()); + } + + public void removeAllNames() { + names.clear(); + } + public Optional getData(UUID uuid) { if (storage.isError()) { return Optional.empty(); } - if (PROFILES.containsKey(uuid)) { - return Optional.of(PROFILES.get(uuid)); + if (profiles.containsKey(uuid)) { + return Optional.of(profiles.get(uuid)); } else if (storage.isStored(uuid)) { final Optional retrievedProfile = storage.retrieve(uuid); - retrievedProfile.ifPresent(profile -> PROFILES.put(uuid, profile)); + retrievedProfile.ifPresent(profile -> profiles.put(uuid, profile)); return retrievedProfile; } else { final NickoProfile newProfile = NickoProfile.EMPTY_PROFILE; - PROFILES.put(uuid, newProfile); + profiles.put(uuid, newProfile); return Optional.of(newProfile); } } @@ -61,8 +80,8 @@ public class PlayerDataStore { return; } - storage.store(player.getUniqueId(), PROFILES.get(player.getUniqueId())); - PROFILES.remove(player.getUniqueId()); + storage.store(player.getUniqueId(), profiles.get(player.getUniqueId())); + profiles.remove(player.getUniqueId()); } public Storage getStorage() { diff --git a/nicko-core/src/main/resources/locale_en.properties b/nicko-core/src/main/resources/locale_en.properties index 57eccec..9b1bbeb 100644 --- a/nicko-core/src/main/resources/locale_en.properties +++ b/nicko-core/src/main/resources/locale_en.properties @@ -5,5 +5,8 @@ error.generic=§cAn unknown error occured. Please contact the developer. error.couldnt_get_name_from_mojang=§cFailed to get username from Mojang. Does the user exists? error.couldnt_get_skin_from_mojang=§cFailed to get skin from Mojang. error.couldnt_get_skin_from_cache=§cFailed to get skin from cache. -event.disguise.success=§aDisguise applied. -event.disguise.fail=§cUnable to apply your disguise. §7§o({0}) \ No newline at end of file +event.disguise.success=§aDisguise applied ! +event.disguise.fail=§cUnable to apply your disguise. §7§o({0}) +event.undisguise.success=§aDisguise removed. +event.undisguise.fail=§cUnable to remove your disguise. It will be set back to default on the next login. Sorry! +event.undisguise.notactive=§cYou do not have an active disguise. \ No newline at end of file diff --git a/nicko-core/src/main/resources/locale_fr.properties b/nicko-core/src/main/resources/locale_fr.properties index 08a90fa..ec152ee 100644 --- a/nicko-core/src/main/resources/locale_fr.properties +++ b/nicko-core/src/main/resources/locale_fr.properties @@ -5,5 +5,8 @@ error.generic=§cUne erreur inconnue est survenue. Veuillez contacter le dévelo error.couldnt_get_name_from_mojang=§cImpossible de récupérer le nom d'utilisateur depuis Mojang. Cet utilisateur existe-il? error.couldnt_get_skin_from_mojang=§cImpossible de récupérer le skin depuis Mojang. error.couldnt_get_skin_from_cache=§cImpossible de récupérer le skin depuis le cache. -event.disguise.success=§aDéguisement appliqué avec succès. -event.disguise.fail=§cImpossible d'appliquer votre déguisement. §7§o({0}) \ No newline at end of file +event.disguise.success=§aDéguisement appliqué ! +event.disguise.fail=§cImpossible d'appliquer votre déguisement. §7§o({0}) +event.undisguise.success=§aDéguisement retiré. +event.undisguise.fail=§cImpossible de retier votre déguisement. Il sera remis par défaut à votre prochaine reconnexion. Désolé ! +event.undisguise.notactive=§cVous n'avez pas de déguisement. \ No newline at end of file