I did a lot, Next commit will be the basics of the webhook.

This commit is contained in:
TheTrouper
2023-07-02 16:33:40 -05:00
parent 1fcea091fe
commit 9257f3d5d2
21 changed files with 1099 additions and 704 deletions

View File

@@ -2,8 +2,8 @@ plugins {
id 'java' id 'java'
} }
group = 'io.github.itzispyder' group = 'io.github.thetrouper'
version = '(YourPluginVersion)' version = '0.0.1'
repositories { repositories {
mavenCentral() mavenCentral()

View File

@@ -1 +1 @@
rootProject.name = 'ExamplePlugin' rootProject.name = 'Sentinel'

View File

@@ -1,67 +0,0 @@
/**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/
package io.github.itzispyder.exampleplugin;
import io.github.itzispyder.exampleplugin.commands.CommandExample;
import io.github.itzispyder.exampleplugin.data.Config;
import io.github.itzispyder.exampleplugin.events.ExampleEvent;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Logger;
/**
* This is your main class, you register everything important here.
*
* To build the jar, go to terminal and run "./gradlew build"
*/
public final class ExamplePlugin extends JavaPlugin {
public static final PluginManager manager = Bukkit.getPluginManager();
public static String starter = "";
public static final Logger log = Bukkit.getLogger();
/**
* Plugin startup logic
*/
@Override
public void onEnable() {
// Files
getConfig().options().copyDefaults();
saveDefaultConfig();
// Plugin startup logic
log.info("Example plugin has loaded! (" + getDescription().getVersion() + ")");
starter = Config.Plugin.getPrefix() + " ";
// Commands -> BE SURE TO REGISTER ANY NEW COMMANDS IN PLUGIN.YML (src/main/java/resources/plugin.yml)!
getCommand("example").setExecutor(new CommandExample());
getCommand("example").setTabCompleter(new CommandExample.Tabs());
// Events
manager.registerEvents(new ExampleEvent(),this);
}
/**
* Plugin shutdown logic
*/
@Override
public void onDisable() {
// Plugin shutdown logic
log.info("Example plugin has disabled! (" + getDescription().getVersion() + ")");
}
/**
* Returns an instance of this plugin
* @return an instance of this plugin
*/
public static Plugin getInstance() {
return manager.getPlugin("ExamplePlugin");
}
}

View File

@@ -1,27 +0,0 @@
/**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/
package io.github.itzispyder.exampleplugin.events;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
/**
* An example event listener
*/
public class ExampleEvent implements Listener {
/**
* Listens for join event, set any event you want in the parameter type!
* Provided by Bukkit API
* @param e the event to listen for
*/
@EventHandler
public static void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
p.sendMessage("Hello, welcome!");
}
}

View File

@@ -0,0 +1,164 @@
/**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/
package io.github.thetrouper.sentinel;
import io.github.thetrouper.sentinel.commands.InfoCommand;
import io.github.thetrouper.sentinel.commands.ReopCommand;
import io.github.thetrouper.sentinel.data.Config;
import io.github.thetrouper.sentinel.events.CmdBlockEvents;
import io.github.thetrouper.sentinel.events.CommandEvent;
import io.github.thetrouper.sentinel.events.NBTEvents;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
import java.util.logging.Logger;
/**
* This is your main class, you register everything important here.
*
* To build the jar, go to terminal and run "./gradlew build"
*/
public final class Sentinel extends JavaPlugin {
public static final PluginManager manager = Bukkit.getPluginManager();
public static String prefix = "";
public static final Logger log = Bukkit.getLogger();
public static String webhook;
public static List<String> trustedPlayers;
public static boolean blockSpecificCommands;
public static boolean preventNBT;
public static boolean logNBT;
public static boolean preventCmdBlocks;
public static boolean logCmdBlocks;
public static List<String> dangerousCommands;
public static boolean logDangerousCommands;
public static List<String> loggedCommands;
public static boolean deop;
public static boolean ban;
public static boolean reopCommand;
/**
* Plugin startup logic
*/
@Override
public void onEnable() {
// Files
getConfig().options().copyDefaults();
saveDefaultConfig();
// Plugin startup logic
loadConfiguration();
log.info("Sentinel has loaded! (" + getDescription().getVersion() + ")");
log.info("\n" +
" ____ __ ___ \n" +
"/\\ _`\\ /\\ \\__ __ /\\_ \\ \n" +
"\\ \\,\\L\\_\\ __ ___\\ \\ ,_\\/\\_\\ ___ __\\//\\ \\ \n" +
" \\/_\\__ \\ /'__`\\/' _ `\\ \\ \\/\\/\\ \\ /' _ `\\ /'__`\\\\ \\ \\ \n" +
" /\\ \\L\\ \\/\\ __//\\ \\/\\ \\ \\ \\_\\ \\ \\/\\ \\/\\ \\/\\ __/ \\_\\ \\_ \n" +
" \\ `\\____\\ \\____\\ \\_\\ \\_\\ \\__\\\\ \\_\\ \\_\\ \\_\\ \\____\\/\\____\\\n" +
" \\/_____/\\/____/\\/_/\\/_/\\/__/ \\/_/\\/_/\\/_/\\/____/\\/____/\n" +
" ]======------ Advanced Anti-Grief ------======[");
prefix = Config.Plugin.getPrefix();
// Commands -> BE SURE TO REGISTER ANY NEW COMMANDS IN PLUGIN.YML (src/main/java/resources/plugin.yml)!
getCommand("sentinel").setExecutor(new InfoCommand());
getCommand("sentinel").setTabCompleter(new InfoCommand.Tabs());
getCommand("reop").setExecutor(new ReopCommand());
// Events
manager.registerEvents(new CommandEvent(),this);
manager.registerEvents(new CmdBlockEvents(), this);
manager.registerEvents(new NBTEvents(), this);
}
/**
* Plugin shutdown logic
*/
@Override
public void onDisable() {
// Plugin shutdown logic
log.info("Sentinel has disabled! (" + getDescription().getVersion() + ") Your server is now no longer protected!");
}
private void loadConfiguration() {
saveDefaultConfig();
FileConfiguration config = getConfig();
// Load prefix
prefix = config.getString("config.plugin.prefix");
// Load webhook
webhook = config.getString("config.plugin.webhook");
// Load trusted players
trustedPlayers = config.getStringList("config.plugin.trusted");
// Load block-specific commands
blockSpecificCommands = config.getBoolean("config.plugin.block-specific");
// Load prevent NBT
preventNBT = config.getBoolean("config.plugin.prevent-nbt");
// Load log NBT
logNBT = config.getBoolean("config.plugin.log-nbt");
// Load prevent command blocks
preventCmdBlocks = config.getBoolean("config.plugin.prevent-cmdblocks");
// Load log command blocks
logCmdBlocks = config.getBoolean("config.plugin.log-cmdblocks");
// Load dangerous commands
dangerousCommands = config.getStringList("config.plugin.dangerous");
// Load log protected commands
logDangerousCommands = config.getBoolean("config.plugin.log-protected");
// Load logged commands
loggedCommands = config.getStringList("config.plugin.logged");
deop = config.getBoolean("config.plugin.deop");
ban = config.getBoolean("config.plugin.ban");
reopCommand = config.getBoolean("config.plugin.reop-command");
}
/**
* Checks if a player is trusted.
* @param player the player to check
* @return true if the player is trusted, false otherwise
*/
public static boolean isTrusted(Player player) {
return trustedPlayers.contains(player.getUniqueId().toString());
}
/**
* Checks if a command is a logged command.
* @param command the command to check
* @return true if the command is logged, false otherwise
*/
public static boolean isLoggedCommand(String command) {
return loggedCommands.contains(command);
}
/**
* Checks if a command is dangerous.
* @param command the command to check
* @return true if the command is dangerous, false otherwise
*/
public static boolean isDangerousCommand(String command) {
return dangerousCommands.contains(command);
}
/**
* Returns an instance of this plugin
* @return an instance of this plugin
*/
public static Plugin getInstance() {
return manager.getPlugin("Sentinel");
}
}

View File

@@ -1,48 +1,49 @@
/** /**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :) * This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/ */
package io.github.itzispyder.exampleplugin.commands; package io.github.thetrouper.sentinel.commands;
import io.github.itzispyder.exampleplugin.exceptions.CmdExHandler; import io.github.thetrouper.sentinel.exceptions.CmdExHandler;
import org.bukkit.command.Command; import io.github.thetrouper.sentinel.server.util.TextUtils;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.TabCompleter; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.util.ArrayList;
import java.util.List; import java.util.ArrayList;
import java.util.List;
/**
* Example command /**
*/ * Example command
public class CommandExample implements CommandExecutor { */
public class InfoCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @Override
try { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
sender.sendMessage("You've executed an example command!"); try {
return true; sender.sendMessage(TextUtils.prefix("This server is running Sentinel by TheTrouper. Hot reloading is not advised."));
} catch (Exception ex) { return true;
CmdExHandler handler = new CmdExHandler(ex,command); } catch (Exception ex) {
sender.sendMessage(handler.getErrorMessage()); CmdExHandler handler = new CmdExHandler(ex,command);
return true; sender.sendMessage(handler.getErrorMessage());
} return true;
} }
}
/**
* Example command's tab completer /**
*/ * Example command's tab completer
public static class Tabs implements TabCompleter { */
public static class Tabs implements TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { @Override
List<String> list = new ArrayList<>(); public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
switch (args.length) { List<String> list = new ArrayList<>();
case 1 -> list.add("test"); switch (args.length) {
} case 1 -> list.add("reload");
list.removeIf(s -> !s.toLowerCase().contains(args[args.length - 1].toLowerCase())); }
return list; list.removeIf(s -> !s.toLowerCase().contains(args[args.length - 1].toLowerCase()));
} return list;
} }
} }
}

