daily pastebin goal
40%
SHARE
TWEET

CLASS

a guest Dec 16th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.KebabCoder.Listeners;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.entity.Player;
  6. import org.bukkit.event.EventHandler;
  7. import org.bukkit.event.Listener;
  8. import org.bukkit.event.entity.PlayerDeathEvent;
  9. import org.bukkit.event.player.PlayerJoinEvent;
  10. import org.bukkit.event.player.PlayerQuitEvent;
  11. import org.bukkit.scoreboard.DisplaySlot;
  12. import org.bukkit.scoreboard.Objective;
  13. import org.bukkit.scoreboard.Score;
  14. import org.bukkit.scoreboard.Scoreboard;
  15. import org.bukkit.scoreboard.ScoreboardManager;
  16.  
  17. import me.KebabCoder.Utilities.ConfigManager;
  18. import me.KebabCoder.Utilities.Utils;
  19. import ru.tehkode.permissions.PermissionUser;
  20. import ru.tehkode.permissions.bukkit.PermissionsEx;
  21.  
  22. public class ScoreboardListener implements Listener {
  23.  
  24.     private static ConfigManager cfgm;
  25.    
  26.     public static void giveScoreboard(Player p) {
  27.  
  28.         PermissionUser user = PermissionsEx.getUser(p);
  29.        
  30.         cfgm = new ConfigManager();
  31.         cfgm.setupStatsConfig();
  32.         int kills = cfgm.getStats().getInt(p.getUniqueId() + ".Kills");
  33.         int deaths = cfgm.getStats().getInt(p.getUniqueId() + ".Deaths");
  34.        
  35.         ScoreboardManager m = Bukkit.getScoreboardManager();
  36.         Scoreboard b = m.getNewScoreboard();
  37.  
  38.         Objective o = b.registerNewObjective("wePvP", "dummy");
  39.         o.setDisplaySlot(DisplaySlot.SIDEBAR);
  40.         o.setDisplayName(Utils.Color("    &2&lGTAM    "));
  41.  
  42.         int score = 15;
  43.  
  44.         Score space = o.getScore(Utils.Color("&1 "));
  45.         space.setScore(15);
  46.  
  47.         score = score - 1;
  48.         Score line = o.getScore(Utils.Color("&1&7&l&m-------------------"));
  49.         line.setScore(score);
  50.  
  51.         score = score - 1;
  52.         Score space2 = o.getScore(Utils.Color("&2 "));
  53.         space2.setScore(score);
  54.  
  55.         score = score - 1;
  56.         Score personal = o.getScore(Utils.Color("&6&lPERSONAL&8&l>"));
  57.         personal.setScore(score);
  58.  
  59.         score = score - 1;
  60.         Score name = o.getScore(Utils.Color("&8» &eName&7: &f" + p.getName()));
  61.         name.setScore(score);
  62.  
  63.         score = score - 1;
  64.         Score rank = o.getScore(Utils.Color("&8» &eRank&7: &f" + ChatColor.stripColor(user.getPrefix())));
  65.         rank.setScore(score);
  66.  
  67.         score = score - 1;
  68.         Score playerKills = o.getScore(Utils.Color("&8» &eKills&7: &f" + kills));
  69.         playerKills.setScore(score);
  70.  
  71.         score = score - 1;
  72.         Score playerDeaths = o.getScore(Utils.Color("&8» &eDeaths&7: &f" + deaths));
  73.         playerDeaths.setScore(score);
  74.  
  75.         score = score - 1;
  76.         Score space3 = o.getScore(Utils.Color("&3 "));
  77.         space3.setScore(score);
  78.  
  79.         score = score - 1;
  80.         Score server = o.getScore(Utils.Color("&6&lSERVER&8&l>"));
  81.         server.setScore(score);
  82.  
  83.         score = score - 1;
  84.         Score online = o.getScore(Utils.Color("&8» &eOnline&7: &f" + Bukkit.getServer().getOnlinePlayers().size()));
  85.         online.setScore(score);
  86.  
  87.  
  88.         score = score - 1;
  89.         Score space4 = o.getScore(Utils.Color("&4 "));
  90.         space4.setScore(score);
  91.  
  92.         score = score - 1;
  93.         Score line2 = o.getScore(Utils.Color("&2&7&l&m-------------------"));
  94.         line2.setScore(score);
  95.  
  96.         p.setScoreboard(b);
  97.  
  98.     }
  99.    
  100.     public static void removeScoreboard(Player p) {
  101.        
  102.         ScoreboardManager m = Bukkit.getScoreboardManager();
  103.         Scoreboard b = m.getNewScoreboard();
  104.  
  105.         Objective o = b.registerNewObjective("noBoard", "dummy");
  106.         o.setDisplaySlot(DisplaySlot.SIDEBAR);
  107.         o.setDisplayName(" ");
  108.        
  109.         p.setScoreboard(b);
  110.     }
  111.  
  112.     @EventHandler
  113.     public void onJoin(PlayerJoinEvent e) {
  114.        
  115.         cfgm = new ConfigManager();
  116.         cfgm.setupStatsConfig();
  117.        
  118.         for(Player all : Bukkit.getOnlinePlayers()) {
  119.             if(cfgm.getStats().getBoolean(all.getUniqueId() + ".Scoreboard")) {
  120.                 giveScoreboard(all);
  121.             }
  122.         }
  123.     }
  124.    
  125.     @EventHandler
  126.     public void onQuit(PlayerQuitEvent e) {
  127.        
  128.         cfgm = new ConfigManager();
  129.         cfgm.setupStatsConfig();
  130.        
  131.         for(Player all : Bukkit.getOnlinePlayers()) {
  132.             if(cfgm.getStats().getBoolean(all.getUniqueId() + ".Scoreboard")) {
  133.                 giveScoreboard(all);
  134.             }
  135.         }
  136.     }
  137.    
  138.     @EventHandler
  139.     public void onDie(PlayerDeathEvent e) {
  140.  
  141.         cfgm = new ConfigManager();
  142.         cfgm.setupStatsConfig();
  143.        
  144.         Player p = e.getEntity();
  145.         Player k = p.getKiller();
  146.        
  147.         int kills = cfgm.getStats().getInt(k.getUniqueId() + ".Kills");
  148.         int deaths = cfgm.getStats().getInt(p.getUniqueId() + ".Deaths");
  149.        
  150.         if(e.getDeathMessage().equalsIgnoreCase(p.getName() + "fell from a high place")) {
  151.             e.setDeathMessage(Utils.Color("&c" + p.getName() + "&7 fell from a high place."));
  152.         }
  153.         if(e.getDeathMessage().contains("slain")) {
  154.             e.setDeathMessage(Utils.Color("&c" + p.getName() + "&7 was slain by &c" + k.getName() + "&7."));
  155.         }
  156.         cfgm.getStats().set(p.getUniqueId() + ".Deaths", deaths + 1);
  157.         if(k != null) {
  158.             cfgm.getStats().set(k.getUniqueId() + ".Kills", kills + 1);
  159.         }
  160.         cfgm.saveStats();
  161.        
  162.        
  163.         if(cfgm.getStats().getBoolean(p.getUniqueId() + ".Scoreboard")) {
  164.             giveScoreboard(p);
  165.         }
  166.        
  167.         if(cfgm.getStats().getBoolean(k.getUniqueId() + ".Scoreboard") && k != null) {
  168.             giveScoreboard(k);
  169.         }
  170.        
  171.     }
  172.    
  173. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top