Advertisement
Guest User

Staffchat

a guest
Aug 24th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. package MainPack;
  2.  
  3. import java.io.PrintStream;
  4. import java.util.HashMap;
  5. import java.util.Set;
  6. import org.bukkit.Server;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.player.AsyncPlayerChatEvent;
  13. import org.bukkit.event.player.PlayerQuitEvent;
  14. import org.bukkit.plugin.Plugin;
  15. import org.bukkit.plugin.PluginManager;
  16. import org.bukkit.plugin.java.JavaPlugin;
  17.  
  18. public class staffchat
  19. extends JavaPlugin
  20. implements Listener {
  21. HashMap<Player, String> map = new HashMap();
  22. String pre;
  23.  
  24. public staffchat() {
  25. this.pre = this.c("&9StaffChat &5>>&7 ");
  26. }
  27.  
  28. public void onEnable() {
  29. System.out.println("Staffchat by Zoreh");
  30. this.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this);
  31. }
  32.  
  33. public void onDisable() {
  34. System.out.println("Staffchat by Zoreh");
  35. }
  36.  
  37. public void onLeave(PlayerQuitEvent e) {
  38. if (this.map.containsKey((Object)e.getPlayer())) {
  39. this.map.remove((Object)e.getPlayer());
  40. }
  41. }
  42.  
  43. @EventHandler
  44. public void onChat(AsyncPlayerChatEvent e) {
  45. Player p = e.getPlayer();
  46. if (this.map.containsKey((Object)p)) {
  47. for (Player ply : this.map.keySet()) {
  48. if (!this.map.get((Object)ply).equalsIgnoreCase(this.map.get((Object)p))) continue;
  49. if (this.map.get((Object)ply).equalsIgnoreCase("staff chat")) {
  50. ply.sendMessage(String.valueOf(this.c(new StringBuilder("&9Staff Chat &5>> &4").append(p.getName()).append("&c&l: ").toString())) + e.getMessage());
  51. continue;
  52. }
  53. ply.sendMessage(String.valueOf(this.pre) + this.c(new StringBuilder("&2").append(p.getName()).append("&7: ").append(e.getMessage()).toString()));
  54. }
  55. e.setCancelled(true);
  56. }
  57. }
  58.  
  59. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  60. String cmd = command.getName();
  61. if (sender instanceof Player) {
  62. Player p = (Player)sender;
  63. if (p.hasPermission("staffchat.toggle") && (cmd.equalsIgnoreCase("sc") || cmd.equalsIgnoreCase("staffchat"))) {
  64. if (this.map.containsKey((Object)p)) {
  65. for (Player ply : this.map.keySet()) {
  66. if (!this.map.get((Object)ply).equalsIgnoreCase(this.map.get((Object)p))) continue;
  67. ply.sendMessage(String.valueOf(this.pre) + this.c(new StringBuilder("The Player ").append(p.getName()).append(" has left the Staff Chat!").toString()));
  68. }
  69. this.map.remove((Object)p);
  70. p.sendMessage(String.valueOf(this.pre) + this.c("You are nolonger in the Staff Chat!"));
  71. } else {
  72. this.map.put(p, "staff chat");
  73. for (Player ply : this.map.keySet()) {
  74. if (!this.map.get((Object)ply).equalsIgnoreCase("staff chat")) continue;
  75. ply.sendMessage(String.valueOf(this.pre) + this.c(new StringBuilder("The Player ").append(p.getName()).append(" has joined the Staff Chat!").toString()));
  76. }
  77. p.sendMessage(String.valueOf(this.pre) + this.c("Now you are in the Staff Chat!"));
  78. }
  79. }
  80. }
  81. return true;
  82. }
  83.  
  84. public String c(String msg) {
  85. return msg.replaceAll("&", "\u00a7");
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement