Implement /f fly (#1023)

This commit is contained in:
Dariasc 2018-03-04 19:13:32 -03:00 committed by Trent Hensler
parent aacee63255
commit a90299d32e
12 changed files with 162 additions and 4 deletions

View File

@ -261,6 +261,16 @@ public interface FPlayer extends EconomyParticipator {
public void setId(String id); public void setId(String id);
public boolean isFlying();
public void setFlying(boolean fly);
public void setFFlying(boolean fly, boolean damage);
public boolean canFlyAtLocation();
public boolean canFlyAtLocation(FLocation location);
// ------------------------------- // -------------------------------
// Warmups // Warmups
// ------------------------------- // -------------------------------

View File

@ -0,0 +1,68 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.util.TL;
public class CmdFly extends FCommand {
public CmdFly() {
super();
this.aliases.add("fly");
this.optionalArgs.put("on/off", "flip");
this.permission = Permission.FLIGHT.node;
this.senderMustBeMember = true;
this.senderMustBeModerator = false;
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("enable-faction-flight", false)) {
fme.msg(TL.COMMAND_FLY_DISABLED);
return;
}
if (args.size() == 0) {
if (!fme.canFlyAtLocation() && !fme.isFlying()) {
Faction factionAtLocation = Board.getInstance().getFactionAt(fme.getLastStoodAt());
fme.msg(TL.COMMAND_FLY_NO_ACCESS, factionAtLocation.getTag(fme));
return;
}
toggleFlight(!fme.isFlying());
} else if (args.size() == 1) {
if (!fme.canFlyAtLocation() && argAsBool(0)) {
Faction factionAtLocation = Board.getInstance().getFactionAt(fme.getLastStoodAt());
fme.msg(TL.COMMAND_FLY_NO_ACCESS, factionAtLocation.getTag(fme));
return;
}
toggleFlight(argAsBool(0));
}
}
private void toggleFlight(final boolean toggle) {
if (!toggle) {
fme.setFlying(false);
return;
}
this.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", new Runnable() {
@Override
public void run() {
fme.setFlying(true);
}
}, this.p.getConfig().getLong("warmups.f-fly", 0));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_FLY_DESCRIPTION;
}
}

View File

@ -20,6 +20,7 @@ public class FCmdRoot extends FCommand {
public CmdDeinvite cmdDeinvite = new CmdDeinvite(); public CmdDeinvite cmdDeinvite = new CmdDeinvite();
public CmdDescription cmdDescription = new CmdDescription(); public CmdDescription cmdDescription = new CmdDescription();
public CmdDisband cmdDisband = new CmdDisband(); public CmdDisband cmdDisband = new CmdDisband();
public CmdFly cmdFly = new CmdFly();
public CmdHelp cmdHelp = new CmdHelp(); public CmdHelp cmdHelp = new CmdHelp();
public CmdHome cmdHome = new CmdHome(); public CmdHome cmdHome = new CmdHome();
public CmdInvite cmdInvite = new CmdInvite(); public CmdInvite cmdInvite = new CmdInvite();
@ -114,6 +115,7 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdDeinvite); this.addSubCommand(this.cmdDeinvite);
this.addSubCommand(this.cmdDescription); this.addSubCommand(this.cmdDescription);
this.addSubCommand(this.cmdDisband); this.addSubCommand(this.cmdDisband);
this.addSubCommand(this.cmdFly);
this.addSubCommand(this.cmdHelp); this.addSubCommand(this.cmdHelp);
this.addSubCommand(this.cmdHome); this.addSubCommand(this.cmdHome);
this.addSubCommand(this.cmdInvite); this.addSubCommand(this.cmdInvite);

View File

