Check for relation when a player tries to create a destination portal in claimed land. Adds #204.

This commit is contained in:
drtshock 2015-01-05 09:58:32 -06:00
parent b666c6f630
commit 0a80b79321
2 changed files with 41 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.TravelAgent;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.entity.minecart.ExplosiveMinecart;
@ -17,6 +18,7 @@ import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
@ -522,6 +524,34 @@ public class FactionsEntityListener implements Listener {
} }
} }
@EventHandler
public void onTravel(PlayerPortalEvent event) {
if (!P.p.getConfig().getBoolean("portals.limit", false)) {
return; // Don't do anything if they don't want us to.
}
TravelAgent agent = event.getPortalTravelAgent();
// If they aren't able to find a portal, it'll try to create one.
if (event.useTravelAgent() && agent.getCanCreatePortal() && agent.findPortal(event.getTo()) == null) {
FLocation loc = new FLocation(event.getTo());
Faction faction = Board.getInstance().getFactionAt(loc);
if (faction.isNone()) {
return; // We don't care about wilderness.
} else if (!faction.isNormal() && !event.getPlayer().isOp()) {
// Don't let non ops make portals in safezone or warzone.
event.setCancelled(true);
return;
}
FPlayer fp = FPlayers.getInstance().getByPlayer(event.getPlayer());
String mininumRelation = P.p.getConfig().getString("portals.minimum-relation", "MEMBER"); // Defaults to Neutral if typed wrong.
if (!fp.getFaction().getRelationTo(faction).isAtLeast(Relation.fromString(mininumRelation))) {
event.setCancelled(true);
}
}
}
private boolean stopEndermanBlockManipulation(Location loc) { private boolean stopEndermanBlockManipulation(Location loc) {
if (loc == null) { if (loc == null) {
return false; return false;

View File

@ -30,6 +30,17 @@ findfactionsexploit:
# This has always been neutral. # This has always been neutral.
default-relation: "neutral" default-relation: "neutral"
# Portal Creation
# Do you want to limit portal creation?
portals:
limit: false # will disable the below check if set to false
# What should the minimum relation be to create a portal in territory?
# Goes in the order of: ENEMY, NEUTRAL, ALLY, MEMBER.
# Minimum relation allows that and all listed to the right to create portals.
# Example: put ALLY to allow ALLY and MEMBER to be able to create portals.
minimum-relation: MEMBER # If typed incorrectly, defaults to NEUTRAL.
### Hard Core Settings ### ### Hard Core Settings ###
# Warps # Warps