View File

@@ -0,0 +1,40 @@
package io.github.thetrouper.sentinel.commands;
import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.exceptions.CmdExHandler;
import io.github.thetrouper.sentinel.server.util.TextUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class ReopCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
if (Sentinel.reopCommand) {
String name = sender.getName().toString();
Player p = sender.getServer().getPlayer(name);
if (Sentinel.isTrusted(p)) {
sender.sendMessage(TextUtils.prefix("Elevating your permissions..."));
p.setOp(true);
Sentinel.log.info("Sentinel has elevated the permissions of " + name + "!");
} else {
sender.sendMessage(TextUtils.prefix("You are not trusted!"));
}
} else {
sender.sendMessage(TextUtils.prefix("This command is not enabled!"));
}
return true;
} catch (Exception ex) {
CmdExHandler handler = new CmdExHandler(ex,command);
sender.sendMessage(handler.getErrorMessage());
return true;
}
}
}

View File

@@ -1,25 +1,25 @@
/** /**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :) * This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/ */
package io.github.itzispyder.exampleplugin.data; package io.github.thetrouper.sentinel.data;
import io.github.itzispyder.exampleplugin.ExamplePlugin; import io.github.thetrouper.sentinel.Sentinel;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
/** /**
* Config loader * Config loader
*/ */
public abstract class Config { public abstract class Config {
private static final FileConfiguration config = ExamplePlugin.getInstance().getConfig(); private static final FileConfiguration config = Sentinel.getInstance().getConfig();
/** /**
* Config plugin section * Config plugin section
*/ */
public class Plugin { public class Plugin {
public static String getPrefix() { public static String getPrefix() {
return config.getString("config.plugin.prefix"); return config.getString("config.plugin.prefix");
} }
} }
} }

