Advertisement
jts3304

Untitled

Jun 29th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. package me.jts3304.denyspawn;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.World;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.LivingEntity;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.entity.CreatureSpawnEvent;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. public class DenySpawn extends JavaPlugin implements Listener{
  18.  
  19. public void onEnable() {
  20. this.getConfig().options().copyDefaults(true);
  21. this.saveDefaultConfig();
  22.  
  23. Bukkit.getServer().getPluginManager().registerEvents(this, this);
  24. }
  25.  
  26. public void onDisable() {
  27. this.saveDefaultConfig();
  28. }
  29.  
  30. public boolean checkEntityFromString(String string) {
  31. if (org.bukkit.entity.EntityType.valueOf(string) == null) return false;
  32.  
  33. return true;
  34. }
  35.  
  36. public boolean worldInConfig(String world) {
  37. if (getServer().getWorld(world) == null) return false;
  38. if (getConfig().getConfigurationSection(world) == null) return false;
  39.  
  40. return true;
  41. }
  42.  
  43. public void removeNullWorlds() {
  44. for (String s : getConfig().getKeys(false)) {
  45. if (Bukkit.getWorld(s) == null) {
  46. getConfig().set(s, null);
  47. saveConfig();
  48. reloadConfig();
  49. }
  50. }
  51. }
  52.  
  53. @EventHandler
  54. public void onMobSpawn(CreatureSpawnEvent event) {
  55. LivingEntity mob = event.getEntity();
  56.  
  57. removeNullWorlds();
  58.  
  59. for (World w : getServer().getWorlds()) {
  60. if (worldInConfig(w.getName())) {
  61. for (String s : getConfig().getStringList(w.getName() + ".DeniedMobs")) {
  62. if (checkEntityFromString(s)) {
  63. if (mob.getType() == org.bukkit.entity.EntityType.valueOf(s)) {
  64. event.setCancelled(true);
  65. }
  66. }
  67. }
  68. }
  69. else {
  70. getConfig().createSection(w.getName());
  71. getConfig().set(w.getName() + ".DeniedMobs", new ArrayList<String>());
  72. saveConfig();
  73. reloadConfig();
  74. }
  75. }
  76. }
  77.  
  78. public boolean onCommand(CommandSender s, Command c, String label, String args[]) {
  79. if (!(s instanceof Player)) {
  80. if (c.getName().equalsIgnoreCase("denyspawn")) {
  81. if (args.length == 1) {
  82. if (args[0].equalsIgnoreCase("reload")) {
  83. reloadConfig();
  84. s.sendMessage("Config reloaded.");
  85. return true;
  86. }
  87. }
  88. }
  89. }
  90.  
  91. Player p = (Player) s;
  92.  
  93. if (args.length == 0) {
  94. if (p.hasPermission("denyspawn.use") || p.isOp()) {
  95. p.sendMessage(ChatColor.GREEN + "/denyspawn reload");
  96. return true;
  97. }
  98. else {
  99. return true;
  100. }
  101. }
  102. else if (args.length == 1) {
  103. if (args[0].equalsIgnoreCase("reload")) {
  104. if (p.hasPermission("denyspawn.reload") || p.isOp()) {
  105. reloadConfig();
  106. p.sendMessage(ChatColor.GREEN + "Config reloaded.");
  107. return true;
  108. }
  109. }
  110. else {
  111. return true;
  112. }
  113. }
  114. else {
  115. return true;
  116. }
  117.  
  118. return false;
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement