Fixed TimedFlagsTimer to enable HEAL_DELAY,HEAL_AMOUNT,GREETING,FAREWELL,NOTIFY_GREET,NOTIFY_FAREWELL, and PASSTHROUGH Flags.

This commit is contained in:
Steven Mattera 2011-04-18 21:10:06 -04:00 committed by sk89q
parent 906dab28c1
commit 66ee09d050
4 changed files with 113 additions and 90 deletions

View File

@ -457,7 +457,7 @@ public void findFreePosition(Player player) {
world.getBlockAt(x,0,z).setTypeId(20); world.getBlockAt(x,0,z).setTypeId(20);
loc.setY(2); loc.setY(2);
} }
player.setFallDistance(0F); // player.setFallDistance(0F);
player.teleport(loc); player.teleport(loc);
} }
return; return;

View File

@ -134,8 +134,7 @@ public void onEnable() {
(new WorldGuardEntityListener(this)).registerEvents(); (new WorldGuardEntityListener(this)).registerEvents();
// 25 equals about 1s real time // 25 equals about 1s real time
getServer().getScheduler().scheduleSyncRepeatingTask( getServer().getScheduler().scheduleAsyncRepeatingTask(this, new TimedFlagsTimer(this), 0, 5);
this, new TimedFlagsTimer(this), 25 * 5, 25 * 5);
if (configuration.suppressTickSyncWarnings) { if (configuration.suppressTickSyncWarnings) {
Logger.getLogger("Minecraft").setFilter( Logger.getLogger("Minecraft").setFilter(

View File

@ -19,6 +19,10 @@
package com.sk89q.worldguard.protection; package com.sk89q.worldguard.protection;
import java.util.List;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
/** /**
* *
* @author Redecouverte * @author Redecouverte
@ -28,13 +32,13 @@ public class TimedFlagPlayerInfo {
public long lastHealTick; public long lastHealTick;
public Long sheduledHealTick; public Long sheduledHealTick;
public int sheduledHealAmount; public int sheduledHealAmount;
public String lastRegion; public List <ProtectedRegion> lastRegions;
public String lastFarewellMsg; public String lastFarewellMsg;
public TimedFlagPlayerInfo() public TimedFlagPlayerInfo()
{ {
this.sheduledHealTick = null; this.sheduledHealTick = null;
this.lastRegion = null; this.lastRegions = null;
this.lastFarewellMsg = null; this.lastFarewellMsg = null;
} }

View File

@ -19,14 +19,22 @@
package com.sk89q.worldguard.protection; package com.sk89q.worldguard.protection;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.flags.DefaultFlag; 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.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.BukkitPlayer; import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*; import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
@ -63,104 +71,116 @@ private TimedFlagPlayerInfo getPlayerInfo(String name) {
} }
public void run() { public void run() {
/*
// get players
Player[] players = plugin.getServer().getOnlinePlayers(); Player[] players = plugin.getServer().getOnlinePlayers();
for (Player player : players) { for (Player player : players) {
TimedFlagPlayerInfo playerInfo = getPlayerInfo(player.getName());
ConfigurationManager config = plugin.getGlobalConfiguration();
WorldConfiguration worldConfig = config.get(player.getWorld());
TimedFlagPlayerInfo nfo = getPlayerInfo(player.getName()); if (worldConfig.useRegions) {
long now = System.currentTimeMillis(); Vector playerLocation = toVector(player.getLocation());
RegionManager regionManager = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet applicableRegions = regionManager.getApplicableRegions(playerLocation);
// check healing flag List <ProtectedRegion> protectedRegions = new ArrayList<ProtectedRegion>();
if (nfo.sheduledHealTick != null && now >= nfo.sheduledHealTick) { Iterator<ProtectedRegion> protectedRegionsIterator = applicableRegions.iterator();
player.setHealth(player.getHealth() + nfo.sheduledHealAmount); Iterator<ProtectedRegion> prevProtectedRegionIterator = null;
nfo.sheduledHealTick = null;
nfo.lastHealTick = now; 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;
} }
if (player.getWorld().getName() == null) { while(protectedRegionsIterator.hasNext()) {
continue; ProtectedRegion protectedRegion = protectedRegionsIterator.next();
}
RegionManager mgr = plugin.getGlobalRegionManager().get(
player.getWorld().getName());
ApplicableRegionSet regions = mgr
.getApplicableRegions(toVector(player.getLocation()));
Integer healDelay = regions.getFlag(DefaultFlag.HEAL_DELAY); Integer healDelay = protectedRegion.getFlag(DefaultFlag.HEAL_DELAY);
Integer healAmount = protectedRegion.getFlag(DefaultFlag.HEAL_AMOUNT);
if (healDelay > 0) { if (healDelay != null && healAmount != null && healDelay > 0) {
healDelay *= 1000; healDelay *= 1000;
int healAmount = regions.getIntegerFlag(
DefaultFlag.HEAL_AMOUNT, true).getValue(1); if (time - playerInfo.lastHealTick > healDelay) {
if (now - nfo.lastHealTick > healDelay) {
if (player.getHealth() < 20) { if (player.getHealth() < 20) {
if (player.getHealth() + healAmount > 20) { if (player.getHealth() + healAmount > 20)
player.setHealth(20); player.setHealth(20);
} else { else
player.setHealth(player.getHealth() + healAmount); player.setHealth(player.getHealth() + healAmount);
} }
} }
} else { else {
nfo.sheduledHealTick = now + healDelay; playerInfo.sheduledHealTick = time + healDelay;
nfo.sheduledHealAmount = healAmount; playerInfo.sheduledHealAmount = healAmount;
} }
} }
// check greeting/farewell flag // ----
String newRegionName = regions.getAffectedRegionId(); // ==== Greeting Flags ====
// ----
if (newRegionName != null) { if (playerInfo.lastRegions != null && !playerInfo.lastRegions.contains(protectedRegion)) {
String greetMsg = protectedRegion.getFlag(DefaultFlag.GREET_MESSAGE);
Boolean notifyGreet = protectedRegion.getFlag(DefaultFlag.NOTIFY_GREET);
if (nfo.lastRegion == null if (greetMsg != null)
|| !newRegionName.equals(nfo.lastRegion)) { player.sendMessage(greetMsg);
String newGreetMsg = regions.getStringFlag(
DefaultFlag.GREET_MESSAGE, true).getValue();
String farewellMsg = regions.getStringFlag(
DefaultFlag.FAREWELL_MESSAGE, true).getValue();
if (nfo.lastFarewellMsg != null) { if (notifyGreet != null && notifyGreet)
player.sendMessage(nfo.lastFarewellMsg); broadcastNotification(ChatColor.YELLOW + "Player " + player.getName() + " entered region " + protectedRegion.getId());
nfo.lastFarewellMsg = null;
}
if (newGreetMsg != null) {
player.sendMessage(newGreetMsg);
}
if (regions.getBooleanFlag(DefaultFlag.NOTIFY_GREET, false)
.getValue(false)) {
broadcastNotification(ChatColor.YELLOW + "Player "
+ player.getName() + " entered region "
+ newRegionName);
}
nfo.lastFarewellMsg = farewellMsg;
nfo.lastRegion = newRegionName;
}
} else {
if (nfo.lastRegion != null) {
if (nfo.lastFarewellMsg != null) {
player.sendMessage(nfo.lastFarewellMsg);
nfo.lastFarewellMsg = null;
}
if (regions.getBooleanFlag(DefaultFlag.NOTIFY_FAREWELL,
false).getValue(false)) {
broadcastNotification(ChatColor.YELLOW + "Player "
+ player.getName() + " left region "
+ nfo.lastRegion);
}
nfo.lastRegion = null;
}
} }
// check passthrough flag // ----
LocalPlayer lplayer = BukkitPlayer.wrapPlayer(plugin, player); // ==== Passthrough Flag ====
if (!regions.isStateFlagAllowed(DefaultFlag.PASSTHROUGH, lplayer)) { // ----
State passthrough = protectedRegion.getFlag(DefaultFlag.PASSTHROUGH);
if (passthrough != null && passthrough == State.DENY) {
Location newLoc = player.getLocation().clone(); Location newLoc = player.getLocation().clone();
newLoc.setX(newLoc.getBlockX() - 30); newLoc.setX(newLoc.getBlockX() - 30);
newLoc.setY(newLoc.getWorld().getHighestBlockYAt(newLoc) + 1); newLoc.setY(newLoc.getWorld().getHighestBlockYAt(newLoc) + 1);
player.teleportTo(newLoc); 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) { public void broadcastNotification(String msg) {