From 0a80b7932142969b603e7d4f8bcbcb5d9b33bc41 Mon Sep 17 00:00:00 2001 From: drtshock Date: Mon, 5 Jan 2015 09:58:32 -0600 Subject: [PATCH] Check for relation when a player tries to create a destination portal in claimed land. Adds #204. --- .../listeners/FactionsEntityListener.java | 30 +++++++++++++++++++ src/main/resources/config.yml | 11 +++++++ 2 files changed, 41 insertions(+) diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java index a8ba44fa..f222ea62 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -6,6 +6,7 @@ import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.MiscUtil; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.TravelAgent; import org.bukkit.block.Block; import org.bukkit.entity.*; 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.RemoveCause; import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; 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) { if (loc == null) { return false; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8749c3d3..9eee8828 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -30,6 +30,17 @@ findfactionsexploit: # This has always been 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 ### # Warps