mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-13 03:41:18 +01:00
implemented heal, greeting and farewell flag
This commit is contained in:
parent
f821e277de
commit
5411a294e7
@ -219,6 +219,10 @@ private void registerEvents() {
|
|||||||
registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal);
|
registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal);
|
||||||
|
|
||||||
permsListener.register(this);
|
permsListener.register(this);
|
||||||
|
|
||||||
|
// 25 equals about 1s real time
|
||||||
|
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimedFlagsTimer(this), 25*5, 25*5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1472,7 +1476,7 @@ String[] getGroups(Player player) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BukkitPlayer wrapPlayer(Player player) {
|
public BukkitPlayer wrapPlayer(Player player) {
|
||||||
return new BukkitPlayer(this, player);
|
return new BukkitPlayer(this, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,8 +191,42 @@ private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
|
|||||||
* @param player null to not check owners and members
|
* @param player null to not check owners and members
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
// todo : check priorities
|
public String getAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||||
private String getAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
|
||||||
|
ProtectedRegion childRegion = getChildRegion();
|
||||||
|
if(childRegion == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player != null && !childRegion.isMember(player)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!inherit)
|
||||||
|
{
|
||||||
|
return childRegion.getFlags().getFlag(name, subname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String value;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
value = childRegion.getFlags().getFlag(name, subname);
|
||||||
|
childRegion = childRegion.getParent();
|
||||||
|
|
||||||
|
} while(value == null && childRegion != null);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the region with the hightest priority that is not a parent.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public ProtectedRegion getChildRegion() {
|
||||||
|
|
||||||
int appSize = applicable.size();
|
int appSize = applicable.size();
|
||||||
|
|
||||||
@ -203,7 +237,7 @@ private String getAreaFlag(String name, String subname, Boolean inherit, LocalPl
|
|||||||
|
|
||||||
else if(appSize < 2)
|
else if(appSize < 2)
|
||||||
{
|
{
|
||||||
return applicable.get(0).getFlags().getFlag(name, subname);
|
return applicable.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> parents = new ArrayList<String>();
|
List<String> parents = new ArrayList<String>();
|
||||||
@ -237,28 +271,7 @@ else if(appSize < 2)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return childRegion;
|
||||||
if (player != null && !childRegion.isMember(player)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!inherit)
|
|
||||||
{
|
|
||||||
return childRegion.getFlags().getFlag(name, subname);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
String value;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
value = childRegion.getFlags().getFlag(name, subname);
|
|
||||||
childRegion = childRegion.getParent();
|
|
||||||
|
|
||||||
} while(value == null && childRegion != null);
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAreaFlag(String name, String subname, String defaultValue, Boolean inherit, LocalPlayer player)
|
public String getAreaFlag(String name, String subname, String defaultValue, Boolean inherit, LocalPlayer player)
|
||||||
|
41
src/com/sk89q/worldguard/protection/TimedFlagPlayerInfo.java
Normal file
41
src/com/sk89q/worldguard/protection/TimedFlagPlayerInfo.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
129
src/com/sk89q/worldguard/protection/TimedFlagsTimer.java
Normal file
129
src/com/sk89q/worldguard/protection/TimedFlagsTimer.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -101,8 +101,8 @@ public void save() throws IOException {
|
|||||||
writeDomains(cuboid.getOwners()),
|
writeDomains(cuboid.getOwners()),
|
||||||
writeDomains(cuboid.getMembers()),
|
writeDomains(cuboid.getMembers()),
|
||||||
writeFlags(cuboid.getFlags()),
|
writeFlags(cuboid.getFlags()),
|
||||||
cuboid.getEnterMessage() != null ? cuboid.getEnterMessage() : "",
|
cuboid.getFlags().getFlag("msg", "g") != null ? cuboid.getFlags().getFlag("msg", "g") : "",
|
||||||
cuboid.getLeaveMessage() != null ? cuboid.getLeaveMessage() : "",
|
cuboid.getFlags().getFlag("msg", "l") != null ? cuboid.getFlags().getFlag("msg", "l") : "",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -165,7 +165,7 @@ public void load() throws IOException {
|
|||||||
region.setPriority(priority);
|
region.setPriority(priority);
|
||||||
region.setFlags(parseFlags(flagsData));
|
region.setFlags(parseFlags(flagsData));
|
||||||
region.setOwners(this.parseDomains(ownersData));
|
region.setOwners(this.parseDomains(ownersData));
|
||||||
region.setEnterMessage(enterMessage);
|
region.getFlags().setFlag("msg", "g", enterMessage);
|
||||||
regions.put(id, region);
|
regions.put(id, region);
|
||||||
} else if (type.equalsIgnoreCase("cuboid.2")) {
|
} else if (type.equalsIgnoreCase("cuboid.2")) {
|
||||||
Vector pt1 = new Vector(
|
Vector pt1 = new Vector(
|
||||||
@ -193,8 +193,8 @@ public void load() throws IOException {
|
|||||||
region.setFlags(parseFlags(flagsData));
|
region.setFlags(parseFlags(flagsData));
|
||||||
region.setOwners(this.parseDomains(ownersData));
|
region.setOwners(this.parseDomains(ownersData));
|
||||||
region.setMembers(this.parseDomains(membersData));
|
region.setMembers(this.parseDomains(membersData));
|
||||||
region.setEnterMessage(enterMessage);
|
region.getFlags().setFlag("msg", "g", enterMessage);
|
||||||
region.setLeaveMessage(leaveMessage);
|
region.getFlags().setFlag("msg", "l", leaveMessage);
|
||||||
regions.put(id, region);
|
regions.put(id, region);
|
||||||
|
|
||||||
// Link children to parents later
|
// Link children to parents later
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.protection.regions;
|
package com.sk89q.worldguard.protection.regions;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
@ -61,19 +59,7 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
|||||||
* Area flags.
|
* Area flags.
|
||||||
*/
|
*/
|
||||||
private AreaFlags flags = new AreaFlags();
|
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.
|
* Construct a new instance of this region.
|
||||||
@ -175,34 +161,6 @@ public void setFlags(AreaFlags flags) {
|
|||||||
this.flags = 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
|
* @return the owners
|
||||||
*/
|
*/
|
||||||
@ -358,19 +316,4 @@ public static boolean intersects(ProtectedRegion region1, ProtectedRegion region
|
|||||||
public static class CircularInheritanceException extends Exception {
|
public static class CircularInheritanceException extends Exception {
|
||||||
private static final long serialVersionUID = 7479613488496776022L;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user