Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.22 KB | None | 0 0
  1.  
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.UUID;
  7.  
  8. import com.mysql.fabric.xmlrpc.base.Array;
  9.  
  10. import fr._roro.friends.mysql.MySQL;
  11. import net.md_5.bungee.BungeeCord;
  12. import net.md_5.bungee.api.CommandSender;
  13. import net.md_5.bungee.api.chat.ClickEvent;
  14. import net.md_5.bungee.api.chat.ClickEvent.Action;
  15. import net.md_5.bungee.api.chat.ComponentBuilder;
  16. import net.md_5.bungee.api.chat.HoverEvent;
  17. import net.md_5.bungee.api.chat.TextComponent;
  18. import net.md_5.bungee.api.config.ServerInfo;
  19. import net.md_5.bungee.api.connection.ProxiedPlayer;
  20. import net.md_5.bungee.api.connection.Server;
  21. import net.md_5.bungee.api.plugin.Command;
  22.  
  23. public class Friends extends Command
  24. {
  25. public Friends(String name)
  26. {
  27. super(name);
  28. }
  29.  
  30. public void execute(CommandSender sender, String[] args) {
  31. if ((sender instanceof ProxiedPlayer)) {
  32. ProxiedPlayer p = (ProxiedPlayer)sender;
  33. try {
  34. if ((args.length == 0) || (args.length > 2 && !args[0].equalsIgnoreCase("list")))
  35. {
  36. p.sendMessage(new TextComponent("§c==================================================="));
  37. p.sendMessage(new TextComponent("§6/friends add <player> §fpermet d'ajouter un ami."));
  38. p.sendMessage(new TextComponent("§6/friends remove <player> §fpermet de supprimer un ami."));
  39. p.sendMessage(new TextComponent("§6/friends track <player> §fpermet de localiser votre ami."));
  40. p.sendMessage(new TextComponent("§6/friends teleport <player> §fpermet de se téléporter sur le serveur d'un ami."));
  41. p.sendMessage(new TextComponent("§6/friends list §fpermet de voir votre list d'amis."));
  42. p.sendMessage(new TextComponent("§c==================================================="));
  43. }
  44. if (args[0].equalsIgnoreCase("list"))
  45. {
  46. ArrayList<UUID> list = MySQL.listFriends(p.getUniqueId());
  47. p.sendMessage(new TextComponent("§c==============================="));
  48. int friendsMax = list.size();
  49. int friendsOnlline = 0;
  50. for(UUID FriendsHIM : list) {
  51. ProxiedPlayer target = BungeeCord.getInstance().getPlayer(FriendsHIM);
  52. if(target != null) {
  53. friendsOnlline++;
  54. }
  55. }
  56. p.sendMessage(new TextComponent(Main.prefix + "§6Vos amis | §8(§6"+friendsOnlline+"§c/§6"+friendsMax+"§8): "));
  57.  
  58. for(UUID FriendsHIM : list) {
  59. ProxiedPlayer target = BungeeCord.getInstance().getPlayer(FriendsHIM);
  60. if(target != null) {
  61. p.sendMessage(new TextComponent("§f- §a" + MySQL.friendsName(FriendsHIM) + " §8[§eServeur§f: §6"+ target.getServer().getInfo().getName() +"§8]" ));
  62. }
  63. if(target == null) {
  64. p.sendMessage(new TextComponent("§f- §c" + MySQL.friendsName(FriendsHIM)));
  65. }
  66. }
  67. p.sendMessage(new TextComponent("§c==============================="));
  68. }
  69. if (args.length == 2)
  70. {
  71.  
  72. if (args[0].equalsIgnoreCase("add"))
  73. {
  74. ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[1]);
  75. if (target != null)
  76. {
  77. try
  78. {
  79. if (target == p)
  80. {
  81. p.sendMessage(new TextComponent("§cVous ne pouvez pas vous ajouter vous même !"));
  82. return;
  83. }
  84. if (MySQL.getFriend(p.getUniqueId(), target.getUniqueId()))
  85. {
  86. p.sendMessage(new TextComponent(Main.prefix + "§cVous êtes déjà ami avec cette personne !"));
  87. }
  88. else if (Main.invitations.get(p.getUniqueId()) != target.getUniqueId())
  89. {
  90. if(MySQL.getSetting(target.getUniqueId(), "friend") == 1) {
  91. p.sendMessage(new TextComponent(Main.prefix + "§aDemande envoyée avec succès !"));
  92. Main.invitations.put(p.getUniqueId(), target.getUniqueId());
  93. target.sendMessage(new TextComponent(Main.prefix + "§e" + p.getName() + " vous a envoyé une demande d'amitié !"));
  94. TextComponent msg = new TextComponent(Main.prefix + "§7/friends accept " + p.getName() + "§e pour accepter cette demande.");
  95. msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§bClique pour accepter !").create()));
  96. msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friends accept " + p.getName()));
  97. target.sendMessage(msg);
  98. } else {
  99. p.sendMessage(new TextComponent("§cCette personne refuse les invitations !"));
  100. }
  101. }
  102. else
  103. {
  104. p.sendMessage(new TextComponent("§cVous avez déjà envoyé une invitation à cette personne !"));
  105. }
  106.  
  107. }
  108. catch (Exception e)
  109. {
  110. e.printStackTrace();
  111. }
  112. }
  113. else
  114. {
  115. p.sendMessage(new TextComponent("§cCe joueur est déconnecté !"));
  116. }
  117. }
  118. if (args[0].equalsIgnoreCase("remove"))
  119. {
  120. try
  121. {
  122. ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[1]);
  123. if (MySQL.getFriend(p.getUniqueId(), target.getUniqueId()))
  124. {
  125. MySQL.deleteFriend(p.getUniqueId(), target.getUniqueId());
  126. p.sendMessage(new TextComponent(Main.prefix + "§a" + args[1] + " a été supprimé avec succès !"));
  127.  
  128. if (target != null)
  129. {
  130. target.sendMessage(new TextComponent(Main.prefix + "§c" + p.getName() + " vous a retiré de ses amis !"));
  131. }
  132. }
  133. else
  134. {
  135. p.sendMessage(new TextComponent(Main.prefix + "§cVous n'êtes pas ami avec cette personne !"));
  136. }
  137. }
  138. catch (Exception e)
  139. {
  140. e.printStackTrace();
  141. }
  142. }
  143. if (args[0].equalsIgnoreCase("accept"))
  144. {
  145. ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[1]);
  146. if (target != null)
  147. {
  148. if (Main.invitations.get(target.getUniqueId()) == p.getUniqueId())
  149. {
  150. MySQL.addFriend(p.getUniqueId(), target.getUniqueId());
  151. Main.invitations.remove(target.getUniqueId());
  152.  
  153. p.sendMessage(new TextComponent(Main.prefix + "§aVous êtes maintenant ami avec " + args[1] + " !"));
  154. target.sendMessage(new TextComponent(Main.prefix + "§aVous êtes maintenant ami avec " + p.getName() + " !"));
  155. }
  156. else
  157. {
  158. p.sendMessage(new TextComponent(Main.prefix + "§cAucune demande d'amitié à cette personne !"));
  159. }
  160. }
  161. else
  162. {
  163. p.sendMessage(new TextComponent(Main.prefix + "§cCe joueur n'est pas connecté !"));
  164. }
  165. }
  166. if (args[0].equalsIgnoreCase("track"))
  167. {
  168. ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[1]);
  169. if (target != null)
  170. {
  171. if (MySQL.getFriend(p.getUniqueId(), target.getUniqueId()))
  172. {
  173. TextComponent tc1 = new TextComponent(Main.prefix + "§e" + target.getName() + " est sur le serveur : " + target.getServer().getInfo().getName() + " !");
  174. tc1.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aCliquez pour vous connecter au serveur: " + target.getServer().getInfo().getName()).create()));
  175. tc1.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friends teleport " + target.getName()));
  176. p.sendMessage(tc1);
  177. }
  178. else
  179. {
  180. p.sendMessage(new TextComponent(Main.prefix + "§cVous n'êtes pas ami avec cette personne !"));
  181. }
  182. }
  183. else
  184. {
  185. p.sendMessage(new TextComponent(Main.prefix + "§cCe joueur n'est pas connecté !"));
  186. }
  187. }
  188. if (args[0].equalsIgnoreCase("teleport"))
  189. {
  190. ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[1]);
  191. if (target != null)
  192. {
  193. if (MySQL.getFriend(p.getUniqueId(), target.getUniqueId()))
  194. {
  195. if (p.getServer().getInfo() != target.getServer().getInfo())
  196. {
  197. p.connect(target.getServer().getInfo());
  198. p.sendMessage(new TextComponent(Main.prefix + "§aVous avez été connecté sur le serveur : " + target.getServer().getInfo().getName() + " !"));
  199. }
  200. else
  201. {
  202. p.sendMessage(new TextComponent(Main.prefix + "§cVous êtes déjà sur ce serveur !"));
  203. }
  204. }
  205. else
  206. {
  207. p.sendMessage(new TextComponent(Main.prefix + "§cVous n'êtes pas ami avec cette personne !"));
  208. }
  209. }
  210. else
  211. {
  212. p.sendMessage(new TextComponent(Main.prefix + "§cCe joueur n'est pas connecté !"));
  213. }
  214. }
  215. }
  216. }catch (Exception e) {
  217.  
  218. }
  219. }
  220. }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement