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

View File

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

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
@ -22,41 +23,16 @@ public class CmdStealth extends FCommand {
}
public void perform() {
if (myFaction != null && !myFaction.isWilderness() && !myFaction.isSafeZone() && !myFaction.isWarZone() && myFaction.isNormal()) {
// Sends Enable/Disable Message
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());
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());
fme.msg(fme.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE);
} else {
fme.msg(TL.COMMAND_STEALTH_MUSTBEMEMBER);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STEALTH_DESCRIPTION;
}
}

View File

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