View File

@@ -0,0 +1,5 @@
package io.github.thetrouper.sentinel.discord;
public class WebHook {
// To be implemented once I have learned how to use JDA
}

View File

@@ -0,0 +1,53 @@
package io.github.thetrouper.sentinel.events;
import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.server.util.DeniedActions;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class CmdBlockEvents implements Listener {
@EventHandler
private void onCMDBlockUse(PlayerInteractEvent e) {
if (!Sentinel.preventCmdBlocks) return;
if (e.getClickedBlock() == null) return;
Block b = e.getClickedBlock();
if (b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK) {
Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) {
e.setCancelled(true);
Sentinel.log.info("Use of a command block has been denied for " + p.getName() + " at X:" + b.getX() + " Y:" + b.getY() + " Z:" + b.getZ());
}
}
}
@EventHandler
private void onCMDBlockPlace(BlockPlaceEvent e) {
if (!Sentinel.preventCmdBlocks) return;
Block b = e.getBlockPlaced();
if (b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK) {
Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) {
e.setCancelled(true);
Sentinel.log.info("Placing a command block has been denied for " + p.getName() + " at X:" + b.getX() + " Y:" + b.getY() + " Z:" + b.getZ());
}
}
}
@EventHandler
private void onCMDBlockMinecartPlace(PlayerInteractEntityEvent e) {
if (!Sentinel.preventCmdBlocks) return;
if (e.getRightClicked().getType() == EntityType.MINECART_COMMAND) {
Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) {
e.setCancelled(true);
Block b = p.getLocation().getBlock();
DeniedActions.handleDeniedAction(p,b);
}
}
}
}

View File

@@ -0,0 +1,31 @@
package io.github.thetrouper.sentinel.events;
import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.server.util.DeniedActions;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class CommandEvent implements Listener {
private String trusted;
@EventHandler
private void onCommand(PlayerCommandPreprocessEvent e) {
Player p = e.getPlayer();
String command = e.getMessage().substring(1).split(" ")[0];
if (Sentinel.isDangerousCommand(command)) {
if (!Sentinel.isTrusted(p)) {
e.setCancelled(true);
DeniedActions.handleDeniedAction(p,command);
}
}
if (Sentinel.blockSpecificCommands) {
if (command.contains(":")) {
if (!Sentinel.isTrusted(p)) {
e.setCancelled(true);
DeniedActions.handleDeniedAction(p,command);
}
}
}
}
}

View File

@@ -0,0 +1,27 @@
package io.github.thetrouper.sentinel.events;
import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.server.util.DeniedActions;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCreativeEvent;
import org.bukkit.inventory.ItemStack;
public class NBTEvents implements Listener {
@EventHandler
private void onNBTPull(InventoryCreativeEvent e) {
if (!(e.getWhoClicked() instanceof Player p)) {
return;
}
ItemStack i = e.getCursor();
if (!Sentinel.isTrusted(p)) {
if (i != null && i.hasItemMeta()) {
e.setCancelled(true);
DeniedActions.handleDeniedAction(p,i);
}
}
}
}

View File

