implemented heal, greeting and farewell flag

This commit is contained in:
Redecouverte 2011-02-24 17:11:12 +01:00
parent f821e277de
commit 5411a294e7
6 changed files with 237 additions and 107 deletions

View File

@ -219,6 +219,10 @@ private void registerEvents() {
registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal);
permsListener.register(this);
// 25 equals about 1s real time
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimedFlagsTimer(this), 25*5, 25*5);
}
/**
@ -303,7 +307,7 @@ public void loadConfiguration() {
disableFireSpread = config.getBoolean("fire.disable-all-fire-spread", false);
disableFireSpreadBlocks = new HashSet<Integer>(config.getIntList("fire.disable-fire-spread-blocks", null));
allowedLavaSpreadOver = new HashSet<Integer>(config.getIntList("fire.lava-spread-blocks", null));
blockCreeperExplosions = config.getBoolean("mobs.block-creeper-explosions", false);
blockCreeperBlockDamage = config.getBoolean("mobs.block-creeper-block-damage", false);
for (String creature: config.getStringList("mobs.block-creature-spawn", null)) {
@ -1472,7 +1476,7 @@ String[] getGroups(Player player) {
}
}
BukkitPlayer wrapPlayer(Player player) {
public BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(this, player);
}

View File

@ -191,53 +191,14 @@ private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
* @param player null to not check owners and members
* @return
*/
// todo : check priorities
private String getAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
public String getAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
int appSize = applicable.size();
if(appSize < 1)
ProtectedRegion childRegion = getChildRegion();
if(childRegion == null)
{
return null;
}
else if(appSize < 2)
{
return applicable.get(0).getFlags().getFlag(name, subname);
}
List<String> parents = new ArrayList<String>();
Iterator<ProtectedRegion> iter = applicable.iterator();
while (iter.hasNext()) {
ProtectedRegion region = iter.next();
ProtectedRegion parent = region.getParent();
if(parent == null)
{
parents.add(region.getId());
}
else
{
parents.add(parent.getId());
}
}
ProtectedRegion childRegion = null;
iter = applicable.iterator();
while (iter.hasNext()) {
ProtectedRegion region = iter.next();
if(!parents.contains(region.getId()))
{
if(childRegion == null || childRegion.getPriority() < region.getPriority())
{
childRegion = region;
}
}
}
if (player != null && !childRegion.isMember(player)) {
return null;
}
@ -261,6 +222,58 @@ else if(appSize < 2)
}
/**
* Gets the region with the hightest priority that is not a parent.
*
*/
public ProtectedRegion getChildRegion() {
int appSize = applicable.size();
if(appSize < 1)
{
return null;
}
else if(appSize < 2)
{
return applicable.get(0);
}
List<String> parents = new ArrayList<String>();
Iterator<ProtectedRegion> iter = applicable.iterator();
while (iter.hasNext()) {
ProtectedRegion region = iter.next();
ProtectedRegion parent = region.getParent();
if(parent == null)
{
parents.add(region.getId());
}
else
{
parents.add(parent.getId());
}
}
ProtectedRegion childRegion = null;
iter = applicable.iterator();
while (iter.hasNext()) {
ProtectedRegion region = iter.next();
if(!parents.contains(region.getId()))
{
if(childRegion == null || childRegion.getPriority() < region.getPriority())
{
childRegion = region;
}
}
}
return childRegion;
}
public String getAreaFlag(String name, String subname, String defaultValue, Boolean inherit, LocalPlayer player)
{
String data = getAreaFlag(name, subname, inherit, player);

View File

@ -0,0 +1,41 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
/**
*
* @author Redecouverte
*/
public class TimedFlagPlayerInfo {
public long lastHealTick;
public Long sheduledHealTick;
public int sheduledHealAmount;
public String lastRegion;
public String lastFarewellMsg;
public TimedFlagPlayerInfo()
{
this.sheduledHealTick = null;
this.lastRegion = null;
this.lastFarewellMsg = null;
}
}

View File

@ -0,0 +1,129 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.bukkit.BukkitPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
/**
*
* @author Michael
*/
public class TimedFlagsTimer implements Runnable {
WorldGuardPlugin wg;
Map<String, TimedFlagPlayerInfo> playerData;
public TimedFlagsTimer(WorldGuardPlugin wg)
{
this.wg = wg;
this.playerData = new HashMap<String, TimedFlagPlayerInfo> ();
}
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() {
//get players
Player[] players = wg.getServer().getOnlinePlayers();
for (Player player : players) {
TimedFlagPlayerInfo nfo = getPlayerInfo(player.getName());
long now = System.currentTimeMillis();
//check healing flag
if(nfo.sheduledHealTick != null && now >= nfo.sheduledHealTick)
{
player.setHealth(player.getHealth() + nfo.sheduledHealAmount);
nfo.sheduledHealTick = null;
nfo.lastHealTick = now;
}
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
ApplicableRegionSet regions = mgr.getApplicableRegions(toVector(player.getLocation()));
int healDelay = regions.getIntAreaFlag("heal", "delay", -1, true, null);
if (healDelay > 0) {
healDelay *= 1000;
int healAmount = regions.getIntAreaFlag("heal", "amount", 1, true, null);
if (now - nfo.lastHealTick > healDelay) {
player.setHealth(player.getHealth() + healAmount);
} else {
nfo.sheduledHealTick = now + healDelay;
nfo.sheduledHealAmount = healAmount;
}
}
//check greeting/farewell flag
ProtectedRegion newRegion = regions.getChildRegion();
String newRegionName = null;
if (newRegion != null) {
newRegionName = newRegion.getId();
if (nfo.lastRegion == null || !newRegionName.equals(nfo.lastRegion)) {
String newGreetMsg = regions.getAreaFlag("msg", "g", null, true, null);
String farewellMsg = regions.getAreaFlag("msg", "f", null, true, null);
if (nfo.lastFarewellMsg != null) {
player.sendMessage(nfo.lastFarewellMsg);
nfo.lastFarewellMsg = null;
}
if (newGreetMsg != null) {
player.sendMessage(newGreetMsg);
}
nfo.lastFarewellMsg = farewellMsg;
nfo.lastRegion = newRegionName;
}
} else {
if (nfo.lastRegion != null) {
if (nfo.lastFarewellMsg != null) {
player.sendMessage(nfo.lastFarewellMsg);
nfo.lastFarewellMsg = null;
}
nfo.lastRegion = null;
}
}
}
}
}

View File

@ -101,8 +101,8 @@ public void save() throws IOException {
writeDomains(cuboid.getOwners()),
writeDomains(cuboid.getMembers()),
writeFlags(cuboid.getFlags()),
cuboid.getEnterMessage() != null ? cuboid.getEnterMessage() : "",
cuboid.getLeaveMessage() != null ? cuboid.getLeaveMessage() : "",
cuboid.getFlags().getFlag("msg", "g") != null ? cuboid.getFlags().getFlag("msg", "g") : "",
cuboid.getFlags().getFlag("msg", "l") != null ? cuboid.getFlags().getFlag("msg", "l") : "",
});
}
} finally {
@ -165,7 +165,7 @@ public void load() throws IOException {
region.setPriority(priority);
region.setFlags(parseFlags(flagsData));
region.setOwners(this.parseDomains(ownersData));
region.setEnterMessage(enterMessage);
region.getFlags().setFlag("msg", "g", enterMessage);
regions.put(id, region);
} else if (type.equalsIgnoreCase("cuboid.2")) {
Vector pt1 = new Vector(
@ -193,8 +193,8 @@ public void load() throws IOException {
region.setFlags(parseFlags(flagsData));
region.setOwners(this.parseDomains(ownersData));
region.setMembers(this.parseDomains(membersData));
region.setEnterMessage(enterMessage);
region.setLeaveMessage(leaveMessage);
region.getFlags().setFlag("msg", "g", enterMessage);
region.getFlags().setFlag("msg", "l", leaveMessage);
regions.put(id, region);
// Link children to parents later

View File

@ -19,8 +19,6 @@
package com.sk89q.worldguard.protection.regions;
import org.bukkit.Location;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
@ -61,19 +59,7 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
* Area flags.
*/
private AreaFlags flags = new AreaFlags();
/**
* Area message.
*/
private String enterMessage;
/**
* Area message.
*/
private String leaveMessage;
/**
* Point of region teleport.
*/
private Location teleportLocation;
/**
* Construct a new instance of this region.
@ -175,34 +161,6 @@ public void setFlags(AreaFlags flags) {
this.flags = flags;
}
/**
* @return the enterMessage
*/
public String getEnterMessage() {
return enterMessage;
}
/**
* @param enterMessage the enterMessage to set
*/
public void setEnterMessage(String enterMessage) {
this.enterMessage = enterMessage;
}
/**
* @return the leaveMessage
*/
public String getLeaveMessage() {
return leaveMessage;
}
/**
* @param leaveMessage the leaveMessage to set
*/
public void setLeaveMessage(String leaveMessage) {
this.leaveMessage = leaveMessage;
}
/**
* @return the owners
*/
@ -358,19 +316,4 @@ public static boolean intersects(ProtectedRegion region1, ProtectedRegion region
public static class CircularInheritanceException extends Exception {
private static final long serialVersionUID = 7479613488496776022L;
}
/**
* Return the teleport location for this region.
*/
public Location getTeleportLocation() {
return teleportLocation;
}
/**
* Set the teleport location for this region.
*/
public void setTeleportLocation(Location teleportLocation){
this.teleportLocation = teleportLocation;
}
}