Implement /f fly (#1023)
This commit is contained in:
parent
aacee63255
commit
a90299d32e
@ -261,6 +261,16 @@ public interface FPlayer extends EconomyParticipator {
|
||||
|
||||
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
|
||||
// -------------------------------
|
||||
|
68
src/main/java/com/massivecraft/factions/cmd/CmdFly.java
Normal file
68
src/main/java/com/massivecraft/factions/cmd/CmdFly.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
@ -20,6 +20,7 @@ public class FCmdRoot extends FCommand {
|
||||
public CmdDeinvite cmdDeinvite = new CmdDeinvite();
|
||||
public CmdDescription cmdDescription = new CmdDescription();
|
||||
public CmdDisband cmdDisband = new CmdDisband();
|
||||
public CmdFly cmdFly = new CmdFly();
|
||||
public CmdHelp cmdHelp = new CmdHelp();
|
||||
public CmdHome cmdHome = new CmdHome();
|
||||
public CmdInvite cmdInvite = new CmdInvite();
|
||||
@ -114,6 +115,7 @@ public class FCmdRoot extends FCommand {
|
||||
this.addSubCommand(this.cmdDeinvite);
|
||||
this.addSubCommand(this.cmdDescription);
|
||||
this.addSubCommand(this.cmdDisband);
|
||||
this.addSubCommand(this.cmdFly);
|
||||
this.addSubCommand(this.cmdHelp);
|
||||
this.addSubCommand(this.cmdHome);
|
||||
this.addSubCommand(this.cmdInvite);
|
||||
|
@ -102,9 +102,11 @@ public class FactionsEntityListener implements Listener {
|
||||
|
||||
if (damagee != null && damagee instanceof Player) {
|
||||
cancelFStuckTeleport((Player) damagee);
|
||||
cancelFFly((Player) damagee);
|
||||
}
|
||||
if (damager instanceof Player) {
|
||||
cancelFStuckTeleport((Player) damager);
|
||||
cancelFFly((Player) damager);
|
||||
}
|
||||
} else if (Conf.safeZonePreventAllDamageToPlayers && isPlayerInSafeZone(event.getEntity())) {
|
||||
// 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) {
|
||||
if (player == null) {
|
||||
return;
|
||||
|
@ -177,6 +177,12 @@ public class FactionsPlayerListener implements Listener {
|
||||
Faction factionTo = Board.getInstance().getFactionAt(to);
|
||||
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 (showTimes.containsKey(player.getUniqueId()) && (showTimes.get(player.getUniqueId()) > System.currentTimeMillis())) {
|
||||
if (P.p.getConfig().getBoolean("findfactionsexploit.log", false)) {
|
||||
|
@ -87,7 +87,8 @@ public enum Permission {
|
||||
TOP("top"),
|
||||
VAULT("vault"),
|
||||
SETMAXVAULTS("setmaxvaults"),
|
||||
WARP("warp");
|
||||
WARP("warp"),
|
||||
FLIGHT("flight");
|
||||
|
||||
public final String node;
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class WarmUpUtil {
|
||||
}
|
||||
|
||||
public enum Warmup {
|
||||
HOME, WARP;
|
||||
HOME, WARP, FLIGHT;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,9 @@ public enum PermissableAction {
|
||||
PROMOTE("promote"),
|
||||
PERMS("perms"),
|
||||
SETWARP("setwarp"),
|
||||
WARP("warp"),;
|
||||
WARP("warp"),
|
||||
FLIGHT("fly"),
|
||||
;
|
||||
|
||||
private String name;
|
||||
|
||||
|
@ -16,6 +16,8 @@ import com.massivecraft.factions.struct.Relation;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.RelationUtil;
|
||||
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 mkremins.fanciful.FancyMessage;
|
||||
import org.bukkit.*;
|
||||
@ -61,6 +63,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
protected int kills, deaths;
|
||||
protected boolean willAutoLeave = true;
|
||||
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 boolean mapAutoUpdating;
|
||||
@ -879,6 +882,43 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
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
|
||||
// -------------------------------------------- //
|
||||
|
@ -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_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_COMMANDFORMAT("<i>/f warp <warpname> [password]"),
|
||||
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_LOG("%1$s unclaimed all war zones."),
|
||||
|
||||
|
||||
/**
|
||||
* 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_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_ALREADY("&cYou are already warming up."),
|
||||
WARMUPS_CANCELLED("&cYou have cancelled your warmup.");
|
||||
|
@ -58,6 +58,10 @@ warp-cost:
|
||||
delwarp: 5
|
||||
warp: 5
|
||||
|
||||
# Faction Fly
|
||||
# Enable Faction Fly:
|
||||
enable-faction-flight: true
|
||||
|
||||
# Pistons
|
||||
# Should we disable pistons in Faction territory? This will prevent people from doing something like:
|
||||
# http://i.gyazo.com/6a1a31222e58a5d60ff341c13f6a8404.gif
|
||||
@ -160,6 +164,8 @@ warmups:
|
||||
f-home: 0
|
||||
# Delay for /f warp
|
||||
f-warp: 0
|
||||
# Delay for /f fly
|
||||
f-fly: 0
|
||||
|
||||
######################################################
|
||||
#################### HCF Features ####################
|
||||
|
@ -283,3 +283,5 @@ permissions:
|
||||
description: Set your /f map height.
|
||||
factions.ban:
|
||||
description: Ban players from Factions
|
||||
factions.flight:
|
||||
description: Allow use of /f fly
|
||||
|
Loading…
Reference in New Issue
Block a user