Added vanish command.

This commit is contained in:
Brianna O'Keefe 2019-02-26 22:08:19 -05:00
parent da9fb516d3
commit f3c6ffe32b
9 changed files with 152 additions and 13 deletions

View File

@ -2,6 +2,7 @@ package com.songoda.ultimatemoderation;
import com.songoda.ultimatemoderation.command.CommandManager;
import com.songoda.ultimatemoderation.listeners.ChatListener;
import com.songoda.ultimatemoderation.listeners.LoginListener;
import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.SettingsManager;
import org.bukkit.Bukkit;
@ -16,7 +17,6 @@ public class UltimateModeration extends JavaPlugin {
private SettingsManager settingsManager;
private CommandManager commandManager;
private Locale locale;
private ChatListener chatListener;
public static UltimateModeration getInstance() {
return INSTANCE;
@ -63,9 +63,9 @@ public class UltimateModeration extends JavaPlugin {
this.commandManager = new CommandManager(this);
this.chatListener = new ChatListener(this);
Bukkit.getPluginManager().registerEvents(this.chatListener, this);
// Register Listeners
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
Bukkit.getPluginManager().registerEvents(new LoginListener(this), this);
}
@ -106,8 +106,5 @@ public class UltimateModeration extends JavaPlugin {
return references;
}
public ChatListener getChatListener() {
return chatListener;
}
}

View File

@ -27,11 +27,13 @@ public class CommandManager implements CommandExecutor {
instance.getCommand("ClearChat").setExecutor(this);
instance.getCommand("ToggleChat").setExecutor(this);
instance.getCommand("RandomPlayer").setExecutor(this);
instance.getCommand("Vanish").setExecutor(this);
AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration());
addCommand(new CommandClearChat());
addCommand(new CommandToggleChat());
addCommand(new CommandRandomPlayer());
addCommand(new CommandVanish());
addCommand(new CommandSettings(commandUltimateModeration));
addCommand(new CommandReload(commandUltimateModeration));

View File

@ -3,6 +3,7 @@ package com.songoda.ultimatemoderation.command.commands;
import com.songoda.ultimatemoderation.Locale;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.listeners.ChatListener;
import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -31,7 +32,7 @@ public class CommandToggleChat extends AbstractCommand {
String strToggledOff = locale.getMessage("command.togglechat.toggledOff");
String messageToSend = prefix + Methods.formatText(toggled ? strToggledOn : strToggledOff);
instance.getChatListener().setChatToggled(toggled);
ChatListener.setChatToggled(toggled);
for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -0,0 +1,101 @@
package com.songoda.ultimatemoderation.command.commands;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.SettingsManager;
import org.bukkit.Bukkit;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class CommandVanish extends AbstractCommand {
private static List<UUID> inVanish = new ArrayList<>();
public CommandVanish() {
super(null, true, "Vanish");
}
@Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
Player player = ((Player)sender);
UUID uuid = player.getUniqueId();
if (inVanish.contains(uuid)) {
inVanish.remove(uuid);
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.vanish.toggledOff")));
} else {
inVanish.add(uuid);
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.vanish.toggledOn")));
}
if (SettingsManager.Setting.VANISH_EFFECTS.getBoolean()) {
player.getWorld().playSound(player.getLocation(), Sound.valueOf(SettingsManager.Setting.VANISH_SOUND.getString()), 1L, 1L);
if (SettingsManager.Setting.VANISH_BATS.getBoolean()) {
List<Entity> entities = new ArrayList<>();
for (int i = 0; i < 5; i++) {
entities.add(player.getWorld().spawnEntity(player.getLocation().add(0, 1, 0), EntityType.BAT));
}
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
for (Entity entity : entities) {
entity.remove();
}
}, 20L * 3L);
}
float xx = (float) (0 + (Math.random() * 1));
float yy = (float) (0 + (Math.random() * 2));
float zz = (float) (0 + (Math.random() * 1));
player.getWorld().spawnParticle(Particle.valueOf(SettingsManager.Setting.VANISH_PARTICLE.getString()), player.getLocation().add(0,1,0), 35, xx, yy, zz, 0);
}
for (Player p : Bukkit.getOnlinePlayers()) {
if (inVanish.contains(uuid))
registerVanishedPlayers(p);
else
p.showPlayer(player);
}
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
return null;
}
public static void registerVanishedPlayers(Player player) {
for (UUID uuid : inVanish) {
Player vanished = Bukkit.getPlayer(uuid);
if (vanished == null) continue;
if(player.hasPermission("um.vanish.bypass")) {
player.showPlayer(vanished);
} else {
player.hidePlayer(vanished);
}
}
}
@Override
public String getPermissionNode() {
return "um.vanish";
}
@Override
public String getSyntax() {
return "/Vanish";
}
@Override
public String getDescription() {
return "Makes you invisible.";
}
}

View File

@ -10,7 +10,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatListener implements Listener {
private UltimateModeration instance;
private boolean isChatToggled = true; // true means people can talk, false means muted
private static boolean isChatToggled = true; // true means people can talk, false means muted
public ChatListener(UltimateModeration ultimateModeration) {
this.instance = ultimateModeration;
@ -25,8 +25,8 @@ public class ChatListener implements Listener {
}
}
public void setChatToggled(boolean toggled) {
this.isChatToggled = toggled;
public static void setChatToggled(boolean toggled) {
isChatToggled = toggled;
}
}

View File

@ -0,0 +1,25 @@
package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandVanish;
import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerLoginEvent;
public class LoginListener implements Listener {
private UltimateModeration instance;
public LoginListener(UltimateModeration ultimateModeration) {
this.instance = ultimateModeration;
}
@EventHandler
public void onLogin(PlayerLoginEvent event) {
Player player = event.getPlayer();
CommandVanish.registerVanishedPlayers(player);
}
}

View File

@ -168,6 +168,11 @@ public class SettingsManager implements Listener {
public enum Setting {
VANISH_EFFECTS("Main.Enable Vanish Effects", true),
VANISH_SOUND("Main.Vanish Sound", "ENTITY_GENERIC_EXPLODE"),
VANISH_BATS("Main.Release Bats On Vanish", true),
VANISH_PARTICLE("Main.Vanish Particle", "EXPLOSION_NORMAL"),
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),
GLASS_TYPE_2("Interfaces.Glass Type 2", 11),
GLASS_TYPE_3("Interfaces.Glass Type 3", 3),

View File

@ -8,4 +8,7 @@ command.clearchat.immune = "&aYou were immune to the clear chat because of your
command.togglechat.toggledOn = "&aChat was globally Unmuted..."
command.togglechat.toggledOff = "&cChat was globally Muted..."
command.togglechat.bypass = "&aYou were immune to the chat toggle because of your perms."
command.togglechat.muted = "&cChat is currently disabled, try again later."
command.togglechat.muted = "&cChat is currently disabled, try again later."
command.vanish.toggledOn = "&7You are now visible."
command.vanish.toggledOff = "&7You are now vanished."

View File

@ -24,4 +24,9 @@ commands:
description: Random Player
default: false
aliases: [rp]
usage: /rp
usage: /rp
Vanish:
description: Vanish
default: false
aliases: [v]
usage: /v