Explorar o código

Implementation of a basic Profile and a profile view, renaming of command /world to /warp.

Jan hai 3 semanas
pai
achega
fe2f24820f

+ 1 - 1
pom.xml

@@ -110,7 +110,7 @@
         <dependency>
             <groupId>me.lethunderhawk</groupId>
             <artifactId>FluxAPI</artifactId>
-            <version>1.2.0</version>
+            <version>1.2.2</version>
             <scope>provided</scope>
         </dependency>
     </dependencies>

+ 12 - 3
src/main/java/me/lethunderhawk/main/BazaarFlux.java

@@ -2,12 +2,12 @@ package me.lethunderhawk.main;
 
 import me.lethunderhawk.clans.ClanModule;
 import me.lethunderhawk.custom.item.CustomItemModule;
-import me.lethunderhawk.dungeon.DungeonModule;
 import me.lethunderhawk.economy.EconomyModule;
 import me.lethunderhawk.fluxapi.FluxService;
 import me.lethunderhawk.fluxapi.util.gui.InventoryManager;
 import me.lethunderhawk.fluxapi.util.interfaces.BazaarFluxModule;
-import me.lethunderhawk.minion.MinionModule;
+import me.lethunderhawk.npc.NPCRegistrator;
+import me.lethunderhawk.profile.ProfileModule;
 import me.lethunderhawk.tradeplugin.TradeModule;
 import me.lethunderhawk.world.WorldModule;
 import org.bukkit.plugin.java.JavaPlugin;
