Advertisement
Guest User

Untitled

a guest
Dec 10th, 2014
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. public class SignsDataManager {
  2.  
  3. FileConfiguration signs = Main.signsConfig;
  4.  
  5. String path = "signs.";
  6.  
  7. public SignsDataManager(){}
  8.  
  9. public void addSign(Location loc, String serverID, int MaxPlayer, String displayName, String minigame){
  10. String path = "signs." + serverID;
  11. /*Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + " Rajout Sign a la location:");
  12. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + " X: " + ChatColor.GREEN + loc.getBlockX());
  13. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + " Y: " + ChatColor.GREEN + loc.getBlockY());
  14. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + " Z: " + ChatColor.GREEN + loc.getBlockZ());
  15. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + " Serveur de Redirection: " + ChatColor.GREEN + serverID);
  16. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + " Joueurs Maximum: " + ChatColor.GREEN + MaxPlayer);
  17. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + " MiniJeux: " + ChatColor.GREEN + minigame);*/
  18. signs.set(path+".x", loc.getBlockX());
  19. signs.set(path+".y", loc.getBlockY());
  20. signs.set(path+".z", loc.getBlockZ());
  21. signs.set(path+".world", loc.getWorld().getName());
  22. signs.set(path+".maxplayer", MaxPlayer);
  23. signs.set(path+".serverid", serverID);
  24. signs.set(path+".displayname", displayName);
  25. signs.set(path+".minigame", minigame);
  26. try{
  27. signs.save(Main.signs);
  28. }catch(IOException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32.  
  33. public void update(){
  34. Set<String> keys = signs.getConfigurationSection("signs").getKeys(false);
  35. for(String entry: keys){
  36. String path = "signs." + entry;
  37. Location l = new Location((World) signs.get(path + ".world"), signs.getInt(path + ".x"), signs.getInt(path + ".y"), signs.getInt(path + ".z"));
  38. if(l.getBlock().getType().equals(Material.SIGN) || l.getBlock().getType().equals(Material.SIGN_POST)){
  39. Sign s = (Sign) l.getBlock().getState();
  40. ByteArrayDataOutput out = ByteStreams.newDataOutput();
  41. out.writeUTF("PlayerCount");
  42. out.writeUTF(path + ".serverid");
  43. String connected = out.toString();
  44. String motd = signs.getString(path + ".motd");
  45. motd.replaceAll("&", "§");
  46. if(connected != null){
  47. s.setLine(0, "[" + signs.getString(path + ".minigame").replaceAll("&", "§") + ChatColor.RESET + "]");
  48. s.setLine(1, connected + "/" + signs.getInt(path+".maxplayer"));
  49. s.setLine(2, signs.getString(path + ".motd").replaceAll("&", "§"));
  50. s.setLine(3, signs.getString(path + ".displayname").replaceAll("&", "§"));
  51. }else{
  52. s.setLine(0, "[" + signs.getString(path + ".minigame").replaceAll("&", "§") + ChatColor.RESET + "]");
  53. s.setLine(1, "");
  54. s.setLine(2, ChatColor.RED + "OFFLINE");
  55. s.setLine(3, "");
  56. }
  57. }
  58. }
  59. }
  60.  
  61. public void delete(String serverid){
  62. String path = "signs." + serverid;
  63. signs.set(path, null);
  64. try{
  65. signs.save(Main.signs);
  66. }catch(IOException e) {
  67. e.printStackTrace();
  68. }
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement