diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 3bca35bf..85057bb7 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -33,6 +33,7 @@ import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.block.Block; +import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -89,6 +90,7 @@ import com.gamingmesh.jobs.listeners.PistonProtectionListener; import com.gamingmesh.jobs.selection.SelectionManager; import com.gamingmesh.jobs.stuff.ActionBar; import com.gamingmesh.jobs.stuff.Loging; +import com.gamingmesh.jobs.stuff.RawMessage; import com.gamingmesh.jobs.stuff.TabComplete; import com.gamingmesh.jobs.stuff.VersionChecker; import com.gamingmesh.jobs.stuff.CMIScoreboardManager; @@ -1231,4 +1233,27 @@ public class Jobs extends JavaPlugin { public static SelectionManager getSelectionManager() { return smanager; } + + public static boolean hasPermission(Object sender, String perm, boolean inform) { + if (sender instanceof Player) { + if (((Player) sender).hasPermission(perm)) + return true; + if (!inform) + return false; + RawMessage rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("general.error.permission"), "&2" + perm); + rm.show((Player) sender); + ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); + Jobs.sendMessage(console, Jobs.getLanguage().getMessage("general.error.permission")); + return false; + } + return true; + } + + public static void sendMessage(Object sender, String msg) { + if (sender instanceof Player) { + ((Player) sender).sendMessage(ChatColor.translateAlternateColorCodes('&', msg)); + } else + ((CommandSender) sender).sendMessage(ChatColor.translateAlternateColorCodes('&', msg)); + } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java index c98c2bda..3369f76a 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java @@ -24,6 +24,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; @@ -34,6 +35,7 @@ import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.stuff.RawMessage; public class JobsCommands implements CommandExecutor { private static final String label = "jobs"; @@ -85,10 +87,18 @@ public class JobsCommands implements CommandExecutor { return true; } - if (!hasCommandPermission(sender, cmd)) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission")); + if (!hasCommandPermission(sender, cmd)) { + if (sender instanceof Player) { + RawMessage rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("general.error.permission"), "&2" + label + ".command." + cmd); + rm.show(sender); + ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); + Jobs.sendMessage(console, Jobs.getLanguage().getMessage("general.error.permission")); + } else + Jobs.sendMessage(sender, Jobs.getLanguage().getMessage("general.error.permission")); return true; } + String[] myArgs = reduceArgs(args); if (myArgs.length > 0) { if (myArgs[myArgs.length - 1].equals("?")) { diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/archive.java b/src/main/java/com/gamingmesh/jobs/commands/list/archive.java index b52e94c4..61cc8f1c 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/archive.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/archive.java @@ -9,7 +9,6 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.stuff.ChatColor; public class archive implements Cmd { @@ -18,8 +17,7 @@ public class archive implements Cmd { public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { JobsPlayer jPlayer = null; if (args.length >= 1) { - if (!sender.hasPermission("jobs.command.admin.archive")) { - sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.permission")); + if (!Jobs.hasPermission(sender, "jobs.command.admin.archive", true)) { return true; } jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/log.java b/src/main/java/com/gamingmesh/jobs/commands/list/log.java index f56d2787..b082a32f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/log.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/log.java @@ -35,8 +35,7 @@ public class log implements Cmd { if (args.length == 0) JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); else if (args.length == 1) { - if (!sender.hasPermission("jobs.commands.log.others")) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission")); + if (!Jobs.hasPermission(sender, "jobs.commands.log.others", true)) { return true; } JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/points.java b/src/main/java/com/gamingmesh/jobs/commands/list/points.java index d2a61b4d..ffd585e3 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/points.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/points.java @@ -8,7 +8,6 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.PlayerPoints; -import com.gamingmesh.jobs.stuff.ChatColor; public class points implements Cmd { @@ -23,8 +22,7 @@ public class points implements Cmd { JobsPlayer jPlayer = null; if (args.length >= 1) { - if (!sender.hasPermission("jobs.command.admin.points")) { - sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.permission")); + if (!Jobs.hasPermission(sender, "jobs.command.admin.points", true)) { return true; } jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/stats.java b/src/main/java/com/gamingmesh/jobs/commands/list/stats.java index 529152e6..482527b3 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/stats.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/stats.java @@ -8,7 +8,6 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.stuff.ChatColor; public class stats implements Cmd { @@ -17,8 +16,7 @@ public class stats implements Cmd { public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { JobsPlayer jPlayer = null; if (args.length >= 1) { - if (!sender.hasPermission("jobs.command.admin.stats")) { - sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.permission")); + if (!Jobs.hasPermission(sender, "jobs.command.admin.stats", true)) { return true; } jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);