API - GPFlags Support

Updated the API to support two new GriefPreventionFlags flags.
This commit is contained in:
ryanhamshire 2016-01-31 09:02:27 -08:00
parent 5867bbd3be
commit 260db50cc3
6 changed files with 152 additions and 19 deletions

View File

@ -27,6 +27,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import me.ryanhamshire.GriefPrevention.events.PreventPvPEvent; import me.ryanhamshire.GriefPrevention.events.PreventPvPEvent;
import me.ryanhamshire.GriefPrevention.events.ProtectDeathDropsEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -442,20 +443,26 @@ public class EntityEventHandler implements Listener
if((isPvPWorld && GriefPrevention.instance.config_lockDeathDropsInPvpWorlds) || if((isPvPWorld && GriefPrevention.instance.config_lockDeathDropsInPvpWorlds) ||
(!isPvPWorld && GriefPrevention.instance.config_lockDeathDropsInNonPvpWorlds)) (!isPvPWorld && GriefPrevention.instance.config_lockDeathDropsInNonPvpWorlds))
{ {
//remember information about these drops so that they can be marked when they spawn as items Claim claim = this.dataStore.getClaimAt(player.getLocation(), false, playerData.lastClaim);
long expirationTime = System.currentTimeMillis() + 3000; //now + 3 seconds ProtectDeathDropsEvent protectionEvent = new ProtectDeathDropsEvent(claim);
Location deathLocation = player.getLocation(); Bukkit.getPluginManager().callEvent(protectionEvent);
UUID playerID = player.getUniqueId(); if(!protectionEvent.isCancelled())
List<ItemStack> drops = event.getDrops();
for(ItemStack stack : drops)
{ {
GriefPrevention.instance.pendingItemWatchList.add( //remember information about these drops so that they can be marked when they spawn as items
new PendingItemProtection(deathLocation, playerID, expirationTime, stack)); long expirationTime = System.currentTimeMillis() + 3000; //now + 3 seconds
Location deathLocation = player.getLocation();
UUID playerID = player.getUniqueId();
List<ItemStack> drops = event.getDrops();
for(ItemStack stack : drops)
{
GriefPrevention.instance.pendingItemWatchList.add(
new PendingItemProtection(deathLocation, playerID, expirationTime, stack));
}
//allow the player to receive a message about how to unlock any drops
playerData.dropsAreUnlocked = false;
playerData.receivedDropUnlockAdvertisement = false;
} }
//allow the player to receive a message about how to unlock any drops
playerData.dropsAreUnlocked = false;
playerData.receivedDropUnlockAdvertisement = false;
} }
} }

View File

