API - GPFlags Support
Updated the API to support two new GriefPreventionFlags flags.
This commit is contained in:
parent
5867bbd3be
commit
260db50cc3
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.PreventPvPEvent;
|
||||
import me.ryanhamshire.GriefPrevention.events.ProtectDeathDropsEvent;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
|
@ -441,6 +442,11 @@ public class EntityEventHandler implements Listener
|
|||
boolean isPvPWorld = GriefPrevention.instance.pvpRulesApply(world);
|
||||
if((isPvPWorld && GriefPrevention.instance.config_lockDeathDropsInPvpWorlds) ||
|
||||
(!isPvPWorld && GriefPrevention.instance.config_lockDeathDropsInNonPvpWorlds))
|
||||
{
|
||||
Claim claim = this.dataStore.getClaimAt(player.getLocation(), false, playerData.lastClaim);
|
||||
ProtectDeathDropsEvent protectionEvent = new ProtectDeathDropsEvent(claim);
|
||||
Bukkit.getPluginManager().callEvent(protectionEvent);
|
||||
if(!protectionEvent.isCancelled())
|
||||
{
|
||||
//remember information about these drops so that they can be marked when they spawn as items
|
||||
long expirationTime = System.currentTimeMillis() + 3000; //now + 3 seconds
|
||||
|
|
@ -458,6 +464,7 @@ public class EntityEventHandler implements Listener
|
|||
playerData.receivedDropUnlockAdvertisement = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//when an entity picks up an item
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException;
|
||||
import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.Achievement;
|
||||
|
|
@ -2194,8 +2195,12 @@ public class GriefPrevention extends JavaPlugin
|
|||
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(claim.isAdminClaim())
|
||||
if(claim.isAdminClaim() && event.getDestination() != null)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, Messages.TrappedWontWorkHere);
|
||||
return true;
|
||||
|
|
@ -2205,7 +2210,7 @@ public class GriefPrevention extends JavaPlugin
|
|||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.RescuePending);
|
||||
|
||||
//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
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -29,13 +29,17 @@ class PlayerRescueTask implements Runnable
|
|||
//original location where /trapped was used
|
||||
private Location location;
|
||||
|
||||
//rescue destination, may be decided at instantiation or at execution
|
||||
private Location destination;
|
||||
|
||||
//player data
|
||||
private Player player;
|
||||
|
||||
public PlayerRescueTask(Player player, Location location)
|
||||
public PlayerRescueTask(Player player, Location location, Location destination)
|
||||
{
|
||||
this.player = player;
|
||||
this.location = location;
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -56,9 +60,16 @@ class PlayerRescueTask implements Runnable
|
|||
}
|
||||
|
||||
//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"
|
||||
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) + ".");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ package me.ryanhamshire.GriefPrevention;
|
|||
import org.bukkit.ChatColor;
|
||||
|
||||
//just a few constants for chat color codes
|
||||
class TextMode
|
||||
public class TextMode
|
||||
{
|
||||
final static ChatColor Info = ChatColor.AQUA;
|
||||
final static ChatColor Instr = ChatColor.YELLOW;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user