Revamped F Stealth

This commit is contained in:
Driftay 2018-09-20 16:55:19 -04:00
parent 496ac17d39
commit e580c7eee9
3 changed files with 14 additions and 38 deletions

@ -193,19 +193,19 @@ public class CmdFly extends FCommand {
FLocation myfloc = new FLocation(me.getLocation()); FLocation myfloc = new FLocation(me.getLocation());
Faction toFac = Board.getInstance().getFactionAt(myfloc); Faction toFac = Board.getInstance().getFactionAt(myfloc);
if (!checkBypassPerms(fme, me, toFac)) return; if (!checkBypassPerms(fme, me, toFac)) return;
List<Entity> entities = me.getNearbyEntities(16, 256, 16); List<Entity> entities = this.me.getNearbyEntities(16.0D, 256.0D, 16.0D);
for (int i = 0; i <= entities.size() - 1; i++) {
for(int i = 0; i <= entities.size() - 1; ++i) {
if (entities.get(i) instanceof Player) { if (entities.get(i) instanceof Player) {
Player eplayer = (Player)entities.get(i); Player eplayer = (Player)entities.get(i);
FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer); FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer);
if (efplayer.getRelationTo(fme) == Relation.ENEMY && !efplayer.isStealthEnabled()) { if (efplayer.getRelationTo(this.fme) == Relation.ENEMY && !efplayer.isStealthEnabled()) {
fme.msg(TL.COMMAND_FLY_CHECK_ENEMY); this.fme.msg(TL.COMMAND_FLY_CHECK_ENEMY);
return; return;
} }
} }
} }
if (args.size() == 0) { if (args.size() == 0) {
toggleFlight(!fme.isFlying(), me); toggleFlight(!fme.isFlying(), me);
} else if (args.size() == 1) { } else if (args.size() == 1) {

@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
@ -22,41 +23,16 @@ public class CmdStealth extends FCommand {
} }
public void perform() { public void perform() {
if (myFaction != null && !myFaction.isWilderness() && !myFaction.isSafeZone() && !myFaction.isWarZone() && myFaction.isNormal()) { Faction faction = fme.getFaction();
if (faction != null && !faction.getId().equalsIgnoreCase("0") && !faction.getId().equalsIgnoreCase("none") && !faction.getId().equalsIgnoreCase("safezone") && !faction.getId().equalsIgnoreCase("warzone")) {
fme.setStealth(!fme.isStealthEnabled());
// Sends Enable/Disable Message fme.msg(fme.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE);
if (fme.isStealthEnabled()) {
fme.setStealth(false);
} else {
/* The FPlayer#takeMoney method calls the FPlayer#hasMoney method beforehand to check if the amount
* can be withdrawn successfully.
* The FPlayer#hasMoney method already sends a deny message so there isn't a need to send another.
* Basically the takeMoney is an all in one solution for taking money :)
*/
fme.takeMoney(P.p.getConfig().getInt("stealth-cost"));
fme.setStealth(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() {
@Override
public void run() {
if (fme.isStealthEnabled()) {
fme.setStealth(false);
fme.msg(TL.COMMAND_STEALTH_DISABLE);
}
}
// We multiplied by 20 here because the value is in ticks.
}, P.p.getConfig().getInt("stealth-timeout") * 20);
}
fme.sendMessage(fme.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE.toString().replace("{timeout}", P.p.getConfig().getInt("stealth-timeout") + "") : TL.COMMAND_STEALTH_DISABLE.toString());
} else { } else {
fme.msg(TL.COMMAND_STEALTH_MUSTBEMEMBER); fme.msg(TL.COMMAND_STEALTH_MUSTBEMEMBER);
} }
} }
@Override
public TL getUsageTranslation() { public TL getUsageTranslation() {
return TL.COMMAND_STEALTH_DESCRIPTION; return TL.COMMAND_STEALTH_DESCRIPTION;
} }
} }

@ -1046,9 +1046,9 @@ public abstract class MemoryFPlayer implements FPlayer {
if (eplayer == null) { continue; } if (eplayer == null) { continue; }
FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer); FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer);
if (efplayer == null) { continue; } if (efplayer == null) { continue; }
if (Conf.allowedStealthFactions != null && !efplayer.isStealthEnabled()) { if (efplayer != null && this.getRelationTo(efplayer).equals(Relation.ENEMY) && !efplayer.isStealthEnabled()) {
this.setFlying(false); setFlying(false);
this.msg(TL.COMMAND_FLY_ENEMY_NEAR); msg(TL.COMMAND_FLY_ENEMY_NEAR);
Bukkit.getServer().getPluginManager().callEvent(new FPlayerStoppedFlying(this)); Bukkit.getServer().getPluginManager().callEvent(new FPlayerStoppedFlying(this));
return true; return true;
} }