Essentials/Essentials/src/main/java/com/earth2me/essentials/commands/Commandvanish.java

47 lines
1.7 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.CommonPlaceholders;
import net.ess3.api.events.VanishStatusChangeEvent;
import org.bukkit.Server;
2015-04-15 06:06:16 +02:00
public class Commandvanish extends EssentialsToggleCommand {
public Commandvanish() {
super("vanish", "essentials.vanish.others");
}
@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
toggleOtherPlayers(server, sender, args);
}
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
handleToggleWithArgs(server, user, args);
2015-04-15 06:06:16 +02:00
}
@Override
protected void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
2015-04-15 06:06:16 +02:00
if (enabled == null) {
enabled = !user.isVanished();
}
2020-10-03 19:46:05 +02:00
final VanishStatusChangeEvent vanishEvent = new VanishStatusChangeEvent(sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null, user, enabled);
2016-07-10 17:09:53 +02:00
ess.getServer().getPluginManager().callEvent(vanishEvent);
if (vanishEvent.isCancelled()) {
return;
}
2015-04-15 06:06:16 +02:00
user.setVanished(enabled);
user.sendTl("vanish", user.getDisplayName(), CommonPlaceholders.enableDisable(user.getSource(), enabled));
2015-04-15 06:06:16 +02:00
2015-06-03 22:11:56 +02:00
if (enabled) {
user.sendTl("vanished");
2015-04-15 06:06:16 +02:00
}
if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) {
sender.sendTl("vanish", user.getDisplayName(), CommonPlaceholders.enableDisable(user.getSource(), enabled));
2015-04-15 06:06:16 +02:00
}
}
2016-07-10 17:09:53 +02:00
}