From d81f41a674c40274fd400143f1ad30aac420e9a4 Mon Sep 17 00:00:00 2001 From: VictorGamer15 Date: Sat, 10 Sep 2022 12:06:30 +0200 Subject: [PATCH] Update (1.5) --- pom.xml | 2 +- .../brandblocker/BrandBlocker.java | 39 +++++++------------ src/main/resources/config.yml | 36 +++++++++++++++++ 3 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 src/main/resources/config.yml diff --git a/pom.xml b/pom.xml index b8ccf79..69fe71c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.victorgamer15 BrandBlocker - 1.4 + 1.5 jar BrandBlocker diff --git a/src/main/java/me/victorgamer15/brandblocker/BrandBlocker.java b/src/main/java/me/victorgamer15/brandblocker/BrandBlocker.java index f41ec20..8c424fe 100644 --- a/src/main/java/me/victorgamer15/brandblocker/BrandBlocker.java +++ b/src/main/java/me/victorgamer15/brandblocker/BrandBlocker.java @@ -4,7 +4,6 @@ import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -14,13 +13,14 @@ import org.bukkit.plugin.messaging.PluginMessageListener; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Objects; public final class BrandBlocker extends JavaPlugin implements PluginMessageListener , Listener { + String prefix; + @Override public void onEnable() { String[] div = Bukkit.getBukkitVersion().split("-")[0].split("\\."); @@ -35,19 +35,8 @@ public void onEnable() { messenger.registerIncomingPluginChannel(this, "minecraft:brand", this); getLogger().info("Registered 1.13+ listener"); } - FileConfiguration config = getConfig(); - config.options().header("BrandBlocker by VictorGamer15\n\nTypes of mode:\nBlacklist: Kick players who are using this brand\nWhitelist: Kick players who are not using this brand\n\nIf you need some help, chat with me on the 'Discussion' tab of the plugin"); - config.addDefault("enable", false); - config.addDefault("mode", "blacklist"); - ArrayList brands = new ArrayList(); - brands.add("lunarclient"); - brands.add("badlion"); - config.addDefault("blocked-brands", brands); - config.addDefault("kick-message", "&cThe client that you're using, is not permitted on our server.\n&cPlease use another client."); - config.addDefault("geyser-support", false); - config.addDefault("geyser-prefix", "*"); - config.options().copyDefaults(true); - saveConfig(); + prefix = ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix")); + saveDefaultConfig(); Bukkit.getServer().getPluginManager().registerEvents(this, this); } @@ -72,23 +61,23 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (args[0].equalsIgnoreCase("check")) { if (sender.hasPermission("brandblocker.usage")) { if (!(args.length > 1)) { - sender.sendMessage("§c§lBrandBlocker §c» §7You need to specify a §eplayer name §7to use this command."); + sender.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', getConfig().getString("specify-player-name"))); } else { if (player_brands.containsKey(args[1])) { - sender.sendMessage("§c§lBrandBlocker §c» §e"+args[1]+"§7 entered to the server with the client brand §e"+player_brands.get(args[1])); + sender.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', getConfig().getString("check-succesful")).replace("%player%", args[1]).replace("%brand%", player_brands.get(args[1]))); } else { - sender.sendMessage("§c§lBrandBlocker §c» §7The player §e"+args[1]+" §7didn't send a client brand packet, or it isn't connected."); + sender.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', getConfig().getString("check-failed")).replace("%player%", args[1])); } } } else { - sender.sendMessage("§c§lBrandBlocker §c» §7You need the permission §ebrandblocker.usage §7to use this command."); + sender.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', getConfig().getString("no-permission"))); } } else if (args[0].equalsIgnoreCase("reload")) { if (sender.hasPermission("brandblocker.usage")) { reloadConfig(); - sender.sendMessage("§c§lBrandBlocker §c» §7The main configuration file was §ereloaded§7."); + sender.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', getConfig().getString("config-reload"))); } else { - sender.sendMessage("§c§lBrandBlocker §c» §7You need the permission §ebrandblocker.usage §7to use this command."); + sender.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', getConfig().getString("no-permission"))); } } } @@ -97,7 +86,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - HashMap player_brands = new HashMap(); + HashMap player_brands = new HashMap<>(); @Override public void onPluginMessageReceived(String channel, Player p, byte[] msg) { @@ -110,10 +99,11 @@ public void onPluginMessageReceived(String channel, Player p, byte[] msg) { while (iterator.hasNext()) { String str = iterator.next(); if (brand.toLowerCase().contains(str.toLowerCase())) { + if(p.hasPermission("brandblocker.bypass")) return; String kickMsg = getConfig().getString("kick-message"); assert kickMsg != null; p.kickPlayer(ChatColor.translateAlternateColorCodes('&', kickMsg)); - getLogger().info(p.getName() + " was kicked for using " + brand); + getLogger().info(getConfig().getString("console-log").replace("%player%", p.getName()).replace("%brand%", brand)); return; } } @@ -124,10 +114,11 @@ public void onPluginMessageReceived(String channel, Player p, byte[] msg) { if (brand.toLowerCase().contains(str.toLowerCase())) return; } + if(p.hasPermission("brandblocker.bypass")) return; String kickMsg = getConfig().getString("kick-message"); assert kickMsg != null; p.kickPlayer(ChatColor.translateAlternateColorCodes('&', kickMsg)); - getLogger().info(p.getName() + " was kicked for using " + brand); + getLogger().info(getConfig().getString("console-log").replace("%player%", p.getName()).replace("%brand%", brand)); return; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..d34ce74 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,36 @@ +# BrandBlocker by VictorGamer15 +# +# Mode types: +# Blacklist: Kick players which have the brand on the brand list below +# Whitelist: Only allow players which have the brand on the brand list below +# +# If you need some help, chat with me on the 'Discussion' tab of the plugin + +# Enable the functionality of BrandBlocker +# Users with the permission brandblocker.bypass will not have any restrictions with brands on joining +enable: false + +# BrandBlocker mode +mode: blacklist + +# List of brands to whitelist or block +blocked-brands: + - lunarclient + - badlion + +# Geyser Support +geyser-support: false +geyser-prefix: "*" + +# Plugin messages +prefix: "&c&lBrandBlocker &c» " +no-permission: "&7You need the permission &ebrandblocker.usage &7to use this command." +specify-player-name: "&7You need to specify a &eplayer name &7to use this command." +check-succesful: "&e%player% &7entered to the server with the client brand &e%brand%&7." +check-failed: "&7The player &e%player% &7didn't send a client brand packet, or it isn't connected." +config-reload: "&7The main configuration file was &ereloaded&7." +console-log: "%player% was kicked for using %brand%." + +kick-message: |- + &cThe client that you're using, is not permitted on our server. + &cPlease use another client. \ No newline at end of file