commit 84ea3c1928da99556fbb4a22dbd6056e448a4696 Author: cloudwithax Date: Sat Aug 13 03:30:32 2022 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4788b4b --- /dev/null +++ b/.gitignore @@ -0,0 +1,113 @@ +# User-specific stuff +.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/README.md b/README.md new file mode 100644 index 0000000..f7f8bae --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# SMPCore + +The last SMP plugin you will ever need. \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..19cea14 --- /dev/null +++ b/pom.xml @@ -0,0 +1,75 @@ + + + 4.0.0 + + me.cloud + smpcore + 1.0 + jar + + Smpcore + + The core for any SMP you will ever need, ever. + + 1.8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 9 + 9 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + org.spigotmc + spigot-api + 1.18.2-R0.1-SNAPSHOT + provided + + + diff --git a/src/main/java/me/cloud/smpcore/Plugin.java b/src/main/java/me/cloud/smpcore/Plugin.java new file mode 100644 index 0000000..9f8eff0 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/Plugin.java @@ -0,0 +1,167 @@ +package me.cloud.smpcore; + +import me.cloud.smpcore.commands.*; +import me.cloud.smpcore.events.*; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.Statistic; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.*; +import java.nio.file.Files; +import java.time.Duration; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; +import java.util.logging.Level; + +public class Plugin extends JavaPlugin { + + private HashMap sleeping = new HashMap<>(); + private HashMap messages = new HashMap<>(); + private ArrayList vanished = new ArrayList<>(); + public FileConfiguration config = getConfig(); + + public ChatColor accentColor = ChatColor.valueOf(config.getString("accent_color")); + + public ArrayList motds = (ArrayList) config.getStringList("motds"); + + public ArrayList joinMOTD = (ArrayList) config.getStringList("join_motd"); + + public String chatPrefix = ChatColor.GRAY + "[" + accentColor + "SMP" + ChatColor.GRAY + "] "; + + public String serverName = config.getString("server_name"); + + public boolean isSleeping(UUID uuid) { return sleeping.containsKey(uuid); } + + public void addToMessages(UUID sender, UUID receiver ) { messages.put(sender, receiver); } + + public void addToVanish(UUID uuid) { vanished.add(uuid); } + + public void removeFromVanish(UUID uuid) { vanished.remove(uuid); } + + public ArrayList getVanished() { return vanished; } + + public boolean isVanished(UUID uuid) { return vanished.contains(uuid); } + + public void removeFromMessages(UUID sender) { messages.remove(sender); } + + public boolean hasRecipient(UUID sender) {return messages.containsKey(sender); } + + public UUID getRecipient(UUID sender) { return messages.get(sender);} + + public void addToSleeping(UUID uuid, Boolean bool) { + sleeping.put(uuid, bool); + } + + public void removeFromSleeping(UUID uuid) { + sleeping.remove(uuid); + } + + public boolean playersSleeping() { + return sleeping.size() > 0; + } + + private static String plural(long num, String unit) { + return num + " " + unit + (num == 1 ? "" : "s"); + } + + @Override + public void reloadConfig() { + super.reloadConfig(); + + saveDefaultConfig(); + config = getConfig(); + config.options().copyDefaults(true); + saveConfig(); + } + + public String formatDuration(Duration duration) { + List parts = new ArrayList<>(); + long days = duration.toDaysPart(); + if (days > 0) { + parts.add(plural(days, "day")); + } + int hours = duration.toHoursPart(); + if (hours > 0 || !parts.isEmpty()) { + parts.add(plural(hours, "hour")); + } + int minutes = duration.toMinutesPart(); + if (minutes > 0 || !parts.isEmpty()) { + parts.add(plural(minutes, "minute")); + } + int seconds = duration.toSecondsPart(); + parts.add(plural(seconds, "second")); + return String.join(", ", parts); + } + + public long startTime = System.currentTimeMillis(); + + @Override + public void onEnable() { + getLogger().info("Plugin has been enabled!"); + getServer().getPluginManager().registerEvents(new PlayerLeave(this), this); + getServer().getPluginManager().registerEvents(new PlayerJoin(this), this); + getServer().getPluginManager().registerEvents(new PlayerChat(), this); + getServer().getPluginManager().registerEvents(new PlayerBedEnter(this), this); + getServer().getPluginManager().registerEvents(new PlayerBedExit(this), this); + getServer().getPluginManager().registerEvents(new ServerListPing(this), this); + getCommand("playtime").setExecutor(new PlaytimeCommand(this)); + getCommand("ping").setExecutor(new PingCommand(this)); + getCommand("alert").setExecutor(new AlertCommand(this)); + getCommand("gms").setExecutor(new GamemodeSurvival(this)); + getCommand("gma").setExecutor(new GamemodeAdventure(this)); + getCommand("gmsp").setExecutor(new GamemodeSpectator(this)); + getCommand("gmc").setExecutor(new GamemodeCreative(this)); + getCommand("msg").setExecutor(new MsgCommand(this)); + getCommand("r").setExecutor(new ReplyCommand(this)); + getCommand("vanish").setExecutor(new VanishCommand(this)); + getCommand("usage").setExecutor(new UsageCommand(this)); + getCommand("smpreload").setExecutor(new ReloadCommand(this)); + getCommand("heal").setExecutor(new HealCommand(this)); + + + getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> { + getServer().dispatchCommand(getServer().getConsoleSender(), "save-all"); + }, 0L, 2000L); + + getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> { + int online = 0; + if (vanished.size() > 0) { + online = Bukkit.getOnlinePlayers().size() - vanished.size(); + } else { + online = Bukkit.getOnlinePlayers().size(); + } + + DateTimeFormatter format = DateTimeFormatter.ofPattern("h:mm a"); + for (Player player : Bukkit.getOnlinePlayers()) { + if (Bukkit.getOnlinePlayers().size() == 0) return; + if (player.hasPermission("smp.owner") || player.isOp()) { + player.setPlayerListName("§8[§cOwner§8] §c" + player.getDisplayName() + "§7 ❘§f ☠ " + player.getStatistic(Statistic.DEATHS)); + + } else { + player.setPlayerListName(player.getDisplayName() + "§7 ❘§f ☠ " + player.getStatistic(Statistic.DEATHS)); + } + + player.setPlayerListHeaderFooter( + ChatColor.translateAlternateColorCodes('&', + "\n &7-- " + accentColor + serverName + " &7-- \n"), + ChatColor.translateAlternateColorCodes('&', "\n &7Players online: " + accentColor + online + + "\n &7Time: " + accentColor + java.time.LocalTime.now().format(format) + "\n")); + } + }, 0L, 20L); + + + } + + @Override + public void onDisable() { + getLogger().info("Plugin has been disabled, goodbye!"); + } + +} diff --git a/src/main/java/me/cloud/smpcore/commands/AlertCommand.java b/src/main/java/me/cloud/smpcore/commands/AlertCommand.java new file mode 100644 index 0000000..f74d72e --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/AlertCommand.java @@ -0,0 +1,35 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class AlertCommand implements CommandExecutor { + + private final Plugin plugin; + public AlertCommand(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + + if (sender != null) { + if (args.length > 0) { + String message = String.join(" ", args); + player.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cAlert&8] &r" + message)); + for (Player serverPlayer : player.getWorld().getPlayers()) { + serverPlayer.playSound(serverPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1F, 0.5F); + } + } else { + return false; + } + } + return true; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/GamemodeAdventure.java b/src/main/java/me/cloud/smpcore/commands/GamemodeAdventure.java new file mode 100644 index 0000000..1242dd3 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/GamemodeAdventure.java @@ -0,0 +1,29 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + + +public class GamemodeAdventure implements CommandExecutor { + + private final Plugin plugin; + public GamemodeAdventure(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + + if (sender != null) { + player.setGameMode(GameMode.ADVENTURE); + player.sendMessage(plugin.chatPrefix + "Your gamemode has been changed to " + plugin.accentColor + "Adventure"); + } + return true; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/GamemodeCreative.java b/src/main/java/me/cloud/smpcore/commands/GamemodeCreative.java new file mode 100644 index 0000000..885361a --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/GamemodeCreative.java @@ -0,0 +1,29 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + + +public class GamemodeCreative implements CommandExecutor { + + private final Plugin plugin; + public GamemodeCreative(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + + if (sender != null) { + player.setGameMode(GameMode.CREATIVE); + player.sendMessage(plugin.chatPrefix + "Your gamemode has been changed to " + plugin.accentColor + "Creative"); + } + return true; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/GamemodeSpectator.java b/src/main/java/me/cloud/smpcore/commands/GamemodeSpectator.java new file mode 100644 index 0000000..83a9371 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/GamemodeSpectator.java @@ -0,0 +1,28 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class GamemodeSpectator implements CommandExecutor { + + private final Plugin plugin; + public GamemodeSpectator(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + + if (sender != null) { + player.setGameMode(GameMode.SPECTATOR); + player.sendMessage(plugin.chatPrefix + "Your gamemode has been changed to " + plugin.accentColor + "Spectator"); + } + return true; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/GamemodeSurvival.java b/src/main/java/me/cloud/smpcore/commands/GamemodeSurvival.java new file mode 100644 index 0000000..5cb4201 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/GamemodeSurvival.java @@ -0,0 +1,28 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class GamemodeSurvival implements CommandExecutor { + + private final Plugin plugin; + public GamemodeSurvival(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + + if (sender != null) { + player.setGameMode(GameMode.SURVIVAL); + player.sendMessage(plugin.chatPrefix + "Your gamemode has been changed to " + plugin.accentColor + "Survival"); + } + return true; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/HealCommand.java b/src/main/java/me/cloud/smpcore/commands/HealCommand.java new file mode 100644 index 0000000..e0cd226 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/HealCommand.java @@ -0,0 +1,48 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class HealCommand implements CommandExecutor { + + private Plugin plugin; + public HealCommand(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + if (sender != null) { + if (args.length > 0) { + if (args[0].equals("*")) { + plugin.getServer().getOnlinePlayers().forEach(target -> { + target.setHealth(20); + target.setFoodLevel(20); + target.sendMessage(plugin.accentColor + "You have been healed."); + player.sendMessage(ChatColor.GRAY + "Healed " + plugin.accentColor + target.getDisplayName()); + }); + + } else { + Player target = plugin.getServer().getPlayer(args[0]); + if (target == null) { + player.sendMessage(ChatColor.RED + "That player isn't online!"); + return true; + } + target.setHealth(20); + target.setFoodLevel(20); + target.sendMessage(plugin.accentColor + "You have been healed."); + player.sendMessage(ChatColor.GRAY + "Healed " + plugin.accentColor + target.getDisplayName()); + } + + } + + + } + return false; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/MsgCommand.java b/src/main/java/me/cloud/smpcore/commands/MsgCommand.java new file mode 100644 index 0000000..82b018e --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/MsgCommand.java @@ -0,0 +1,49 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.Arrays; + +public class MsgCommand implements CommandExecutor { + + private final Plugin plugin; + + public MsgCommand(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + if (sender != null) { + if (args.length > 0) { + Player target = plugin.getServer().getPlayer(args[0]); + if (target == null) { + player.sendMessage(ChatColor.RED + "That player isn't online!"); + return true; + } + String[] formattedMessage = Arrays.copyOfRange(args, 1, args.length); + String message = String.join(" ", formattedMessage); + player.sendMessage( + ChatColor.GRAY + "[" + plugin.accentColor + "you" +ChatColor.GRAY + "-> " + plugin.accentColor + target.getDisplayName() + ChatColor.GRAY + "] " + message + ); + target.sendMessage( + ChatColor.GRAY + "[" + plugin.accentColor + player.getDisplayName() + ChatColor.GRAY + "-> " + plugin.accentColor + "you" + ChatColor.GRAY + "] " + message + ); + plugin.addToMessages(player.getUniqueId(), target.getUniqueId()); + plugin.addToMessages(target.getUniqueId(), player.getUniqueId()); + player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1F, 0.5F); + target.playSound(target.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1F, 2F); + } else { + return false; + } + } + return true; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/PingCommand.java b/src/main/java/me/cloud/smpcore/commands/PingCommand.java new file mode 100644 index 0000000..afd81b3 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/PingCommand.java @@ -0,0 +1,29 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + + +public class PingCommand implements CommandExecutor { + + private final Plugin plugin; + + public PingCommand(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + + if (sender != null) { + player.sendMessage(plugin.chatPrefix + "Your ping is " + plugin.accentColor + player.getPing() + "ms"); + } + + return true; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/PlaytimeCommand.java b/src/main/java/me/cloud/smpcore/commands/PlaytimeCommand.java new file mode 100644 index 0000000..b08ef91 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/PlaytimeCommand.java @@ -0,0 +1,34 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.Statistic; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.time.Duration; + +public class PlaytimeCommand implements CommandExecutor { + + private final Plugin plugin; + + public PlaytimeCommand(Plugin plugin) { + this.plugin = plugin; + } + + @Override + @SuppressWarnings("NullableProblems") + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + + if (sender != null) { + long minutesPlayed = player.getStatistic(Statistic.PLAY_ONE_MINUTE); + Duration msPlayed = Duration.ofMillis(minutesPlayed * 50); + String humanized = plugin.formatDuration(msPlayed); + player.sendMessage(plugin.chatPrefix + ChatColor.GRAY + "You have played on the server for " + plugin.accentColor + humanized); + } + return true; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/ReloadCommand.java b/src/main/java/me/cloud/smpcore/commands/ReloadCommand.java new file mode 100644 index 0000000..35900e3 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/ReloadCommand.java @@ -0,0 +1,32 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +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 java.util.logging.Level; + +public class ReloadCommand implements CommandExecutor { + + private final Plugin plugin; + public ReloadCommand(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + if (sender != null) { + try { + plugin.reloadConfig(); + } catch (Exception e){ + player.sendMessage(ChatColor.RED + "Hey stupid! Check the console, you fucked up."); + } + return true; + } + return false; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/ReplyCommand.java b/src/main/java/me/cloud/smpcore/commands/ReplyCommand.java new file mode 100644 index 0000000..ed057f8 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/ReplyCommand.java @@ -0,0 +1,55 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + + +public class ReplyCommand implements CommandExecutor { + + private final Plugin plugin; + + public ReplyCommand(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + + if (sender != null) { + Player target = plugin.getServer().getPlayer(plugin.getRecipient(player.getUniqueId())); + + if (!plugin.hasRecipient(player.getUniqueId())) { + player.sendMessage(ChatColor.RED + "You have no one to reply to!"); + return true; + } + + if (target == null) { + player.sendMessage(ChatColor.RED + "That player isn't online!"); + return true; + } + + if (args.length > 0) { + String message = String.join(" ", args); + player.sendMessage( + ChatColor.GRAY + "[" + plugin.accentColor + "you" +ChatColor.GRAY + "-> " + plugin.accentColor + target.getDisplayName() + ChatColor.GRAY + "] " + message + ); + target.sendMessage( + ChatColor.GRAY + "[" + plugin.accentColor + player.getDisplayName() + ChatColor.GRAY + "-> " + plugin.accentColor + "you" + ChatColor.GRAY + "] " + message + ); + plugin.addToMessages(player.getUniqueId(), target.getUniqueId()); + plugin.addToMessages(target.getUniqueId(), player.getUniqueId()); + player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1F, 0.5F); + target.playSound(target.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1F, 2F); + } else { + return false; + } + } + return true; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/UsageCommand.java b/src/main/java/me/cloud/smpcore/commands/UsageCommand.java new file mode 100644 index 0000000..7222988 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/UsageCommand.java @@ -0,0 +1,40 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +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 java.time.Duration; + +public class UsageCommand implements CommandExecutor { + + private final Plugin plugin; + + public UsageCommand(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + float usedMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); + float totalMem = Runtime.getRuntime().maxMemory(); + String fmtUsedMem = Math.round(usedMem / 1048576) + "MB"; + String fmtTotalMem = Math.round(totalMem / 1048576) + "MB"; + long currentMs = System.currentTimeMillis(); + Duration elapsedDuration = Duration.ofMillis(currentMs - plugin.startTime); + String fmtElapsed = plugin.formatDuration(elapsedDuration); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.chatPrefix + "Used Memory: " + plugin.accentColor + fmtUsedMem)); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.chatPrefix + "Total Memory: " + plugin.accentColor + fmtTotalMem)); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.chatPrefix + "Uptime: " + plugin.accentColor + fmtElapsed)); + + + return true; + } + return false; + } +} diff --git a/src/main/java/me/cloud/smpcore/commands/VanishCommand.java b/src/main/java/me/cloud/smpcore/commands/VanishCommand.java new file mode 100644 index 0000000..3f208bb --- /dev/null +++ b/src/main/java/me/cloud/smpcore/commands/VanishCommand.java @@ -0,0 +1,40 @@ +package me.cloud.smpcore.commands; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class VanishCommand implements CommandExecutor { + private final Plugin plugin; + + public VanishCommand(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player player = (Player) sender; + if (plugin.isVanished(player.getUniqueId())) { + plugin.removeFromVanish(player.getUniqueId()); + player.sendMessage(plugin.chatPrefix + "You have been" + ChatColor.GREEN + " unvanished"); + plugin.getServer().broadcastMessage(ChatColor.GRAY + "[" + plugin.accentColor + "+" + ChatColor.GRAY + "] " + plugin.accentColor + player.getDisplayName() + ChatColor.GRAY + " joined the game"); + + for (Player serverPlayer : plugin.getServer().getOnlinePlayers()) { + serverPlayer.showPlayer(plugin, player); + } + } else { + plugin.addToVanish(player.getUniqueId()); + player.sendMessage(plugin.chatPrefix + "You have been" + ChatColor.GREEN + " vanished"); + plugin.getServer().broadcastMessage(ChatColor.GRAY + "[" + plugin.accentColor + "-" + ChatColor.GRAY + "] " + plugin.accentColor + player.getDisplayName() + ChatColor.GRAY + " left the game"); + + for (Player serverPlayer : plugin.getServer().getOnlinePlayers()) { + serverPlayer.hidePlayer(plugin, player); + } + + } + return true; + } +} diff --git a/src/main/java/me/cloud/smpcore/events/PlayerBedEnter.java b/src/main/java/me/cloud/smpcore/events/PlayerBedEnter.java new file mode 100644 index 0000000..0efec92 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/events/PlayerBedEnter.java @@ -0,0 +1,38 @@ +package me.cloud.smpcore.events; + +import me.cloud.smpcore.Plugin; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerBedEnterEvent; + +public class PlayerBedEnter implements Listener { + + private final Plugin plugin; + + public PlayerBedEnter(Plugin plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onBedEnter(PlayerBedEnterEvent event) { + if (!event.getBedEnterResult().toString().equals("OK")) return; + plugin.getServer().broadcastMessage(plugin.accentColor + event.getPlayer().getDisplayName() + ChatColor.GRAY + " is sleeping! Shh..."); + if (plugin.playersSleeping()) return; + plugin.addToSleeping(event.getPlayer().getUniqueId(), true); + Bukkit.getScheduler().runTaskLater(plugin, () -> { + if (plugin.isSleeping(event.getPlayer().getUniqueId())) { + event.getPlayer().getWorld().setTime(1000); + if (event.getPlayer().getWorld().hasStorm()) { + event.getPlayer().getWorld().setThundering(false); + event.getPlayer().getWorld().setStorm(false); + } + plugin.removeFromSleeping(event.getPlayer().getUniqueId()); + + } + }, 80); + + + } +} diff --git a/src/main/java/me/cloud/smpcore/events/PlayerBedExit.java b/src/main/java/me/cloud/smpcore/events/PlayerBedExit.java new file mode 100644 index 0000000..2a61c46 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/events/PlayerBedExit.java @@ -0,0 +1,23 @@ +package me.cloud.smpcore.events; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerBedLeaveEvent; + +public class PlayerBedExit implements Listener { + private final Plugin plugin; + + public PlayerBedExit(Plugin plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onBedExit(PlayerBedLeaveEvent event) { + if (plugin.isSleeping(event.getPlayer().getUniqueId())) { + plugin.getServer().broadcastMessage(plugin.accentColor + event.getPlayer().getDisplayName() + ChatColor.GRAY + " left their bed, fast forward to day cancelled!"); + plugin.removeFromSleeping(event.getPlayer().getUniqueId()); + } + } +} diff --git a/src/main/java/me/cloud/smpcore/events/PlayerChat.java b/src/main/java/me/cloud/smpcore/events/PlayerChat.java new file mode 100644 index 0000000..9042cee --- /dev/null +++ b/src/main/java/me/cloud/smpcore/events/PlayerChat.java @@ -0,0 +1,19 @@ +package me.cloud.smpcore.events; + +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + + +public class PlayerChat implements Listener { + + @EventHandler + public void onChat(AsyncPlayerChatEvent event) { + if (event.getPlayer().hasPermission("smp.owner") || event.getPlayer().isOp()) { + event.setFormat(ChatColor.translateAlternateColorCodes('&', "&8[&cOwner&8] ") + ChatColor.RED + event.getPlayer().getDisplayName() + ChatColor.WHITE + ": " + event.getMessage()); + } else { + event.setFormat(ChatColor.GRAY + event.getPlayer().getDisplayName() + ": " + ChatColor.WHITE + event.getMessage()); + } + } +} diff --git a/src/main/java/me/cloud/smpcore/events/PlayerJoin.java b/src/main/java/me/cloud/smpcore/events/PlayerJoin.java new file mode 100644 index 0000000..d4ba824 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/events/PlayerJoin.java @@ -0,0 +1,66 @@ +package me.cloud.smpcore.events; + +import me.cloud.smpcore.Plugin; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.util.UUID; + +public class PlayerJoin implements Listener { + + private final Plugin plugin; + + public PlayerJoin(Plugin plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + if (!plugin.isVanished(player.getUniqueId())) { + event.setJoinMessage(ChatColor.GRAY + "[" + plugin.accentColor + "+" + ChatColor.GRAY + "] " + plugin.accentColor + event.getPlayer().getDisplayName() + ChatColor.GRAY + " joined the game"); + } else { + event.setJoinMessage(""); + } + player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 1F); + Bukkit.getScheduler().runTaskLater(plugin, () -> { + plugin.joinMOTD.forEach(line -> { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', line)); + }); + }, 5); + + if (plugin.getVanished().size() > 0) { + for (UUID uuid : plugin.getVanished()) { + Player vanished = plugin.getServer().getPlayer(uuid); + for (Player serverPlayer : plugin.getServer().getOnlinePlayers()) { + serverPlayer.hidePlayer(plugin, vanished); + } + } + } + + if (plugin.isVanished(player.getUniqueId())) { + Bukkit.getScheduler().runTaskLater(plugin, () -> { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7[" + plugin.accentColor + "SMP" + "&7] You are still &avanished&7!")); + player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1F, 1F); + }, 10); + } + + + + + + + + + } +} diff --git a/src/main/java/me/cloud/smpcore/events/PlayerLeave.java b/src/main/java/me/cloud/smpcore/events/PlayerLeave.java new file mode 100644 index 0000000..e219a9e --- /dev/null +++ b/src/main/java/me/cloud/smpcore/events/PlayerLeave.java @@ -0,0 +1,28 @@ +package me.cloud.smpcore.events; + +import me.cloud.smpcore.Plugin; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerLeave implements Listener { + + private final Plugin plugin; + + public PlayerLeave(Plugin plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onLeave(PlayerQuitEvent event) { + if (!plugin.isVanished(event.getPlayer().getUniqueId())) { + event.setQuitMessage(ChatColor.GRAY + "[" + plugin.accentColor + "-" + ChatColor.GRAY + "] " + plugin.accentColor + event.getPlayer().getDisplayName() + ChatColor.GRAY + " left the game"); + } else { + event.setQuitMessage(""); + } + if (plugin.hasRecipient(event.getPlayer().getUniqueId())) { + plugin.removeFromMessages(event.getPlayer().getUniqueId()); + } + } +} diff --git a/src/main/java/me/cloud/smpcore/events/ServerListPing.java b/src/main/java/me/cloud/smpcore/events/ServerListPing.java new file mode 100644 index 0000000..6316345 --- /dev/null +++ b/src/main/java/me/cloud/smpcore/events/ServerListPing.java @@ -0,0 +1,29 @@ +package me.cloud.smpcore.events; + +import me.cloud.smpcore.Plugin; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerListPingEvent; + +import java.util.ArrayList; +import java.util.Random; + + +public class ServerListPing implements Listener { + + private final Plugin plugin; + + public ServerListPing(Plugin plugin) { this.plugin = plugin; } + + @EventHandler + public void onServerListPing(ServerListPingEvent event) { + Random generator = new Random(); + ArrayList motds = plugin.motds; + int index = generator.nextInt(motds.size()); + String motd = motds.get(index); + event.setMotd(ChatColor.translateAlternateColorCodes('&', motd.replace("%nl%", "\n"))); + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..0ad5ce9 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,12 @@ +# Config file for SMP Core +accent_color: GREEN +server_name: "The Default SMP" +motds: [ + "welcome to the smp", + "this is a second motd" +] + +join_motd: [ + "this is line one", + "this is line two" +] \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..3e98c6c --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,69 @@ +name: SMPCore +version: '${project.version}' +main: me.cloud.smpcore.Plugin +api-version: 1.18 +prefix: SMP Core +load: STARTUP +authors: [ cloudwithax ] +description: The core for any SMP you will ever need, ever. + +commands: + playtime: + description: Shows how much time you played on the server + usage: / + ping: + description: Shows your ping to the server + usage: / + alert: + description: Sends a message to all players on the server + permission: smp.owner + usage: / [text] + gms: + description: Alias for /gamemode survival + permission: smp.owner + usage: / + gma: + description: Alias for /gamemode adventure + permission: smp.owner + usage: / + gmsp: + description: Alias for /gamemode spectator + permission: smp.owner + usage: / + gmc: + description: Alias for /gamemode creative + permission: smp.owner + usage: / + msg: + description: Messages a player + usage: / [player] [message] + r: + description: Replies to a player + usage: / [message] + vanish: + aliases: [ "v" ] + permission: smp.owner + description: Toggles vanish mode + usage: / + usage: + permission: smp.owner + description: Shows server usage and resources + usage: / + smpreload: + permission: smp.owner + description: Reloads the config + usage: / + heal: + permission: smp.owner + description: Heals a player or all players using '*' + usage: / [player|*] + +permissions: + smp.owner: + description: Allows access to owner-only commands + default: op + smp.*: + description: Base permission for smp + default: op + children: + smp.owner: true