Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.54 KB | None | 0 0
  1. package de.astra0815.cuthelper;
  2.  
  3. import com.sk89q.worldedit.BlockVector;
  4. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
  5. import com.sk89q.worldguard.domains.DefaultDomain;
  6. import com.sk89q.worldguard.protection.ApplicableRegionSet;
  7. import com.sk89q.worldguard.protection.managers.RegionManager;
  8. import com.sk89q.worldguard.protection.regions.ProtectedRegion;
  9. import java.util.Iterator;
  10. import java.util.LinkedList;
  11. import java.util.logging.Logger;
  12. import org.bukkit.ChatColor;
  13. import org.bukkit.Location;
  14. import org.bukkit.Material;
  15. import org.bukkit.Server;
  16. import org.bukkit.World;
  17. import org.bukkit.block.Block;
  18. import org.bukkit.command.Command;
  19. import org.bukkit.command.CommandSender;
  20. import org.bukkit.configuration.file.FileConfiguration;
  21. import org.bukkit.configuration.file.FileConfigurationOptions;
  22. import org.bukkit.entity.Player;
  23. import org.bukkit.event.HandlerList;
  24. import org.bukkit.plugin.Plugin;
  25. import org.bukkit.plugin.PluginManager;
  26. import org.bukkit.plugin.java.JavaPlugin;
  27.  
  28. public final class Cuthelper extends JavaPlugin
  29. {
  30. public void loadConfiguration()
  31. {
  32. getConfig().addDefault("mysql.database", "database");
  33. getConfig().addDefault("mysql.user", "user");
  34. getConfig().addDefault("mysql.password", "password");
  35. getConfig().addDefault("mysql.dsn", "jdbc:mysql://localhost:3306/");
  36.  
  37. getConfig().options().copyDefaults(true);
  38.  
  39. saveConfig();
  40. }
  41.  
  42. public void onEnable()
  43. {
  44. getLogger().info("Cuthelper loaded and ready");
  45. loadConfiguration();
  46. }
  47.  
  48. public void onDisable()
  49. {
  50. getLogger().info("onDisable has been invoked!");
  51. HandlerList.unregisterAll(this);
  52. }
  53.  
  54. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
  55. {
  56. if (cmd.getName().equalsIgnoreCase("cutme"))
  57. {
  58. if (args.length == 0)
  59. {
  60. sender.sendMessage("Willkommen im Cuthelper!");
  61. sender.sendMessage("----------------------------");
  62. sender.sendMessage("/cutme info");
  63. sender.sendMessage("/cutme tp <GSName>");
  64. sender.sendMessage("/cutme clean");
  65.  
  66. return true;
  67. }
  68.  
  69. if (!(sender instanceof Player))
  70. {
  71. sender.sendMessage("This command can only be run by a player.");
  72. }
  73. else
  74. {
  75. Player player = (Player)sender;
  76. String command = args[0];
  77.  
  78. if (command.equalsIgnoreCase("info"))
  79. {
  80. if ((player.isOp()) || (player.hasPermission("cutme.info"))) {
  81. World currentWorld = player.getWorld();
  82.  
  83. LinkedList regions = myregion(player);
  84. if (regions.isEmpty()) {
  85. sender.sendMessage(ChatColor.GREEN + "Hier ist kein Grundstück, du kannst dir keine Infos anzeigen.");
  86. }
  87. else
  88. {
  89. ProtectedRegion myRegion = getRegionIfExists(currentWorld, regions.getFirst().toString());
  90. sender.sendMessage(ChatColor.GREEN + "Grundstücksname: " + regions.getFirst().toString());
  91. sender.sendMessage(ChatColor.GREEN + "Eigentümer: " + myRegion.getOwners().toPlayersString());
  92.  
  93. player.chat("/seen " + myRegion.getOwners().toPlayersString());
  94. }
  95. }
  96. else
  97. {
  98. sender.sendMessage(ChatColor.RED + "Du darfst diesen Befehl nicht ausführen!");
  99. }
  100.  
  101. return true;
  102. }
  103.  
  104. if (command.equalsIgnoreCase("tp"))
  105. {
  106. if ((player.isOp()) || (player.hasPermission("cutme.cantp")))
  107. {
  108. World currentWorld = player.getWorld();
  109. ProtectedRegion myRegion = getRegionIfExists(currentWorld, args[1]);
  110. if (myRegion == null) {
  111. sender.sendMessage(ChatColor.RED + "Das Grundstück existiert in dieser Welt nicht !");
  112. }
  113. else
  114. {
  115. Location loc = new Location(currentWorld, myRegion.getMaximumPoint().getX() + 1.0D, 65.0D, myRegion.getMaximumPoint().getZ() + 1.0D);
  116. player.teleport(loc);
  117. }
  118. } else {
  119. sender.sendMessage(ChatColor.RED + "Du darfst diesen Befehl nicht ausführen!");
  120. }
  121.  
  122. return true;
  123. }
  124.  
  125. if (command.equalsIgnoreCase("clean"))
  126. {
  127. if ((player.isOp()) || (player.hasPermission("cutme.canclean"))) {
  128. World currentWorld = player.getWorld();
  129.  
  130. LinkedList regions = myregion(player);
  131. if (regions.isEmpty()) {
  132. sender.sendMessage(ChatColor.GREEN + "Hier ist kein Grundstück, du kannst dir keine Infos anzeigen.");
  133. }
  134. else
  135. {
  136. ProtectedRegion myRegion = getRegionIfExists(currentWorld, regions.getFirst().toString());
  137.  
  138. if (myRegion.getPriority() >= 0) {
  139. for (int x = myRegion.getMinimumPoint().getBlockX(); x <= myRegion.getMaximumPoint().getBlockX(); x++) {
  140. for (int z = myRegion.getMinimumPoint().getBlockZ(); z <= myRegion.getMaximumPoint().getBlockZ(); z++) {
  141. for (int y = 1; y <= 255; y++)
  142. {
  143. Block block = player.getWorld().getBlockAt(x, y, z);
  144. if (block.getType() == Material.CHEST) {
  145. block.setType(Material.STONE);
  146. }
  147. if (block.getType() == Material.FURNACE) {
  148. block.setType(Material.STONE);
  149. }
  150. if (block.getType() == Material.HOPPER) {
  151. block.setType(Material.STONE);
  152. }
  153.  
  154. if ((y >= 65) && (block.getType() != Material.AIR))
  155. block.setType(Material.AIR);
  156. else if ((y <= 64) && (y >= 55))
  157. block.setType(Material.GRASS);
  158. else if ((y < 64) && (block.getType() != Material.STONE)) {
  159. block.setType(Material.STONE);
  160. }
  161. }
  162.  
  163. }
  164.  
  165. }
  166.  
  167. for (int x = myRegion.getMinimumPoint().getBlockX(); x <= myRegion.getMinimumPoint().getBlockX() + 4; x++) {
  168. Block block = player.getWorld().getBlockAt(x + 6, 65, myRegion.getMinimumPoint().getBlockZ() + 3);
  169. block.setType(Material.SAND);
  170. }
  171. Block block = player.getWorld().getBlockAt(myRegion.getMinimumPoint().getBlockX() + 8, 65, myRegion.getMinimumPoint().getBlockZ() + 4);
  172. block.setType(Material.SAND);
  173. block = player.getWorld().getBlockAt(myRegion.getMinimumPoint().getBlockX() + 10, 65, myRegion.getMinimumPoint().getBlockZ() + 4);
  174. block.setType(Material.SAND);
  175. block = player.getWorld().getBlockAt(myRegion.getMinimumPoint().getBlockX() + 10, 65, myRegion.getMinimumPoint().getBlockZ() + 5);
  176. block.setType(Material.SAND);
  177.  
  178. int x = myRegion.getMaximumPoint().getBlockX() - myRegion.getMinimumPoint().getBlockX();
  179. int z = myRegion.getMaximumPoint().getBlockZ() - myRegion.getMinimumPoint().getBlockZ();
  180. x /= 2;
  181. z /= 2;
  182. block = player.getWorld().getBlockAt(myRegion.getMinimumPoint().getBlockX() + x, 64, myRegion.getMinimumPoint().getBlockZ() + z);
  183. block.setType(Material.BRICK);
  184.  
  185. player.chat("//rg select " + regions.getFirst().toString());
  186. player.chat("//rg set owner");
  187. player.chat("/remove drops 100");
  188. }
  189. else {
  190. sender.sendMessage(ChatColor.RED + "Die Region resette ich nicht :p");
  191. }
  192. sender.sendMessage(ChatColor.GREEN + "Grundstück resetet");
  193. }
  194. } else {
  195. sender.sendMessage(ChatColor.RED + "Du darfst diesen Befehl nicht ausführen!");
  196. }
  197.  
  198. return true;
  199. }
  200.  
  201. sender.sendMessage("Den Befehl verstehe ich nicht.");
  202. }
  203. }
  204.  
  205. return false;
  206. }
  207.  
  208. private WorldGuardPlugin getWorldGuard() {
  209. Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
  210. getLogger().info("plugins loaded: " + getServer().getPluginManager().getPlugins().length);
  211.  
  212. if ((plugin == null) || (!(plugin instanceof WorldGuardPlugin))) {
  213. getLogger().info("Couldn't load world guard plugin...");
  214. return null;
  215. }
  216.  
  217. return (WorldGuardPlugin)plugin;
  218. }
  219.  
  220. private LinkedList myregion(Player player)
  221. {
  222. World currentWorld = player.getWorld();
  223. RegionManager regionManager = getRegionManager(currentWorld);
  224. ApplicableRegionSet set = regionManager.getApplicableRegions(player.getLocation());
  225. LinkedList parentNames = new LinkedList();
  226. LinkedList regions = new LinkedList();
  227. ProtectedRegion parent;
  228. for (Iterator localIterator = set.iterator(); localIterator.hasNext();
  229. parent != null)
  230. {
  231. ProtectedRegion region = (ProtectedRegion)localIterator.next();
  232. String id = region.getId();
  233. regions.add(id);
  234. parent = region.getParent();
  235. continue;
  236. parentNames.add(parent.getId());
  237. parent = parent.getParent();
  238. }
  239.  
  240. return regions;
  241. }
  242.  
  243. private RegionManager getRegionManager(World world) {
  244. return getWorldGuard().getRegionManager(world);
  245. }
  246.  
  247. private ProtectedRegion getRegionIfExists(World world, String regionName) {
  248. RegionManager regionManager = getRegionManager(world);
  249. return regionManager.getRegion(regionName);
  250. }
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement