Skip to content

Commit

Permalink
New additions + new major changes!
Browse files Browse the repository at this point in the history
  • Loading branch information
zS0bye committed Jan 7, 2023
1 parent 928e265 commit 017de38
Show file tree
Hide file tree
Showing 32 changed files with 760 additions and 103 deletions.
14 changes: 12 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>it.zS0bye</groupId>
<artifactId>BetterSecurity</artifactId>
<version>1.5</version>
<version>1.6</version>
<packaging>jar</packaging>

<name>BetterSecurity</name>
Expand All @@ -18,7 +18,7 @@
</properties>

<build>
<finalName>BetterSecurity-v1.5</finalName>
<finalName>BetterSecurity-v1.6</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -58,6 +58,10 @@
<pattern>org.json</pattern>
<shadedPattern>it.zs0bye.bettersecurity.external.json</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>it.zs0bye.bettersecurity.external.kyori</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
Expand Down Expand Up @@ -160,5 +164,11 @@
<version>20220924</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bungeecord</artifactId>
<version>4.2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.EventExecutor;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -130,16 +136,15 @@ private void loadListeners() {
}

public void registerListeners() {
this.getServer().getPluginManager().registerEvents(new BlockSyntaxListener(this), this);
this.getServer().getPluginManager().registerEvents(new BlocksCmdsListener(this), this);
this.getServer().getPluginManager().registerEvents(new CmdsOnlyConsoleListener(this), this);
this.getServer().getPluginManager().registerEvents(new CmdsOnlyPlayersListener(this), this);
new BlocksCmdsListener(this);
new BlockSyntaxListener(this);
new CmdsOnlyConsoleListener(this);
new CmdsOnlyPlayersListener(this);
new UnknownCommandListener(this);
new BlockCustomCmdsListener(this);

this.getServer().getPluginManager().registerEvents(new PermissionPreventionListener(this), this);
this.getServer().getPluginManager().registerEvents(new PortBypassPreventionListener(this), this);
this.getServer().getPluginManager().registerEvents(new UnknownCommandListener(this), this);

Config.BLOCK_CUSTOM_COMMANDS.getConfigurationSection().forEach(command ->
this.getServer().getPluginManager().registerEvents(new BlockCustomCmdsListener(this, command), this));

if(VersionCheck.legacy()) return;
this.getServer().getPluginManager().registerEvents(new BlockTabCompleteListener(), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import it.zs0bye.bettersecurity.bukkit.BetterSecurityBukkit;
import it.zs0bye.bettersecurity.bukkit.files.enums.Config;
import it.zs0bye.bettersecurity.bukkit.hooks.HooksManager;
import it.zs0bye.bettersecurity.common.utils.CStringUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

Expand All @@ -26,12 +27,14 @@ protected String getType() {

protected void apply() {

final String msg = this.hooks.getPlaceholders(this.player, this.execute
String msg = this.hooks.getPlaceholders(this.player, this.execute
.replace(this.getType(), "")
.replace("%prefix%", Config.SETTINGS_PREFIX.getString()));
if(msg.contains("%center%")) msg = CStringUtils.center(msg.replace("%center%", ""));

if(msg.startsWith("@")) {
Bukkit.getOnlinePlayers().forEach(players -> this.run(players, msg));
final String finalMsg = msg;
Bukkit.getOnlinePlayers().forEach(players -> this.run(players, finalMsg));
return;
}

Expand All @@ -42,4 +45,5 @@ private void run(final Player player, final String msg) {
player.sendMessage(msg
.replaceFirst("@", ""));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,27 @@ public enum Config implements IFiles {
WARNINGS_FORMATS_PBP_CONSOLE("Warnings.formats.port_bypass_prevention.console"),
WARNINGS_LOG_CONSOLE("Warnings.log_console"),
UNKNOWN_COMMAND_ENABLED("Unknown_Command.enabled"),
UNKNOWN_COMMAND_PRIORITY("Unknown_Command.priority"),
UNKNOWN_COMMAND_EXEMPT_COMMANDS("Unknown_Command.exempt_commands"),
UNKNOWN_COMMAND_USE_SPIGOT_MESSAGE("Unknown_Command.use_spigot_message"),
UNKNOWN_COMMAND_EXECUTORS("Unknown_Command.executors"),
BLOCK_SYNTAX_ENABLED("Block_Syntax.enabled"),
BLOCK_SYNTAX_PRIORITY("Block_Syntax.priority"),
BLOCK_SYNTAX_WARNING("Block_Syntax.warning"),
BLOCK_SYNTAX_EXECUTORS("Block_Syntax.executors"),
BLOCKS_COMMANDS_ENABLED("Blocks_Commands.enabled"),
BLOCKS_COMMANDS_PRIORITY("Blocks_Commands.priority"),
BLOCKS_COMMANDS_WARNING("Blocks_Commands.warning"),
BLOCKS_COMMANDS_METHOD("Blocks_Commands.method"),
BLOCKS_COMMANDS_EXECUTORS("Blocks_Commands.executors"),
BLOCKS_COMMANDS("Blocks_Commands.commands"),
COMMANDS_ONLY_CONSOLE_ENABLED("Commands_Only_Console.enabled"),
COMMANDS_ONLY_CONSOLE_PRIORITY("Commands_Only_Console.priority"),
COMMANDS_ONLY_CONSOLE_WARNING("Commands_Only_Console.warning"),
COMMANDS_ONLY_CONSOLE_EXECUTORS("Commands_Only_Console.executors"),
COMMANDS_ONLY_CONSOLE("Commands_Only_Console.commands"),
COMMANDS_ONLY_PLAYERS_ENABLED("Commands_Only_Players.enabled"),
COMMANDS_ONLY_PLAYERS_PRIORITY("Commands_Only_Players.priority"),
COMMANDS_ONLY_PLAYERS_WARNING("Commands_Only_Players.warning"),
COMMANDS_ONLY_PLAYERS_EXECUTORS("Commands_Only_Players.executors"),
COMMANDS_ONLY_PLAYERS_BYPASS("Commands_Only_Players.bypass_players"),
Expand All @@ -59,6 +64,7 @@ public enum Config implements IFiles {
BLOCK_CUSTOM_COMMANDS("Block_Custom_Commands.commands"),
BLOCK_CUSTOM_COMMANDS_COMMAND(".command"),
BLOCK_CUSTOM_COMMANDS_COMMANDS(".commands"),
BLOCK_CUSTOM_COMMANDS_PRIORITY(".priority"),
BLOCK_CUSTOM_COMMANDS_EXECUTORS(".executors"),
BLOCK_CUSTOM_COMMANDS_WARNING(".warning"),
BLOCK_CUSTOM_COMMANDS_PERMISSION_REQUIRED(".permission_required"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ public class BlockCustomCmdsListener implements Listener {
private String permission_required;
private List<String> required_players;

public BlockCustomCmdsListener(final BetterSecurityBukkit plugin) {
this.plugin = plugin;
this.placeholders = this.plugin.getCmdsPlaceholders();
if(!Config.BLOCK_CUSTOM_COMMANDS_ENABLED.getBoolean()) return;
Config.BLOCK_CUSTOM_COMMANDS.getConfigurationSection().forEach(command -> {
final String path = Config.BLOCK_CUSTOM_COMMANDS.getPath() + "." + command;
final String priority = Config.BLOCK_CUSTOM_COMMANDS_PRIORITY.getString(path).toUpperCase();
final BlockCustomCmdsListener cmdsListener = new BlockCustomCmdsListener(this.plugin, command);
this.plugin.getServer().getPluginManager().registerEvent(
PlayerCommandPreprocessEvent.class,
cmdsListener,
EventPriority.valueOf(priority),
(listener, event) -> cmdsListener.onCommandPreprocess((PlayerCommandPreprocessEvent) event),
this.plugin);
});
}

public BlockCustomCmdsListener(final BetterSecurityBukkit plugin, final String command) {
this.plugin = plugin;
this.placeholders = this.plugin.getCmdsPlaceholders();
Expand Down Expand Up @@ -58,7 +75,7 @@ public BlockCustomCmdsListener(final BetterSecurityBukkit plugin, final String c
if(this.contains(required_players_path)) this.required_players = Config.CUSTOM.getStringList(required_players_path);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.MONITOR)
public void onCommandPreprocess(final PlayerCommandPreprocessEvent event) {

if(!Config.BLOCK_CUSTOM_COMMANDS_ENABLED.getBoolean()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ public class BlockSyntaxListener implements Listener {
public BlockSyntaxListener(final BetterSecurityBukkit plugin) {
this.plugin = plugin;
this.placeholders = this.plugin.getCmdsPlaceholders();
if(!Config.BLOCK_SYNTAX_ENABLED.getBoolean()) return;
this.plugin.getServer().getPluginManager().registerEvent(
PlayerCommandPreprocessEvent.class,
this,
EventPriority.valueOf(Config.BLOCK_SYNTAX_PRIORITY.getString().toUpperCase()),
((listener, event) -> this.onCommandPreprocess((PlayerCommandPreprocessEvent) event)),
this.plugin);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.MONITOR)
public void onCommandPreprocess(final PlayerCommandPreprocessEvent event) {

if(!Config.BLOCK_SYNTAX_ENABLED.getBoolean()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ public class BlocksCmdsListener implements Listener {
public BlocksCmdsListener(final BetterSecurityBukkit plugin) {
this.plugin = plugin;
this.placeholders = this.plugin.getCmdsPlaceholders();
if(!Config.BLOCKS_COMMANDS_ENABLED.getBoolean()) return;
this.plugin.getServer().getPluginManager().registerEvent(
PlayerCommandPreprocessEvent.class,
this,
EventPriority.valueOf(Config.BLOCKS_COMMANDS_PRIORITY.getString().toUpperCase()),
((listener, event) -> this.onCommandPreprocess((PlayerCommandPreprocessEvent) event)),
this.plugin);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.MONITOR)
public void onCommandPreprocess(final PlayerCommandPreprocessEvent event) {

if(!Config.BLOCKS_COMMANDS_ENABLED.getBoolean()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ public class CmdsOnlyConsoleListener implements Listener {
public CmdsOnlyConsoleListener(final BetterSecurityBukkit plugin) {
this.plugin = plugin;
this.placeholders = this.plugin.getCmdsPlaceholders();
if(!Config.COMMANDS_ONLY_CONSOLE_ENABLED.getBoolean()) return;
this.plugin.getServer().getPluginManager().registerEvent(
PlayerCommandPreprocessEvent.class,
this,
EventPriority.valueOf(Config.COMMANDS_ONLY_CONSOLE_PRIORITY.getString().toUpperCase()),
((listener, event) -> this.onCommandPreprocess((PlayerCommandPreprocessEvent) event)),
this.plugin);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.MONITOR)
public void onCommandPreprocess(final PlayerCommandPreprocessEvent event) {

if(!Config.COMMANDS_ONLY_CONSOLE_ENABLED.getBoolean()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ public class CmdsOnlyPlayersListener implements Listener {
public CmdsOnlyPlayersListener(final BetterSecurityBukkit plugin) {
this.plugin = plugin;
this.placeholders = this.plugin.getCmdsPlaceholders();
if(!Config.COMMANDS_ONLY_PLAYERS_ENABLED.getBoolean()) return;
this.plugin.getServer().getPluginManager().registerEvent(
PlayerCommandPreprocessEvent.class,
this,
EventPriority.valueOf(Config.COMMANDS_ONLY_PLAYERS_PRIORITY.getString().toUpperCase()),
((listener, event) -> this.onCommandPreprocess((PlayerCommandPreprocessEvent) event)),
this.plugin);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.MONITOR)
public void onCommandPreprocess(final PlayerCommandPreprocessEvent event) {

if(!Config.COMMANDS_ONLY_PLAYERS_ENABLED.getBoolean()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import it.zs0bye.bettersecurity.bukkit.utils.StringUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

Expand All @@ -19,6 +20,14 @@ public class UnknownCommandListener implements Listener {
public UnknownCommandListener(final BetterSecurityBukkit plugin) {
this.plugin = plugin;
this.placeholders = this.plugin.getCmdsPlaceholders();
if(!Config.UNKNOWN_COMMAND_ENABLED.getBoolean()) return;

this.plugin.getServer().getPluginManager().registerEvent(
PlayerCommandPreprocessEvent.class,
this,
EventPriority.valueOf(Config.UNKNOWN_COMMAND_PRIORITY.getString().toUpperCase()),
((listener, event) -> this.onCommandPreProcess((PlayerCommandPreprocessEvent) event)),
this.plugin, true);
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void run() {
this.cancel();
task.remove(player);
}
}.runTaskLater(this.plugin, this.seconds * 20L));
}.runTaskLaterAsynchronously(this.plugin, this.seconds * 20L));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import it.zs0bye.bettersecurity.common.updater.VandalUpdater;
import it.zs0bye.bettersecurity.common.utils.enums.ConsoleUtils;
import lombok.Getter;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.md_5.bungee.api.plugin.Plugin;
import org.bstats.bungeecord.Metrics;

Expand All @@ -22,6 +23,7 @@ public class BetterSecurityBungee extends Plugin {

private FileManager configFile;
private FileManager languagesFile;
private BungeeAudiences adventure;

private String updateMsg;

Expand Down Expand Up @@ -54,6 +56,8 @@ public void onEnable() {
this.loadCommands();
this.loadListeners();

this.adventure = BungeeAudiences.create(this);

this.getProxy().registerChannel("bsecurity:sender");

this.loadUpdater();
Expand All @@ -65,6 +69,12 @@ public void onEnable() {

}

@Override
public void onDisable() {
if(this.adventure == null) return;
this.adventure.close();
}

private void loadFiles() {
this.getLogger().info("");
this.getLogger().info(ConsoleUtils.YELLOW + "┃ Loading resources.." + ConsoleUtils.RESET);
Expand Down Expand Up @@ -92,6 +102,7 @@ private void loadListeners() {
this.getProxy().getPluginManager().registerListener(this, new BlocksCmdsListener(this));
this.getProxy().getPluginManager().registerListener(this, new PluginMessageListener(this));
this.getProxy().getPluginManager().registerListener(this, new BlockTabCompleteListener());
this.getProxy().getPluginManager().registerListener(this, new PreventCmdSpamListener(this));

if(Config.BLOCK_TAB_COMPLETE_WATERFALL_PREVENTION.getBoolean())
this.getProxy().getPluginManager().registerListener(this, new WaterTabCompleteListener());
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/it/zs0bye/bettersecurity/bungee/Warnings.java

This file was deleted.

Loading

0 comments on commit 017de38

Please sign in to comment.