2018-07-30 18:05:28 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2018-08-27 05:27:55 +02:00
|
|
|
import com.massivecraft.factions.P;
|
|
|
|
import com.massivecraft.factions.integration.Econ;
|
2018-07-30 18:05:28 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2018-08-27 05:27:55 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2018-07-30 18:05:28 +02:00
|
|
|
|
|
|
|
public class CmdStealth extends FCommand {
|
|
|
|
public CmdStealth() {
|
|
|
|
this.aliases.add("ninja");
|
|
|
|
this.aliases.add("stealth");
|
|
|
|
this.permission = Permission.STEALTH.node;
|
|
|
|
|
|
|
|
this.disableOnLock = true;
|
|
|
|
|
|
|
|
this.senderMustBePlayer = true;
|
|
|
|
this.senderMustBeMember = false;
|
|
|
|
this.senderMustBeModerator = false;
|
|
|
|
this.senderMustBeColeader = false;
|
|
|
|
this.senderMustBeAdmin = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void perform() {
|
2018-08-02 16:32:53 +02:00
|
|
|
if (myFaction != null && !myFaction.isWilderness() && !myFaction.isSafeZone() && !myFaction.isWarZone() && myFaction.isNormal()) {
|
2018-08-27 05:27:55 +02:00
|
|
|
|
|
|
|
|
2018-08-02 16:32:53 +02:00
|
|
|
// Sends Enable/Disable Message
|
2018-08-27 05:27:55 +02:00
|
|
|
if (fme.isStealthEnabled()) {
|
|
|
|
fme.setStealth(false);
|
|
|
|
} else {
|
2018-08-27 17:39:34 +02:00
|
|
|
/* 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"));
|
2018-08-27 05:27:55 +02:00
|
|
|
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());
|
2018-07-30 18:05:28 +02:00
|
|
|
} else {
|
2018-08-02 16:32:53 +02:00
|
|
|
fme.msg(TL.COMMAND_STEALTH_MUSTBEMEMBER);
|
2018-07-30 18:05:28 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-02 16:32:53 +02:00
|
|
|
|
2018-07-30 18:05:28 +02:00
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_STEALTH_DESCRIPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|