@@ -1,46 +1,46 @@
/** /**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :) * This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/ */
package io.github.itzispyder.exampleplugin.exceptions; package io.github.thetrouper.sentinel.exceptions;
import org.bukkit.command.Command; import org.bukkit.command.Command;
/** /**
* Handles a command exception * Handles a command exception
*/ */
public class CmdExHandler { public class CmdExHandler {
private Exception exception; private Exception exception;
private Command command; private Command command;
/** /**
* Constructs the command exception * Constructs the command exception
* @param exception the exception caught * @param exception the exception caught
* @param command the command run * @param command the command run
*/ */
public CmdExHandler(Exception exception, Command command) { public CmdExHandler(Exception exception, Command command) {
this.exception = exception; this.exception = exception;
this.command = command; this.command = command;
} }
/** /**
* Returns the error message * Returns the error message
* @return the error message * @return the error message
*/ */
public String getErrorMessage() { public String getErrorMessage() {
String msg = "§cCommand Error: "; String msg = "§cCommand Error: ";
if (exception instanceof NullPointerException) msg += "Command contains a null value!"; if (exception instanceof NullPointerException) msg += "Command contains a null value!";
else if (exception instanceof IndexOutOfBoundsException) msg += "Unknown or incomplete command!"; else if (exception instanceof IndexOutOfBoundsException) msg += "Unknown or incomplete command!";
else msg += exception.getMessage(); else msg += exception.getMessage();
return msg + "\n§cCorrect usage: §7" + command.getUsage(); return msg + "\n§cCorrect usage: §7" + command.getUsage();
} }
public Exception getException() { public Exception getException() {
return exception; return exception;
} }
public Command getCommand() { public Command getCommand() {
return command; return command;
} }
} }

View File