@@ -23,7 +23,16 @@ public class BazaarFlux extends JavaPlugin{
         FluxService.register(BazaarFlux.class, this);
 
         InventoryManager.register(this);
-        registerAllModules(new CustomItemModule(this), new TradeModule(this), new ClanModule(this), new EconomyModule(this), new MinionModule(this), new DungeonModule(this), new WorldModule(this));
+        registerAllModules(
+                new CustomItemModule(this),
+                new TradeModule(this),
+                new ClanModule(this),
+                new EconomyModule(this),
+                //new MinionModule(this),
+                //new DungeonModule(this),
+                new WorldModule(this),
+                new ProfileModule(this),
+                new NPCRegistrator(this));
     }
     private void registerAllModules(BazaarFluxModule... modules){
         for(BazaarFluxModule module : modules){

+ 36 - 0
src/main/java/me/lethunderhawk/npc/NPCRegistrator.java

@@ -0,0 +1,36 @@
+package me.lethunderhawk.npc;
+
+import me.lethunderhawk.fluxapi.npc.registry.NPCRegistry;
+import me.lethunderhawk.fluxapi.util.interfaces.BazaarFluxModule;
+import me.lethunderhawk.npc.types.IslandNPC;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class NPCRegistrator extends BazaarFluxModule {
+    public NPCRegistrator(JavaPlugin plugin) {
+        super(plugin);
+    }
+
+    @Override
+    public String getPrefix() {
+        return "[NPCRegistrator] [You should never see this!]";
+    }
+
+    @Override
+    public void onEnable() {
+        registerNPCSubTypes();
+        finalizeNPCLoading();
+    }
+
+    private void finalizeNPCLoading() {
+        NPCRegistry.finalizeRegistration();
+    }
+
+    private void registerNPCSubTypes() {
+        NPCRegistry.registerNPC(IslandNPC.class);
+    }
+
+    @Override
+    public void onDisable() {
+
+    }
+}

+ 46 - 0
src/main/java/me/lethunderhawk/npc/types/IslandNPC.java

@@ -0,0 +1,46 @@
+package me.lethunderhawk.npc.types;
+
+import me.lethunderhawk.fluxapi.npc.abstraction.NPC;
+import me.lethunderhawk.fluxapi.npc.abstraction.NPCOptions;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Map;
+import java.util.UUID;
+
+public class IslandNPC extends NPC {
+    private UUID ownerUUID;
+    public IslandNPC(UUID ownerUUID, NPCOptions npcOptions) {
+        super(npcOptions);
+        this.ownerUUID = ownerUUID;
+    }
+
+    @Override
+    public void onLeftClick(Player player) {
+        if(player.getUniqueId().equals(ownerUUID)) {
+            player.sendMessage(Component.text("Hey you are the owner of this island! How exciting!", NamedTextColor.GREEN));
+        }else{
+            player.sendMessage(Component.text("You are not the owner of this island! Try this on your own island!", NamedTextColor.RED));
+        }
+    }
+
+    @Override
+    public void onRightClick(Player player) {
+        onLeftClick(player);
+    }
+
+    @Override
+    public @NotNull Map<String, Object> serialize() {
+        return Map.of(
+                "options", getOptions(),
+                "ownerUUID", ownerUUID.toString()
+        );
+    }
+
+    public static IslandNPC deserialize(Map<String, Object> map) {
+        return new IslandNPC(UUID.fromString((String) map.get("ownerUUID")), (NPCOptions) map.get("options"));
+    }
+
+}

+ 34 - 0
src/main/java/me/lethunderhawk/profile/ProfileModule.java

@@ -0,0 +1,34 @@
+package me.lethunderhawk.profile;
+
+import me.lethunderhawk.fluxapi.profile.representation.FluxProfile;
+import me.lethunderhawk.fluxapi.util.interfaces.BazaarFluxModule;
+import me.lethunderhawk.profile.command.ProfileCommand;
+import me.lethunderhawk.profile.test.BazaarFluxStats;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class ProfileModule extends BazaarFluxModule {
+    public ProfileModule(JavaPlugin plugin) {
+        super(plugin);
+    }
+
+    @Override
+    public String getPrefix() {
+        return "[Profile]";
+    }
+
+    @Override
+    public void onEnable() {
+        FluxProfile.registerSubProfile(
+                "stats",
+                BazaarFluxStats.class,
+                uuid -> new BazaarFluxStats()
+        );
+
+        plugin.getCommand("profile").setExecutor(new ProfileCommand(this));
+    }
+
+    @Override
+    public void onDisable() {
+
+    }
+}

+ 38 - 0
src/main/java/me/lethunderhawk/profile/command/ProfileCommand.java

@@ -0,0 +1,38 @@
+package me.lethunderhawk.profile.command;
+
+import me.lethunderhawk.fluxapi.FluxService;
+import me.lethunderhawk.fluxapi.profile.ProfileManager;
+import me.lethunderhawk.fluxapi.profile.representation.FluxProfile;
+import me.lethunderhawk.fluxapi.util.command.CommandNode;
+import me.lethunderhawk.fluxapi.util.command.CustomCommand;
+import me.lethunderhawk.fluxapi.util.gui.InventoryManager;
+import me.lethunderhawk.fluxapi.util.interfaces.BazaarFluxModule;
+import me.lethunderhawk.profile.gui.StatsGUI;
+import me.lethunderhawk.profile.test.BazaarFluxStats;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class ProfileCommand extends CustomCommand {
+    public ProfileCommand(BazaarFluxModule module) {
+        super(new CommandNode("profile", "base command", null), module);
+    }
+
+    @Override
+    public void createCommands() {
+        registerCommand("show", "shows your profile", this::showProfile);
+    }
+
+    private void addTest(CommandSender sender, String[] strings) {
+        if(!(sender instanceof Player p)) return;
+        FluxProfile profile = FluxService.get(ProfileManager.class).getProfile(p.getUniqueId());
+
+        BazaarFluxStats stats = profile.getSubProfile( "stats", BazaarFluxStats.class);
+        stats.addKill();
+    }
+
+    private void showProfile(CommandSender sender, String[] strings) {
+        if(!(sender instanceof Player p)) return;
+        StatsGUI stats = new StatsGUI(p);
+        InventoryManager.openFor(p, stats);
+    }
+}

+ 54 - 0
src/main/java/me/lethunderhawk/profile/gui/StatsGUI.java

@@ -0,0 +1,54 @@
+package me.lethunderhawk.profile.gui;
+
+import me.lethunderhawk.fluxapi.util.CustomHeadCreator;
+import me.lethunderhawk.fluxapi.util.gui.InventoryGUI;
+import me.lethunderhawk.fluxapi.util.itemdesign.ItemOptions;
+import me.lethunderhawk.fluxapi.util.itemdesign.LoreDesigner;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.ClickType;
+import org.bukkit.inventory.ItemStack;
+
+public class StatsGUI extends InventoryGUI {
+    public Player player;
+    public StatsGUI(Player player) {
+        super("Stats", 45);
+        this.player = player;
+        buildGUI();
+    }
+
+    private void buildGUI() {
+        fillGlassPaneBackground();
+        ItemStack item = createPlayerHead();
+
+        setItemWithClickAction(4, item, this::displayEasterEgg);
+    }
+
+    private void displayEasterEgg(Player player, ClickType type) {
+        setItem(34, createEasterEgg());
+    }
+
+    private ItemStack createEasterEgg() {
+        return new ItemOptions(Material.GOLD_INGOT)
+                .setName(Component.text("Wow you found this!", NamedTextColor.YELLOW))
+                .setLore(
+                        LoreDesigner.createLore("Actually i didn't even think you would see this! Congrats, this is an easter egg, if you found it, tell me and i will reward you!",
+                                "Actually i didn't even think", NamedTextColor.GRAY)
+                )
+                .buildItemStack();
+    }
+
+    private ItemStack createPlayerHead() {
+        return CustomHeadCreator.createCustomHead(player, Component.text("This is you!", NamedTextColor.YELLOW),
+                LoreDesigner.createLore(
+                        "This shows your data, there is a lot to be added soon!", "This shows your data,", NamedTextColor.GRAY
+                ));
+    }
+
+    @Override
+    public void update() {
+
+    }
+}

+ 46 - 0
src/main/java/me/lethunderhawk/profile/test/BazaarFluxStats.java

@@ -0,0 +1,46 @@
+package me.lethunderhawk.profile.test;
+
+import org.bukkit.configuration.serialization.ConfigurationSerializable;
+import org.jspecify.annotations.NonNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class BazaarFluxStats implements ConfigurationSerializable {
+
+    private int kills;
+    private int deaths;
+    private transient Runnable changeListener;
+
+    public BazaarFluxStats() {
+    }
+
+    public BazaarFluxStats(Map<String, Object> map) {
+        this.kills = (int) map.get("kills");
+        this.deaths = (int) map.get("deaths");
+    }
+
+    public void addKill() {
+        this.kills++;
+        notifyChange();
+    }
+
+    private void notifyChange() {
+        if (changeListener != null) {
+            changeListener.run();
+        }
+    }
+
+    @Override
+    public @NonNull Map<String, Object> serialize() {
+        Map<String, Object> map = new HashMap<>();
+        map.put("kills", kills);
+        map.put("deaths", deaths);
+        return map;
+    }
+
+    public static BazaarFluxStats deserialize(Map<String, Object> map) {
+        return new BazaarFluxStats(map);
+    }
+
+}

+ 1 - 8
src/main/java/me/lethunderhawk/world/WorldModule.java

@@ -30,13 +30,6 @@ public class WorldModule extends BazaarFluxModule {
         BazaarFlux bazaarFlux = FluxService.get(BazaarFlux.class);
 
         initWorldStorage();
-        /*File islandsFolder = new File(bazaarFlux.getServer().getWorldContainer(), "islands");
-
-        if (!islandsFolder.exists()) {
-            islandsFolder.mkdirs();
-        }*/
-        /*WorldManager worldManager = new WorldManager();
-        FluxService.register(WorldManager.class, worldManager);*/
 
         bazaarFlux.getLogger().info("World folders initialized!");
         registerCommands(bazaarFlux);
@@ -60,7 +53,7 @@ public class WorldModule extends BazaarFluxModule {
 
     private void registerCommands(BazaarFlux bazaarFlux) {
         WorldCommand worldCommand = new WorldCommand(this);
-        Objects.requireNonNull(bazaarFlux.getCommand("world")).setExecutor(worldCommand);
+        Objects.requireNonNull(bazaarFlux.getCommand("warp")).setExecutor(worldCommand);
     }
 
     @Override

+ 2 - 2
src/main/java/me/lethunderhawk/world/command/WorldCommand.java

@@ -22,7 +22,7 @@ public class WorldCommand extends CustomCommand {
     private Map<String, Location> locations = new HashMap<>();
 
     public WorldCommand(BazaarFluxModule module) {
-        super(new CommandNode("world", "Hop between worlds!", null), module);
+        super(new CommandNode("warp", "Hop between worlds!", null), module);
         populateLocationMap();
     }
 
@@ -103,7 +103,7 @@ public class WorldCommand extends CustomCommand {
 
         if (world == null) {
             module.sendText(player, Component.text("You are new here! Let us create an island first...", NamedTextColor.GREEN));
-            world = manager.createIslandWorld(worldName);
+            world = manager.createIslandWorld(player.getUniqueId(), worldName);
         }
         module.sendText(player, Component.text("Warping to island...", NamedTextColor.GREEN));
         player.teleportAsync(world.getSpawnLocation());

+ 11 - 21
src/main/java/me/lethunderhawk/world/manager/NestedWorldStorageManager.java

@@ -1,9 +1,11 @@
 package me.lethunderhawk.world.manager;
 
 import me.lethunderhawk.fluxapi.FluxService;
+import me.lethunderhawk.fluxapi.npc.abstraction.NPC;
+import me.lethunderhawk.fluxapi.npc.abstraction.NPCOptions;
+import me.lethunderhawk.fluxapi.npc.manager.NPCManager;
 import me.lethunderhawk.main.BazaarFlux;
-import me.lethunderhawk.npc.abstraction.NPC;
-import me.lethunderhawk.npc.abstraction.NPCOptions;
+import me.lethunderhawk.npc.types.IslandNPC;
 import me.lethunderhawk.world.abstraction.WorldStorageManager;
 import me.lethunderhawk.world.island.IslandWorld;
 import me.lethunderhawk.world.util.schematic.Rotation;
@@ -176,8 +178,8 @@ public final class NestedWorldStorageManager implements WorldStorageManager {
         return worldFolder.exists();
     }
 
-    public World createIslandWorld(String playerUUID) {
-        World world = createWorld("islands", playerUUID, creator -> {
+    public World createIslandWorld(UUID playerUUID, String worldName) {
+        World world = createWorld("islands", worldName, creator -> {
             creator.environment(World.Environment.NORMAL);
             creator.type(WorldType.NORMAL);
             creator.generateStructures(false);
@@ -200,27 +202,15 @@ public final class NestedWorldStorageManager implements WorldStorageManager {
             pdc.set(GENERATED_KEY, PersistentDataType.BYTE, (byte) 1);
             FluxService.get(BazaarFlux.class).getLogger().info("Created island in world: " + world.getName());
         }
-        NPCOptions options = new NPCOptions()
-                .setLocation(spawn)
+        NPCOptions options = new NPCOptions(UUID.randomUUID())
                 .setName("Local Guide")
                 .setLookingAtNearest(true)
                 .setEntityType(EntityType.VILLAGER)
-                .setLocation(spawn.add(-2, 0, 0));
-
-        NPC npc = new NPC(options){
-            @Override
-            public void onLeftClick(Player player) {
-                player.sendMessage("<"+this.getName()+"> Im your guide for now!");
-                player.sendMessage("<"+this.getName()+"> Still a lot of work ahead though!");
-            }
-
-            @Override
-            public void onRightClick(Player player) {
-                onLeftClick(player);
-            }
-        };
-        npc.register();
+                .setBukkitLocation(spawn.add(-2, 0, 0));
 
+        NPC npc = new IslandNPC(playerUUID, options);
+        npc.spawn();
+        FluxService.get(NPCManager.class).registerNPC(npc);
         return world;
     }
 

+ 2 - 2
src/main/java/me/lethunderhawk/world/util/WorldManager.java

@@ -20,7 +20,7 @@ public class WorldManager {
     }
 
     public CustomWorld getOrCreateIslandWorld(Player player) {
-        String worldName = "island_" + player.getUniqueId().toString();
+        String worldName = "island_" + player.getUniqueId();
         String worldPath = "islands/" + worldName;
 
         World world = Bukkit.getWorld(worldPath);
@@ -55,7 +55,7 @@ public class WorldManager {
     }
 
     private void returnPlayer(Player player, CustomWorld cWorld) {
-        cWorld.warpBack(player);
+        //cWorld.warpBack(player);
     }
 
     public void cleanWorlds(String worldsFolderName) {

+ 1 - 45
src/main/java/me/lethunderhawk/world/wrapper/CustomWorld.java

@@ -6,9 +6,7 @@ import org.jetbrains.annotations.NotNull;
 
 import java.util.*;
 
-public class CustomWorld {
-    private final Map<UUID, String> returnWorlds = new HashMap<>();
-    private final Map<UUID, Location> returnLocs = new HashMap<>();
+public class CustomWorld{
     private final World world;
 
     public CustomWorld(World world) {
@@ -16,53 +14,11 @@ public class CustomWorld {
     }
 
     public void warpIntoWorld(Player player) {
-        returnWorlds.put(player.getUniqueId(), player.getWorld().getName());
-        returnLocs.put(player.getUniqueId(), player.getLocation().clone());
-
         Location spawn = new Location(world, 0.5, 100, 0.5);
         player.teleport(spawn);
         player.sendMessage(ChatColor.GREEN + "Teleportiert!");
     }
 
-    public void warpBack(Player player) {
-        UUID uuid = player.getUniqueId();
-        String returnWorldName = returnWorlds.remove(uuid);
-        Location returnLoc = returnLocs.remove(uuid);
-
-        if (returnWorldName != null && returnLoc != null) {
-            World returnWorld = Bukkit.getWorld(returnWorldName);
-
-            if (returnWorld == null) {
-                // Versuche, die Welt zu laden
-                returnWorld = new WorldCreator(returnWorldName).createWorld();
-            }
-
-            if (returnWorld != null) {
-                returnLoc.setWorld(returnWorld);
-
-                player.sendMessage("§eKehre zurück...");
-                player.teleport(returnLoc);
-                return;
-            }
-        }
-
-        // Fallback
-        World mainWorld = Bukkit.getWorlds().getFirst();
-        player.teleport(mainWorld.getSpawnLocation());
-        player.sendMessage("§cRückkehr nicht möglich, teleportiere zur Hauptwelt.");
-    }
-
-    public void returnAllPlayers() {
-        List<UUID> toReturn = new ArrayList<>(returnWorlds.keySet());
-
-        for (UUID uuid : toReturn) {
-            Player player = Bukkit.getPlayer(uuid);
-            if (player != null) {
-                warpBack(player);
-            }
-        }
-    }
-
     public @NotNull World getWorld() {
         return world;
     }

+ 20 - 4
src/main/resources/plugin.yml

@@ -10,44 +10,60 @@ commands:
     description: Economy administration command
     usage: /eco <set|add|remove|get> <player> <amount>
     permission: currency.eco
+
   trade:
     description: Send a trade request
+
   tradeaccept:
     description: Accept a trade request
+
   clan:
     description: Clan management command
     usage: /clan <join|rule>
+
   customItems:
     description: Custom Item management command
     usage: /customItem
     permission: customItem.commands
+
   minion:
     description: Minion management command
     usage: /minion
     permission: minion.commands
+
   dungeon:
     description: Dungeons command
     usage: /dungeon
     permission: dungeons.commands
-  world:
+
+  warp:
     description: Warping between worlds
-    usage: /world
-    permission: world.commands
+    usage: /warp
+    permission: warp.commands
+
+  profile:
+    description: Shows your profile
+    usage: /profile
 
 permissions:
   minion.commands:
     description: Allows use of Minion commands
     default: op
-  world.commands:
+
+  warp.commands:
     description: Allows use of warping commands
     default: op
+
   customItem.commands:
     description: Allows use of custom Items commands
     default: op
+
   currency.eco:
     description: Allows economy administration
     default: op
+
   trade.trade:
     description: Allows initiating a trade
+
   trade.acceptTrade:
     description: Allows accepting a trade