Implement debug listener and optimize permission handling (#9)

* Improve permission handling and implement debug listener

* Fix custom no-permission message

* Fix ender dragon egg teleport bypass when sneaking
This commit is contained in:
NotMyFault authored and GitHub committed 2020-09-10 21:40:02 +02:00
1 parent 4abd7644aa
commit 17041d4c47
32 files changed
+97 -56

No files matched your search

@@ -37,16 +37,12 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class Main extends JavaPlugin {
private static final Logger logger = LoggerFactory.getLogger("BU/" + Main.class.getSimpleName());
public static final String MSG_PREFIX = ChatColor.DARK_AQUA + "BuildersUtils> " + ChatColor.AQUA;
public static final String MSG_ERROR = ChatColor.DARK_RED + "Error: " + ChatColor.RED;
public static final String MSG_PREFIX = ChatColor.DARK_AQUA + "Builders-Utilities > " + ChatColor.AQUA;
public static final String MSG_NO_PERMISSION = MSG_PREFIX + ChatColor.AQUA + "You do not have access to this command. Lacking permission: " + ChatColor.RED;
public static final String MSG_ERROR = MSG_PREFIX + ChatColor.DARK_RED + "Error: " + ChatColor.RED;
private static final int BSTATS_ID = 5168;
private static Main instance;
private Settings settings;
@@ -71,7 +67,6 @@ public final class Main extends JavaPlugin {
BannerUtil.addColors();
BannerUtil.addPatterns();
Metrics metrics = new Metrics(this, BSTATS_ID);
this.getServer().getPluginManager().registerEvents(new BlockBreakListener(), this);
@@ -39,6 +39,7 @@ public class Settings {
public static boolean fixAttackSpeed;
public static boolean preventDragonEggTeleport;
public static boolean sendErrorMessages;
public static boolean sendDebugMessages;
private final CustomConfig customConfig;
@@ -58,5 +59,6 @@ public class Settings {
fixAttackSpeed = customConfig.get("fix-attackspeed", Boolean.class, false);
preventDragonEggTeleport = customConfig.get("prevent-dragon-egg-teleport", Boolean.class, true);
sendErrorMessages = customConfig.get("send-error-messages", Boolean.class, true);
sendDebugMessages = customConfig.get("send-debug-messages", Boolean.class, true);
}
}
@@ -37,7 +37,7 @@ public class AdvancedFlyCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.advancedfly")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.advancedfly");
}
return;
}
@@ -37,7 +37,7 @@ public class BannerCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.banner")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.banner");
}
return;
}
@@ -36,7 +36,7 @@ public class ColorCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.color")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.color");
}
return;
}
@@ -36,7 +36,7 @@ public class HelpCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.help")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.help");
}
}
}
@@ -38,7 +38,7 @@ public class NightVisionCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.nightvision")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.nightvision");
}
return;
}
@@ -38,7 +38,7 @@ public class NoClipCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.noclip")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.noclip");
}
return;
}
@@ -36,7 +36,7 @@ public class SecretBlockCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.secretblocks")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.secretblocks");
}
return;
}
@@ -36,7 +36,7 @@ public class UtilsCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.gui")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.gui");
}
return;
}
@@ -35,7 +35,7 @@ public class ConvexSelectionAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -35,7 +35,7 @@ public class CopyAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -35,7 +35,7 @@ public class CuboidSelectionAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -37,7 +37,7 @@ public class DeformRotateAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -35,7 +35,7 @@ public class FlipAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -35,7 +35,7 @@ public class FlySpeedAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -35,7 +35,7 @@ public class PasteAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -35,7 +35,7 @@ public class PosOneAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -35,7 +35,7 @@ public class PosTwoAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -35,7 +35,7 @@ public class ReplaceAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -36,7 +36,7 @@ public class ScaleAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -35,7 +35,7 @@ public class SetAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -37,7 +37,7 @@ public class TwistAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -35,7 +35,7 @@ public class WalkSpeedAliasCommand implements ICommand {
public void execute(Player player, String[] args) {
if (!player.hasPermission("builders.util.aliases")) {
if (Settings.sendErrorMessages) {
player.sendMessage(Main.MSG_ERROR + "You do not have access to this command.");
player.sendMessage(Main.MSG_NO_PERMISSION + "builders.util.aliases");
}
return;
}
@@ -26,12 +26,16 @@
package net.arcaniax.buildersutilities.listeners;
import net.arcaniax.buildersutilities.Settings;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BlockPhysicsListener implements Listener {
private static final Logger logger = LoggerFactory.getLogger("BU/" + BlockPhysicsListener.class.getSimpleName());
@EventHandler
public void onPhysics(BlockPhysicsEvent e) {
try {
@@ -71,10 +75,19 @@ public class BlockPhysicsListener implements Listener {
if (e.getChangedType().hasGravity()) {
if (Settings.disableGravityPhysics) {
e.setCancelled(true);
if (Settings.sendDebugMessages) {
logger.info(
"Gravity physics were cancelled because disable-gravity-physics: true");
}
}
} else {
if (Settings.disablePhysics) {
e.setCancelled(true);
if (Settings.sendDebugMessages) {
logger.info(
"Physics were cancelled because disable-physics: true");
}
}
}
@@ -29,12 +29,21 @@ import net.arcaniax.buildersutilities.Settings;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExplosionListener implements Listener {
private static final Logger logger = LoggerFactory.getLogger("BU/" + ExplosionListener.class.getSimpleName());
@EventHandler
public void onExplode(EntityExplodeEvent event) {
if (Settings.disableExplosions) {
event.setCancelled(true);
if (Settings.sendDebugMessages) {
logger.info(
"Explosion was cancelled because disable-explosions: true");
}
}
}
@@ -29,12 +29,21 @@ import net.arcaniax.buildersutilities.Settings;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.LeavesDecayEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LeafDecayListener implements Listener {
private static final Logger logger = LoggerFactory.getLogger("BU/" + LeafDecayListener.class.getSimpleName());
@EventHandler
public void onLeafDecay(LeavesDecayEvent event) {
if (Settings.disableLeavesDecay) {
event.setCancelled(true);
if (Settings.sendDebugMessages) {
logger.info(
"Leaf decay was cancelled because disable-leaves-decay: true");
}
}
}
@@ -33,8 +33,13 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PlayerInteractListener implements Listener {
private static final Logger logger = LoggerFactory.getLogger("BU/" + PlayerInteractListener.class.getSimpleName());
@EventHandler(priority = EventPriority.MONITOR)
public void onDragonEggTP(PlayerInteractEvent event) {
if (event.isCancelled()) {
@@ -42,9 +47,12 @@ public class PlayerInteractListener implements Listener {
}
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
&& event.getClickedBlock().getType().equals(Material.DRAGON_EGG)
&& (!event.getPlayer().isSneaking())
&& Settings.preventDragonEggTeleport) {
event.setCancelled(true);
if (Settings.sendDebugMessages) {
logger.info(
"Dragon egg teleport was cancelled because prevent-dragon-egg-teleport: true");
}
}
}
@@ -59,6 +67,10 @@ public class PlayerInteractListener implements Listener {
if (block != null && block.getType() == Material.FARMLAND) {
event.setUseInteractedBlock(org.bukkit.event.Event.Result.DENY);
event.setCancelled(true);
if (Settings.sendDebugMessages) {
logger.info(
"Soil trampling was cancelled because disable-soil-trample: true");
}
}
}
}
@@ -25,20 +25,29 @@
package net.arcaniax.buildersutilities.listeners;
import net.arcaniax.buildersutilities.Settings;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TeleportListener implements Listener {
private static final Logger logger = LoggerFactory.getLogger("BU/" + TeleportListener.class.getSimpleName());
@EventHandler
public void onTeleport(PlayerTeleportEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.SPECTATE)) {
//TODO what is this tpgm3 lol
if (!event.getPlayer().hasPermission("builders.util.tpgm3")) {
event.setCancelled(true);
if (Settings.sendDebugMessages) {
logger.info(
"Spectate teleport was cancelled because {} lacks the permission builders.util.tpgm3", event.getPlayer());
}
}
}
}
@@ -29,12 +29,21 @@ import net.arcaniax.buildersutilities.Settings;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WeatherChangeListener implements Listener {
private static final Logger logger = LoggerFactory.getLogger("BU/" + WeatherChangeListener.class.getSimpleName());
@EventHandler
public void onWeather(WeatherChangeEvent e) {
if (Settings.disableWeatherChanges) {
e.setCancelled(true);
if (Settings.sendDebugMessages) {
logger.info(
"Weather changing was cancelled because disable-weather-changes: true");
}
}
}
}