@ -102,9 +102,11 @@ public class FactionsEntityListener implements Listener {
if (damagee != null && damagee instanceof Player) { if (damagee != null && damagee instanceof Player) {
cancelFStuckTeleport((Player) damagee); cancelFStuckTeleport((Player) damagee);
cancelFFly((Player) damagee);
} }
if (damager instanceof Player) { if (damager instanceof Player) {
cancelFStuckTeleport((Player) damager); cancelFStuckTeleport((Player) damager);
cancelFFly((Player) damager);
} }
} else if (Conf.safeZonePreventAllDamageToPlayers && isPlayerInSafeZone(event.getEntity())) { } else if (Conf.safeZonePreventAllDamageToPlayers && isPlayerInSafeZone(event.getEntity())) {
// Players can not take any damage in a Safe Zone // Players can not take any damage in a Safe Zone
@ -124,6 +126,17 @@ public class FactionsEntityListener implements Listener {
} }
} }
private void cancelFFly(Player player) {
if (player == null) {
return;
}
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
if (fPlayer.isFlying()) {
fPlayer.setFFlying(false, true);
}
}
public void cancelFStuckTeleport(Player player) { public void cancelFStuckTeleport(Player player) {
if (player == null) { if (player == null) {
return; return;

View File

@ -177,6 +177,12 @@ public class FactionsPlayerListener implements Listener {
Faction factionTo = Board.getInstance().getFactionAt(to); Faction factionTo = Board.getInstance().getFactionAt(to);
boolean changedFaction = (factionFrom != factionTo); boolean changedFaction = (factionFrom != factionTo);
if (p.getConfig().getBoolean("enable-faction-flight", false) && changedFaction) {
if (!me.canFlyAtLocation() && me.isFlying()) {
me.setFlying(false);
}
}
if (me.isMapAutoUpdating()) { if (me.isMapAutoUpdating()) {
if (showTimes.containsKey(player.getUniqueId()) && (showTimes.get(player.getUniqueId()) > System.currentTimeMillis())) { if (showTimes.containsKey(player.getUniqueId()) && (showTimes.get(player.getUniqueId()) > System.currentTimeMillis())) {
if (P.p.getConfig().getBoolean("findfactionsexploit.log", false)) { if (P.p.getConfig().getBoolean("findfactionsexploit.log", false)) {

View File

@ -87,7 +87,8 @@ public enum Permission {
TOP("top"), TOP("top"),
VAULT("vault"), VAULT("vault"),
SETMAXVAULTS("setmaxvaults"), SETMAXVAULTS("setmaxvaults"),
WARP("warp"); WARP("warp"),
FLIGHT("flight");
public final String node; public final String node;

View File

@ -36,7 +36,7 @@ public class WarmUpUtil {
} }
public enum Warmup { public enum Warmup {
HOME, WARP; HOME, WARP, FLIGHT;
} }
} }

View File

@ -33,7 +33,9 @@ public enum PermissableAction {
PROMOTE("promote"), PROMOTE("promote"),
PERMS("perms"), PERMS("perms"),
SETWARP("setwarp"), SETWARP("setwarp"),
WARP("warp"),; WARP("warp"),
FLIGHT("fly"),
;
private String name; private String name;

View File

@ -16,6 +16,8 @@ import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage; import mkremins.fanciful.FancyMessage;
import org.bukkit.*; import org.bukkit.*;
@ -61,6 +63,7 @@ public abstract class MemoryFPlayer implements FPlayer {
protected int kills, deaths; protected int kills, deaths;
protected boolean willAutoLeave = true; protected boolean willAutoLeave = true;
protected int mapHeight = 8; // default to old value protected int mapHeight = 8; // default to old value
protected boolean isFlying = false;
protected transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked? protected transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked?
protected transient boolean mapAutoUpdating; protected transient boolean mapAutoUpdating;
@ -879,6 +882,43 @@ public abstract class MemoryFPlayer implements FPlayer {
return !isOnline(); return !isOnline();
} }
public boolean isFlying() {
return isFlying;
}
public void setFlying(boolean fly) {
setFFlying(fly, false);
}
public void setFFlying(boolean fly, boolean damage) {
getPlayer().setAllowFlight(fly);
getPlayer().setFlying(fly);
if (!damage) {
msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled");
} else {
msg(TL.COMMAND_FLY_DAMAGE);
}
isFlying = fly;
}
public boolean canFlyAtLocation() {
return canFlyAtLocation(lastStoodAt);
}
public boolean canFlyAtLocation(FLocation location) {
Faction faction = Board.getInstance().getFactionAt(location);
if (faction.isWilderness() || faction.isSafeZone() || faction.isWarZone()) {
return false;
}
if (faction == getFaction() && getRole() == Role.ADMIN) {
return true;
}
Access access = faction.getAccess(this, PermissableAction.FLIGHT);
return access != null && access == Access.ALLOW;
}
// -------------------------------------------- // // -------------------------------------------- //
// Message Sending Helpers // Message Sending Helpers
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -187,6 +187,12 @@ public enum TL {
COMMAND_DISBAND_HOLDINGS("<i>You have been given the disbanded faction's bank, totaling %1$s."), COMMAND_DISBAND_HOLDINGS("<i>You have been given the disbanded faction's bank, totaling %1$s."),
COMMAND_DISBAND_DESCRIPTION("Disband a faction"), COMMAND_DISBAND_DESCRIPTION("Disband a faction"),
COMMAND_FLY_DISABLED("&cSorry, Faction flight is disabled on this server"),
COMMAND_FLY_DESCRIPTION("Enter or leave Faction flight mode"),
COMMAND_FLY_CHANGE("&eFaction flight &d%1$s"),
COMMAND_FLY_DAMAGE("&eFaction flight &ddisabled&e due to entering combat"),
COMMAND_FLY_NO_ACCESS("&cCannot fly in territory of %1$s"),
COMMAND_FWARP_CLICKTOWARP("Click to warp!"), COMMAND_FWARP_CLICKTOWARP("Click to warp!"),
COMMAND_FWARP_COMMANDFORMAT("<i>/f warp <warpname> [password]"), COMMAND_FWARP_COMMANDFORMAT("<i>/f warp <warpname> [password]"),
COMMAND_FWARP_WARPED("<i>Warped to <a>%1$s"), COMMAND_FWARP_WARPED("<i>Warped to <a>%1$s"),
@ -579,6 +585,7 @@ public enum TL {
COMMAND_WARUNCLAIMALL_SUCCESS("<i>You unclaimed ALL war zone land."), COMMAND_WARUNCLAIMALL_SUCCESS("<i>You unclaimed ALL war zone land."),
COMMAND_WARUNCLAIMALL_LOG("%1$s unclaimed all war zones."), COMMAND_WARUNCLAIMALL_LOG("%1$s unclaimed all war zones."),
/** /**
* Leaving - This is accessed through a command, and so it MAY need a COMMAND_* slug :s * Leaving - This is accessed through a command, and so it MAY need a COMMAND_* slug :s
*/ */
@ -779,6 +786,7 @@ public enum TL {
/** /**
* Warmups * Warmups
*/ */
WARMUPS_NOTIFY_FLIGHT("&eFlight will enable in &d%2$d &eseconds."),
WARMUPS_NOTIFY_TELEPORT("&eYou will teleport to &d%1$s &ein &d%2$d &eseconds."), WARMUPS_NOTIFY_TELEPORT("&eYou will teleport to &d%1$s &ein &d%2$d &eseconds."),
WARMUPS_ALREADY("&cYou are already warming up."), WARMUPS_ALREADY("&cYou are already warming up."),
WARMUPS_CANCELLED("&cYou have cancelled your warmup."); WARMUPS_CANCELLED("&cYou have cancelled your warmup.");

View File

@ -58,6 +58,10 @@ warp-cost:
delwarp: 5 delwarp: 5
warp: 5 warp: 5
# Faction Fly
# Enable Faction Fly:
enable-faction-flight: true
# Pistons # Pistons
# Should we disable pistons in Faction territory? This will prevent people from doing something like: # Should we disable pistons in Faction territory? This will prevent people from doing something like:
# http://i.gyazo.com/6a1a31222e58a5d60ff341c13f6a8404.gif # http://i.gyazo.com/6a1a31222e58a5d60ff341c13f6a8404.gif
@ -160,6 +164,8 @@ warmups:
f-home: 0 f-home: 0
# Delay for /f warp # Delay for /f warp
f-warp: 0 f-warp: 0
# Delay for /f fly
f-fly: 0
###################################################### ######################################################
#################### HCF Features #################### #################### HCF Features ####################

View File

@ -282,4 +282,6 @@ permissions:
factions.mapheight: factions.mapheight:
description: Set your /f map height. description: Set your /f map height.
factions.ban: factions.ban:
description: Ban players from Factions description: Ban players from Factions
factions.flight:
description: Allow use of /f fly