@ -33,6 +33,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException; import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException;
import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.Achievement; import org.bukkit.Achievement;
@ -2194,8 +2195,12 @@ public class GriefPrevention extends JavaPlugin
return true; return true;
} }
//rescue destination may be set by GPFlags, ask to find out
SaveTrappedPlayerEvent event = new SaveTrappedPlayerEvent(claim);
Bukkit.getPluginManager().callEvent(event);
//if the player is in an administrative claim, he should contact an admin //if the player is in an administrative claim, he should contact an admin
if(claim.isAdminClaim()) if(claim.isAdminClaim() && event.getDestination() != null)
{ {
GriefPrevention.sendMessage(player, TextMode.Err, Messages.TrappedWontWorkHere); GriefPrevention.sendMessage(player, TextMode.Err, Messages.TrappedWontWorkHere);
return true; return true;
@ -2205,7 +2210,7 @@ public class GriefPrevention extends JavaPlugin
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.RescuePending); GriefPrevention.sendMessage(player, TextMode.Instr, Messages.RescuePending);
//create a task to rescue this player in a little while //create a task to rescue this player in a little while
PlayerRescueTask task = new PlayerRescueTask(player, player.getLocation()); PlayerRescueTask task = new PlayerRescueTask(player, player.getLocation(), event.getDestination());
this.getServer().getScheduler().scheduleSyncDelayedTask(this, task, 200L); //20L ~ 1 second this.getServer().getScheduler().scheduleSyncDelayedTask(this, task, 200L); //20L ~ 1 second
return true; return true;

View File

@ -29,13 +29,17 @@ class PlayerRescueTask implements Runnable
//original location where /trapped was used //original location where /trapped was used
private Location location; private Location location;
//rescue destination, may be decided at instantiation or at execution
private Location destination;
//player data //player data
private Player player; private Player player;
public PlayerRescueTask(Player player, Location location) public PlayerRescueTask(Player player, Location location, Location destination)
{ {
this.player = player; this.player = player;
this.location = location; this.location = location;
this.destination = destination;
} }
@Override @Override
@ -56,9 +60,16 @@ class PlayerRescueTask implements Runnable
} }
//otherwise find a place to teleport him //otherwise find a place to teleport him
Location destination = GriefPrevention.instance.ejectPlayer(this.player); if(this.destination == null)
{
this.destination = GriefPrevention.instance.ejectPlayer(this.player);
}
else
{
player.teleport(this.destination);
}
//log entry, in case admins want to investigate the "trap" //log entry, in case admins want to investigate the "trap"
GriefPrevention.AddLogEntry("Rescued trapped player " + player.getName() + " from " + GriefPrevention.getfriendlyLocationString(this.location) + " to " + GriefPrevention.getfriendlyLocationString(destination) + "."); GriefPrevention.AddLogEntry("Rescued trapped player " + player.getName() + " from " + GriefPrevention.getfriendlyLocationString(this.location) + " to " + GriefPrevention.getfriendlyLocationString(this.destination) + ".");
} }
} }

View File

@ -21,7 +21,7 @@ package me.ryanhamshire.GriefPrevention;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
//just a few constants for chat color codes //just a few constants for chat color codes
class TextMode public class TextMode
{ {
final static ChatColor Info = ChatColor.AQUA; final static ChatColor Info = ChatColor.AQUA;
final static ChatColor Instr = ChatColor.YELLOW; final static ChatColor Instr = ChatColor.YELLOW;

View File

@ -0,0 +1,49 @@
package me.ryanhamshire.GriefPrevention.events;
import me.ryanhamshire.GriefPrevention.Claim;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
//if cancelled, GriefPrevention will not protect items dropped by a player on death
public class ProtectDeathDropsEvent extends Event implements Cancellable
{
private static final HandlerList handlers = new HandlerList();
private boolean cancelled = false;
public static HandlerList getHandlerList()
{
return handlers;
}
Claim claim;
public ProtectDeathDropsEvent(Claim claim)
{
this.claim = claim;
}
public Claim getClaim()
{
return this.claim;
}
@Override
public HandlerList getHandlers()
{
return handlers;
}
@Override
public boolean isCancelled()
{
return this.cancelled;
}
@Override
public void setCancelled(boolean cancelled)
{
this.cancelled = cancelled;
}
}

View File

@ -0,0 +1,61 @@
package me.ryanhamshire.GriefPrevention.events;
import me.ryanhamshire.GriefPrevention.Claim;
import org.bukkit.Location;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
//if destination field is set, then GriefPrevention will send the player to that location instead of searching for one
public class SaveTrappedPlayerEvent extends Event implements Cancellable
{
private static final HandlerList handlers = new HandlerList();
private boolean cancelled = false;
private Location destination = null;
public static HandlerList getHandlerList()
{
return handlers;
}
Claim claim;
public SaveTrappedPlayerEvent(Claim claim)
{
this.claim = claim;
}
public Location getDestination()
{
return destination;
}
public void setDestination(Location destination)
{
this.destination = destination;
}
public Claim getClaim()
{
return this.claim;
}
@Override
public HandlerList getHandlers()
{
return handlers;
}
@Override
public boolean isCancelled()
{
return this.cancelled;
}
@Override
public void setCancelled(boolean cancelled)
{
this.cancelled = cancelled;
}
}