mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-10-04 17:47:41 +02:00
Fixed TimedFlagsTimer to enable HEAL_DELAY,HEAL_AMOUNT,GREETING,FAREWELL,NOTIFY_GREET,NOTIFY_FAREWELL, and PASSTHROUGH Flags.
This commit is contained in:
parent
906dab28c1
commit
66ee09d050
@ -457,7 +457,7 @@ public void findFreePosition(Player player) {
|
||||
world.getBlockAt(x,0,z).setTypeId(20);
|
||||
loc.setY(2);
|
||||
}
|
||||
player.setFallDistance(0F);
|
||||
// player.setFallDistance(0F);
|
||||
player.teleport(loc);
|
||||
}
|
||||
return;
|
||||
|
@ -134,8 +134,7 @@ public void onEnable() {
|
||||
(new WorldGuardEntityListener(this)).registerEvents();
|
||||
|
||||
// 25 equals about 1s real time
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(
|
||||
this, new TimedFlagsTimer(this), 25 * 5, 25 * 5);
|
||||
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new TimedFlagsTimer(this), 0, 5);
|
||||
|
||||
if (configuration.suppressTickSyncWarnings) {
|
||||
Logger.getLogger("Minecraft").setFilter(
|
||||
|
@ -19,6 +19,10 @@
|
||||
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Redecouverte
|
||||
@ -28,13 +32,13 @@ public class TimedFlagPlayerInfo {
|
||||
public long lastHealTick;
|
||||
public Long sheduledHealTick;
|
||||
public int sheduledHealAmount;
|
||||
public String lastRegion;
|
||||
public List <ProtectedRegion> lastRegions;
|
||||
public String lastFarewellMsg;
|
||||
|
||||
public TimedFlagPlayerInfo()
|
||||
{
|
||||
this.sheduledHealTick = null;
|
||||
this.lastRegion = null;
|
||||
this.lastRegions = null;
|
||||
this.lastFarewellMsg = null;
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,22 @@
|
||||
|
||||
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.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.BukkitPlayer;
|
||||
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.*;
|
||||
@ -63,104 +71,116 @@ private TimedFlagPlayerInfo getPlayerInfo(String name) {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
/*
|
||||
// get players
|
||||
Player[] players = plugin.getServer().getOnlinePlayers();
|
||||
|
||||
for (Player player : players) {
|
||||
TimedFlagPlayerInfo playerInfo = getPlayerInfo(player.getName());
|
||||
ConfigurationManager config = plugin.getGlobalConfiguration();
|
||||
WorldConfiguration worldConfig = config.get(player.getWorld());
|
||||
|
||||
TimedFlagPlayerInfo nfo = getPlayerInfo(player.getName());
|
||||
long now = System.currentTimeMillis();
|
||||
if (worldConfig.useRegions) {
|
||||
Vector playerLocation = toVector(player.getLocation());
|
||||
RegionManager regionManager = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
ApplicableRegionSet applicableRegions = regionManager.getApplicableRegions(playerLocation);
|
||||
|
||||
// check healing flag
|
||||
if (nfo.sheduledHealTick != null && now >= nfo.sheduledHealTick) {
|
||||
player.setHealth(player.getHealth() + nfo.sheduledHealAmount);
|
||||
nfo.sheduledHealTick = null;
|
||||
nfo.lastHealTick = now;
|
||||
List <ProtectedRegion> protectedRegions = new ArrayList<ProtectedRegion>();
|
||||
Iterator<ProtectedRegion> protectedRegionsIterator = applicableRegions.iterator();
|
||||
Iterator<ProtectedRegion> 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;
|
||||
}
|
||||
|
||||
if (player.getWorld().getName() == null) {
|
||||
continue;
|
||||
}
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(
|
||||
player.getWorld().getName());
|
||||
ApplicableRegionSet regions = mgr
|
||||
.getApplicableRegions(toVector(player.getLocation()));
|
||||
while(protectedRegionsIterator.hasNext()) {
|
||||
ProtectedRegion protectedRegion = protectedRegionsIterator.next();
|
||||
|
||||
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;
|
||||
int healAmount = regions.getIntegerFlag(
|
||||
DefaultFlag.HEAL_AMOUNT, true).getValue(1);
|
||||
if (now - nfo.lastHealTick > healDelay) {
|
||||
|
||||
if (time - playerInfo.lastHealTick > healDelay) {
|
||||
if (player.getHealth() < 20) {
|
||||
if (player.getHealth() + healAmount > 20) {
|
||||
if (player.getHealth() + healAmount > 20)
|
||||
player.setHealth(20);
|
||||
} else {
|
||||
else
|
||||
player.setHealth(player.getHealth() + healAmount);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nfo.sheduledHealTick = now + healDelay;
|
||||
nfo.sheduledHealAmount = healAmount;
|
||||
else {
|
||||
playerInfo.sheduledHealTick = time + healDelay;
|
||||
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
|
||||
|| !newRegionName.equals(nfo.lastRegion)) {
|
||||
String newGreetMsg = regions.getStringFlag(
|
||||
DefaultFlag.GREET_MESSAGE, true).getValue();
|
||||
String farewellMsg = regions.getStringFlag(
|
||||
DefaultFlag.FAREWELL_MESSAGE, true).getValue();
|
||||
if (greetMsg != null)
|
||||
player.sendMessage(greetMsg);
|
||||
|
||||
if (nfo.lastFarewellMsg != null) {
|
||||
player.sendMessage(nfo.lastFarewellMsg);
|
||||
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;
|
||||
}
|
||||
if (notifyGreet != null && notifyGreet)
|
||||
broadcastNotification(ChatColor.YELLOW + "Player " + player.getName() + " entered region " + protectedRegion.getId());
|
||||
}
|
||||
|
||||
// check passthrough flag
|
||||
LocalPlayer lplayer = BukkitPlayer.wrapPlayer(plugin, player);
|
||||
if (!regions.isStateFlagAllowed(DefaultFlag.PASSTHROUGH, lplayer)) {
|
||||
// ----
|
||||
// ==== 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.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) {
|
||||
|
Loading…
Reference in New Issue
Block a user