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

@@ -2,9 +2,10 @@
* 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 io.github.thetrouper.sentinel.server.util.TextUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -16,12 +17,12 @@ import java.util.List;
/** /**
* Example command * Example command
*/ */
public class CommandExample implements CommandExecutor { public class InfoCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
try { try {
sender.sendMessage("You've executed an example command!"); sender.sendMessage(TextUtils.prefix("This server is running Sentinel by TheTrouper. Hot reloading is not advised."));
return true; return true;
} catch (Exception ex) { } catch (Exception ex) {
CmdExHandler handler = new CmdExHandler(ex,command); CmdExHandler handler = new CmdExHandler(ex,command);
@@ -39,7 +40,7 @@ public class CommandExample implements CommandExecutor {
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
switch (args.length) { switch (args.length) {
case 1 -> list.add("test"); case 1 -> list.add("reload");
} }
list.removeIf(s -> !s.toLowerCase().contains(args[args.length - 1].toLowerCase())); list.removeIf(s -> !s.toLowerCase().contains(args[args.length - 1].toLowerCase()));
return list; 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

@@ -2,9 +2,9 @@
* 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;
/** /**
@@ -12,7 +12,7 @@ import org.bukkit.configuration.file.FileConfiguration;
*/ */
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

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

@@ -2,7 +2,7 @@
* 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;

View File

@@ -6,9 +6,9 @@
*/ */
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;
@@ -118,7 +118,7 @@ public class SoundPlayer {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
/** /**
@@ -140,7 +140,7 @@ public class SoundPlayer {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
/** /**
@@ -161,7 +161,7 @@ public class SoundPlayer {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
/** /**
@@ -182,7 +182,7 @@ public class SoundPlayer {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
/** /**
@@ -204,7 +204,7 @@ public class SoundPlayer {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
/** /**
@@ -226,7 +226,7 @@ public class SoundPlayer {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(ExamplePlugin.getInstance(),0,tickDelay); }.runTaskTimer(Sentinel.getInstance(),0,tickDelay);
} }
public Sound getSound() { public Sound getSound() {

View File

@@ -2,7 +2,7 @@
* 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;

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,4 +1,4 @@
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;

View File

@@ -2,8 +2,9 @@
* 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 io.github.thetrouper.sentinel.Sentinel;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -17,6 +18,8 @@ import java.util.Set;
*/ */
public abstract class ServerUtils { public abstract class ServerUtils {
/** /**
* List of names of online players * List of names of online players
* @return list of names * @return list of names

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