#KIt Sorting System

1 messages · Page 1 of 1 (latest)

heady zephyr
#

hey. does anyone have an idea how to do a kit sorting system, i already did a object where i can specify the name, the content. but i want to do a sorting system. so basiclly the player can choose on what slot the sword should be or the webs. and idk how i can do this. every idea helps me thanks

azure hazel
#

make your kit class implements Comparable

#

and do whatever you want with the method inside it

steep kraken
#

You need a per-player serializable object that stores the data in a Map<Integer, ItemStack>

mint basin
#

i believe i once did this using a Map<Integer, Integer> storing which slots the player had switched arround

steep kraken
#

^ Oh yeah you can also do a weak coherence approach by mapping the original slots to the players chosen slots

heady zephyr
#

ok thanks for the ideas i will try to implement it

heady zephyr
mint basin
heady zephyr
mint basin
#

well uhh why dont you share some code

heady zephyr
#

wait i can do it

#
    Map<Integer, ItemStack> newSort = new HashMap<Integer, ItemStack>();

    @Override
    public boolean onCommand(CommandSender s, Command c, String l, String[] args) {
        Player player = (Player) s;
        KitManager.givePlayerKit(player, KitManager.getKit("tank"));
        player.sendMessage("Sort test");
        
        for(int i = 0; i < player.getInventory().getSize(); i++) {
            newSort.put(i, player.getInventory().getItem(i));
        }
        
        return false;
    }
    @EventHandler
    void onChat(PlayerChatEvent e) throws IOException {
        System.out.println(newSort);
        
        KitManager.givePlayerKitWithCustomSort(e.getPlayer(), KitManager.getKit("tank"));
        Main.yamlConfiguration.set(e.getPlayer().getName()+ "tankkit", newSort);
        Main.yamlConfiguration.save(Main.file);
    }
    ``` im trying to save it, but it just doesnt contain anything. i maybe just be stupid rn idk xd
mint basin
#

so ur trying to do it the way 7smile7 suggested right

#

keep in mind that that way uses considerably more space

#

did you register your listener?

heady zephyr
#

yes i did.

#

the chatevent works, it saves it in the config, but without the data i provided in the map (the items etc)

mint basin
#

im not sure u can save a map like that

#

i think u need to loop through and save each entry

heady zephyr
#

is there another way?

heady zephyr
#

im trying to do something like that

mint basin
#

well then. no i think there isnt much else u can do