From 994bbb585f541da5ad6667f798267b90069a6802 Mon Sep 17 00:00:00 2001 From: Sangelo Date: Tue, 7 Jun 2022 18:56:51 +0200 Subject: [PATCH] Initial commit --- .gitattributes | 2 + .gitignore | 113 ++++++++++++++++++ LICENSE | 21 ++++ config-backup.yml | 79 ++++++++++++ pom.xml | 63 ++++++++++ .../java/space/sangelo/unique/Unique.java | 82 +++++++++++++ .../sangelo/unique/commands/FeedCommand.java | 49 ++++++++ .../sangelo/unique/commands/FlyCommand.java | 59 +++++++++ .../unique/commands/ForceReloadCommand.java | 28 +++++ .../unique/commands/GamemodeACommand.java | 60 ++++++++++ .../unique/commands/GamemodeCCommand.java | 60 ++++++++++ .../unique/commands/GamemodeSCommand.java | 60 ++++++++++ .../unique/commands/GamemodeSpCommand.java | 61 ++++++++++ .../sangelo/unique/commands/GodCommand.java | 60 ++++++++++ .../sangelo/unique/commands/HealCommand.java | 51 ++++++++ .../sangelo/unique/commands/PrintCommand.java | 42 +++++++ .../unique/commands/SetSpawnCommand.java | 34 ++++++ .../sangelo/unique/commands/SpawnCommand.java | 90 ++++++++++++++ .../unique/commands/UniqueCommand.java | 29 +++++ .../unique/commands/VanishCommand.java | 85 +++++++++++++ .../listeners/PlayerConnectionListener.java | 29 +++++ .../unique/listeners/SpawnListener.java | 40 +++++++ .../unique/listeners/VanishLoginListener.java | 43 +++++++ .../listeners/VanishPlayerListener.java | 51 ++++++++ .../sangelo/unique/util/MessageUtil.java | 60 ++++++++++ .../sangelo/unique/util/VanishManager.java | 51 ++++++++ src/main/resources/config.yml | 20 ++++ src/main/resources/messages.yml | 78 ++++++++++++ src/main/resources/plugin.yml | 87 ++++++++++++++ 29 files changed, 1587 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 config-backup.yml create mode 100644 pom.xml create mode 100644 src/main/java/space/sangelo/unique/Unique.java create mode 100644 src/main/java/space/sangelo/unique/commands/FeedCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/FlyCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/ForceReloadCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/GamemodeACommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/GamemodeCCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/GamemodeSCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/GamemodeSpCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/GodCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/HealCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/PrintCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/SetSpawnCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/SpawnCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/UniqueCommand.java create mode 100644 src/main/java/space/sangelo/unique/commands/VanishCommand.java create mode 100644 src/main/java/space/sangelo/unique/listeners/PlayerConnectionListener.java create mode 100644 src/main/java/space/sangelo/unique/listeners/SpawnListener.java create mode 100644 src/main/java/space/sangelo/unique/listeners/VanishLoginListener.java create mode 100644 src/main/java/space/sangelo/unique/listeners/VanishPlayerListener.java create mode 100644 src/main/java/space/sangelo/unique/util/MessageUtil.java create mode 100644 src/main/java/space/sangelo/unique/util/VanishManager.java create mode 100644 src/main/resources/config.yml create mode 100644 src/main/resources/messages.yml create mode 100644 src/main/resources/plugin.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..db78b5d --- /dev/null +++ b/.gitignore @@ -0,0 +1,113 @@ +# User-specific +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +target/ + +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next + +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +# Common working directory +run/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0e964bc --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Sangelo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/config-backup.yml b/config-backup.yml new file mode 100644 index 0000000..b397e7d --- /dev/null +++ b/config-backup.yml @@ -0,0 +1,79 @@ +# __ __ _ +# / / / /___ (_)___ ___ _____ +# / / / / __ \/ / __ `/ / / / _ \ +#/ /_/ / / / / / /_/ / /_/ / __/ +#\____/_/ /_/_/\__, /\__,_/\___/ +# /_/ + +# !! INFO +# Placeholders: +# %p is the player's name. +# %t is the target's name. +# %c is the placeholder for the command itself. +# %u is the command's usage. +# !! Do not replace the placeholders, or change them up, as it will break things !! +# For example: +# - Do not do this: Replace %c in no-args-msg with %p. +# - Do this: Move it around inside of the message, so it makes sense when you translate messages. + +# Sets the prefix for chat messages. +prefix: '&8[&2Unique&8]&r ' + +# This message will be sent when a player couldn't be found. +player-not-online-msg: "&cThis player is not online or doesn't exist." +# This is the message that will be sent to the console when it has to be ran in game. +console-not-allowed-msg: "&cYou need to be on the server to use this command." +# This is the message that is sent to the player, when they don't have the required permissions +no-perms-msg: "&cYou don't have the required permissions to execute this command." +# This is the error that will be sent when no arguments were given. +no-args-msg: "&cNo arguments were given. Usage: &6/%c %u&c." +# These are the join and leave messages. +join-msg: "&8[&2+&8]&a %p" +quit-msg: "&8[&4-&8]&c %p" + +# These are the toggle messages for god mode. +god-enabled-msg: '&2God mode is now &aenabled&2.' +god-disabled-msg: '&2God mode is now &cdisabled&2.' +# These are the toggle messages for god mode, on the sender's side. +god-enabled-others-msg: '&2You have &aenabled&2 god mode for &6%t&2.' +god-disabled-others-msg: '&2You have &cdisabled&2 god mode for &6%t&2.' +# These are the toggle messages for god mode, on the target's side. +god-enabled-target-msg: '&2God mode has now been &aenabled&2 for you by &6%p&2.' +god-disabled-target-msg: '&2God mode has now been &cdisabled&2 for you by &6%p&2.' + +# These are the toggle messages for flight. +flight-enabled-msg: '&2Flight is now &aenabled&2.' +flight-disabled-msg: '&2Flight is now &cdisabled&2.' +# These are the toggle messages for flight, on the sender's side. +flight-enabled-others-msg: '&2You have &aenabled&2 flight for &6%t&2.' +flight-disabled-others-msg: '&2You have &cdisabled&2 flight for &6%t&2.' +# These are the toggle messages for flight, on the target's side. +flight-enabled-target-msg: '&2Flight has now been &aenabled&2 for you by &6%p&2.' +flight-disabled-target-msg: '&2Flight has now been &cdisabled&2 for you by &6%p&2.' + +# These are the toggle messages for vanish. +vanish-enabled-msg: '&2You are now &ainvisible&2.' +vanish-disabled-msg: '&2You are now &cvisible&2.' + +# These are the feed messages. +feed-msg: "&2You have now been fed." +feed-others-msg: '&2You have now fed &6%t&2.' +feed-target-msg: '&2You have been fed by &6%p&2.' + +# These are the heal messages. +heal-msg: "&2You have now been healed." +heal-others-msg: '&2You have now healed &6%t&2.' +heal-target-msg: '&2You have been healed by &6%p&2.' + +# This is the message that is sent to the mod, when they set a new spawn point. +setspawn-msg: "&2Spawn location has now been set &asuccessfully." +# This is the confirmation message that is sent to the player, when they teleport to the spawn point. +spawn-tp-msg: "&2You have been teleported to spawn." +# This is the message that is sent to the player, when they tried to teleport to the spawn point, but have to wait for the cooldown. +spawn-cooldown-msg: "&cYou cannot teleport for another &6%s&c seconds." +# This is the message that is sent to the player, when they tried to teleport to the spawn point, but there is none set. +spawn-no-location-msg: "&cThere is no spawn location set. Couldn't initiate teleport." +# This is the message that is sent to the moderator, when they tried to teleport to the spawn point, but there is none set. +spawn-mod-no-location-msg: "&cThere is no spawn location set. Couldn't initiate teleport. Use &6/setspawn &cto set one." +# This is the command cooldown in seconds. You can type 0 to disable it, or any other number to enable it. Default is 3. +spawn-command-cooldown: 3 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8eb2c6f --- /dev/null +++ b/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + space.sangelo + unique + 1.0.0 + jar + + Unique + + Escape the ordinary – Be Unique! + + 17 + UTF-8 + + https://sangelo.space + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 17 + + + + + + src/main/resources + true + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + jitpack.io + https://jitpack.io + + + + + + io.papermc.paper + paper-api + 1.18.2-R0.1-SNAPSHOT + provided + + + diff --git a/src/main/java/space/sangelo/unique/Unique.java b/src/main/java/space/sangelo/unique/Unique.java new file mode 100644 index 0000000..2612d3c --- /dev/null +++ b/src/main/java/space/sangelo/unique/Unique.java @@ -0,0 +1,82 @@ +package space.sangelo.unique; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import space.sangelo.unique.commands.*; +import space.sangelo.unique.listeners.PlayerConnectionListener; +import space.sangelo.unique.listeners.SpawnListener; +import space.sangelo.unique.listeners.VanishLoginListener; +import space.sangelo.unique.listeners.VanishPlayerListener; +import space.sangelo.unique.util.MessageUtil; +import space.sangelo.unique.util.VanishManager; + +import java.io.File; + +public final class Unique extends JavaPlugin { + private MessageUtil messageUtil; + private VanishManager vanishManager; + //public Config config = new Config("config.yml", this.getDataFolder().getAbsolutePath(), this.getResource("config.yml")); + + @Override + public void onEnable() { + messageUtil = new MessageUtil(this, new File(getDataFolder(), "messages.yml")); + vanishManager = new VanishManager(this); + loadListeners(); + loadConfig(); + loadCommands(); + Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Unique] " + ChatColor.GREEN + "Plugin has started."); + } + + // Load Commands + public void loadCommands() { + Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Unique] " + ChatColor.YELLOW + "Loading commands..."); + getCommand("unique").setExecutor(new UniqueCommand(this)); + getCommand("print").setExecutor(new PrintCommand(this)); + getCommand("god").setExecutor(new GodCommand(this)); + getCommand("fly").setExecutor(new FlyCommand(this)); + getCommand("vanish").setExecutor(new VanishCommand(this)); + getCommand("heal").setExecutor(new HealCommand(this)); + getCommand("feed").setExecutor(new FeedCommand(this)); + getCommand("setspawn").setExecutor(new SetSpawnCommand(this)); + getCommand("spawn").setExecutor(new SpawnCommand(this)); + getCommand("forcereload").setExecutor(new ForceReloadCommand(this)); + getCommand("gmc").setExecutor(new GamemodeCCommand(this)); + getCommand("gms").setExecutor(new GamemodeSCommand(this)); + getCommand("gmsp").setExecutor(new GamemodeSpCommand(this)); + getCommand("gma").setExecutor(new GamemodeACommand(this)); + Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Unique] " + ChatColor.GOLD + "Commands loaded."); + } + + // Load Config + public void loadConfig() { + Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Unique] " + ChatColor.YELLOW + "Loading config..."); + saveResource("config.yml", false); + reloadConfig(); + Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Unique] " + ChatColor.GOLD + "Loading config complete"); + } + + // Load Listeners + public void loadListeners() { + final PluginManager pluginManager = getServer().getPluginManager(); + pluginManager.registerEvents(new PlayerConnectionListener(this), this); + pluginManager.registerEvents(new SpawnListener(this), this); + pluginManager.registerEvents(new VanishLoginListener(this), this); + pluginManager.registerEvents(new VanishPlayerListener(this), this); + } + + @Override + public void onDisable() { + Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Unique] " + ChatColor.GOLD + "Shutting down..."); + } + + public MessageUtil getMessageUtil() { + return messageUtil; + } + + public VanishManager getVanishManager() { + return vanishManager; + } + +} diff --git a/src/main/java/space/sangelo/unique/commands/FeedCommand.java b/src/main/java/space/sangelo/unique/commands/FeedCommand.java new file mode 100644 index 0000000..280ffde --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/FeedCommand.java @@ -0,0 +1,49 @@ +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +public class FeedCommand implements CommandExecutor { + private final MessageUtil messageUtil; + + public FeedCommand(final Unique plugin) { + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (sender instanceof Player player) { + if (args.length == 0) { + if (player.hasPermission("unique.moderation.feed")) { + player.setFoodLevel(20); + player.setSaturation(20); + messageUtil.sendMessageWithPrefix(player, "feed-msg"); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } else { + final String playerName = args[0]; + final Player target = Bukkit.getServer().getPlayerExact(playerName); + if (target == null) { + messageUtil.sendMessageWithPrefix(player, "player-not-online-msg"); + } else { + if (player.hasPermission("unique.moderation.feed.others")) { + target.setFoodLevel(20); + target.setSaturation(20); + messageUtil.sendMessageWithPrefix(target, "feed-target-msg", Placeholder.component("player", player.displayName())); + messageUtil.sendMessageWithPrefix(player, "feed-others-msg", Placeholder.component("target", target.displayName())); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } + } + } + return true; + } +} \ No newline at end of file diff --git a/src/main/java/space/sangelo/unique/commands/FlyCommand.java b/src/main/java/space/sangelo/unique/commands/FlyCommand.java new file mode 100644 index 0000000..8fdcc25 --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/FlyCommand.java @@ -0,0 +1,59 @@ +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +public class FlyCommand implements CommandExecutor { + private final MessageUtil messageUtil; + private final Unique plugin; + + public FlyCommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (sender instanceof Player player) + if (args.length == 0) { + if (player.hasPermission("unique.moderation.fly")) { + if (player.getAllowFlight()) { + player.setAllowFlight(false); + messageUtil.sendMessageWithPrefix(player, "flight-disabled-msg"); + } else { + player.setAllowFlight(true); + messageUtil.sendMessageWithPrefix(player, "flight-enabled-msg"); + } + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } else { + final String playerName = args[0]; + final Player target = Bukkit.getServer().getPlayerExact(playerName); + if (player.hasPermission("unique.moderation.fly.set")) { + if (target == null) { + messageUtil.sendMessageWithPrefix(player, "player-not-online-msg"); + } else { + if (target.getAllowFlight()) { + target.setAllowFlight(false); + messageUtil.sendMessageWithPrefix(player, "flight-disabled-target-msg", Placeholder.component("player", player.displayName())); + messageUtil.sendMessageWithPrefix(player, "flight-disabled-others-msg", Placeholder.component("target", target.displayName())); + } else { + target.setAllowFlight(true); + messageUtil.sendMessageWithPrefix(player, "flight-enabled-target-msg", Placeholder.component("player", player.displayName())); + messageUtil.sendMessageWithPrefix(player, "flight-enabled-others-msg", Placeholder.component("target", target.displayName())); + } + } + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } + return true; + } +} diff --git a/src/main/java/space/sangelo/unique/commands/ForceReloadCommand.java b/src/main/java/space/sangelo/unique/commands/ForceReloadCommand.java new file mode 100644 index 0000000..3802df0 --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/ForceReloadCommand.java @@ -0,0 +1,28 @@ +package space.sangelo.unique.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + + +public class ForceReloadCommand implements CommandExecutor { + private final Unique plugin; + private final MessageUtil messageUtil; + + public ForceReloadCommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (sender.hasPermission("unique.admin.forcereload")) { + messageUtil.sendMessageWithPrefix(sender, "force-reload-msg"); + plugin.reloadConfig(); + messageUtil.sendMessageWithPrefix(sender, "force-reload-complete-msg"); + } + return true; + } +} diff --git a/src/main/java/space/sangelo/unique/commands/GamemodeACommand.java b/src/main/java/space/sangelo/unique/commands/GamemodeACommand.java new file mode 100644 index 0000000..bca913a --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/GamemodeACommand.java @@ -0,0 +1,60 @@ +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +public class GamemodeACommand implements CommandExecutor { + private final Unique plugin; + private final MessageUtil messageUtil; + + public GamemodeACommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { + if (sender instanceof Player player && args.length == 0) { + adventurePlayerSelf(player); + } else if (sender instanceof Player player) { + final Player target = Bukkit.getPlayerExact(args[0]); + if (player.hasPermission("unique.moderation.adventure.others")) { + if (player == target) { + player.setGameMode(GameMode.ADVENTURE); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "adventure")); + } else { + target.setGameMode(GameMode.ADVENTURE); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-others-msg", Placeholder.unparsed("gamemode", "adventure"), Placeholder.component("target", target.displayName())); + messageUtil.sendMessageWithPrefix(target, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "adventure")); + } + } + } + if (sender instanceof ConsoleCommandSender && args.length == 0) { + messageUtil.sendMessageWithPrefix(sender, "console-specify-player"); + } + return true; + } + + public void adventurePlayerSelf(final Player player) { + if (player.getGameMode() == GameMode.ADVENTURE) { + if (player.hasPermission("unique.moderation.gamemode.adventure.self")) { + messageUtil.sendMessageWithPrefix(player, "gamemode-already-set-msg", Placeholder.unparsed("gamemode", "adventure")); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } else if (player.hasPermission("unique.moderation.gamemode.adventure.self")) { + player.setGameMode(GameMode.ADVENTURE); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "adventure")); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } +} diff --git a/src/main/java/space/sangelo/unique/commands/GamemodeCCommand.java b/src/main/java/space/sangelo/unique/commands/GamemodeCCommand.java new file mode 100644 index 0000000..e446a94 --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/GamemodeCCommand.java @@ -0,0 +1,60 @@ +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +public class GamemodeCCommand implements CommandExecutor { + private final Unique plugin; + private final MessageUtil messageUtil; + + public GamemodeCCommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { + if (sender instanceof Player player && args.length == 0) { + creativePlayerSelf(player); + } else if (sender instanceof Player player) { + final Player target = Bukkit.getPlayerExact(args[0]); + if (player.hasPermission("unique.moderation.gamemode.creative.others")) { + if (player == target) { + player.setGameMode(GameMode.CREATIVE); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "creative")); + } else { + target.setGameMode(GameMode.CREATIVE); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-others-msg", Placeholder.unparsed("gamemode", "creative"), Placeholder.component("target", target.displayName())); + messageUtil.sendMessageWithPrefix(target, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "creative")); + } + } + } + if (sender instanceof ConsoleCommandSender && args.length == 0) { + messageUtil.sendMessageWithPrefix(sender, "console-specify-player"); + } + return true; + } + + public void creativePlayerSelf(final Player player) { + if (player.getGameMode() == GameMode.CREATIVE) { + if (player.hasPermission("unique.moderation.gamemode.creative.self")) { + messageUtil.sendMessageWithPrefix(player, "gamemode-already-set-msg", Placeholder.unparsed("gamemode", "creative")); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } else if (player.hasPermission("unique.moderation.gamemode.creative.self")) { + player.setGameMode(GameMode.CREATIVE); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "creative")); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } +} diff --git a/src/main/java/space/sangelo/unique/commands/GamemodeSCommand.java b/src/main/java/space/sangelo/unique/commands/GamemodeSCommand.java new file mode 100644 index 0000000..3c671be --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/GamemodeSCommand.java @@ -0,0 +1,60 @@ +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +public class GamemodeSCommand implements CommandExecutor { + private final Unique plugin; + private final MessageUtil messageUtil; + + public GamemodeSCommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { + if (sender instanceof Player player && args.length == 0) { + survivalPlayerSelf(player); + } else if (sender instanceof Player player) { + final Player target = Bukkit.getPlayerExact(args[0]); + if (player.hasPermission("unique.moderation.gamemode.survival.others")) { + if (player == target) { + player.setGameMode(GameMode.SURVIVAL); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "survival")); + } else { + target.setGameMode(GameMode.SURVIVAL); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-others-msg", Placeholder.unparsed("gamemode", "survival"), Placeholder.component("target", target.displayName())); + messageUtil.sendMessageWithPrefix(target, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "survival")); + } + } + } + if (sender instanceof ConsoleCommandSender && args.length == 0) { + messageUtil.sendMessageWithPrefix(sender, "console-specify-player"); + } + return true; + } + + public void survivalPlayerSelf(final Player player) { + if (player.getGameMode() == GameMode.SURVIVAL) { + if (player.hasPermission("unique.moderation.gamemode.survival.self")) { + messageUtil.sendMessageWithPrefix(player, "gamemode-already-set-msg", Placeholder.unparsed("gamemode", "survival")); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } else if (player.hasPermission("unique.moderation.gamemode.survival.self")) { + player.setGameMode(GameMode.SURVIVAL); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "survival")); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } +} diff --git a/src/main/java/space/sangelo/unique/commands/GamemodeSpCommand.java b/src/main/java/space/sangelo/unique/commands/GamemodeSpCommand.java new file mode 100644 index 0000000..79f4559 --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/GamemodeSpCommand.java @@ -0,0 +1,61 @@ +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +public class GamemodeSpCommand implements CommandExecutor { + private final Unique plugin; + private final MessageUtil messageUtil; + + public GamemodeSpCommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { + if (sender instanceof Player player && args.length == 0) { + spectatorPlayerSelf(player); + } else if (sender instanceof Player player) { + final Player target = Bukkit.getPlayerExact(args[0]); + if (player.hasPermission("unique.moderation.gamemode.spectator.others")) { + if (player == target) { + player.setGameMode(GameMode.SPECTATOR); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "spectator")); + } else { + target.setGameMode(GameMode.SPECTATOR); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-others-msg", Placeholder.unparsed("gamemode", "spectator"), Placeholder.component("target", target.displayName())); + messageUtil.sendMessageWithPrefix(target, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "spectator")); + } + } + } + if (sender instanceof ConsoleCommandSender && args.length == 0) { + messageUtil.sendMessageWithPrefix(sender, "console-specify-player"); + } + return true; + } + + public void spectatorPlayerSelf(final Player player) { + if (player.getGameMode() == GameMode.SPECTATOR) { + if (player.hasPermission("unique.moderation.gamemode.spectator.self")) { + messageUtil.sendMessageWithPrefix(player, "gamemode-already-set-msg", Placeholder.unparsed("gamemode", "spectator")); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } else if (player.hasPermission("unique.moderation.gamemode.spectator.self")) { + player.setGameMode(GameMode.SPECTATOR); + messageUtil.sendMessageWithPrefix(player, "gamemode-switcher-msg", Placeholder.unparsed("gamemode", "spectator")); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } +} + diff --git a/src/main/java/space/sangelo/unique/commands/GodCommand.java b/src/main/java/space/sangelo/unique/commands/GodCommand.java new file mode 100644 index 0000000..19c9481 --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/GodCommand.java @@ -0,0 +1,60 @@ +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +public class GodCommand implements CommandExecutor { + private final Unique plugin; + private final MessageUtil messageUtil; + + public GodCommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (sender instanceof Player player) { + if (args.length == 0) { + if (player.hasPermission("unique.moderation.god.use")) { + if (player.isInvulnerable()) { + player.setInvulnerable(false); + messageUtil.sendMessageWithPrefix(player, "god-disabled-msg"); + } else { + player.setInvulnerable(true); + messageUtil.sendMessageWithPrefix(player, "god-enabled-msg"); + } + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } else { + final String playerName = args[0]; + final Player target = Bukkit.getServer().getPlayerExact(playerName); + if (player.hasPermission("unique.moderation.god.set")) { + if (target == null) { + messageUtil.sendMessageWithPrefix(player, "player-not-online"); + } else { + if (target.isInvulnerable()) { + target.setInvulnerable(false); + messageUtil.sendMessageWithPrefix(target, "god-disabled-target-msg", Placeholder.component("player", player.displayName())); + messageUtil.sendMessageWithPrefix(player, "god-disabled-others-msg", Placeholder.component("target", target.displayName())); + } else { + target.setInvulnerable(true); + messageUtil.sendMessageWithPrefix(target, "god-enabled-target-msg", Placeholder.component("player", player.displayName())); + messageUtil.sendMessageWithPrefix(player, "god-enabled-others-msg", Placeholder.component("target", target.displayName())); + } + } + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } + } + return true; + } +} \ No newline at end of file diff --git a/src/main/java/space/sangelo/unique/commands/HealCommand.java b/src/main/java/space/sangelo/unique/commands/HealCommand.java new file mode 100644 index 0000000..59df9bb --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/HealCommand.java @@ -0,0 +1,51 @@ +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +import static org.bukkit.attribute.Attribute.GENERIC_MAX_HEALTH; + +public class HealCommand implements CommandExecutor { + private final Unique plugin; + private final MessageUtil messageUtil; + + public HealCommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (sender instanceof Player player) { + if (args.length == 0) { + if (player.hasPermission("unique.moderation.heal")) { + player.setHealth(player.getAttribute(GENERIC_MAX_HEALTH).getDefaultValue()); + messageUtil.sendMessageWithPrefix(player, "heal-msg"); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } else { + final String playerName = args[0]; + final Player target = Bukkit.getServer().getPlayerExact(playerName); + if (target == null) { + messageUtil.sendMessageWithPrefix(player, "player-not-online-msg"); + } else { + if (player.hasPermission("unique.moderation.heal.others")) { + target.setHealth(target.getAttribute(GENERIC_MAX_HEALTH).getDefaultValue()); + messageUtil.sendMessageWithPrefix(target, "heal-target-msg", Placeholder.component("player", player.displayName())); + messageUtil.sendMessageWithPrefix(player, "heal-others-msg", Placeholder.component("target", target.displayName())); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } + } + } + return true; + } +} \ No newline at end of file diff --git a/src/main/java/space/sangelo/unique/commands/PrintCommand.java b/src/main/java/space/sangelo/unique/commands/PrintCommand.java new file mode 100644 index 0000000..425d664 --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/PrintCommand.java @@ -0,0 +1,42 @@ +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +public class PrintCommand implements CommandExecutor { + private final Unique plugin; + + private final MessageUtil messageUtil; + + public PrintCommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (sender instanceof Player player) { + if (args.length == 0) { + messageUtil.sendMessageWithPrefix(player, "no-args-msg", Placeholder.unparsed("command", "print {message}")); + } else if (args.length == 1) { + final String printMessage = args[0]; + messageUtil.sendMessageWithPrefix(player, "print-msg", Placeholder.parsed("message", printMessage)); + } else { + final StringBuilder builder = new StringBuilder(); + for (int i = 0; i < args.length; i++) { + builder.append(args[i]); + builder.append(" "); + } + String printFinalMessage = builder.toString(); + printFinalMessage = printFinalMessage.stripTrailing(); + messageUtil.sendMessageWithPrefix(player, "print-msg", Placeholder.parsed("message", printFinalMessage)); + } + } + return true; + } +} diff --git a/src/main/java/space/sangelo/unique/commands/SetSpawnCommand.java b/src/main/java/space/sangelo/unique/commands/SetSpawnCommand.java new file mode 100644 index 0000000..54605e5 --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/SetSpawnCommand.java @@ -0,0 +1,34 @@ +package space.sangelo.unique.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +public class SetSpawnCommand implements CommandExecutor { + private final Unique plugin; + private final MessageUtil messageUtil; + + public SetSpawnCommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (sender instanceof Player player) { + if (player.hasPermission("unique.moderation.setspawn")) { + plugin.getConfig().set("spawn", player.getLocation()); + plugin.saveConfig(); + messageUtil.sendMessageWithPrefix(player, "setspawn-msg"); + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } else { + messageUtil.sendMessageWithPrefix(sender, "console-not-allowed-msg"); + } + return true; + } +} \ No newline at end of file diff --git a/src/main/java/space/sangelo/unique/commands/SpawnCommand.java b/src/main/java/space/sangelo/unique/commands/SpawnCommand.java new file mode 100644 index 0000000..c3507f0 --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/SpawnCommand.java @@ -0,0 +1,90 @@ +// Warning! Very duplicate code bc i don't have a clue. +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +import java.util.HashMap; +import java.util.UUID; + +public class SpawnCommand implements CommandExecutor { + private final Unique plugin; + private final MessageUtil messageUtil; + + private final HashMap cooldown; + + public SpawnCommand(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + this.cooldown = new HashMap<>(); + } + + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + + final Location location = plugin.getConfig().getLocation("spawn"); + + if (sender instanceof Player player) { + if (!player.hasPermission("unique.moderation.bypass.cooldown")) { + if (!this.cooldown.containsKey(player.getUniqueId())) { + this.cooldown.put(player.getUniqueId(), System.currentTimeMillis()); + if (location != null) { + player.teleport(location); + messageUtil.sendMessageWithPrefix(player, "spawn-tp-msg"); + } else { + if (!player.hasPermission("unique.moderation.setspawn")) { + messageUtil.sendMessageWithPrefix(player, "spawn-no-location-msg"); + } else { + messageUtil.sendMessageWithPrefix(player, "spawn-mod-no-location-msg"); + } + } + } else { + final long timeElapsedMs = System.currentTimeMillis() - cooldown.get(player.getUniqueId()); + final long timeElapsed = (timeElapsedMs / 1000) % 60; + if (timeElapsed >= plugin.getConfig().getLong("spawn-command-cooldown")) { + this.cooldown.put(player.getUniqueId(), System.currentTimeMillis()); + if (player.hasPermission("unique.moderation.setspawn")) { + if (location != null) { + player.teleport(location); + messageUtil.sendMessageWithPrefix(player, "spawn-tp-msg"); + } else { + if (player.hasPermission("unique.moderation.setspawn")) { + messageUtil.sendMessageWithPrefix(player, "spawn-mod-no-location-msg"); + } else { + messageUtil.sendMessageWithPrefix(player, "spawn-no-location-msg"); + } + } + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } else { + messageUtil.sendMessageWithPrefix(player, "spawn-mod-no-location-msg", Placeholder.unparsed("remaining", String.valueOf(plugin.getConfig().getLong("spawn-command-cooldown") - timeElapsed))); + } + } + } else { + if (player.hasPermission("unique.general.spawn")) { + if (location != null) { + player.teleport(location); + messageUtil.sendMessageWithPrefix(player, "spawn-tp-msg"); + } else { + if (player.hasPermission("unique.moderation.setspawn")) { + messageUtil.sendMessageWithPrefix(player, "spawn-mod-no-location-msg"); + } else { + messageUtil.sendMessageWithPrefix(player, "spawn-no-location-msg"); + } + } + } else { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + } + } + } + return true; + } +} diff --git a/src/main/java/space/sangelo/unique/commands/UniqueCommand.java b/src/main/java/space/sangelo/unique/commands/UniqueCommand.java new file mode 100644 index 0000000..021fd3a --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/UniqueCommand.java @@ -0,0 +1,29 @@ +package space.sangelo.unique.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; + +public class UniqueCommand implements CommandExecutor { + private final Unique plugin; + + public UniqueCommand(final Unique plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (sender instanceof Player player) { +// p.sendMessage(ChatColor.DARK_GREEN + "-=-=-=-=-=-=-"); + player.sendMessage(ChatColor.DARK_GREEN + "Unique - " + ChatColor.GOLD + "v" + plugin.getDescription().getVersion()); +// p.sendMessage(ChatColor.DARK_GREEN + "-=-=-=-=-=-=-"); + player.sendMessage(ChatColor.DARK_GRAY + "Author: " + ChatColor.AQUA + "Sangelo"); + player.sendMessage(ChatColor.DARK_GRAY + "Website: " + ChatColor.BLUE + "" + ChatColor.UNDERLINE + "https://sangelo.space"); + player.sendMessage(ChatColor.DARK_GREEN + "For help, type " + ChatColor.GOLD + "/help unique"); + } + return true; + } +} diff --git a/src/main/java/space/sangelo/unique/commands/VanishCommand.java b/src/main/java/space/sangelo/unique/commands/VanishCommand.java new file mode 100644 index 0000000..0e4bfb1 --- /dev/null +++ b/src/main/java/space/sangelo/unique/commands/VanishCommand.java @@ -0,0 +1,85 @@ +package space.sangelo.unique.commands; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; +import space.sangelo.unique.util.VanishManager; + +public class VanishCommand implements CommandExecutor { + + private final Unique plugin; + private final VanishManager vanishManager; + private final MessageUtil messageUtil; + + public VanishCommand(final Unique plugin) { + this.plugin = plugin; + this.vanishManager = plugin.getVanishManager(); + this.messageUtil = plugin.getMessageUtil(); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) { + if (!(sender instanceof final Player player)) return false; + if (args.length > 0) { + if (args[0].equalsIgnoreCase("list")) { + if (!player.hasPermission("unique.moderation.vanish.list")) { + messageUtil.sendMessageWithPrefix(player, "no-perms-msg"); + return true; + } + if (vanishManager.getHiddenUsernames().size() > 0) { + final StringBuilder builder = new StringBuilder(); + for (int i = 0; i < vanishManager.getHiddenUsernames().size(); i++) { + builder.append(vanishManager.getHiddenUsernames().get(i)); + if (i < vanishManager.getHiddenUsernames().size() - 1) { + builder.append(", "); + } + } + messageUtil.sendMessageWithPrefix(player, "vanish-hidden-list-msg", Placeholder.unparsed("playerlist", String.valueOf(builder))); + } else { + messageUtil.sendMessageWithPrefix(player, "vanish-hidden-none"); + } + return true; + } else if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) { + return false; + } else if (player.hasPermission("unique.moderation.vanish.other")) { + Player target = plugin.getServer().getPlayer(args[0]); + if (target == null) target = plugin.getServer().getPlayerExact(args[0]); + if (target == null) { + messageUtil.sendMessageWithPrefix(player, "player-not-online-msg"); + return true; + } + + if (!vanishManager.isVanished(target)) { + vanishManager.vanishPlayer(target); + messageUtil.sendMessageWithPrefix(player, "vanish-enabled-msg"); + messageUtil.sendMessageWithPrefix(player, "vanish-enabled-others-msg", Placeholder.component("player", player.displayName())); + plugin.getServer().broadcast(messageUtil.getMessage("quit-msg", Placeholder.component("player", player.displayName()))); + return true; + } else { + vanishManager.showPlayer(target); + messageUtil.sendMessageWithPrefix(player, "vanish-disabled-msg"); + messageUtil.sendMessageWithPrefix(player, "vanish-disabled-others-msg", Placeholder.component("player", player.displayName())); + plugin.getServer().broadcast(messageUtil.getMessage("join-msg", Placeholder.component("player", player.displayName()))); + return true; + } + } + } else if (player.hasPermission("unique.moderation.vanish.use")) { + if (!vanishManager.isVanished(player)) { + vanishManager.vanishPlayer(player); + messageUtil.sendMessageWithPrefix(player, "vanish-enabled-msg"); + plugin.getServer().broadcast(messageUtil.getMessage("quit-msg", Placeholder.component("player", player.displayName()))); + return true; + } else { + vanishManager.showPlayer(player); + messageUtil.sendMessageWithPrefix(player, "vanish-disabled-msg"); + plugin.getServer().broadcast(messageUtil.getMessage("join-msg", Placeholder.component("player", player.displayName()))); + return true; + } + } + return false; + } +} diff --git a/src/main/java/space/sangelo/unique/listeners/PlayerConnectionListener.java b/src/main/java/space/sangelo/unique/listeners/PlayerConnectionListener.java new file mode 100644 index 0000000..4c71e0c --- /dev/null +++ b/src/main/java/space/sangelo/unique/listeners/PlayerConnectionListener.java @@ -0,0 +1,29 @@ +package space.sangelo.unique.listeners; + +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.MessageUtil; + +public class PlayerConnectionListener implements Listener { + private final Unique plugin; + private final MessageUtil messageUtil; + + public PlayerConnectionListener(final Unique plugin) { + this.plugin = plugin; + this.messageUtil = plugin.getMessageUtil(); + } + + @EventHandler + public void onJoin(final PlayerJoinEvent event) { + event.joinMessage(messageUtil.getMessage("join-msg", Placeholder.component("player", event.getPlayer().displayName()))); + } + + @EventHandler + public void onLeave(final PlayerQuitEvent event) { + event.quitMessage(messageUtil.getMessage("quit-msg", Placeholder.component("player", event.getPlayer().displayName()))); + } +} diff --git a/src/main/java/space/sangelo/unique/listeners/SpawnListener.java b/src/main/java/space/sangelo/unique/listeners/SpawnListener.java new file mode 100644 index 0000000..e14fdd2 --- /dev/null +++ b/src/main/java/space/sangelo/unique/listeners/SpawnListener.java @@ -0,0 +1,40 @@ +package space.sangelo.unique.listeners; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import space.sangelo.unique.Unique; + +public class SpawnListener implements Listener { + private final Unique plugin; + + public SpawnListener(final Unique plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onPlayerJoin(final PlayerJoinEvent e) { + // Spawn the player on the spawn location on first join, if one's set. + final Player p = e.getPlayer(); + if (!e.getPlayer().hasPlayedBefore()) { + final Location location = plugin.getConfig().getLocation("spawn"); + if (location != null) { + p.teleport(location); + } + } + } + + @EventHandler + public void onPlayerRespawn(final PlayerRespawnEvent e) { + // Respawn the player at the spawn location, if one's set. + final Location location = plugin.getConfig().getLocation("spawn"); + if (location != null) { + if (e.getPlayer().getBedSpawnLocation() == null) { + e.setRespawnLocation(location); + } + } + } +} diff --git a/src/main/java/space/sangelo/unique/listeners/VanishLoginListener.java b/src/main/java/space/sangelo/unique/listeners/VanishLoginListener.java new file mode 100644 index 0000000..2a163e6 --- /dev/null +++ b/src/main/java/space/sangelo/unique/listeners/VanishLoginListener.java @@ -0,0 +1,43 @@ +package space.sangelo.unique.listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.VanishManager; + +public class VanishLoginListener implements Listener { + private final Unique plugin; + private final VanishManager vanishManager; + + public VanishLoginListener(final Unique plugin) { + this.plugin = plugin; + this.vanishManager = plugin.getVanishManager(); + } + + @EventHandler + public void handleLogin(final PlayerLoginEvent event) { + final Player player = event.getPlayer(); + + if (vanishManager.isVanished(player)) { + vanishManager.showPlayer(player); + } + if (player.hasPermission("unique.moderation.vanish.see")) return; + for (final Player p1 : plugin.getServer().getOnlinePlayers()) { + if (vanishManager.isVanished(p1) && !player.equals(p1)) { + player.hidePlayer(plugin, p1); + } + } + } + + @EventHandler + public void handleQuit(final PlayerQuitEvent event) { + final Player player = event.getPlayer(); + + if (vanishManager.isVanished(player)) { + vanishManager.showPlayer(player); + } + } +} \ No newline at end of file diff --git a/src/main/java/space/sangelo/unique/listeners/VanishPlayerListener.java b/src/main/java/space/sangelo/unique/listeners/VanishPlayerListener.java new file mode 100644 index 0000000..8982608 --- /dev/null +++ b/src/main/java/space/sangelo/unique/listeners/VanishPlayerListener.java @@ -0,0 +1,51 @@ +package space.sangelo.unique.listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByBlockEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityPickupItemEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import space.sangelo.unique.Unique; +import space.sangelo.unique.util.VanishManager; + +public class VanishPlayerListener implements Listener { + + private final VanishManager vanishManager; + + public VanishPlayerListener(final Unique plugin) { + this.vanishManager = plugin.getVanishManager(); + } + + @EventHandler + public void onEntityTarget(final EntityTargetEvent event) { + if (event.getEntity() instanceof Player player && vanishManager.isVanished(player)) { + event.setCancelled(true); + } + } + + + @EventHandler + public void onDamageByBlock(final EntityDamageByBlockEvent event) { + if (event.getEntity() instanceof Player player && vanishManager.isVanished(player)) { + event.setCancelled(true); + } + } + + @EventHandler + public void onDamageByEntity(final EntityDamageByEntityEvent event) { + if (event.getDamager() instanceof Player player && vanishManager.isVanished(player)) { + event.setCancelled(true); + } else if (event.getEntity() instanceof Player player && vanishManager.isVanished(player)) { + event.setCancelled(true); + } + } + + @EventHandler + public void onItemPickup(final EntityPickupItemEvent event) { + if (event.getEntity() instanceof Player player && vanishManager.isVanished(player)) { + event.setCancelled(true); + } + } +} diff --git a/src/main/java/space/sangelo/unique/util/MessageUtil.java b/src/main/java/space/sangelo/unique/util/MessageUtil.java new file mode 100644 index 0000000..a07c38c --- /dev/null +++ b/src/main/java/space/sangelo/unique/util/MessageUtil.java @@ -0,0 +1,60 @@ +package space.sangelo.unique.util; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import space.sangelo.unique.Unique; + +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class MessageUtil { + + private final FileConfiguration externalConfig; + private final FileConfiguration internalConfig; + private final Component prefix; + + public MessageUtil(final Unique plugin, final File messageConfig) { + if (!messageConfig.exists()) { + plugin.saveResource(messageConfig.getName(), false); + } + externalConfig = YamlConfiguration.loadConfiguration(messageConfig); + + final InputStream inputStream = plugin.getResource(messageConfig.getName()); + + assert inputStream != null; + final InputStreamReader inputStreamReader = new InputStreamReader(inputStream); + internalConfig = YamlConfiguration.loadConfiguration(inputStreamReader); + + prefix = MiniMessage.miniMessage().deserialize(getString("prefix")); + } + + public void sendMessage(final CommandSender sender, final String configString, final TagResolver... tagResolvers) { + sender.sendMessage(getMessage(configString, tagResolvers)); + } + + public void sendMessageWithPrefix(final CommandSender sender, final String configString, final TagResolver... tagResolvers) { + sender.sendMessage(getMessageWithPrefix(configString, tagResolvers)); + } + + public Component getMessage(final String configString, final TagResolver... tagResolvers) { + return MiniMessage.miniMessage().deserialize(getString(configString), tagResolvers); + } + + + public Component getMessageWithPrefix(final String configString, final TagResolver... tagResolvers) { + return prefix.append(getMessage(configString, tagResolvers)); + } + + public String getString(final String configString) { + if (externalConfig.contains(configString)) { + return externalConfig.getString(configString); + } else { + return internalConfig.getString(configString); + } + } +} diff --git a/src/main/java/space/sangelo/unique/util/VanishManager.java b/src/main/java/space/sangelo/unique/util/VanishManager.java new file mode 100644 index 0000000..e642ccb --- /dev/null +++ b/src/main/java/space/sangelo/unique/util/VanishManager.java @@ -0,0 +1,51 @@ +package space.sangelo.unique.util; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import space.sangelo.unique.Unique; + +import java.util.ArrayList; + +public class VanishManager { + private final ArrayList hiddenUsernames; + + private final Unique plugin; + + public VanishManager(final Unique plugin) { + this.plugin = plugin; + this.hiddenUsernames = new ArrayList<>(); + } + + public boolean isVanished(final Player player) { + return hiddenUsernames.contains(player.getName()); + } + + public void vanishPlayer(final Player p) { + final String vanishModLogsMsg = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("prefix") + plugin.getConfig().getString("vanish-mod-logs-msg")); + hiddenUsernames.add(p.getName()); + for (final Player p1 : plugin.getServer().getOnlinePlayers()) { + if (p1 == p) { + continue; + } else if (p1.hasPermission("unique.moderation.vanish.see")) { + p1.sendMessage(vanishModLogsMsg.replace("%p", p.getName())); + continue; + } else if (p1.hasPermission("unique.moderation.vanish.list")) { + p1.hidePlayer(plugin, p); + p1.sendMessage(vanishModLogsMsg.replace("%p", p.getName())); + continue; + } + p1.hidePlayer(plugin, p); + } + } + + public void showPlayer(final Player player) { + hiddenUsernames.remove(player.getName()); + for (final Player p1 : plugin.getServer().getOnlinePlayers()) { + p1.showPlayer(plugin, player); + } + } + + public ArrayList getHiddenUsernames() { + return hiddenUsernames; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..985b6d8 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,20 @@ +# __ __ _ +# / / / /___ (_)___ ___ _____ +# / / / / __ \/ / __ `/ / / / _ \ +#/ /_/ / / / / / /_/ / /_/ / __/ +#\____/_/ /_/_/\__, /\__,_/\___/ +# /_/ + +# !! INFO +# Placeholders: +# %p is the player's name. +# %t is the target's name. +# %c is the placeholder for the command itself. +# %u is the command's usage. +# !! Do not replace the placeholders, or change them up, as it will break things !! +# For example: +# - Do not do this: Replace %c in no-args-msg with %p. +# - Do this: Move it around inside of the message, so it makes sense when you translate messages. + +# This is the command cooldown in seconds. You can type 0 to disable it, or any other number to enable it. Default is 3. +spawn-command-cooldown: 3 \ No newline at end of file diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml new file mode 100644 index 0000000..d8ccafa --- /dev/null +++ b/src/main/resources/messages.yml @@ -0,0 +1,78 @@ +# Sets the prefix for chat messages. +prefix: '[Unique] ' +print-msg: '(print) ' + +# This message will be sent when a player couldn't be found. +player-not-online-msg: "This player is not online or doesn't exist." +# This message is sent to the console, when they try to run a command that only works on players. +console-specify-player: 'Please specify a player.' +# This is the message that will be sent to the console when it has to be ran in game. +console-not-allowed-msg: "You need to be on the server to use this command." +# This is the message that is sent to the player, when they don't have the required permissions +no-perms-msg: "You don't have the required permissions to execute this command." +# This is the error that will be sent when no arguments were given. +no-args-msg: "No arguments were given. Usage: / ." +# This are the force reload messages. +force-reload-msg: "Forcing reload of the plugin..." +force-reload-complete-msg: "Forcing reload of the plugin complete!" +# These are the join and leave messages. +join-msg: "[+] " +quit-msg: "[-] " + +# These are the toggle messages for god mode. +god-enabled-msg: 'God mode is now enabled.' +god-disabled-msg: 'God mode is now disabled.' +# These are the toggle messages for god mode, on the sender's side. +god-enabled-others-msg: 'You have enabled god mode for .' +god-disabled-others-msg: 'You have disabled god mode for .' +# These are the toggle messages for god mode, on the target's side. +god-enabled-target-msg: 'God mode has now been enabled for you by .' +god-disabled-target-msg: 'God mode has now been disabled for you by .' + +# These are the toggle messages for flight. +flight-enabled-msg: 'Flight is now enabled.' +flight-disabled-msg: 'Flight is now disabled.' +# These are the toggle messages for flight, on the sender's side. +flight-enabled-others-msg: 'You have enabled flight for .' +flight-disabled-others-msg: 'You have disabled flight for .' +# These are the toggle messages for flight, on the target's side. +flight-enabled-target-msg: 'Flight has now been enabled for you by .' +flight-disabled-target-msg: 'Flight has now been disabled for you by .' + +# These are the toggle messages for vanish. +vanish-enabled-msg: 'You are now invisible.' +vanish-disabled-msg: 'You are now visible.' +vanish-enabled-others-msg: ' is now invisible.' +vanish-disabled-others-msg: ' is now visible.' +# Other vanish related messages. +vanish-hidden-list-msg: 'Hidden players: ' +vanish-hidden-none-msg: 'There are no hidden players.' +vanish-mod-logs-msg: ' has vanished.' + + +# These are the feed messages. +feed-msg: "You have now been fed." +feed-others-msg: 'You have now fed .' +feed-target-msg: 'You have been fed by .' + +# These are the heal messages. +heal-msg: "You have now been healed." +heal-others-msg: 'You have now healed .' +heal-target-msg: 'You have been healed by .' + +# These are the gamemode switcher messages. +gamemode-switcher-msg: 'Your gamemode has been updated to .' +gamemode-already-set-msg: 'You already are in .' +gamemode-already-set-others-msg: "'s gamemode is already set to ." +gamemode-switch-others-msg: "You have changed 's to ." + +# This is the message that is sent to the mod, when they set a new spawn point. +setspawn-msg: "Spawn location has now been set successfully." +# This is the confirmation message that is sent to the player, when they teleport to the spawn point. +spawn-tp-msg: "You have been teleported to spawn." +# This is the message that is sent to the player, when they tried to teleport to the spawn point, but have to wait for the cooldown. +spawn-cooldown-msg: "You cannot teleport for another seconds." +# This is the message that is sent to the player, when they tried to teleport to the spawn point, but there is none set. +spawn-no-location-msg: "There is no spawn location set. Couldn't initiate teleport." +# This is the message that is sent to the moderator, when they try to teleport to the spawn point, but there is none set. +spawn-mod-no-location-msg: "There is no spawn location set. Couldn't initiate teleport. Use /setspawn to set one." diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..d0e3dd4 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,87 @@ +name: Unique +version: '${project.version}' +main: space.sangelo.unique.Unique +api-version: 1.18 +authors: [ Sangelo ] +description: Escape the ordinary – Be Unique! +website: https://sangelo.space +commands: + unique: + description: Main Plugin Command. Just a little about page. + usage: / + aliases: + - uq + - about + print: + description: Print a message. + usage: / {message} + aliases: + - hello + - test + - message + god: + description: Become invulnerable! Or let anyone else be. + usage: / [player] + fly: + description: Be able to fly! Or let anyone else be. + usage: / [player] + vanish: + description: Become invisible to others! + usage: / + aliases: + - v + - invis + - invisible + heal: + description: Heal yourself (or if you'd like, someone else)! + usage: / [player] + feed: + description: Feed yourself (or if you'd like, someone else)! + usage: / [player] + aliases: + - food + gmc: + description: Set your gamemode to creative. + usage: / [player] + aliases: + - gamemodec + - modec + - creative + - c + gms: + description: Set your gamemode to survival. + usage: / [player] + aliases: + - gamemodes + - modes + - survival + - s + gma: + description: Set your gamemode to adventure. + usage: / [player] + aliases: + - gamemodea + - modea + - adventure + - a + gmsp: + description: Set your gamemode to spectator. + usage: / [player] + aliases: + - gamemodesp + - modesp + - spectator + - sp + setspawn: + description: Sets the spawnpoint to the current player location. + usage: / + spawn: + description: Teleports the player to the spawnpoint, if there is one specified. + usage: / + forcereload: + description: Force the server to reload the plugin configuration. + usage: / + aliases: + - rlu + - rlunique + - reloadunique \ No newline at end of file