Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.63 KB | None | 0 0
  1. package me.camdenorrb.bukkit.plugins;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import java.util.UUID;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.ChatColor;
  12. import org.bukkit.DyeColor;
  13. import org.bukkit.Material;
  14. import org.bukkit.command.Command;
  15. import org.bukkit.command.CommandExecutor;
  16. import org.bukkit.command.CommandSender;
  17. import org.bukkit.command.ConsoleCommandSender;
  18. import org.bukkit.configuration.file.FileConfiguration;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.event.EventHandler;
  21. import org.bukkit.event.Listener;
  22. import org.bukkit.event.inventory.InventoryClickEvent;
  23. import org.bukkit.event.player.AsyncPlayerChatEvent;
  24. import org.bukkit.event.player.PlayerJoinEvent;
  25. import org.bukkit.inventory.Inventory;
  26. import org.bukkit.inventory.ItemStack;
  27. import org.bukkit.inventory.meta.ItemMeta;
  28. import org.bukkit.material.Dye;
  29. import org.bukkit.material.Wool;
  30. import org.bukkit.plugin.Plugin;
  31. import org.bukkit.plugin.java.JavaPlugin;
  32.  
  33. public class Chat extends JavaPlugin implements Listener, CommandExecutor {
  34.  
  35. Wool wool = new Wool(DyeColor.PINK);
  36. ItemStack pink = wool.toItemStack();
  37.  
  38. private final Map<UUID, ChatColor> playerColors = new HashMap<>();
  39. private final ArrayList<String> words = new ArrayList<>(Arrays.asList("cunt", "twat", "faggot", "asshole", "fuck", "shit", "pussy", "dick", "bitch", "anal", "penis", "nigger", "nigga", "vagina"));
  40. private final ArrayList<String> WhiteList = new ArrayList<>(Arrays.asList("bass", "derp"));
  41. private static Plugin plugin;
  42. private static Listener plugin2;
  43. private static boolean bool;
  44. FileConfiguration config = getConfig();
  45.  
  46. public Inventory inv;
  47. Dye on = new Dye();
  48. Dye off = new Dye();
  49. ItemStack Lapis = new ItemStack(Material.LAPIS_BLOCK);
  50. ItemStack redstone = new ItemStack(Material.REDSTONE_BLOCK);
  51. ItemStack emerald = new ItemStack(Material.EMERALD_BLOCK);
  52. ItemStack gold = new ItemStack(Material.GOLD_BLOCK);
  53. ItemMeta Pink = pink.getItemMeta();
  54. ItemMeta diamondMETA = Lapis.getItemMeta();
  55. ItemMeta redstoneMETA = redstone.getItemMeta();
  56. ItemMeta emeraldMETA = emerald.getItemMeta();
  57. ItemMeta goldMETA = gold.getItemMeta();
  58.  
  59. List<String> toggled = new ArrayList<>();
  60.  
  61. public void openGUI(Player p) {
  62. inv = Bukkit.createInventory(null, 9, ChatColor.RED + "Colors!"); //format: null, size of inventory (must be divisible by 9), "GUI name"
  63. diamondMETA.setDisplayName(ChatColor.BLUE + "BLUE!");
  64.  
  65. redstoneMETA.setDisplayName(ChatColor.RED + "Red");
  66. emeraldMETA.setDisplayName(ChatColor.GREEN + "Green");
  67. goldMETA.setDisplayName(ChatColor.YELLOW + "Yellow");
  68. Pink.setDisplayName(ChatColor.LIGHT_PURPLE + "Pink");
  69.  
  70. Lapis.setItemMeta(diamondMETA);
  71. redstone.setItemMeta(redstoneMETA);
  72. emerald.setItemMeta(emeraldMETA);
  73. gold.setItemMeta(goldMETA);
  74. pink.setItemMeta(Pink);
  75.  
  76. inv.setItem(0, new ItemStack(Lapis));
  77. inv.setItem(1, new ItemStack(redstone));
  78. inv.setItem(2, new ItemStack(emerald));
  79. inv.setItem(3, new ItemStack(gold));
  80. inv.setItem(4, new ItemStack(pink));
  81. p.openInventory(inv);
  82. }
  83.  
  84. @Override
  85. public void onEnable() {
  86. plugin = this;
  87. plugin2 = this;
  88.  
  89. getServer().getPluginManager().registerEvents(plugin2, plugin);
  90. intializeConfig();
  91. for (Player p : Bukkit.getOnlinePlayers()) {
  92. playerJoin(p.getUniqueId());
  93. }
  94.  
  95. }
  96.  
  97. @Override
  98. public void onDisable() {
  99. plugin = null;
  100. plugin2 = null;
  101.  
  102. // TODO: Place any custom disable code here.
  103. }
  104.  
  105. private void intializeConfig() {
  106.  
  107. config.addDefault("BlockMessageOn?", true);
  108. config.addDefault("words", words);
  109. config.addDefault("whitelist", WhiteList);
  110. config.addDefault("Showmessage", "&cThe use of foul language is prohibitedd.");
  111. config.addDefault("message", "&4Please do not use foul language.");
  112. config.options().copyDefaults(true);
  113. saveConfig();
  114. }
  115.  
  116. @Override
  117. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  118.  
  119. if (cmd.getLabel().equalsIgnoreCase("color") && args.length == 1) {
  120. if (sender instanceof ConsoleCommandSender) {
  121. sender.sendMessage("This command can only be run by a player.");
  122.  
  123. return false;
  124. } else {
  125. Player player = (Player) sender;
  126.  
  127. if (args[0].equalsIgnoreCase("toggle")) {
  128. if (sender instanceof ConsoleCommandSender) {
  129. sender.sendMessage("This command can only be run by a player.");
  130. return false;
  131. } else {
  132.  
  133. if (toggled.contains(player.getName())) {
  134. sender.sendMessage(ChatColor.GREEN + "Turn On Color With /color");
  135. toggled.add(player.getName());
  136. return true;
  137. } else {
  138.  
  139. playerColors.put(player.getUniqueId(), ChatColor.RESET);
  140. sender.sendMessage(ChatColor.GREEN + "You DeActivated Your Chat Color!@!");
  141. toggled.remove(player.getName());
  142. return true;
  143. }
  144. }
  145. } else if (args[0].equalsIgnoreCase("reload")) {
  146. if(player.hasPermission("color.reload")){
  147.  
  148. return true;
  149. }else{
  150. player.sendMessage(ChatColor.GREEN+"You Do Not Have Permissions Required To "+ChatColor.RED+"Reload");
  151. return true;
  152. }
  153.  
  154. }
  155. }
  156. } else if (cmd.getLabel().equalsIgnoreCase("color") && args.length == 0) {
  157.  
  158. if (sender instanceof ConsoleCommandSender) {
  159. sender.sendMessage("This command can only be run by a player.");
  160. return false;
  161. } else {
  162. Player player = (Player) sender;
  163. openGUI(player);
  164. return true;
  165. }
  166. }
  167.  
  168. return false;
  169. }
  170.  
  171. @EventHandler
  172. public void playerChat(AsyncPlayerChatEvent e) {
  173. String message = getConfig().getString("message").replaceAll("(&([a-f0-9]))", "\u00A7$2").replaceAll("($([a-f0-9]))", "\u00A7$2").replaceAll("(%([a-f0-9]))", "\u00A7$2");
  174. String Showmessage = getConfig().getString("Showmessage").replaceAll("(&([a-f0-9]))", "\u00A7$2").replaceAll("($([a-f0-9]))", "\u00A7$2").replaceAll("(%([a-f0-9]))", "\u00A7$2");
  175.  
  176. if (config.getStringList("whitelist").contains(e.getMessage().toLowerCase())) {
  177.  
  178.  
  179.  
  180. bool = false;
  181. }else{
  182. bool = true;
  183.  
  184.  
  185. if (bool == true) {
  186. for (String word : getConfig().getStringList("words")) {
  187. String sent = e.getMessage().toLowerCase().replaceAll("\\.", "").replaceAll("&", "");
  188. if (sent.contains(word)) {
  189.  
  190. bool = true;
  191.  
  192. if (config.getBoolean("BlockMessageOn?") == true && bool == true) {
  193.  
  194. e.setMessage(Showmessage.replaceAll("'", "").replaceAll("’", "").replaceAll("‘", ""));
  195. e.getPlayer().sendMessage(message.replaceAll("'", "").replaceAll("’", "").replaceAll("‘", ""));
  196.  
  197.  
  198.  
  199.  
  200. } else {
  201.  
  202. bool = false;
  203.  
  204.  
  205.  
  206. }
  207. }
  208. }
  209. }
  210. }
  211.  
  212. ChatColor test = playerColors.get(e.getPlayer().getUniqueId());
  213. e.setMessage(test + e.getMessage());
  214.  
  215. }
  216.  
  217. @EventHandler
  218. public void onJoinEvent(PlayerJoinEvent e) {
  219. if (playerColors.get(e.getPlayer().getUniqueId()) != null) {
  220. } else {
  221. playerJoin(e.getPlayer().getUniqueId());
  222. }
  223. }
  224.  
  225. public void playerJoin(UUID u) {
  226.  
  227. playerColors.put(u, ChatColor.RESET);
  228. }
  229.  
  230. @EventHandler //MAKE SURE YOU HAVE THIS
  231. public void InventoryClick(InventoryClickEvent e) {
  232. Player p = (Player) e.getWhoClicked();
  233.  
  234. if (e.getInventory().getTitle().contains(ChatColor.RED + "Colors!")) {
  235. e.setCancelled(true); //Cancel the event so they can't take items out of the GUI
  236.  
  237. if (e.getCurrentItem() == null) {
  238. } else {
  239.  
  240. if (e.getCurrentItem().getType() == Material.LAPIS_BLOCK) {
  241. //gets called when the current item's type (The item the player clicked) is a diamond
  242.  
  243. playerColors.put(p.getUniqueId(), ChatColor.BLUE);
  244. p.closeInventory(); //call if you want to close the inventory when they click it
  245.  
  246. } else if (e.getCurrentItem().getType() == Material.REDSTONE_BLOCK) {
  247. //gets called when the current item's type (The item the player clicked) is a diamond
  248.  
  249. playerColors.put(p.getUniqueId(), ChatColor.RED);
  250. p.closeInventory(); //call if you want to close the inventory when they click it
  251. intializeConfig();
  252.  
  253. } else if (e.getCurrentItem().getType() == Material.EMERALD_BLOCK) {
  254. //gets called when the current item's type (The item the player clicked) is a diamond
  255.  
  256. playerColors.put(p.getUniqueId(), ChatColor.GREEN);
  257. p.closeInventory(); //call if you want to close the inventory when they click it
  258. intializeConfig();
  259.  
  260. } else if (e.getCurrentItem().getType() == Material.GOLD_BLOCK) {
  261. //gets called when the current item's type (The item the player clicked) is a diamond
  262.  
  263. playerColors.put(p.getUniqueId(), ChatColor.YELLOW);
  264.  
  265. p.closeInventory(); //call if you want to close the inventory when they click it
  266.  
  267. } else if (e.getCurrentItem().getItemMeta().equals(Pink)) {
  268. //gets called when the current item's type (The item the player clicked) is a diamond
  269.  
  270. playerColors.put(p.getUniqueId(), ChatColor.LIGHT_PURPLE);
  271.  
  272. p.closeInventory(); //call if you want to close the inventory when they click it
  273.  
  274. }
  275. }
  276. }
  277. }
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement