diff --git a/ALL PERMISSIONS.txt b/ALL PERMISSIONS.txt index d964708..159eb8d 100644 --- a/ALL PERMISSIONS.txt +++ b/ALL PERMISSIONS.txt @@ -9,3 +9,4 @@ Permissions: - /unban - core.unban - /kick - core.kick - /discord - none +- /toggle - core.toggle diff --git a/java/coreplugin/coreplugin/Core.java b/java/coreplugin/coreplugin/Core.java index cfc52ca..ed4c933 100644 --- a/java/coreplugin/coreplugin/Core.java +++ b/java/coreplugin/coreplugin/Core.java @@ -10,6 +10,9 @@ import coreplugin.coreplugin.commands.heal; import coreplugin.coreplugin.commands.punish.ban; import coreplugin.coreplugin.commands.punish.kick; import coreplugin.coreplugin.commands.punish.unban; +import coreplugin.coreplugin.commands.toggle; +import coreplugin.coreplugin.events.OnPlayerJoin; +import coreplugin.coreplugin.events.OnPlayerLeave; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -22,6 +25,8 @@ public final class Core extends JavaPlugin { this.getConfig().options().copyDefaults(); saveDefaultConfig(); PluginManager plm = org.bukkit.Bukkit.getPluginManager(); + plm.registerEvents(new OnPlayerJoin(), this); + plm.registerEvents(new OnPlayerLeave(), this); registerCMD(); } public static Core getInstance() { @@ -38,5 +43,6 @@ public final class Core extends JavaPlugin { getCommand("ban").setExecutor(new ban()); getCommand("unban").setExecutor(new unban()); getCommand("discord").setExecutor(new discord()); + getCommand("toggle").setExecutor(new toggle()); } } \ No newline at end of file diff --git a/java/coreplugin/coreplugin/commands/discord.java b/java/coreplugin/coreplugin/commands/discord.java index 5463fd4..7d7ec2a 100644 --- a/java/coreplugin/coreplugin/commands/discord.java +++ b/java/coreplugin/coreplugin/commands/discord.java @@ -13,9 +13,20 @@ public class discord implements CommandExecutor { } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - String Discord = Core.getInstance().getConfig().getString("Discord"); - Player p = (Player) sender; - p.sendMessage(color(Discord)); + boolean t; + t = toggle.DiscordToggle; + if (t) { + if (label.equalsIgnoreCase("discord")) { + String Discord = Core.getInstance().getConfig().getString("Discord"); + Player p = (Player) sender; + p.sendMessage(color(Discord)); + } + } + else { + String CommandDisabled = Core.getInstance().getConfig().getString("CommandDisabled"); + Player p = (Player) sender; + p.sendMessage(color(CommandDisabled)); + } return false; } } diff --git a/java/coreplugin/coreplugin/commands/toggle.java b/java/coreplugin/coreplugin/commands/toggle.java new file mode 100644 index 0000000..72e98b9 --- /dev/null +++ b/java/coreplugin/coreplugin/commands/toggle.java @@ -0,0 +1,69 @@ +package coreplugin.coreplugin.commands; + +import coreplugin.coreplugin.Core; +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 toggle implements CommandExecutor { + + private String color(String string) { + return ChatColor.translateAlternateColorCodes('&', string); + } + public static boolean DiscordToggle; + public static boolean JoinToggle; + public static boolean LeaveToggle; + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player) sender; + if (p.hasPermission("core.toggle")) { + if (label.equalsIgnoreCase("toggle")){ + if (args.length > 0) { + if (args[0].equalsIgnoreCase("discord")) { + DiscordToggle = !DiscordToggle; + if (DiscordToggle) { + p.sendMessage(color("&aFeature enabled.")); + } + else { + p.sendMessage(color("&cFeature disabled.")); + } + } else if (args[0].equalsIgnoreCase("join")) { + JoinToggle = !JoinToggle; + if (JoinToggle) { + p.sendMessage(color("&aFeature enabled.")); + } + else { + p.sendMessage(color("&cFeature disabled.")); + } + } + else if (args[0].equalsIgnoreCase("leave")){ + LeaveToggle = !LeaveToggle; + if (LeaveToggle) { + p.sendMessage(color("&aFeature enabled.")); + } + else { + p.sendMessage(color("&cFeature disabled.")); + } + } + else { + String InvalidArgument = Core.getInstance().getConfig().getString("InvalidArgument"); + p.sendMessage(color(InvalidArgument)); + } + } + else { + String InvalidArgument = Core.getInstance().getConfig().getString("InvalidArgument"); + p.sendMessage(color(InvalidArgument)); + } + + } + + } + else { + String MissingPermission = Core.getInstance().getConfig().getString("MissingPermission"); + p.sendMessage(color(MissingPermission)); + } + return false; + } +} diff --git a/java/coreplugin/coreplugin/events/OnPlayerJoin.java b/java/coreplugin/coreplugin/events/OnPlayerJoin.java new file mode 100644 index 0000000..65a9b95 --- /dev/null +++ b/java/coreplugin/coreplugin/events/OnPlayerJoin.java @@ -0,0 +1,26 @@ +package coreplugin.coreplugin.events; + +import coreplugin.coreplugin.Core; +import coreplugin.coreplugin.commands.toggle; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class OnPlayerJoin implements Listener { + private String color(String string) { + return ChatColor.translateAlternateColorCodes('&', string); + } + + @EventHandler + public void OnPlayerJoin(PlayerJoinEvent event) { + boolean t; + t = toggle.JoinToggle; + if (t) { + Player p = event.getPlayer(); + String CustomJoin = Core.getInstance().getConfig().getString("CustomJoin"); + event.setJoinMessage(color(CustomJoin + " " + p.getDisplayName())); + } + } +} diff --git a/java/coreplugin/coreplugin/events/OnPlayerLeave.java b/java/coreplugin/coreplugin/events/OnPlayerLeave.java new file mode 100644 index 0000000..cf27f7f --- /dev/null +++ b/java/coreplugin/coreplugin/events/OnPlayerLeave.java @@ -0,0 +1,26 @@ +package coreplugin.coreplugin.events; + +import coreplugin.coreplugin.Core; +import coreplugin.coreplugin.commands.toggle; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +public class OnPlayerLeave implements Listener { + private String color(String string) { + return ChatColor.translateAlternateColorCodes('&', string); + } + + @EventHandler + public void OnPlayerLeave(PlayerQuitEvent event){ + boolean t; + t = toggle.LeaveToggle; + if (t) { + Player p = event.getPlayer(); + String CustomLeave = Core.getInstance().getConfig().getString("CustomLeave"); + event.setQuitMessage(color(CustomLeave + " " + p.getDisplayName())); + } + } +} diff --git a/resources/config.yml b/resources/config.yml index 35c1e20..af0984a 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -38,9 +38,16 @@ BroadcastBan: 'has been banned for: &e' # Last color code is the color that the BroadcastUnban: 'has been unbanned.' -# Other +# Leave/Join messages. +CustomJoin: '&7[&a+&7]&b' +CustomLeave: '&7[&c-&7]&b' + +# Errors CannotFindPlayer: '&4Error: Cannot find the specified player.' MissingPermission: '&4&lYou do not have permission to execute this command!' Console: '&cYou can only run this command as a player.' InvalidArgument: '&4Error: Invalid argument.' +CommandDisabled: '&bThis command has been disabled.' + +# Other Discord: '&bhttps://discord.gg/YourDiscordLinkHere' # Please put in your discord link. \ No newline at end of file diff --git a/resources/plugin.yml b/resources/plugin.yml index 15faaaa..67dcd4a 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -24,4 +24,6 @@ commands: unban: description: You can unban people with this! discord: - description: Send your discord link in chat! \ No newline at end of file + description: Send your discord link in chat! + toggle: + description: You can toggle certain features with this! \ No newline at end of file