Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package co.uk.tekkitservers.walkonwater;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerCommandPreprocessEvent;
- import org.bukkit.event.player.PlayerMoveEvent;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitScheduler;
- import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
- import com.sk89q.worldguard.protection.ApplicableRegionSet;
- import com.sk89q.worldguard.protection.regions.ProtectedRegion;
- import me.ryanhamshire.GriefPrevention.Claim;
- import me.ryanhamshire.GriefPrevention.GriefPrevention;
- public class main extends JavaPlugin implements Listener {
- WorldGuardPlugin wgp;
- public List<ProtectedRegion> pr = new ArrayList();
- @Override
- public void onEnable() {
- getCommand("waterwalktoggle").setExecutor(new main());
- Bukkit.getPluginManager().registerEvents(this, this);
- this.wgp = getWorldGuard();
- }
- public WorldGuardPlugin getWorldGuardPlugin()
- {
- return this.wgp;
- }
- private WorldGuardPlugin getWorldGuard()
- {
- Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
- if ((plugin == null) || (!(plugin instanceof WorldGuardPlugin))) {
- return null;
- }
- return (WorldGuardPlugin)plugin;
- }
- @EventHandler
- public void onWaterWalkToggle(PlayerCommandPreprocessEvent e){
- Player p = e.getPlayer();
- ApplicableRegionSet ars = getWorldGuardPlugin().getRegionManager(e.getPlayer().getWorld()).getApplicableRegions(p.getLocation());
- Claim claim = GriefPrevention.instance.dataStore.getClaimAt(p.getLocation(), false, null);
- if ((e.getMessage().startsWith("/waterwalktoggle")) && ((claim != null) || (ars.iterator().hasNext()))){
- p.sendMessage("§3Water§bWalk: §cYou cannot enable this in a claim/world guard region!");
- e.setCancelled(true);
- }
- }
- @EventHandler
- public void onJesusWalking(PlayerMoveEvent e) {
- final Player player = e.getPlayer();
- if (player == null){
- return;
- }
- if (!player.hasPermission("walk.onwater")){
- return;
- }
- if (waterwalk.contains(player.getUniqueId())){
- return;
- }
- ApplicableRegionSet ars = getWorldGuardPlugin().getRegionManager(e.getPlayer().getWorld()).getApplicableRegions(player.getLocation());
- if ((ars.iterator().hasNext()) && (!waterwalk.contains(player.getUniqueId()))){
- player.sendMessage("§3Water§bWalk: §cToggled Off, You cannot waterwalk in a WG Region!");
- waterwalk.add(player.getUniqueId());
- return;
- }
- Claim claim = GriefPrevention.instance.dataStore.getClaimAt(player.getLocation(), false, null);
- if ((claim != null) && (!waterwalk.contains(player.getUniqueId()))){
- player.sendMessage("§3Water§bWalk: §cToggled Off, You cannot waterwalk in a claim!");
- waterwalk.add(player.getUniqueId());
- return;
- }
- Location playerLocation = player.getLocation();
- final int x = playerLocation.getBlockX();
- final int y = playerLocation.getBlockY() - 1;
- final int z = playerLocation.getBlockZ();
- Map<Location, Material> changes = new HashMap<Location, Material>();
- List<Location> checkLocations = new ArrayList<Location>();
- for (int xInc = -23; xInc <= 3; xInc++) {
- int tempX = x + xInc;
- for (int zInc = -3; zInc <= 3; zInc++) {
- int tempZ = z + zInc;
- for (int yInc = -1; yInc <= 0; yInc++) {
- int tempY = y + yInc;
- checkLocations.add(new Location(playerLocation.getWorld(), tempX, tempY, tempZ));
- }
- }
- }
- for (Location loc : checkLocations) {
- Block block = loc.getBlock();
- if (block == null || block.getType() == null)
- continue;
- if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) {
- changes.put(loc, block.getType());
- block.setType(Material.ICE);
- }
- }
- if (changes.size() == 0)
- return;
- schedule(player, changes);
- }
- private void schedule(final Player player, Map<Location, Material> changes) {
- Map<Location, Material> additionalChanges = new HashMap<Location, Material>();
- BukkitScheduler scheduler = Bukkit.getScheduler();
- scheduler.scheduleSyncDelayedTask(this, new Runnable() {
- @Override
- public void run() {
- Location currentLocation = player.getLocation();
- for (Entry<Location, Material> entry : changes.entrySet()) {
- if (entry.getKey().distance(currentLocation) > 3) {
- entry.getKey().getBlock().setType(entry.getValue());
- } else {
- additionalChanges.put(entry.getKey(), entry.getValue());
- }
- }
- if (additionalChanges.size() != 0) {
- schedule(player, additionalChanges);
- }
- }
- }, (long) (20 * 2));
- }
- public static ArrayList<UUID> waterwalk = new ArrayList();
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
- {
- if (cmd.getName().equalsIgnoreCase("waterwalktoggle"))
- {
- Player p = (Player)sender;
- if (waterwalk.contains(p.getUniqueId())){
- waterwalk.remove(p.getUniqueId());
- p.sendMessage("§3Water§bWalk: §aToggled On!");
- return true;
- }
- waterwalk.add(p.getUniqueId());
- p.sendMessage("§3Water§bWalk: §cToggled Off");
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement