Skip to content

Commit

Permalink
Update (1.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Menacho15 committed Sep 10, 2022
1 parent 8e7a4c4 commit d81f41a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.victorgamer15</groupId>
<artifactId>BrandBlocker</artifactId>
<version>1.4</version>
<version>1.5</version>
<packaging>jar</packaging>

<name>BrandBlocker</name>
Expand Down
39 changes: 15 additions & 24 deletions src/main/java/me/victorgamer15/brandblocker/BrandBlocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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("\\.");
Expand All @@ -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<String> brands = new ArrayList<String>();
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);
}

Expand All @@ -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")));
}
}
}
Expand All @@ -97,7 +86,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return false;
}

HashMap<String, String> player_brands = new HashMap<String, String>();
HashMap<String, String> player_brands = new HashMap<>();

@Override
public void onPluginMessageReceived(String channel, Player p, byte[] msg) {
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
36 changes: 36 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit d81f41a

Please sign in to comment.