mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-23 03:54:56 +00:00
Add vanish
This commit is contained in:
parent
24fcaa081b
commit
c8d686238c
2 changed files with 165 additions and 0 deletions
|
@ -0,0 +1,58 @@
|
||||||
|
package me.StevenLawson.TotalFreedomMod.commands;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.manager.VanishManager;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
||||||
|
public class Command_vanish extends FreedomCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd,
|
||||||
|
String commandLabel, String[] args, boolean senderIsConsole) {
|
||||||
|
boolean shouldIVanish = true;
|
||||||
|
boolean silent = false;
|
||||||
|
|
||||||
|
if (args.length > 0) {
|
||||||
|
if (args[0].equalsIgnoreCase("off")) {
|
||||||
|
shouldIVanish = false;
|
||||||
|
} else {
|
||||||
|
shouldIVanish = !VanishManager.isVanished(sender_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length > 1) {
|
||||||
|
if (args[1].toLowerCase().startsWith("-s")) {
|
||||||
|
silent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (VanishManager.isVanished(sender_p)) {
|
||||||
|
shouldIVanish = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandLabel.equalsIgnoreCase("uv") || commandLabel.equalsIgnoreCase("unvanish")) {
|
||||||
|
shouldIVanish = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldIVanish) {
|
||||||
|
VanishManager.vanishPlayer(sender_p);
|
||||||
|
|
||||||
|
if (!silent) {
|
||||||
|
VanishManager.fakeLeave(sender_p);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
VanishManager.unvanishPlayer(sender_p);
|
||||||
|
|
||||||
|
if (!silent) {
|
||||||
|
VanishManager.fakeJoin(sender_p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
playerMsg(sender,
|
||||||
|
String.format("Your vanish has been %s.", (shouldIVanish) ? "enabled" : "disabled"));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
package me.StevenLawson.TotalFreedomMod.manager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.admin.Admin;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.discord.bridge.DiscordBridge;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.player.PlayerData;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.player.PlayerRank;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class VanishManager {
|
||||||
|
|
||||||
|
private static final ArrayList<Player> vanishedPlayers = new ArrayList<>();
|
||||||
|
|
||||||
|
public static void vanishPlayer(Player player) {
|
||||||
|
if (vanishedPlayers.contains(player)) {
|
||||||
|
// Fail silently
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vanishedPlayers.add(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void unvanishPlayer(Player player) {
|
||||||
|
if (!vanishedPlayers.contains(player)) {
|
||||||
|
// Fail silently
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vanishedPlayers.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isVanished(Player player) {
|
||||||
|
return vanishedPlayers.contains(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadVanishedPlayers(Player player) {
|
||||||
|
for (Player vanishedPlayer : vanishedPlayers) {
|
||||||
|
player.hidePlayer(vanishedPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fakeLeave(Player player) {
|
||||||
|
TotalFreedomMod.fuckoffEnabledFor.remove(player);
|
||||||
|
|
||||||
|
final PlayerData playerdata = PlayerData.getPlayerData(player);
|
||||||
|
|
||||||
|
playerdata.disarmMP44();
|
||||||
|
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (!onlinePlayer.equals(player)) {
|
||||||
|
onlinePlayer.hidePlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscordBridge.transmitMessage(String.format("**%s left the server**",
|
||||||
|
DiscordBridge.fullySanitizeDiscordMessage(player.getDisplayName())));
|
||||||
|
|
||||||
|
TextComponent leftComponent = new TextComponent(
|
||||||
|
String.format("%s left the game.", player.getName()));
|
||||||
|
leftComponent.setColor(ChatColor.YELLOW);
|
||||||
|
|
||||||
|
Bukkit.spigot().broadcast(leftComponent);
|
||||||
|
|
||||||
|
vanishPlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fakeJoin(Player player) {
|
||||||
|
Admin asAdmin = AdminList.getEntry(player);
|
||||||
|
|
||||||
|
TranslatableComponent joinComponent = new TranslatableComponent(
|
||||||
|
"multiplayer.player.joined");
|
||||||
|
joinComponent.addWith(player.getName());
|
||||||
|
joinComponent.setColor(ChatColor.YELLOW);
|
||||||
|
|
||||||
|
TextComponent loginComponent = Utilities.fromBaseComponents(
|
||||||
|
TextComponent.fromLegacyText(
|
||||||
|
String.format(ChatColor.AQUA + "%s is %s", player.getName(),
|
||||||
|
Utilities.colorize(PlayerRank.getLoginMessage(player)))));
|
||||||
|
|
||||||
|
Bukkit.spigot().broadcast(loginComponent);
|
||||||
|
Bukkit.spigot().broadcast(joinComponent);
|
||||||
|
|
||||||
|
DiscordBridge.transmitMessage(String.format("**%s joined the server**", player.getName()));
|
||||||
|
|
||||||
|
unvanishPlayer(player);
|
||||||
|
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
onlinePlayer.showPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getFakeOnlinePlayers() {
|
||||||
|
if (vanishedPlayers.size() == 0) {
|
||||||
|
return Bukkit.getOnlinePlayers().size();
|
||||||
|
}
|
||||||
|
return Bukkit.getOnlinePlayers().size() - vanishedPlayers.size();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue