Packet Scoreboard Scorename verändern

Wenn ihr bei eurem Plugin nicht weiter kommt, könnt ihr hier euer Problem beschreiben und um Hilfe bitten.

Packet Scoreboard Scorename verändern

Beitragvon Letsplaybar » Mo 12. Sep 2016, 22:34

hab das Problem wenn sich ein wert wie Coins ändert steht es plötzlich 2x da und nun ist meine Frage wie ich den alten Score loswerde?
hier die Klasse:
Code: Alles auswählen
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package de.letsplaybar.lobbysystem.features;
  7. import de.letsplaybar.lobbysystem.economy.Coins;
  8. import de.letsplaybar.lobbysystem.system.Main;
  9. import java.io.File;
  10. import java.io.IOException;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13. import net.minecraft.server.v1_8_R3.Packet;
  14. import net.minecraft.server.v1_8_R3.PacketPlayOutScoreboardDisplayObjective;
  15. import net.minecraft.server.v1_8_R3.PacketPlayOutScoreboardObjective;
  16. import net.minecraft.server.v1_8_R3.PacketPlayOutScoreboardScore;
  17. import net.minecraft.server.v1_8_R3.Scoreboard;
  18. import net.minecraft.server.v1_8_R3.ScoreboardBaseCriteria;
  19. import net.minecraft.server.v1_8_R3.ScoreboardScore;
  20. import org.bukkit.ChatColor;
  21. import org.bukkit.configuration.file.FileConfiguration;
  22. import org.bukkit.configuration.file.YamlConfiguration;
  23. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
  24. import org.bukkit.entity.Player;
  25. /**
  26. *
  27. * @author Letsplaybar
  28. */
  29. public class Scorboards {
  30.    
  31.     private Player p;
  32.     private Main plugin;
  33.     private File file;
  34.     private FileConfiguration cfg;
  35.     private String name;
  36.     private String rank;
  37.     private String servername;
  38.     private String ts3name;
  39.     private String website;
  40.     private Scoreboard board = new Scoreboard();
  41.    
  42.    
  43.    
  44.     public Scorboards(Player p, Main main){
  45.         this.p = p;
  46.         this.plugin = main;
  47.         plugin.scores.put(p, this);
  48.         file = new File("plugins/Lobbysystem/", "Scorboard.yml");
  49.         cfg = YamlConfiguration.loadConfiguration(file);
  50.         if(!file.exists()){
  51.     cfg.addDefault("Scoreboardname", "&4Letsplaybar.de" );
  52.     cfg.addDefault("Servername", "&3Lobby - 1");
  53.     cfg.addDefault("TS3-IP", "Letsplaybar.de ");
  54.     cfg.addDefault("Website", "Letsplaybar.de");
  55.    
  56.     cfg.options().copyDefaults(true);
  57.     save();
  58.         }
  59.        
  60.         name = ChatColor.translateAlternateColorCodes('&', cfg.getString("Scoreboardname"));
  61.         rank = "Kein Rank!!!";
  62.       
  63.        if(p.getName().equalsIgnoreCase("Letsplaybar")){
  64.          rank = "Owner";
  65.        }else if(p.getName().equalsIgnoreCase("shalomalo")){
  66.          rank = "Administrator";
  67.        }else if(p.getName().equalsIgnoreCase("Rotpiltzhd")){
  68.          rank = "Administrator";
  69.        }else if(p.hasPermission("lobby.vip")){
  70.          rank = "VIP";
  71.         
  72.        }else if(p.hasPermission("lobby.vipp")){
  73.          rank = "VIP+";
  74.        }else if(p.hasPermission("lobby.yt")){
  75.          rank = "Youtuber";
  76.        }else if(p.hasPermission("lobby.srmod")){
  77.          rank = "Senior Moderator";
  78.         
  79.        }else if(p.hasPermission("lobby.mod")){
  80.          rank = "Moderator";
  81.        }else if(p.hasPermission("lobby.build")){
  82.          rank = "Builder";
  83.        }else if(p.hasPermission("lobby.dev")){
  84.          rank = "DEVLOPER";
  85.        }else if(p.hasPermission("lobby.admin")){
  86.          rank = "Administrator";
  87.        }else if(p.hasPermission("lobby.owner")){
  88.          rank = "Owner";
  89.        }
  90.         servername = ChatColor.translateAlternateColorCodes('&', cfg.getString("Servername"));
  91.         ts3name = ChatColor.translateAlternateColorCodes('&', cfg.getString("TS3-IP"));
  92.         website = ChatColor.translateAlternateColorCodes('&', cfg.getString("Website"));
  93.        
  94.     }
  95.    
  96.     public void setScoreboard(){
  97.         Coins c = plugin.getCoins(p);
  98.       double coins = c.getCoins();
  99.       double token = c.getToken();
  100.        
  101.         if (board.getObjective(name) == null) {
  102.       board.registerObjective(name, new ScoreboardBaseCriteria(name));
  103.    
  104.         PacketPlayOutScoreboardObjective packet = new PacketPlayOutScoreboardObjective(board.getObjective(name), 0);
  105.         sendPacket(packet);
  106.         }
  107.         PacketPlayOutScoreboardDisplayObjective display = new PacketPlayOutScoreboardDisplayObjective(1, board.getObjective(name));
  108.        
  109.         sendPacket(display);
  110.         board.getScoresForObjective(board.getObjective(name)).stream().forEach((score)->{
  111.             if(!equals(score, coins, token)){
  112.             score.setScore(-1);
  113.             PacketPlayOutScoreboardScore scoreItemP = new PacketPlayOutScoreboardScore(score);
  114.             sendPacket(scoreItemP);}
  115.         });
  116.        
  117.        
  118.         ScoreboardScore scoreItem = board.getPlayerScoreForObjective("§9Server", board.getObjective(name));
  119.         scoreItem.setScore(14);
  120.         ScoreboardScore scoreItem2 = board.getPlayerScoreForObjective(servername, board.getObjective(name));
  121.         scoreItem2.setScore(13);
  122.         ScoreboardScore scoreItem3 = board.getPlayerScoreForObjective("§1 ", board.getObjective(name));
  123.         scoreItem3.setScore(12);
  124.         ScoreboardScore scoreItem4 = board.getPlayerScoreForObjective("§2Money", board.getObjective(name));
  125.         scoreItem4.setScore(11);
  126.         ScoreboardScore scoreItem5 = board.getPlayerScoreForObjective("§6"+coins+" §3Coins", board.getObjective(name));
  127.         scoreItem5.setScore(10);
  128.         ScoreboardScore scoreItem6 = board.getPlayerScoreForObjective("§2"+token+ " §3Token", board.getObjective(name));
  129.         scoreItem6.setScore(9);
  130.         ScoreboardScore scoreItem7 = board.getPlayerScoreForObjective("§1  ", board.getObjective(name));
  131.         scoreItem7.setScore(8);
  132.         ScoreboardScore scoreItem8 = board.getPlayerScoreForObjective("§cRank", board.getObjective(name));
  133.         scoreItem8.setScore(7);
  134.         ScoreboardScore scoreItem9 = board.getPlayerScoreForObjective(rank, board.getObjective(name));
  135.         scoreItem9.setScore(6);
  136.         ScoreboardScore scoreItem10 = board.getPlayerScoreForObjective("§1   ", board.getObjective(name));
  137.         scoreItem10.setScore(5);
  138.         ScoreboardScore scoreItem11 = board.getPlayerScoreForObjective("§1Teamspeak - 3", board.getObjective(name));
  139.         scoreItem11.setScore(4);
  140.         ScoreboardScore scoreItem12 = board.getPlayerScoreForObjective(ts3name, board.getObjective(name));
  141.         scoreItem12.setScore(3);
  142.         ScoreboardScore scoreItem13 = board.getPlayerScoreForObjective("§1    ", board.getObjective(name));
  143.         scoreItem13.setScore(2);
  144.         ScoreboardScore scoreItem14 = board.getPlayerScoreForObjective("§aWebsite", board.getObjective(name));
  145.         scoreItem14.setScore(1);
  146.         ScoreboardScore scoreItem15 = board.getPlayerScoreForObjective(website, board.getObjective(name));
  147.         scoreItem15.setScore(0);
  148.         PacketPlayOutScoreboardScore scoreItemP = new PacketPlayOutScoreboardScore(scoreItem);
  149.         PacketPlayOutScoreboardScore scoreItemP2 = new PacketPlayOutScoreboardScore(scoreItem2);
  150.         PacketPlayOutScoreboardScore scoreItemP3 = new PacketPlayOutScoreboardScore(scoreItem3);
  151.         PacketPlayOutScoreboardScore scoreItemP4 = new PacketPlayOutScoreboardScore(scoreItem4);
  152.         PacketPlayOutScoreboardScore scoreItemP5 = new PacketPlayOutScoreboardScore(scoreItem5);
  153.         PacketPlayOutScoreboardScore scoreItemP6 = new PacketPlayOutScoreboardScore(scoreItem6);
  154.         PacketPlayOutScoreboardScore scoreItemP7 = new PacketPlayOutScoreboardScore(scoreItem7);
  155.         PacketPlayOutScoreboardScore scoreItemP8 = new PacketPlayOutScoreboardScore(scoreItem8);
  156.         PacketPlayOutScoreboardScore scoreItemP9 = new PacketPlayOutScoreboardScore(scoreItem9);
  157.         PacketPlayOutScoreboardScore scoreItemP10 = new PacketPlayOutScoreboardScore(scoreItem10);
  158.         PacketPlayOutScoreboardScore scoreItemP11 = new PacketPlayOutScoreboardScore(scoreItem11);
  159.         PacketPlayOutScoreboardScore scoreItemP12 = new PacketPlayOutScoreboardScore(scoreItem12);
  160.         PacketPlayOutScoreboardScore scoreItemP13 = new PacketPlayOutScoreboardScore(scoreItem13);
  161.         PacketPlayOutScoreboardScore scoreItemP14 = new PacketPlayOutScoreboardScore(scoreItem14);
  162.         PacketPlayOutScoreboardScore scoreItemP15 = new PacketPlayOutScoreboardScore(scoreItem15);
  163.         sendPacket( scoreItemP);
  164.         sendPacket( scoreItemP2);
  165.         sendPacket( scoreItemP3);
  166.         sendPacket( scoreItemP4);
  167.         sendPacket( scoreItemP5);
  168.         sendPacket( scoreItemP6);
  169.         sendPacket( scoreItemP7);
  170.         sendPacket( scoreItemP8);
  171.         sendPacket( scoreItemP9);
  172.         sendPacket( scoreItemP10);
  173.         sendPacket( scoreItemP11);
  174.         sendPacket( scoreItemP12);
  175.         sendPacket( scoreItemP13);
  176.         sendPacket( scoreItemP14);
  177.         sendPacket( scoreItemP15);
  178.     }
  179.    
  180.     public void updateScoreboard(){
  181.         rank = "Kein Rank!!!";
  182.       
  183.        if(p.getName().equalsIgnoreCase("Letsplaybar")){
  184.          rank = "Owner";
  185.        }else if(p.getName().equalsIgnoreCase("shalomalo")){
  186.          rank = "Administrator";
  187.        }else if(p.getName().equalsIgnoreCase("Rotpiltzhd")){
  188.          rank = "Administrator";
  189.        }else if(p.hasPermission("lobby.vip")){
  190.          rank = "VIP";
  191.         
  192.        }else if(p.hasPermission("lobby.vipp")){
  193.          rank = "VIP+";
  194.        }else if(p.hasPermission("lobby.yt")){
  195.          rank = "Youtuber";
  196.        }else if(p.hasPermission("lobby.srmod")){
  197.          rank = "Senior Moderator";
  198.         
  199.        }else if(p.hasPermission("lobby.mod")){
  200.          rank = "Moderator";
  201.        }else if(p.hasPermission("lobby.build")){
  202.          rank = "Builder";
  203.        }else if(p.hasPermission("lobby.dev")){
  204.          rank = "DEVLOPER";
  205.        }else if(p.hasPermission("lobby.admin")){
  206.          rank = "Administrator";
  207.        }else if(p.hasPermission("lobby.owner")){
  208.          rank = "Owner";
  209.        }
  210.         this.setScoreboard();
  211.     }
  212.     public void updateScoreboard(String name){
  213.        
  214.         rank = "Kein Rank!!!";
  215.       
  216.        if(p.getName().equalsIgnoreCase("Letsplaybar")){
  217.          rank = "Owner";
  218.        }else if(p.getName().equalsIgnoreCase("shalomalo")){
  219.          rank = "Administrator";
  220.        }else if(p.getName().equalsIgnoreCase("Rotpiltzhd")){
  221.          rank = "Administrator";
  222.        }else if(p.hasPermission("lobby.vip")){
  223.          rank = "VIP";
  224.         
  225.        }else if(p.hasPermission("lobby.vipp")){
  226.          rank = "VIP+";
  227.        }else if(p.hasPermission("lobby.yt")){
  228.          rank = "Youtuber";
  229.        }else if(p.hasPermission("lobby.srmod")){
  230.          rank = "Senior Moderator";
  231.         
  232.        }else if(p.hasPermission("lobby.mod")){
  233.          rank = "Moderator";
  234.        }else if(p.hasPermission("lobby.build")){
  235.          rank = "Builder";
  236.        }else if(p.hasPermission("lobby.dev")){
  237.          rank = "DEVLOPER";
  238.        }else if(p.hasPermission("lobby.admin")){
  239.          rank = "Administrator";
  240.        }else if(p.hasPermission("lobby.owner")){
  241.          rank = "Owner";
  242.        }
  243.             this.name = name;
  244.         this.setScoreboard();
  245.     }
  246.    
  247.    
  248.     private void save(){
  249.         try {
  250.             cfg.save(file);
  251.         } catch (IOException ex) {
  252.             Logger.getLogger(Scorboards.class.getName()).log(Level.SEVERE, null, ex);
  253.         }
  254.     }
  255.    
  256.     private void sendPacket(Packet packet){
  257.         ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
  258.     }
  259.    
  260.     private boolean equals(ScoreboardScore score, double coins, double token){
  261.         return score.toString().equalsIgnoreCase("§9Server")|| score.toString().equalsIgnoreCase(servername)|| score.toString().equalsIgnoreCase("§1 ")
  262.                 || score.toString().equalsIgnoreCase("§2Money")|| score.toString().equalsIgnoreCase("§6"+coins+" §3Coins")|| score.toString().equalsIgnoreCase("§2"+token+ " §3Token")
  263.                 || score.toString().equalsIgnoreCase("§1  ")|| score.toString().equalsIgnoreCase("§cRank")|| score.toString().equalsIgnoreCase(rank)
  264.                 || score.toString().equalsIgnoreCase("§1   ")|| score.toString().equalsIgnoreCase("§1Teamspeak - 3")|| score.toString().equalsIgnoreCase(ts3name)
  265.                 || score.toString().equalsIgnoreCase("§1    ")|| score.toString().equalsIgnoreCase("§aWebsite")|| score.toString().equalsIgnoreCase(website);
  266.     }
  267. }

momentan helfe ich mir nur so das ich den wert so nitrig setzte so das er nicht mehr angezeigt wird.
Bild
Helfe Wo ich kann.
Mein MinecraftServer: Letsplaybaro.de - Suchen Developer/Bilder

I hacked 127.0.0.1!!! :)
Benutzeravatar
Letsplaybar
 
Beiträge: 195
Registriert: Mo 1. Feb 2016, 17:21
Wohnort: Berlin

Re: Packet Scoreboard Scorename verändern

Beitragvon Knadda » Mo 12. Sep 2016, 23:46

Du musst den alten score erst löschen. Dies machst du einfach mit "new PacketPlayOutScoreboardObjective(objective, 1);". Dann kannst du einen neuen setzen. :)
Benutzeravatar
Knadda
 
Beiträge: 49
Registriert: Mo 1. Aug 2016, 07:06


Zurück zu Hilfe und Support

Wer ist online?

Mitglieder in diesem Forum: Google [Bot], MSN [Bot] und 18 Gäste

cron