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'
}
group = 'io.github.itzispyder'
version = '(YourPluginVersion)'
group = 'io.github.thetrouper'
version = '0.0.1'
repositories {
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 :)
*/
package io.github.itzispyder.exampleplugin.commands;
import io.github.itzispyder.exampleplugin.exceptions.CmdExHandler;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.util.ArrayList;
import java.util.List;
/**
* Example command
*/
public class CommandExample implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
sender.sendMessage("You've executed an example command!");
return true;
} catch (Exception ex) {
CmdExHandler handler = new CmdExHandler(ex,command);
sender.sendMessage(handler.getErrorMessage());
return true;
}
}
/**
* Example command's tab completer
*/
public static class Tabs implements TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> list = new ArrayList<>();
switch (args.length) {
case 1 -> list.add("test");
}
list.removeIf(s -> !s.toLowerCase().contains(args[args.length - 1].toLowerCase()));
return list;
}
}
}
/**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/
package io.github.thetrouper.sentinel.commands;
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 java.util.ArrayList;
import java.util.List;
/**
* Example command
*/
public class InfoCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
sender.sendMessage(TextUtils.prefix("This server is running Sentinel by TheTrouper. Hot reloading is not advised."));
return true;
} catch (Exception ex) {
CmdExHandler handler = new CmdExHandler(ex,command);
sender.sendMessage(handler.getErrorMessage());
return true;
}
}
/**
* Example command's tab completer
*/
public static class Tabs implements TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> list = new ArrayList<>();
switch (args.length) {
case 1 -> list.add("reload");
}
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 :)
*/
package io.github.itzispyder.exampleplugin.data;
import io.github.itzispyder.exampleplugin.ExamplePlugin;
import org.bukkit.configuration.file.FileConfiguration;
/**
* Config loader
*/
public abstract class Config {
private static final FileConfiguration config = ExamplePlugin.getInstance().getConfig();
/**
* Config plugin section
*/
public class Plugin {
public static String getPrefix() {
return config.getString("config.plugin.prefix");
}
}
}
/**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/
package io.github.thetrouper.sentinel.data;
import io.github.thetrouper.sentinel.Sentinel;
import org.bukkit.configuration.file.FileConfiguration;
/**
* Config loader
*/
public abstract class Config {
private static final FileConfiguration config = Sentinel.getInstance().getConfig();
/**
* Config plugin section
*/
public class Plugin {
public static String getPrefix() {
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 :)
*/
package io.github.itzispyder.exampleplugin.exceptions;
import org.bukkit.command.Command;
/**
* Handles a command exception
*/
public class CmdExHandler {
private Exception exception;
private Command command;
/**
* Constructs the command exception
* @param exception the exception caught
* @param command the command run
*/
public CmdExHandler(Exception exception, Command command) {
this.exception = exception;
this.command = command;
}
/**
* Returns the error message
* @return the error message
*/
public String getErrorMessage() {
String msg = "§cCommand Error: ";
if (exception instanceof NullPointerException) msg += "Command contains a null value!";
else if (exception instanceof IndexOutOfBoundsException) msg += "Unknown or incomplete command!";
else msg += exception.getMessage();
return msg + "\n§cCorrect usage: §7" + command.getUsage();
}
public Exception getException() {
return exception;
}
public Command getCommand() {
return command;
}
}
/**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/
package io.github.thetrouper.sentinel.exceptions;
import org.bukkit.command.Command;
/**
* Handles a command exception
*/
public class CmdExHandler {
private Exception exception;
private Command command;
/**
* Constructs the command exception
* @param exception the exception caught
* @param command the command run
*/
public CmdExHandler(Exception exception, Command command) {
this.exception = exception;
this.command = command;
}
/**
* Returns the error message
* @return the error message
*/
public String getErrorMessage() {
String msg = "§cCommand Error: ";
if (exception instanceof NullPointerException) msg += "Command contains a null value!";
else if (exception instanceof IndexOutOfBoundsException) msg += "Unknown or incomplete command!";
else msg += exception.getMessage();
return msg + "\n§cCorrect usage: §7" + command.getUsage();
}
public Exception getException() {
return exception;
}
public Command getCommand() {
return command;
}
}

View File

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

View File

@@ -1,90 +1,90 @@
/**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/
package io.github.itzispyder.exampleplugin.server.util;
import java.util.List;
import java.util.Set;
/**
* Represents Argument builder
*/
public class ArgBuilder {
private String result;
/**
* Constructs an argument builder.
*/
public ArgBuilder() {
this.result = " ";
}
/**
* Constructs an argument builder with a string.
* @param begin the beginner string
*/
public ArgBuilder(String begin) {
this.result = begin + " ";
}
/**
* Appends a string
* @param string string
* @return this class
*/
public ArgBuilder append(String string) {
this.result += string + " ";
return this;
}
/**
* Appends a string array
* @param args string array
* @return this class
*/
public ArgBuilder append(String[] args) {
StringBuilder builder = new StringBuilder();
for (String arg : args) builder.append(arg).append(" ");
this.result += builder.toString();
return this;
}
/**
* Appends a string list
* @param args string list
* @return this class
*/
public ArgBuilder append(List<String> args) {
StringBuilder builder = new StringBuilder();
for (String arg : args) builder.append(arg).append(" ");
this.result += builder.toString();
return this;
}
/**
* Appends a string set
* @param args string set
* @return this class
*/
public ArgBuilder append(Set<String> args) {
StringBuilder builder = new StringBuilder();
for (String arg : args) builder.append(arg).append(" ");
this.result += builder.toString();
return this;
}
/**
* Returns this class as a string
* @return this class as a string
*/
public String build() {
return this.toString().trim();
}
@Override
public String toString() {
return result;
}
}
/**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/
package io.github.thetrouper.sentinel.server.util;
import java.util.List;
import java.util.Set;
/**
* Represents Argument builder
*/
public class ArgBuilder {
private String result;
/**
* Constructs an argument builder.
*/
public ArgBuilder() {
this.result = " ";
}
/**
* Constructs an argument builder with a string.
* @param begin the beginner string
*/
public ArgBuilder(String begin) {
this.result = begin + " ";
}
/**
* Appends a string
* @param string string
* @return this class
*/
public ArgBuilder append(String string) {
this.result += string + " ";
return this;
}
/**
* Appends a string array
* @param args string array
* @return this class
*/
public ArgBuilder append(String[] args) {
StringBuilder builder = new StringBuilder();
for (String arg : args) builder.append(arg).append(" ");
this.result += builder.toString();
return this;
}
/**
* Appends a string list
* @param args string list
* @return this class
*/
public ArgBuilder append(List<String> args) {
StringBuilder builder = new StringBuilder();
for (String arg : args) builder.append(arg).append(" ");
this.result += builder.toString();
return this;
}
/**
* Appends a string set
* @param args string set
* @return this class
*/
public ArgBuilder append(Set<String> args) {
StringBuilder builder = new StringBuilder();
for (String arg : args) builder.append(arg).append(" ");
this.result += builder.toString();
return this;
}
/**
* Returns this class as a string
* @return this class as a string
*/
public String build() {
return this.toString().trim();
}
@Override
public String toString() {
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;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Randomize items from a list
* @param <T> list of?
*/
public class Randomizer<T> {
private final List<T> array;
/**
* From array list
* @param array list
*/
public Randomizer(List<T> array) {
this.array = array;
}
/**
* From set
* @param array set
*/
public Randomizer(Set<T> array) {
this.array = new ArrayList<>(array);
}
/**
* From array
* @param array array
*/
public Randomizer(T[] array) {
this.array = List.of(array);
}
/**
* Pick random from the array
* @return random of list of?
*/
public T pickRand() {
return array.get(rand(array.size() - 1));
}
/**
* Generates a random integer from 1 to (max)
* @param max max value
* @return random
*/
public static int rand(int max) {
if (max <= 0) throw new IllegalArgumentException("max cannot be less than 1!");
return (int) Math.ceil(Math.random() * max);
}
/**
* Generates a random integer from (min) to (max)
* @param min min value
* @param max max value
* @return random
*/
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 <= min) throw new IllegalArgumentException("max cannot be less than or equal to min!");
return min + (int) Math.floor(Math.random() * (max - min + 1));
}
}
package io.github.thetrouper.sentinel.server.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Randomize items from a list
* @param <T> list of?
*/
public class Randomizer<T> {
private final List<T> array;
/**
* From array list
* @param array list
*/
public Randomizer(List<T> array) {
this.array = array;
}
/**
* From set
* @param array set
*/
public Randomizer(Set<T> array) {
this.array = new ArrayList<>(array);
}
/**
* From array
* @param array array
*/
public Randomizer(T[] array) {
this.array = List.of(array);
}
/**
* Pick random from the array
* @return random of list of?
*/
public T pickRand() {
return array.get(rand(array.size() - 1));
}
/**
* Generates a random integer from 1 to (max)
* @param max max value
* @return random
*/
public static int rand(int max) {
if (max <= 0) throw new IllegalArgumentException("max cannot be less than 1!");
return (int) Math.ceil(Math.random() * max);
}
/**
* Generates a random integer from (min) to (max)
* @param min min value
* @param max max value
* @return random
*/
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 <= min) throw new IllegalArgumentException("max cannot be less than or equal to min!");
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 :)
*/
package io.github.itzispyder.exampleplugin.server.util;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Server utils
*/
public abstract class ServerUtils {
/**
* List of names of online players
* @return list of names
*/
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<String> list =new ArrayList<>();
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() {
Set<Player> list = new HashSet<>();
Bukkit.getOnlinePlayers().forEach(p -> {
if (p.isOp()) list.add(p);
});
return list;
}
}
/**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*/
package io.github.thetrouper.sentinel.server.util;
import io.github.thetrouper.sentinel.Sentinel;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Server utils
*/
public abstract class ServerUtils {
/**
* List of names of online players
* @return list of names
*/
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<String> list =new ArrayList<>();
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() {
Set<Player> list = new HashSet<>();
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:
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}'
main: io.github.itzispyder.exampleplugin.ExamplePlugin
main: io.github.thetrouper.sentinel.Sentinel
api-version: 1.17
authors: [ YourNameHere ]
description: An example plugin template for Spigot/Paper.
website: https://ItziSpyder.github.io/
authors: [ TheTrouper ]
description: Detect Block and Ban players who attempt to grief your server.
website: https://thetrouper.github.io/
permissions:
example.commands:
description: An example permission
sentinel.info:
description: Permission to view sentinel info
default: op
commands:
example:
description: An example command.
usage: /example
permission: example.commands
permission-message: You do not have permission!
sentinel:
description: An info command.
usage: /sentinel
permission: sentinel.info
permission-message: You do not have permission!
reop:
description: Allows trusted players to elevate their permissions
usage: /reop