Solved Punishment GUI History Problem

Discussion in 'Plugin Development' started by Boobah, May 25, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Boobah

    I am trying to make history for my punishment GUI and I have a problem with the history.

    Here's my code:
    Code:
    @SuppressWarnings("deprecation")
        private void updateHistory(String target){
            Player player = Bukkit.getPlayer(target);
            OfflinePlayer op;
            UUID uuid;
            if(player == null){
                op = Bukkit.getOfflinePlayer(target);
                uuid = op.getUniqueId();
            }else{
                uuid = player.getUniqueId();
            }
            PlayersDataCF pd = null;
            if(player == null){
                pd = new PlayersDataCF(uuid);
            }else{
                pd = PlayerData.dataMap.get(uuid);
            }
            if(!pd.exists()){
                System.out.println("[MPCORE] Error occured: PlayerData with UUID \"" + uuid + "\" does not exist!");
                return;
            }
            pd.load();
            if(pd.get().getBoolean("player.punish.history.8.state")){
                pd.get().set("player.punish.history.9.state", true);
                pd.get().set("player.punish.history.9.lore", pd.get().getStringList("player.punish.history.8.lore"));
                pd.get().set("player.punish.history.9.end", pd.get().getLong("player.punish.history.8.end"));
                if(pd.get().getBoolean("player.punish.history.8.removed")){
                    pd.get().set("player.punish.history.9.removed", true);
                    pd.get().set("player.punish.history.9.removeAdmin", pd.get().getString("player.punish.history.8.removeAdmin"));
                    pd.get().set("player.punish.history.9.removeReason", pd.get().getString("player.punish.history.8.removeReason"));
                }
            }else if(pd.get().getBoolean("player.punish.history.7.state")){
                pd.get().set("player.punish.history.8.state", true);
                pd.get().set("player.punish.history.8.lore", pd.get().getStringList("player.punish.history.7.lore"));
                pd.get().set("player.punish.history.8.end", pd.get().getLong("player.punish.history.7.end"));
                if(pd.get().getBoolean("player.punish.history.7.removed")){
                    pd.get().set("player.punish.history.8.removed", true);
                    pd.get().set("player.punish.history.8.removeAdmin", pd.get().getString("player.punish.history.7.removeAdmin"));
                    pd.get().set("player.punish.history.8.removeReason", pd.get().getString("player.punish.history.7.removeReason"));
                }
            }else if(pd.get().getBoolean("player.punish.history.6.state")){
                pd.get().set("player.punish.history.7.state", true);
                pd.get().set("player.punish.history.7.lore", pd.get().getStringList("player.punish.history.6.lore"));
                pd.get().set("player.punish.history.7.end", pd.get().getLong("player.punish.history.6.end"));
                if(pd.get().getBoolean("player.punish.history.6.removed")){
                    pd.get().set("player.punish.history.7.removed", true);
                    pd.get().set("player.punish.history.7.removeAdmin", pd.get().getString("player.punish.history.6.removeAdmin"));
                    pd.get().set("player.punish.history.7.removeReason", pd.get().getString("player.punish.history.6.removeReason"));
                }
            }else if(pd.get().getBoolean("player.punish.history.5.state")){
                pd.get().set("player.punish.history.6.state", true);
                pd.get().set("player.punish.history.6.lore", pd.get().getStringList("player.punish.history.5.lore"));
                pd.get().set("player.punish.history.6.end", pd.get().getLong("player.punish.history.5.end"));
                if(pd.get().getBoolean("player.punish.history.5.removed")){
                    pd.get().set("player.punish.history.6.removed", true);
                    pd.get().set("player.punish.history.6.removeAdmin", pd.get().getString("player.punish.history.5.removeAdmin"));
                    pd.get().set("player.punish.history.6.removeReason", pd.get().getString("player.punish.history.5.removeReason"));
                }
            }else if(pd.get().getBoolean("player.punish.history.4.state")){
                pd.get().set("player.punish.history.5.state", true);
                pd.get().set("player.punish.history.5.lore", pd.get().getStringList("player.punish.history.4.lore"));
                pd.get().set("player.punish.history.5.end", pd.get().getLong("player.punish.history.4.end"));
                if(pd.get().getBoolean("player.punish.history.4.removed")){
                    pd.get().set("player.punish.history.5.removed", true);
                    pd.get().set("player.punish.history.5.removeAdmin", pd.get().getString("player.punish.history.4.removeAdmin"));
                    pd.get().set("player.punish.history.5.removeReason", pd.get().getString("player.punish.history.4.removeReason"));
                }
            }else if(pd.get().getBoolean("player.punish.history.3.state")){
                pd.get().set("player.punish.history.4.state", true);
                pd.get().set("player.punish.history.4.lore", pd.get().getStringList("player.punish.history.3.lore"));
                pd.get().set("player.punish.history.4.end", pd.get().getLong("player.punish.history.3.end"));
                pd.save();
                if(pd.get().getBoolean("player.punish.history.3.removed")){
                    pd.get().set("player.punish.history.4.removed", true);
                    pd.get().set("player.punish.history.4.removeAdmin", pd.get().getString("player.punish.history.3.removeAdmin"));
                    pd.get().set("player.punish.history.4.removeReason", pd.get().getString("player.punish.history.3.removeReason"));
                    pd.save();
                }
            }else if(pd.get().getBoolean("player.punish.history.2.state")){
                pd.get().set("player.punish.history.3.state", true);
                pd.get().set("player.punish.history.3.lore", pd.get().getStringList("player.punish.history.2.lore"));
                pd.get().set("player.punish.history.3.end", pd.get().getLong("player.punish.history.2.end"));
                pd.save();
                if(pd.get().getBoolean("player.punish.history.2.removed")){
                    pd.get().set("player.punish.history.3.removed", true);
                    pd.get().set("player.punish.history.3.removeAdmin", pd.get().getString("player.punish.history.2.removeAdmin"));
                    pd.get().set("player.punish.history.3.removeReason", pd.get().getString("player.punish.history.2.removeReason"));
                    pd.save();
                }
            }else if(pd.get().getBoolean("player.punish.history.1.state")){
                pd.get().set("player.punish.history.2.state", true);
                pd.get().set("player.punish.history.2.lore", pd.get().getStringList("player.punish.history.1.lore"));
                pd.get().set("player.punish.history.2.end", pd.get().getLong("player.punish.history.1.end"));
                pd.save();
                if(pd.get().getBoolean("player.punish.history.1.removed")){
                    pd.get().set("player.punish.history.2.removed", true);
                    pd.get().set("player.punish.history.2.removeAdmin", pd.get().getString("player.punish.history.1.removeAdmin"));
                    pd.get().set("player.punish.history.2.removeReason", pd.get().getString("player.punish.history.1.removeReason"));
                    pd.save();
                }
            }
            pd.save();
    
        }

    Here's how I use the method:
    Code:
    @SuppressWarnings("deprecation")
        private void addHistory(String target, ArrayList<String> lore, long end){
            Player player = Bukkit.getPlayer(target);
            OfflinePlayer op;
            UUID uuid;
            if(player == null){
                op = Bukkit.getOfflinePlayer(target);
                uuid = op.getUniqueId();
            }else{
                uuid = player.getUniqueId();
            }
            PlayersDataCF pd = null;
            if(player == null){
                pd = new PlayersDataCF(uuid);
            }else{
                pd = PlayerData.dataMap.get(uuid);
            }
            if(!pd.exists()){
                System.out.println("[MPCORE] Error occured: PlayerData with UUID \"" + uuid + "\" does not exist!");
                return;
            }
            pd.load();
            if(pd.get().getBoolean("player.punish.history.1.state") && pd.get().getBoolean("player.punish.history.2.state") && pd.get().getBoolean("player.punish.history.3.state")  && pd.get().getBoolean("player.punish.history.4.state") && pd.get().getBoolean("player.punish.history.5.state") && pd.get().getBoolean("player.punish.history.6.state") && pd.get().getBoolean("player.punish.history.7.state") && pd.get().getBoolean("player.punish.history.8.state") && pd.get().getBoolean("player.punish.history.9.state")){
                updateAllHistory(target);
            }else{
                updateHistory(target);
            }
            pd.get().set("player.punish.history.1.state", true);
            pd.get().set("player.punish.history.1.lore", lore);
            pd.get().set("player.punish.history.1.end", (end + System.currentTimeMillis()));
            pd.get().set("player.punish.history.1.removed", false);
            pd.get().set("player.punish.history.1.removeAdmin", null);
            pd.get().set("player.punish.history.1.removeReason", null);
            pd.save();
        }
    And I use addHistory() here:

    Code:
    if(event.getCurrentItem().getItemMeta().getDisplayName().equals("§a§lSeverity 1") && event.getSlot() == 19){
                long time = 2 * 60 * 60;
                if(target1 == null){
                    Punish_Mute.mute(t1.getUniqueId().toString(), player.getName(), reason, time);
                }else{
                    Punish_Mute.mute(target1.getUniqueId().toString(), player.getName(), reason, time);
                }
                pd.load();
                pd.get().set("player.punish.chatOffense.severity.1.offences", pd.get().getInt("player.punish.chatOffense.severity.1.offences") + 1);
                pd.save();
                ArrayList<String> lore = new ArrayList<>();
                lore.add(ChatColor.YELLOW + "Punishment Type: " + ChatColor.WHITE + "ChatOffense");
                lore.add(ChatColor.YELLOW + "Severity: " + ChatColor.WHITE + "1");
                lore.add("");
                lore.add(ChatColor.YELLOW + "Reason: " + ChatColor.WHITE + reason);
                lore.add("");
                lore.add(ChatColor.YELLOW + "Staff: " + ChatColor.WHITE + player.getName());
                lore.add("");
                lore.add(ChatColor.YELLOW + "Date: " + ChatColor.WHITE + format.format(now));
                addHistory(target, lore, time * 1000);
                player.closeInventory();
            }



    Here's the problem:

    [​IMG]
    [​IMG]


    I punished the player 6 times, only two of the punishments show. help please

    Player's playerdata:
    Code:
        history:
          '1':
            state: true
            lore:
            - '§ePunishment Type: §fChatOffense'
            - '§eSeverity: §f4'
            - ''
            - '§eReason: §fhi'
            - ''
            - '§eStaff: §fBoobah'
            - ''
            - '§eDate: §f05-25-2017 13:16:49'
            end: 1495732609582
            removed: false
          '2':
            state: true
            lore:
            - '§ePunishment Type: §rOther'
            - ''
            - '§eReason: §fThis is the first punishment.'
            - ''
            - '§eStaff: §fBoobah'
            - ''
            - '§eDate: §f05-25-2017 13:06:21'
            end: 1495731981360
     
  2. Offline

    Zombie_Striker

    @Boobah
    Instead of the code above, use:
    Code:
    
    for(int i = 2; i < 20;i++){
    
            if(pd.get().getBoolean("player.punish.history."+(i-1)+".state")){
                pd.get().set("player.punish.history."+i+".state", true);
                pd.get().set("player.punish.history."+i+".lore", pd.get().getStringList("player.punish.history."+(i-1)+".lore"));
                pd.get().set("player.punish.history."+i+".end", pd.get().getLong("player.punish.history."+(i-1)+".end"));
                pd.save();
                if(pd.get().getBoolean("player.punish.history."+(i-1)+".removed")){
                    pd.get().set("player.punish.history."+i+".removed", true);
                    pd.get().set("player.punish.history."+i+".removeAdmin", pd.get().getString("player.punish.history."+(i-1)+".removeAdmin"));
                    pd.get().set("player.punish.history."+i+".removeReason", pd.get().getString("player.punish.history."+(i-1)+".removeReason"));
                    pd.save();
                }
    break;
            }
    }
    .Instead of having all those if statements, this will now reduce the amount of lines about 90 lines.

    Now, back to your main problem, how does the server know you banned the player six times? Do they count the amount of reports in the config, or are you using some other system to store that information?

    Also, have you debugged? Do you know if the other else statements ever get called? I would recommend using the code above and print out what the maximum of I is equal to (at what point it stops counting up)
     
  3. Offline

    Boobah

    The server knows because it saves it in the playerdata.

    @Zombie_Striker
    Just did a debug and nothing is wrong. I think it's something with the pd.get().set("player.punish.history.2") part though since when i punish someone and check their playerdata, they only have player.punish.history.1 in there, no number 2

    any help with what could be wrong with it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2017
Thread Status:
Not open for further replies.

Share This Page