Add ability to block chorus fruit and ender pearl teleportation. Fixes #51
This commit is contained in:
parent
8e169ea269
commit
e4f0b8e3de
@ -26,6 +26,7 @@ import com.massivecraft.factions.engine.EngineChat;
|
||||
import com.massivecraft.factions.engine.EngineChunkChange;
|
||||
import com.massivecraft.factions.engine.EngineCleanInactivity;
|
||||
import com.massivecraft.factions.engine.EngineDenyCommands;
|
||||
import com.massivecraft.factions.engine.EngineDenyTeleport;
|
||||
import com.massivecraft.factions.engine.EngineEcon;
|
||||
import com.massivecraft.factions.engine.EngineExploit;
|
||||
import com.massivecraft.factions.engine.EngineFlagEndergrief;
|
||||
@ -218,6 +219,7 @@ public class Factions extends MassivePlugin
|
||||
EngineChunkChange.class,
|
||||
EngineCleanInactivity.class,
|
||||
EngineDenyCommands.class,
|
||||
EngineDenyTeleport.class,
|
||||
EngineExploit.class,
|
||||
EngineFlagEndergrief.class,
|
||||
EngineFlagExplosion.class,
|
||||
|
130
src/com/massivecraft/factions/engine/EngineDenyTeleport.java
Normal file
130
src/com/massivecraft/factions/engine/EngineDenyTeleport.java
Normal file
@ -0,0 +1,130 @@
|
||||
package com.massivecraft.factions.engine;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.Couple;
|
||||
import com.massivecraft.massivecore.Engine;
|
||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class EngineDenyTeleport extends Engine
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static EngineDenyTeleport i = new EngineDenyTeleport();
|
||||
public static EngineDenyTeleport get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CAN COMBAT DAMAGE HAPPEN
|
||||
// -------------------------------------------- //
|
||||
|
||||
private enum TerritoryType
|
||||
{
|
||||
ENEMY,
|
||||
WILDERNESS,
|
||||
OWN,
|
||||
OTHER
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void canTeleportHappen(PlayerTeleportEvent event)
|
||||
{
|
||||
Entry<TeleportCause, TerritoryType> entry = shouldBeCancelled(event);
|
||||
if (entry == null) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
TeleportCause cause = entry.getKey();
|
||||
TerritoryType deny = entry.getValue();
|
||||
|
||||
String teleportDesc = Txt.getNicedEnum(cause);
|
||||
String denyDesc = "";
|
||||
if (deny == TerritoryType.ENEMY) denyDesc = "enemy";
|
||||
if (deny == TerritoryType.WILDERNESS) denyDesc = "wilderness";
|
||||
if (deny == TerritoryType.OWN) denyDesc = "your own";
|
||||
if (deny == TerritoryType.OTHER) denyDesc = "other faction's";
|
||||
|
||||
Player player = event.getPlayer();
|
||||
MixinMessage.get().msgOne(player, "<b>Teleportation with %s is not allowed in %s territory.", teleportDesc, denyDesc);
|
||||
}
|
||||
|
||||
private Entry<TeleportCause, TerritoryType> shouldBeCancelled(PlayerTeleportEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
if (MUtil.isntPlayer(player)) return null;
|
||||
|
||||
MPlayer mplayer = MPlayer.get(player);
|
||||
|
||||
PS from = PS.valueOf(event.getFrom());
|
||||
PS to = PS.valueOf(event.getTo());
|
||||
|
||||
TerritoryType typeFrom = getTerritoryType(mplayer, from);
|
||||
TerritoryType typeTo = getTerritoryType(mplayer, to);
|
||||
List<TerritoryType> types = MUtil.list(typeFrom, typeTo);
|
||||
|
||||
TeleportCause cause = event.getCause();
|
||||
MConf mconf = MConf.get();
|
||||
|
||||
if (cause == TeleportCause.CHORUS_FRUIT)
|
||||
{
|
||||
if (!mconf.allowChorusFruitInEnemyTerritory && types.contains(TerritoryType.ENEMY))
|
||||
return Couple.valueOf(cause, TerritoryType.ENEMY);
|
||||
|
||||
if (!mconf.allowChorusFruitInWildernessTerritory && types.contains(TerritoryType.WILDERNESS))
|
||||
return Couple.valueOf(cause, TerritoryType.WILDERNESS);
|
||||
|
||||
if (!mconf.allowChorusFruitInOwnTerritory && types.contains(TerritoryType.OWN))
|
||||
return Couple.valueOf(cause, TerritoryType.OWN);
|
||||
|
||||
if (!mconf.allowChorusFruitInOtherTerritory && types.contains(TerritoryType.OTHER))
|
||||
return Couple.valueOf(cause, TerritoryType.OTHER);
|
||||
}
|
||||
else if (cause == TeleportCause.ENDER_PEARL)
|
||||
{
|
||||
if (!mconf.allowEnderPearlInEnemyTerritory && types.contains(TerritoryType.ENEMY))
|
||||
return Couple.valueOf(cause, TerritoryType.ENEMY);
|
||||
|
||||
if (!mconf.allowEnderPearlInWildernessTerritory && types.contains(TerritoryType.WILDERNESS))
|
||||
return Couple.valueOf(cause, TerritoryType.WILDERNESS);
|
||||
|
||||
if (!mconf.allowEnderPearlInOwnTerritory && types.contains(TerritoryType.OWN))
|
||||
return Couple.valueOf(cause, TerritoryType.OWN);
|
||||
|
||||
if (!mconf.allowEnderPearlInOtherTerritory && types.contains(TerritoryType.OTHER))
|
||||
return Couple.valueOf(cause, TerritoryType.OTHER);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Don't cancel other kinds of teleports
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private TerritoryType getTerritoryType(MPlayer mplayer, PS territory)
|
||||
{
|
||||
Faction territoryFaction = BoardColl.get().getFactionAt(territory);
|
||||
Rel relation = territoryFaction.getRelationTo(mplayer);
|
||||
|
||||
if (territoryFaction.isNone()) return TerritoryType.WILDERNESS;
|
||||
if (relation == Rel.ENEMY) return TerritoryType.ENEMY;
|
||||
if (relation == Rel.FACTION) return TerritoryType.OWN;
|
||||
return TerritoryType.OTHER;
|
||||
}
|
||||
|
||||
}
|
@ -479,6 +479,20 @@ public class MConf extends Entity<MConf>
|
||||
public int unstuckSeconds = 30;
|
||||
public int unstuckChunkRadius = 10;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ENDER PEARL AND CHORUS FRUIT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean allowEnderPearlInEnemyTerritory = true;
|
||||
public boolean allowEnderPearlInWildernessTerritory = true;
|
||||
public boolean allowEnderPearlInOwnTerritory = true;
|
||||
public boolean allowEnderPearlInOtherTerritory = true;
|
||||
|
||||
public boolean allowChorusFruitInEnemyTerritory = true;
|
||||
public boolean allowChorusFruitInWildernessTerritory = true;
|
||||
public boolean allowChorusFruitInOwnTerritory = true;
|
||||
public boolean allowChorusFruitInOtherTerritory = true;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// LOGGING
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user