Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. package co.uk.tekkitservers.walkonwater;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.Map.Entry;
  8. import java.util.UUID;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.Location;
  12. import org.bukkit.Material;
  13. import org.bukkit.block.Block;
  14. import org.bukkit.command.Command;
  15. import org.bukkit.command.CommandSender;
  16. import org.bukkit.entity.Player;
  17. import org.bukkit.event.EventHandler;
  18. import org.bukkit.event.Listener;
  19. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
  20. import org.bukkit.event.player.PlayerMoveEvent;
  21. import org.bukkit.plugin.Plugin;
  22. import org.bukkit.plugin.java.JavaPlugin;
  23. import org.bukkit.scheduler.BukkitScheduler;
  24.  
  25. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
  26. import com.sk89q.worldguard.protection.ApplicableRegionSet;
  27. import com.sk89q.worldguard.protection.regions.ProtectedRegion;
  28.  
  29. import me.ryanhamshire.GriefPrevention.Claim;
  30. import me.ryanhamshire.GriefPrevention.GriefPrevention;
  31.  
  32. public class main extends JavaPlugin implements Listener {
  33. WorldGuardPlugin wgp;
  34. public List<ProtectedRegion> pr = new ArrayList();
  35. @Override
  36. public void onEnable() {
  37. getCommand("waterwalktoggle").setExecutor(new main());
  38. Bukkit.getPluginManager().registerEvents(this, this);
  39. this.wgp = getWorldGuard();
  40. }
  41. public WorldGuardPlugin getWorldGuardPlugin()
  42. {
  43. return this.wgp;
  44. }
  45.  
  46. private WorldGuardPlugin getWorldGuard()
  47. {
  48. Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
  49. if ((plugin == null) || (!(plugin instanceof WorldGuardPlugin))) {
  50. return null;
  51. }
  52. return (WorldGuardPlugin)plugin;
  53. }
  54. @EventHandler
  55. public void onWaterWalkToggle(PlayerCommandPreprocessEvent e){
  56. Player p = e.getPlayer();
  57. ApplicableRegionSet ars = getWorldGuardPlugin().getRegionManager(e.getPlayer().getWorld()).getApplicableRegions(p.getLocation());
  58. Claim claim = GriefPrevention.instance.dataStore.getClaimAt(p.getLocation(), false, null);
  59. if ((e.getMessage().startsWith("/waterwalktoggle")) && ((claim != null) || (ars.iterator().hasNext()))){
  60. p.sendMessage("§3Water§bWalk: §cYou cannot enable this in a claim/world guard region!");
  61. e.setCancelled(true);
  62.  
  63. }
  64.  
  65. }
  66. @EventHandler
  67. public void onJesusWalking(PlayerMoveEvent e) {
  68. final Player player = e.getPlayer();
  69. if (player == null){
  70. return;
  71. }
  72. if (!player.hasPermission("walk.onwater")){
  73. return;
  74. }
  75. if (waterwalk.contains(player.getUniqueId())){
  76. return;
  77. }
  78. ApplicableRegionSet ars = getWorldGuardPlugin().getRegionManager(e.getPlayer().getWorld()).getApplicableRegions(player.getLocation());
  79. if ((ars.iterator().hasNext()) && (!waterwalk.contains(player.getUniqueId()))){
  80. player.sendMessage("§3Water§bWalk: §cToggled Off, You cannot waterwalk in a WG Region!");
  81. waterwalk.add(player.getUniqueId());
  82. return;
  83. }
  84. Claim claim = GriefPrevention.instance.dataStore.getClaimAt(player.getLocation(), false, null);
  85. if ((claim != null) && (!waterwalk.contains(player.getUniqueId()))){
  86. player.sendMessage("§3Water§bWalk: §cToggled Off, You cannot waterwalk in a claim!");
  87. waterwalk.add(player.getUniqueId());
  88. return;
  89. }
  90.  
  91. Location playerLocation = player.getLocation();
  92. final int x = playerLocation.getBlockX();
  93. final int y = playerLocation.getBlockY() - 1;
  94. final int z = playerLocation.getBlockZ();
  95. Map<Location, Material> changes = new HashMap<Location, Material>();
  96. List<Location> checkLocations = new ArrayList<Location>();
  97. for (int xInc = -23; xInc <= 3; xInc++) {
  98. int tempX = x + xInc;
  99. for (int zInc = -3; zInc <= 3; zInc++) {
  100. int tempZ = z + zInc;
  101. for (int yInc = -1; yInc <= 0; yInc++) {
  102. int tempY = y + yInc;
  103. checkLocations.add(new Location(playerLocation.getWorld(), tempX, tempY, tempZ));
  104. }
  105. }
  106. }
  107. for (Location loc : checkLocations) {
  108. Block block = loc.getBlock();
  109. if (block == null || block.getType() == null)
  110. continue;
  111. if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) {
  112. changes.put(loc, block.getType());
  113. block.setType(Material.ICE);
  114. }
  115. }
  116. if (changes.size() == 0)
  117. return;
  118. schedule(player, changes);
  119. }
  120.  
  121. private void schedule(final Player player, Map<Location, Material> changes) {
  122. Map<Location, Material> additionalChanges = new HashMap<Location, Material>();
  123. BukkitScheduler scheduler = Bukkit.getScheduler();
  124. scheduler.scheduleSyncDelayedTask(this, new Runnable() {
  125. @Override
  126. public void run() {
  127. Location currentLocation = player.getLocation();
  128. for (Entry<Location, Material> entry : changes.entrySet()) {
  129. if (entry.getKey().distance(currentLocation) > 3) {
  130. entry.getKey().getBlock().setType(entry.getValue());
  131. } else {
  132. additionalChanges.put(entry.getKey(), entry.getValue());
  133. }
  134. }
  135. if (additionalChanges.size() != 0) {
  136. schedule(player, additionalChanges);
  137. }
  138. }
  139. }, (long) (20 * 2));
  140. }
  141.  
  142. public static ArrayList<UUID> waterwalk = new ArrayList();
  143. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
  144. {
  145. if (cmd.getName().equalsIgnoreCase("waterwalktoggle"))
  146. {
  147. Player p = (Player)sender;
  148. if (waterwalk.contains(p.getUniqueId())){
  149. waterwalk.remove(p.getUniqueId());
  150. p.sendMessage("§3Water§bWalk: §aToggled On!");
  151. return true;
  152. }
  153. waterwalk.add(p.getUniqueId());
  154. p.sendMessage("§3Water§bWalk: §cToggled Off");
  155. return true;
  156. }
  157. return false;
  158. }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement