From b58e04707dc3dd8db5c20881e401bff736be970f Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 4 May 2011 00:52:17 -0700 Subject: [PATCH] Timer flags timer removed. It will be restored when it gets rewritten to not leak memory and to handle messages better. --- .../worldguard/bukkit/WorldGuardPlugin.java | 3 - .../protection/TimedFlagPlayerInfo.java | 45 ---- .../protection/TimedFlagsTimer.java | 194 ------------------ .../protection/regions/ProtectedRegion.java | 12 ++ 4 files changed, 12 insertions(+), 242 deletions(-) delete mode 100644 src/main/java/com/sk89q/worldguard/protection/TimedFlagPlayerInfo.java delete mode 100644 src/main/java/com/sk89q/worldguard/protection/TimedFlagsTimer.java diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index e8c28174..274ffe49 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -134,9 +134,6 @@ public void onEnable() { (new WorldGuardEntityListener(this)).registerEvents(); (new WorldGuardWeatherListener(this)).registerEvents(); - // 25 equals about 1s real time - getServer().getScheduler().scheduleAsyncRepeatingTask(this, new TimedFlagsTimer(this), 0, 5); - if (configuration.suppressTickSyncWarnings) { Logger.getLogger("Minecraft").setFilter( new TickSyncDelayLoggerFilter()); diff --git a/src/main/java/com/sk89q/worldguard/protection/TimedFlagPlayerInfo.java b/src/main/java/com/sk89q/worldguard/protection/TimedFlagPlayerInfo.java deleted file mode 100644 index 77e65017..00000000 --- a/src/main/java/com/sk89q/worldguard/protection/TimedFlagPlayerInfo.java +++ /dev/null @@ -1,45 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -package com.sk89q.worldguard.protection; - -import java.util.List; - -import com.sk89q.worldguard.protection.regions.ProtectedRegion; - -/** - * - * @author Redecouverte - */ -public class TimedFlagPlayerInfo { - - public long lastHealTick; - public Long sheduledHealTick; - public int sheduledHealAmount; - public List lastRegions; - public String lastFarewellMsg; - - public TimedFlagPlayerInfo() - { - this.sheduledHealTick = null; - this.lastRegions = null; - this.lastFarewellMsg = null; - } - -} diff --git a/src/main/java/com/sk89q/worldguard/protection/TimedFlagsTimer.java b/src/main/java/com/sk89q/worldguard/protection/TimedFlagsTimer.java deleted file mode 100644 index dcba8fdc..00000000 --- a/src/main/java/com/sk89q/worldguard/protection/TimedFlagsTimer.java +++ /dev/null @@ -1,194 +0,0 @@ -// $Id$ -/* - * WorldGuard - * Copyright (C) 2010 sk89q - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.protection; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.protection.flags.DefaultFlag; -import com.sk89q.worldguard.protection.flags.StateFlag.State; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import com.sk89q.worldguard.bukkit.ConfigurationManager; -import com.sk89q.worldguard.bukkit.WorldConfiguration; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import org.bukkit.entity.Player; -import static com.sk89q.worldguard.bukkit.BukkitUtil.*; - -/** - * Timer for handling flags that require a constant timer.. - * - * @author Michael - */ -public class TimedFlagsTimer implements Runnable { - - private WorldGuardPlugin plugin; - - private Map playerData; - - /** - * Construct the object. - * - * @param plugin - */ - public TimedFlagsTimer(WorldGuardPlugin plugin) { - this.plugin = plugin; - this.playerData = new HashMap(); - } - - private TimedFlagPlayerInfo getPlayerInfo(String name) { - TimedFlagPlayerInfo ret = playerData.get(name); - if (ret == null) { - ret = new TimedFlagPlayerInfo(); - playerData.put(name, ret); - } - - return ret; - } - - public void run() { - Player[] players = plugin.getServer().getOnlinePlayers(); - - for (Player player : players) { - TimedFlagPlayerInfo playerInfo = getPlayerInfo(player.getName()); - ConfigurationManager config = plugin.getGlobalConfiguration(); - WorldConfiguration worldConfig = config.get(player.getWorld()); - - if (worldConfig.useRegions) { - Vector playerLocation = toVector(player.getLocation()); - RegionManager regionManager = plugin.getGlobalRegionManager().get(player.getWorld()); - ApplicableRegionSet applicableRegions = regionManager.getApplicableRegions(playerLocation); - - List protectedRegions = new ArrayList(); - Iterator protectedRegionsIterator = applicableRegions.iterator(); - Iterator prevProtectedRegionIterator = null; - - if (playerInfo.lastRegions != null) - prevProtectedRegionIterator = playerInfo.lastRegions.iterator(); - - // ---- - // ==== Healing Flags ==== - // ---- - - long time = System.currentTimeMillis(); - - if (playerInfo.sheduledHealTick != null && time >= playerInfo.sheduledHealTick) { - player.setHealth(player.getHealth() + playerInfo.sheduledHealAmount); - playerInfo.sheduledHealTick = null; - playerInfo.lastHealTick = time; - } - - while(protectedRegionsIterator.hasNext()) { - ProtectedRegion protectedRegion = protectedRegionsIterator.next(); - - Integer healDelay = protectedRegion.getFlag(DefaultFlag.HEAL_DELAY); - Integer healAmount = protectedRegion.getFlag(DefaultFlag.HEAL_AMOUNT); - - if (healDelay != null && healAmount != null && healDelay > 0) { - healDelay *= 1000; - - if (time - playerInfo.lastHealTick > healDelay) { - if (player.getHealth() < 20) { - if (player.getHealth() + healAmount > 20) - player.setHealth(20); - else - player.setHealth(player.getHealth() + healAmount); - } - } - else { - playerInfo.sheduledHealTick = time + healDelay; - playerInfo.sheduledHealAmount = healAmount; - } - } - - // ---- - // ==== Greeting Flags ==== - // ---- - - if (playerInfo.lastRegions != null && !playerInfo.lastRegions.contains(protectedRegion)) { - String greetMsg = protectedRegion.getFlag(DefaultFlag.GREET_MESSAGE); - Boolean notifyGreet = protectedRegion.getFlag(DefaultFlag.NOTIFY_GREET); - - if (greetMsg != null) - player.sendMessage(greetMsg); - - if (notifyGreet != null && notifyGreet) - broadcastNotification(ChatColor.YELLOW + "Player " + player.getName() + " entered region " + protectedRegion.getId()); - } - - // ---- - // ==== Passthrough Flag ==== - // ---- - - State passthrough = protectedRegion.getFlag(DefaultFlag.PASSTHROUGH); - - if (passthrough != null && passthrough == State.DENY) { - Location newLoc = player.getLocation().clone(); - newLoc.setX(newLoc.getBlockX() - 30); - newLoc.setY(newLoc.getWorld().getHighestBlockYAt(newLoc) + 1); - player.teleport(newLoc); - } - - if (!protectedRegions.contains(protectedRegion)) - protectedRegions.add(protectedRegion); - } - - // ---- - // ==== Farewell Flags ==== - // ---- - - if (prevProtectedRegionIterator != null) { - while(prevProtectedRegionIterator.hasNext()) { - ProtectedRegion protectedRegion = prevProtectedRegionIterator.next(); - - if (!protectedRegions.contains(protectedRegion)) { - String farewellMsg = protectedRegion.getFlag(DefaultFlag.FAREWELL_MESSAGE); - Boolean notifyFarewell = protectedRegion.getFlag(DefaultFlag.NOTIFY_FAREWELL); - - if (farewellMsg != null) - player.sendMessage(farewellMsg); - - if (notifyFarewell != null && notifyFarewell) - broadcastNotification(ChatColor.YELLOW + "Player " + player.getName() + " left region " + protectedRegion.getId()); - } - } - } - - playerInfo.lastRegions = protectedRegions; - } - } - } - - public void broadcastNotification(String msg) { - for (Player player : plugin.getServer().getOnlinePlayers()) { - if (plugin.hasPermission(player, "notify_onenter")) { - player.sendMessage(msg); - } - } - } - -} diff --git a/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegion.java b/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegion.java index 79541c71..10ce8b9b 100644 --- a/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegion.java +++ b/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegion.java @@ -43,22 +43,27 @@ public abstract class ProtectedRegion implements Comparable { * Holds the region's ID. */ private String id; + /** * Priority. */ private int priority = 0; + /** * Holds the curParent. */ private ProtectedRegion parent; + /** * List of owners. */ private DefaultDomain owners = new DefaultDomain(); + /** * List of members. */ private DefaultDomain members = new DefaultDomain(); + /** * List of flags. */ @@ -314,6 +319,13 @@ public int compareTo(ProtectedRegion other) { */ public abstract String getTypeName(); + /** + * Get a list of intersecting regions. + * + * @param regions + * @return + * @throws UnsupportedIntersectionException + */ public abstract List getIntersectingRegions( List regions) throws UnsupportedIntersectionException;