@@ -1,263 +1,263 @@
/** /**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :) * This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
* *
* I made this cuz Bukkit API sounds management is trash. * I made this cuz Bukkit API sounds management is trash.
* by ImproperIssues * by ImproperIssues
*/ */
package io.github.itzispyder.exampleplugin.server.sound; package io.github.thetrouper.sentinel.server.sound;
import io.github.itzispyder.exampleplugin.ExamplePlugin; import io.github.thetrouper.sentinel.Sentinel;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class SoundPlayer { public class SoundPlayer {
private Location location; private Location location;
private Sound sound; private Sound sound;
private float volume; private float volume;
private float pitch; private float pitch;
/** /**
* Constructs a new sound, this aims to add more methods to * Constructs a new sound, this aims to add more methods to
* the Bukkit APIs Sound class, as they don't have many * the Bukkit APIs Sound class, as they don't have many
* methods to use. * methods to use.
* *
* @param location Location * @param location Location
* @param sound Sound * @param sound Sound
* @param volume float * @param volume float
* @param pitch float * @param pitch float
*/ */
public SoundPlayer(Location location, Sound sound, float volume, float pitch) { public SoundPlayer(Location location, Sound sound, float volume, float pitch) {
this.location = location; this.location = location;
this.sound = sound; this.sound = sound;
this.pitch = pitch; this.pitch = pitch;
this.volume = volume; this.volume = volume;
} }
/** /**
* Plays a sound to a player but at the store location * Plays a sound to a player but at the store location
* *
* @param player Player * @param player Player
*/ */
public void play(Player player) { public void play(Player player) {
player.playSound(this.location,this.sound,this.volume,this.pitch); player.playSound(this.location,this.sound,this.volume,this.pitch);
} }
/** /**
* Plays a sound to a player but at the player's location * Plays a sound to a player but at the player's location
* *
* @param player Player * @param player Player
*/ */
public void playAt(Player player) { public void playAt(Player player) {
player.playSound(player.getLocation(),this.sound,this.volume,this.pitch); player.playSound(player.getLocation(),this.sound,this.volume,this.pitch);
} }
/** /**
* Plays the sound to all players within a distance, but at the stored location. * Plays the sound to all players within a distance, but at the stored location.
* *
* @param distance double * @param distance double
*/ */
public void playWithin(double distance) { public void playWithin(double distance) {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) { if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) {
p.playSound(this.location,this.sound,this.volume,this.pitch); p.playSound(this.location,this.sound,this.volume,this.pitch);
} }
} }
} }
/** /**
* Plays the sound to all players within a distance, but at the players' location. * Plays the sound to all players within a distance, but at the players' location.
* *
* @param distance double * @param distance double
*/ */
public void playWithinAt(double distance) { public void playWithinAt(double distance) {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) { if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) {
p.playSound(p.getLocation(),this.sound,this.volume,this.pitch); p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
} }
} }
} }
/** /**
* Plays the sound to all players on the server, but at the stored location. * Plays the sound to all players on the server, but at the stored location.
*/ */
public void playAll() { public void playAll() {
for (Player p : Bukkit.getOnlinePlayers()) p.playSound(this.location,this.sound,this.volume,this.pitch); for (Player p : Bukkit.getOnlinePlayers()) p.playSound(this.location,this.sound,this.volume,this.pitch);
} }
/** /**
* Plays the sound to all players on the server, but at the players' location. * Plays the sound to all players on the server, but at the players' location.
*/ */
public void playAllAt() { public void playAllAt() {
for (Player p : Bukkit.getOnlinePlayers()) p.playSound(p.getLocation(),this.sound,this.volume,this.pitch); for (Player p : Bukkit.getOnlinePlayers()) p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
} }
/** /**
* Repeats a sound to a player, but at the stored location. * Repeats a sound to a player, but at the stored location.
* *
* @param player Player * @param player Player
* @param times int * @param times int
* @param tickDelay int * @param tickDelay int
*/ */
public void repeat(Player player, int times, int tickDelay) { public void repeat(Player player, int times, int tickDelay) {
new BukkitRunnable() { new BukkitRunnable() {
int i = 0; int i = 0;
@Override @Override
public void run() { public void run() {
if (i < times) { if (i < times) {
play(player); play(player);
i ++; i ++;
} else { } else {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
/** /**
* Repeats a sound to a player, but at the player's location. * Repeats a sound to a player, but at the player's location.
* *
* @param player Player * @param player Player
* @param times int * @param times int
* @param tickDelay int * @param tickDelay int
*/ */
public void repeatAt(Player player, int times, int tickDelay) { public void repeatAt(Player player, int times, int tickDelay) {
new BukkitRunnable() { new BukkitRunnable() {
int i = 0; int i = 0;
@Override @Override
public void run() { public void run() {
if (i < times) { if (i < times) {
playAt(player); playAt(player);
i ++; i ++;
} else { } else {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
/** /**
* Repeats a sound to all players on the server, but at the stored location. * Repeats a sound to all players on the server, but at the stored location.
* *
* @param times int * @param times int
* @param tickDelay int * @param tickDelay int
*/ */
public void repeatAll(int times, int tickDelay) { public void repeatAll(int times, int tickDelay) {
new BukkitRunnable() { new BukkitRunnable() {
int i = 0; int i = 0;
@Override @Override
public void run() { public void run() {
if (i < times) { if (i < times) {
playAll(); playAll();
i ++; i ++;
} else { } else {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
/** /**
* Repeats a sound to all players on the server, but at the players' location. * Repeats a sound to all players on the server, but at the players' location.
* *
* @param times int * @param times int
* @param tickDelay int * @param tickDelay int
*/ */
public void repeatAllAt(int times, int tickDelay) { public void repeatAllAt(int times, int tickDelay) {
new BukkitRunnable() { new BukkitRunnable() {
int i = 0; int i = 0;
@Override @Override
public void run() { public void run() {
if (i < times) { if (i < times) {
playAllAt(); playAllAt();
i ++; i ++;
} else { } else {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
/** /**
* Repeats a sound to all players within a radius, but at the stored location. * Repeats a sound to all players within a radius, but at the stored location.
* *
* @param radius double * @param radius double
* @param times int * @param times int
* @param tickDelay int * @param tickDelay int
*/ */
public void repeatAll(double radius,int times, int tickDelay) { public void repeatAll(double radius,int times, int tickDelay) {
new BukkitRunnable() { new BukkitRunnable() {
int i = 0; int i = 0;
@Override @Override
public void run() { public void run() {
if (i < times) { if (i < times) {
playWithin(radius); playWithin(radius);
i ++; i ++;
} else { } else {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
/** /**
* Repeats a sound to all players within a radius, but at the players' location. * Repeats a sound to all players within a radius, but at the players' location.
* *
* @param distance double * @param distance double
* @param times int * @param times int
* @param tickDelay int * @param tickDelay int
*/ */
public void repeatAllAt(double distance, int times, int tickDelay) { public void repeatAllAt(double distance, int times, int tickDelay) {
new BukkitRunnable() { new BukkitRunnable() {
int i = 0; int i = 0;
@Override @Override
public void run() { public void run() {
if (i < times) { if (i < times) {
playWithinAt(distance); playWithinAt(distance);
i ++; i ++;
} else { } else {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
public Sound getSound() { public Sound getSound() {
return sound; return sound;
} }
public float getPitch() { public float getPitch() {
return pitch; return pitch;
} }
public float getVolume() { public float getVolume() {
return volume; return volume;
} }
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
public void setPitch(float pitch) { public void setPitch(float pitch) {
this.pitch = pitch; this.pitch = pitch;
} }
public void setVolume(float volume) { public void setVolume(float volume) {
this.volume = volume; this.volume = volume;
} }
public void setSound(Sound sound) { public void setSound(Sound sound) {
this.sound = sound; this.sound = sound;
} }
public void setLocation(Location location) { public void setLocation(Location location) {
this.location = location; this.location = location;
} }
} }

View File

@@ -1,90 +1,90 @@
/** /**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :) * This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/ */
package io.github.itzispyder.exampleplugin.server.util; package io.github.thetrouper.sentinel.server.util;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
* Represents Argument builder * Represents Argument builder
*/ */
public class ArgBuilder { public class ArgBuilder {
private String result; private String result;
/** /**
* Constructs an argument builder. * Constructs an argument builder.
*/ */
public ArgBuilder() { public ArgBuilder() {
this.result = " "; this.result = " ";
} }
/** /**
* Constructs an argument builder with a string. * Constructs an argument builder with a string.
* @param begin the beginner string * @param begin the beginner string
*/ */
public ArgBuilder(String begin) { public ArgBuilder(String begin) {
this.result = begin + " "; this.result = begin + " ";
} }
/** /**
* Appends a string * Appends a string
* @param string string * @param string string
* @return this class * @return this class
*/ */
public ArgBuilder append(String string) { public ArgBuilder append(String string) {
this.result += string + " "; this.result += string + " ";
return this; return this;
} }
/** /**
* Appends a string array * Appends a string array
* @param args string array * @param args string array
* @return this class * @return this class
*/ */
public ArgBuilder append(String[] args) { public ArgBuilder append(String[] args) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (String arg : args) builder.append(arg).append(" "); for (String arg : args) builder.append(arg).append(" ");
this.result += builder.toString(); this.result += builder.toString();
return this; return this;
} }
/** /**
* Appends a string list * Appends a string list
* @param args string list * @param args string list
* @return this class * @return this class
*/ */
public ArgBuilder append(List<String> args) { public ArgBuilder append(List<String> args) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (String arg : args) builder.append(arg).append(" "); for (String arg : args) builder.append(arg).append(" ");
this.result += builder.toString(); this.result += builder.toString();
return this; return this;
} }
/** /**
* Appends a string set * Appends a string set
* @param args string set * @param args string set
* @return this class * @return this class
*/ */
public ArgBuilder append(Set<String> args) { public ArgBuilder append(Set<String> args) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (String arg : args) builder.append(arg).append(" "); for (String arg : args) builder.append(arg).append(" ");
this.result += builder.toString(); this.result += builder.toString();
return this; return this;
} }
/** /**
* Returns this class as a string * Returns this class as a string
* @return this class as a string * @return this class as a string
*/ */
public String build() { public String build() {
return this.toString().trim(); return this.toString().trim();
} }
@Override @Override
public String toString() { public String toString() {
return result; return result;
} }
} }

View File

@@ -0,0 +1,128 @@
package io.github.thetrouper.sentinel.server.util;
import io.github.thetrouper.sentinel.Sentinel;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.hover.content.Text;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.inventory.ItemStack;
public class DeniedActions {
private static String logMessage;
public static void handleDeniedAction(Player p, String command) {
if (!Sentinel.logDangerousCommands) return;
logMessage = "]==-- Sentinel --==[\n" +
"A Dangerous command has been attempted!\n" +
"Player: " + p.getName() + "\n" +
"Command: " + command + "\n";
if (Sentinel.deop) {
p.setOp(false);
logMessage = logMessage + "Operator Removed: ✔\n";
} else {
logMessage = logMessage + "Operator Removed: ✘\n";
}
if (Sentinel.ban) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ban " + p.getName() + " ]=- Sentinel Anti-Grief -=[ You have been banned for attempting a dangerous command. Contact an administrator if you believe this to be a mistake.");
logMessage = logMessage + "Banned: ✔\n";
} else {
logMessage = logMessage + "Banned: ✘\n";
}
logMessage = logMessage + "Denied: ✔";
Sentinel.log.info(logMessage);
notifyTrusted(p, command);
}
public static void handleDeniedAction(Player p, Block block) {
if (!Sentinel.logCmdBlocks) return;
logMessage = "]==-- Sentinel --==[\n" +
"A Dangerous block usage has been detected!\n" +
"Player: " + p.getName() + "\n" +
"BlockType: " + block.getType() + "\n";
if (Sentinel.deop) {
p.setOp(false);
logMessage = logMessage + "Operator Removed: ✔\n";
} else {
logMessage = logMessage + "Operator Removed: ✘\n";
}
if (Sentinel.ban) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ban " + p.getName() + " ]=- Sentinel Anti-Grief -=[ You have been banned for attempting to use dangerous blocks. Contact an administrator if you believe this to be a mistake.");
logMessage = logMessage + "Banned: ✔\n";
} else {
logMessage = logMessage + "Banned: ✘\n";
}
logMessage = logMessage + "Denied: ✔";
Sentinel.log.info(logMessage);
notifyTrusted(p, block);
}
public static void handleDeniedAction(Player p, ItemStack i) {
if (!Sentinel.logNBT) return;
logMessage = "]==-- Sentinel --==[\n" +
"A Dangerous item has been detected!\n" +
"Player: " + p.getName() + "\n" +
"ItemType: " + i.getType() + "\n";
if (Sentinel.deop) {
p.setOp(false);
logMessage = logMessage + "Operator Removed: ✔\n";
} else {
logMessage = logMessage + "Operator Removed: ✘\n";
}
if (Sentinel.ban) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ban " + p.getName() + " ]=- Sentinel Anti-Grief -=[ You have been banned for attempting a dangerous command. Contact an administrator if you believe this to be a mistake.");
logMessage = logMessage + "Banned: ✔\n";
} else {
logMessage = logMessage + "Banned: ✘\n";
}
logMessage = logMessage + "Denied: ✔";
Sentinel.log.info(logMessage);
notifyTrusted(p, i);
}
private static void notifyTrusted(Player p, String command) {
TextComponent message = new TextComponent(TextUtils.prefix(p.getName() + " has attempted a dangerous command!"));
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(
"§8]==-- §d§lSentinel §8--==[\n" +
"§7Player: §b" + p.getName() + "\n" +
"§7Command: §b" + command + "\n" +
"§7Trusted: §cfalse\n" +
"§7Denied: §atrue")));
for (Player trustedPlayer : Bukkit.getOnlinePlayers()) {
if (Sentinel.isTrusted(trustedPlayer)) {
trustedPlayer.spigot().sendMessage(message);
}
}
}
private static void notifyTrusted(Player p, Block b) {
TextComponent message = new TextComponent(TextUtils.prefix(p.getName() + " has attempted to use a dangerous block!"));
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(
"§8]==-- §d§lSentinel §8--==[\n" +
"§7Player: §b" + p.getName() + "\n" +
"§7BlockType: §b" + b.getType() + "\n" +
"§7Trusted: §cfalse\n" +
"§7Denied: §atrue")));
for (Player trustedPlayer : Bukkit.getOnlinePlayers()) {
if (Sentinel.isTrusted(trustedPlayer)) {
trustedPlayer.spigot().sendMessage(message);
}
}
}
private static void notifyTrusted(Player p, ItemStack i) {
TextComponent message = new TextComponent(TextUtils.prefix(p.getName() + " has attempted to use a dangerous item"));
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(
"§8]==-- §d§lSentinel §8--==[\n" +
"§7Player: §b" + p.getName() + "\n" +
"§7ItemType: §b" + i.getType() + "\n" +
"§7Trusted: §cfalse\n" +
"§7Denied: §atrue\n" +
"§8(Click to copy ItemMeta)")));
message.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, new String(
i.getItemMeta().toString()
)));
for (Player trustedPlayer : Bukkit.getOnlinePlayers()) {
if (Sentinel.isTrusted(trustedPlayer)) {
trustedPlayer.spigot().sendMessage(message);
}
}
}
}

View File

@@ -1,68 +1,68 @@
package io.github.itzispyder.exampleplugin.server.util; package io.github.thetrouper.sentinel.server.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
* Randomize items from a list * Randomize items from a list
* @param <T> list of? * @param <T> list of?
*/ */
public class Randomizer<T> { public class Randomizer<T> {
private final List<T> array; private final List<T> array;
/** /**
* From array list * From array list
* @param array list * @param array list
*/ */
public Randomizer(List<T> array) { public Randomizer(List<T> array) {
this.array = array; this.array = array;
} }
/** /**
* From set * From set
* @param array set * @param array set
*/ */
public Randomizer(Set<T> array) { public Randomizer(Set<T> array) {
this.array = new ArrayList<>(array); this.array = new ArrayList<>(array);
} }
/** /**
* From array * From array
* @param array array * @param array array
*/ */
public Randomizer(T[] array) { public Randomizer(T[] array) {
this.array = List.of(array); this.array = List.of(array);
} }
/** /**
* Pick random from the array * Pick random from the array
* @return random of list of? * @return random of list of?
*/ */
public T pickRand() { public T pickRand() {
return array.get(rand(array.size() - 1)); return array.get(rand(array.size() - 1));
} }
/** /**
* Generates a random integer from 1 to (max) * Generates a random integer from 1 to (max)
* @param max max value * @param max max value
* @return random * @return random
*/ */
public static int rand(int max) { public static int rand(int max) {
if (max <= 0) throw new IllegalArgumentException("max cannot be less than 1!"); if (max <= 0) throw new IllegalArgumentException("max cannot be less than 1!");
return (int) Math.ceil(Math.random() * max); return (int) Math.ceil(Math.random() * max);
} }
/** /**
* Generates a random integer from (min) to (max) * Generates a random integer from (min) to (max)
* @param min min value * @param min min value
* @param max max value * @param max max value
* @return random * @return random
*/ */
public static int rand(int min, int max) { public static int rand(int min, int max) {
if (max <= 0 || min <= 0) throw new IllegalArgumentException("max or min cannot be less than 1!"); if (max <= 0 || min <= 0) throw new IllegalArgumentException("max or min cannot be less than 1!");
if (max <= min) throw new IllegalArgumentException("max cannot be less than or equal to min!"); if (max <= min) throw new IllegalArgumentException("max cannot be less than or equal to min!");
return min + (int) Math.floor(Math.random() * (max - min + 1)); return min + (int) Math.floor(Math.random() * (max - min + 1));
} }
} }

View File

@@ -1,53 +1,56 @@
/** /**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :) * This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/ */
package io.github.itzispyder.exampleplugin.server.util; package io.github.thetrouper.sentinel.server.util;
import org.bukkit.Bukkit; import io.github.thetrouper.sentinel.Sentinel;
import org.bukkit.entity.Player; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashSet; import java.util.ArrayList;
import java.util.List; import java.util.HashSet;
import java.util.Set; import java.util.List;
import java.util.Set;
/**
* Server utils /**
*/ * Server utils
public abstract class ServerUtils { */
public abstract class ServerUtils {
/**
* List of names of online players
* @return list of names
*/ /**
public static List<String> listPlayers() { * List of names of online players
List<String> list =new ArrayList<>(); * @return list of names
Bukkit.getOnlinePlayers().forEach(p -> list.add(p.getName())); */
return list; public static List<String> listPlayers() {
} List<String> list =new ArrayList<>();
Bukkit.getOnlinePlayers().forEach(p -> list.add(p.getName()));
/** return list;
* List of names of online staff }
* @return list of names
*/ /**
public static List<String> listStaff() { * List of names of online staff
List<String> list =new ArrayList<>(); * @return list of names
Bukkit.getOnlinePlayers().forEach(p -> { */
if (p.isOp()) list.add(p.getName()); public static List<String> listStaff() {
}); List<String> list =new ArrayList<>();
return list; Bukkit.getOnlinePlayers().forEach(p -> {
} if (p.isOp()) list.add(p.getName());
});
/** return list;
* List of names of online staff }
* @return list of staff
*/ /**
public static Set<Player> getStaff() { * List of names of online staff
Set<Player> list = new HashSet<>(); * @return list of staff
Bukkit.getOnlinePlayers().forEach(p -> { */
if (p.isOp()) list.add(p); public static Set<Player> getStaff() {
}); Set<Player> list = new HashSet<>();
return list; Bukkit.getOnlinePlayers().forEach(p -> {
} if (p.isOp()) list.add(p);
} });
return list;
}
}

View File

@@ -0,0 +1,12 @@
package io.github.thetrouper.sentinel.server.util;
import io.github.thetrouper.sentinel.Sentinel;
public class TextUtils {
public static String prefix(String text) {
String prefix = Sentinel.prefix;
return prefix + text;
}
}

View File

@@ -1,8 +1,30 @@
# #
# #
# This will be your plugin config! # Configure the plugin here, the default config may not be adequate to your needs.
# #
# #
config: config:
plugin: plugin:
prefix: 7[§aExamplePlugin§7]" prefix: d§lSentinel §8» §7" # Prefix of the plugin. Line below is the discord webhook for logs to be sent to
webhook: "https://discord.com/api/webhooks/1124908469842096211/https://discord.com/api/webhooks/1124908469842096211/7NGOeFvtmxQ4n0_hSvbqhZUjnzRHIicLpHKETYU92n9JaLUPPsueBSn7w4wUfAnhjlLF"
trusted: # List the UUIDs of players who are trusted, will bypass the plugin and be immune to logs and are able to re-op themeselves
- "049460f7-21cb-42f5-8059-d42752bf406f" # obvWolf
block-specific: true # Defaulted true | Weather or not to block ALL plugin specific commands from non-trusted members (EX: minecraft:ban) these will not be logged.
prevent-nbt: true # Defaulted true | Should NBT items be blocked from the creative hotbar
log-nbt: true # Defaulted true | Should items and their NBT's be logged
prevent-cmdblocks: true # Defaulted true | Should all command block actions be blocked
log-cmdblocks: true # Defaulted true | Log attempts of command-block place-ery
dangerous: # These commands can only be run by "trusted" users
- "op"
- "deop"
- "stop"
- "execute"
- "sudo"
- ""
log-dangerous: true # Default true | Weather or not to log when a dangerous command is executed
logged: # Commands that will always be logged when executed.
- "gamemode"
- "give"
deop: true # Defaulted true | This will remove an untrusted player's operator permissions whenever they attempt dangerous actions
ban: false # Defaulted false | This will ban a player when they attempt dangerous actions
reop-command: false # Defaulted false | This enables the command allowing trusted players to op themselves if they get deoped.

View File

@@ -1,17 +1,20 @@
name: ExamplePlugin name: Sentinel
version: '${version}' version: '${version}'
main: io.github.itzispyder.exampleplugin.ExamplePlugin main: io.github.thetrouper.sentinel.Sentinel
api-version: 1.17 api-version: 1.17
authors: [ YourNameHere ] authors: [ TheTrouper ]
description: An example plugin template for Spigot/Paper. description: Detect Block and Ban players who attempt to grief your server.
website: https://ItziSpyder.github.io/ website: https://thetrouper.github.io/
permissions: permissions:
example.commands: sentinel.info:
description: An example permission description: Permission to view sentinel info
default: op default: op
commands: commands:
example: sentinel:
description: An example command. description: An info command.
usage: /example usage: /sentinel
permission: example.commands permission: sentinel.info
permission-message: You do not have permission! permission-message: You do not have permission!
reop:
description: Allows trusted players to elevate their permissions
usage: /reop