From 6f85761f7fc7949b478c0dec44240f93d4b08a02 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Wed, 16 Oct 2013 20:59:39 +0100 Subject: [PATCH] Extract CommandSender to CommandSource, this should prevent Ess user object leaks. --- .gitignore | 2 - .idea/.name | 1 + .idea/ant.xml | 7 + .idea/compiler.xml | 28 + .idea/copyright/profiles_settings.xml | 5 + .idea/encodings.xml | 13 + .../libraries/Maven__com_iCo6_iConomy_6_0.xml | 13 + .../Maven__com_iConomy_iConomy_5_0.xml | 13 + .../Maven__commons_io_commons_io_2_4.xml | 13 + .../Maven__cosine_BOSEconomy_0_7.xml | 13 + .../Maven__jivesoftware_smack_3_1_0.xml | 13 + .idea/libraries/Maven__junit_junit_4_10.xml | 13 + ...aven__me_ashtheking_MultiCurrency_0_05.xml | 13 + .../Maven__net_milkbowl_Vault_1_2.xml | 13 + ..._apache_commons_commons_compress_1_4_1.xml | 13 + ..._org_bukkit_bukkit_1_4_2_R0_3_SNAPSHOT.xml | 13 + .../Maven__org_hamcrest_hamcrest_core_1_1.xml | 13 + .../Maven__org_mockito_mockito_core_1_9_5.xml | 13 + .../Maven__org_objenesis_objenesis_1_0.xml | 13 + ...Maven__org_projectlombok_lombok_0_11_6.xml | 13 + .idea/libraries/Maven__org_tukaani_xz_1_0.xml | 13 + .idea/misc.xml | 44 ++ .idea/modules.xml | 12 + .idea/scopes/scope_settings.xml | 5 + .idea/uiDesigner.xml | 125 ++++ .idea/vcs.xml | 8 + .idea/workspace.xml | 642 ++++++++++++++++++ Essentials/Essentials.iml | 31 + .../earth2me/essentials/CommandSource.java | 61 ++ .../src/com/earth2me/essentials/Console.java | 6 +- .../com/earth2me/essentials/Essentials.java | 47 +- .../essentials/EssentialsEntityListener.java | 16 +- .../essentials/EssentialsPlayerListener.java | 24 +- .../com/earth2me/essentials/IEssentials.java | 7 +- .../src/com/earth2me/essentials/IReplyTo.java | 6 +- .../src/com/earth2me/essentials/IUser.java | 31 +- .../src/com/earth2me/essentials/Jails.java | 3 +- .../src/com/earth2me/essentials/Kit.java | 2 +- .../earth2me/essentials/MetaItemStack.java | 17 +- .../src/com/earth2me/essentials/SpawnMob.java | 22 +- .../earth2me/essentials/TimedTeleport.java | 2 +- .../src/com/earth2me/essentials/User.java | 16 +- .../essentials/commands/Commandafk.java | 4 +- .../essentials/commands/Commandbackup.java | 4 +- .../essentials/commands/Commandbalance.java | 4 +- .../commands/Commandbalancetop.java | 12 +- .../essentials/commands/Commandban.java | 9 +- .../essentials/commands/Commandbanip.java | 7 +- .../essentials/commands/Commandbroadcast.java | 6 +- .../essentials/commands/Commandburn.java | 4 +- .../commands/Commandclearinventory.java | 14 +- .../commands/Commandcustomtext.java | 4 +- .../essentials/commands/Commanddelhome.java | 6 +- .../essentials/commands/Commanddeljail.java | 4 +- .../essentials/commands/Commanddelwarp.java | 4 +- .../essentials/commands/Commandeco.java | 10 +- .../essentials/commands/Commandenchant.java | 2 +- .../commands/Commandessentials.java | 80 +-- .../essentials/commands/Commandexp.java | 38 +- .../essentials/commands/Commandext.java | 8 +- .../essentials/commands/Commandfeed.java | 8 +- .../essentials/commands/Commandfirework.java | 2 +- .../essentials/commands/Commandfly.java | 14 +- .../essentials/commands/Commandgamemode.java | 12 +- .../essentials/commands/Commandgc.java | 4 +- .../essentials/commands/Commandgetpos.java | 10 +- .../essentials/commands/Commandgive.java | 19 +- .../essentials/commands/Commandgod.java | 17 +- .../essentials/commands/Commandheal.java | 8 +- .../essentials/commands/Commandhelp.java | 10 +- .../essentials/commands/Commandhelpop.java | 7 +- .../essentials/commands/Commandinfo.java | 4 +- .../essentials/commands/Commanditem.java | 2 +- .../essentials/commands/Commanditemdb.java | 6 +- .../essentials/commands/Commandjails.java | 4 +- .../essentials/commands/Commandkick.java | 11 +- .../essentials/commands/Commandkickall.java | 6 +- .../essentials/commands/Commandkill.java | 10 +- .../essentials/commands/Commandkillall.java | 8 +- .../essentials/commands/Commandkit.java | 4 +- .../essentials/commands/Commandlightning.java | 8 +- .../essentials/commands/Commandlist.java | 11 +- .../essentials/commands/Commandmail.java | 4 +- .../essentials/commands/Commandme.java | 4 +- .../essentials/commands/Commandmotd.java | 4 +- .../essentials/commands/Commandmsg.java | 24 +- .../essentials/commands/Commandmute.java | 9 +- .../essentials/commands/Commandnear.java | 4 +- .../essentials/commands/Commandnick.java | 14 +- .../essentials/commands/Commandnuke.java | 4 +- .../essentials/commands/Commandpay.java | 8 +- .../essentials/commands/Commandping.java | 4 +- .../essentials/commands/Commandpotion.java | 2 +- .../essentials/commands/Commandpowertool.java | 11 +- .../essentials/commands/Commandptime.java | 33 +- .../essentials/commands/Commandpweather.java | 33 +- .../essentials/commands/Commandr.java | 16 +- .../essentials/commands/Commandrealname.java | 6 +- .../essentials/commands/Commandrecipe.java | 19 +- .../essentials/commands/Commandremove.java | 10 +- .../essentials/commands/Commandrules.java | 4 +- .../essentials/commands/Commandseen.java | 19 +- .../essentials/commands/Commandsetworth.java | 4 +- .../essentials/commands/Commandsocialspy.java | 14 +- .../essentials/commands/Commandspawnmob.java | 6 +- .../essentials/commands/Commandspeed.java | 10 +- .../essentials/commands/Commandsudo.java | 4 +- .../essentials/commands/Commandtempban.java | 12 +- .../essentials/commands/Commandtime.java | 24 +- .../commands/Commandtogglejail.java | 9 +- .../essentials/commands/Commandtp.java | 4 +- .../essentials/commands/Commandtpaall.java | 10 +- .../essentials/commands/Commandtpaccept.java | 2 +- .../essentials/commands/Commandtpall.java | 10 +- .../essentials/commands/Commandtppos.java | 4 +- .../essentials/commands/Commandtptoggle.java | 14 +- .../essentials/commands/Commandunban.java | 7 +- .../essentials/commands/Commandunbanip.java | 7 +- .../essentials/commands/Commandvanish.java | 14 +- .../essentials/commands/Commandwarp.java | 8 +- .../essentials/commands/Commandweather.java | 4 +- .../essentials/commands/Commandwhois.java | 7 +- .../essentials/commands/Commandworth.java | 8 +- .../commands/EssentialsCommand.java | 13 +- .../commands/EssentialsLoopCommand.java | 12 +- .../commands/EssentialsToggleCommand.java | 8 +- .../commands/IEssentialsCommand.java | 4 +- .../essentials/signs/EssentialsSign.java | 20 +- .../earth2me/essentials/signs/SignInfo.java | 6 +- .../essentials/signs/SignSpawnmob.java | 2 +- .../textreader/KeywordReplacer.java | 32 +- .../textreader/SimpleTextPager.java | 5 +- .../essentials/textreader/TextInput.java | 12 +- .../essentials/textreader/TextPager.java | 4 +- .../com/earth2me/essentials/ToggleTest.java | 2 +- EssentialsAntiBuild/EssentialsAntiBuild.iml | 27 + .../EssentialsAntiBuildListener.java | 4 +- EssentialsChat/EssentialsChat.iml | 27 + .../essentials/chat/EssentialsChatPlayer.java | 2 +- EssentialsGeoIP/EssentialsGeoIP.iml | 27 + .../EssentialsProtectEntityListener.java | 18 +- .../essentials/spawn/Commandspawn.java | 4 +- .../spawn/EssentialsSpawnPlayerListener.java | 2 +- .../earth2me/essentials/xmpp/Commandxmpp.java | 6 +- .../essentials/xmpp/Commandxmppspy.java | 4 +- 145 files changed, 1848 insertions(+), 590 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/ant.xml create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/libraries/Maven__com_iCo6_iConomy_6_0.xml create mode 100644 .idea/libraries/Maven__com_iConomy_iConomy_5_0.xml create mode 100644 .idea/libraries/Maven__commons_io_commons_io_2_4.xml create mode 100644 .idea/libraries/Maven__cosine_BOSEconomy_0_7.xml create mode 100644 .idea/libraries/Maven__jivesoftware_smack_3_1_0.xml create mode 100644 .idea/libraries/Maven__junit_junit_4_10.xml create mode 100644 .idea/libraries/Maven__me_ashtheking_MultiCurrency_0_05.xml create mode 100644 .idea/libraries/Maven__net_milkbowl_Vault_1_2.xml create mode 100644 .idea/libraries/Maven__org_apache_commons_commons_compress_1_4_1.xml create mode 100644 .idea/libraries/Maven__org_bukkit_bukkit_1_4_2_R0_3_SNAPSHOT.xml create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml create mode 100644 .idea/libraries/Maven__org_mockito_mockito_core_1_9_5.xml create mode 100644 .idea/libraries/Maven__org_objenesis_objenesis_1_0.xml create mode 100644 .idea/libraries/Maven__org_projectlombok_lombok_0_11_6.xml create mode 100644 .idea/libraries/Maven__org_tukaani_xz_1_0.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 Essentials/Essentials.iml create mode 100644 Essentials/src/com/earth2me/essentials/CommandSource.java create mode 100644 EssentialsAntiBuild/EssentialsAntiBuild.iml create mode 100644 EssentialsChat/EssentialsChat.iml create mode 100644 EssentialsGeoIP/EssentialsGeoIP.iml diff --git a/.gitignore b/.gitignore index 9251ca7e6..199130ecb 100644 --- a/.gitignore +++ b/.gitignore @@ -36,8 +36,6 @@ /EssentialsUpdate/build/ /WebPush/apikey.php /WebPush/nbproject/private -/.idea -*.iml /EssentialsGroupManager/bin /EssentialsGroupManager/.externalToolBuilders /EssentialsAntiBuild/nbproject/private/ diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 000000000..7fd826920 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Essentials \ No newline at end of file diff --git a/.idea/ant.xml b/.idea/ant.xml new file mode 100644 index 000000000..23e6fe04c --- /dev/null +++ b/.idea/ant.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 000000000..074eb5c80 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,28 @@ + + + + + + + + diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 000000000..3572571ad --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 000000000..77d25dd5b --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.idea/libraries/Maven__com_iCo6_iConomy_6_0.xml b/.idea/libraries/Maven__com_iCo6_iConomy_6_0.xml new file mode 100644 index 000000000..e1c635d69 --- /dev/null +++ b/.idea/libraries/Maven__com_iCo6_iConomy_6_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_iConomy_iConomy_5_0.xml b/.idea/libraries/Maven__com_iConomy_iConomy_5_0.xml new file mode 100644 index 000000000..68a212375 --- /dev/null +++ b/.idea/libraries/Maven__com_iConomy_iConomy_5_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_io_commons_io_2_4.xml b/.idea/libraries/Maven__commons_io_commons_io_2_4.xml new file mode 100644 index 000000000..bc2aad0ed --- /dev/null +++ b/.idea/libraries/Maven__commons_io_commons_io_2_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__cosine_BOSEconomy_0_7.xml b/.idea/libraries/Maven__cosine_BOSEconomy_0_7.xml new file mode 100644 index 000000000..8d8f8be1f --- /dev/null +++ b/.idea/libraries/Maven__cosine_BOSEconomy_0_7.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__jivesoftware_smack_3_1_0.xml b/.idea/libraries/Maven__jivesoftware_smack_3_1_0.xml new file mode 100644 index 000000000..8d0da5dbb --- /dev/null +++ b/.idea/libraries/Maven__jivesoftware_smack_3_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_10.xml b/.idea/libraries/Maven__junit_junit_4_10.xml new file mode 100644 index 000000000..ed8bf5fe7 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_10.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__me_ashtheking_MultiCurrency_0_05.xml b/.idea/libraries/Maven__me_ashtheking_MultiCurrency_0_05.xml new file mode 100644 index 000000000..61fbfb70f --- /dev/null +++ b/.idea/libraries/Maven__me_ashtheking_MultiCurrency_0_05.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__net_milkbowl_Vault_1_2.xml b/.idea/libraries/Maven__net_milkbowl_Vault_1_2.xml new file mode 100644 index 000000000..351770097 --- /dev/null +++ b/.idea/libraries/Maven__net_milkbowl_Vault_1_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_commons_commons_compress_1_4_1.xml b/.idea/libraries/Maven__org_apache_commons_commons_compress_1_4_1.xml new file mode 100644 index 000000000..190209ed6 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_commons_commons_compress_1_4_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_bukkit_bukkit_1_4_2_R0_3_SNAPSHOT.xml b/.idea/libraries/Maven__org_bukkit_bukkit_1_4_2_R0_3_SNAPSHOT.xml new file mode 100644 index 000000000..8ed2cfef1 --- /dev/null +++ b/.idea/libraries/Maven__org_bukkit_bukkit_1_4_2_R0_3_SNAPSHOT.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml new file mode 100644 index 000000000..acdf44300 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mockito_mockito_core_1_9_5.xml b/.idea/libraries/Maven__org_mockito_mockito_core_1_9_5.xml new file mode 100644 index 000000000..5f7f780bf --- /dev/null +++ b/.idea/libraries/Maven__org_mockito_mockito_core_1_9_5.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_objenesis_objenesis_1_0.xml b/.idea/libraries/Maven__org_objenesis_objenesis_1_0.xml new file mode 100644 index 000000000..c79fa27d2 --- /dev/null +++ b/.idea/libraries/Maven__org_objenesis_objenesis_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_projectlombok_lombok_0_11_6.xml b/.idea/libraries/Maven__org_projectlombok_lombok_0_11_6.xml new file mode 100644 index 000000000..6b05a518b --- /dev/null +++ b/.idea/libraries/Maven__org_projectlombok_lombok_0_11_6.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_tukaani_xz_1_0.xml b/.idea/libraries/Maven__org_tukaani_xz_1_0.xml new file mode 100644 index 000000000..8b8042f39 --- /dev/null +++ b/.idea/libraries/Maven__org_tukaani_xz_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..2d5ca7c0a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + http://www.w3.org/1999/xhtml + + + + + + + + + 1.7 + + + + + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..fc221b0a7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 000000000..922003b84 --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 000000000..3b0002030 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..9d32e507a --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 000000000..8a2df0463 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,642 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + + 1352756031122 + 1352756031122 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Essentials/Essentials.iml b/Essentials/Essentials.iml new file mode 100644 index 000000000..198129876 --- /dev/null +++ b/Essentials/Essentials.iml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Essentials/src/com/earth2me/essentials/CommandSource.java b/Essentials/src/com/earth2me/essentials/CommandSource.java new file mode 100644 index 000000000..689431a37 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/CommandSource.java @@ -0,0 +1,61 @@ +package com.earth2me.essentials; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + + +public class CommandSource implements IReplyTo +{ + private CommandSource replyTo = null; + protected CommandSender sender; + + public CommandSource(final CommandSender base) + { + this.sender = base; + } + + public final CommandSender getSender() + { + return sender; + } + + public final Player getPlayer() + { + if (sender instanceof Player) + { + return (Player)sender; + } + return null; + } + + public final boolean isPlayer() + { + return (sender instanceof Player); + } + + public final CommandSender setSender(final CommandSender base) + { + return this.sender = base; + } + + + public void sendMessage(String message) + { + if (!message.isEmpty()) + { + sender.sendMessage(message); + } + } + + @Override + public void setReplyTo(final CommandSource user) + { + replyTo = user; + } + + @Override + public CommandSource getReplyTo() + { + return replyTo; + } +} diff --git a/Essentials/src/com/earth2me/essentials/Console.java b/Essentials/src/com/earth2me/essentials/Console.java index d07171c63..8596a585b 100644 --- a/Essentials/src/com/earth2me/essentials/Console.java +++ b/Essentials/src/com/earth2me/essentials/Console.java @@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender; public final class Console implements IReplyTo { private static Console instance = new Console(); - private CommandSender replyTo; + private CommandSource replyTo; public final static String NAME = "Console"; private Console() @@ -20,13 +20,13 @@ public final class Console implements IReplyTo } @Override - public void setReplyTo(CommandSender user) + public void setReplyTo(CommandSource user) { replyTo = user; } @Override - public CommandSender getReplyTo() + public CommandSource getReplyTo() { return replyTo; } diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 665018a3f..373f201c3 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -374,7 +374,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials } @Override - public boolean onCommandEssentials(final CommandSender sender, final Command command, final String commandLabel, final String[] args, final ClassLoader classLoader, final String commandPath, final String permissionPrefix, final IEssentialsModule module) + public boolean onCommandEssentials(final CommandSender cSender, final Command command, final String commandLabel, final String[] args, final ClassLoader classLoader, final String commandPath, final String permissionPrefix, final IEssentialsModule module) { // Allow plugins to override the command via onCommand if (!getSettings().isCommandOverridden(command.getName()) && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName()))) @@ -385,12 +385,12 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials alternativeCommandsHandler.executed(commandLabel, pc); try { - return pc.execute(sender, commandLabel, args); + return pc.execute(cSender, commandLabel, args); } catch (final Exception ex) { Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); - sender.sendMessage(ChatColor.RED + "An internal error occurred while attempting to perform this command"); + cSender.sendMessage(ChatColor.RED + "An internal error occurred while attempting to perform this command"); return true; } } @@ -398,15 +398,16 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials try { + User user = null; Block bSenderBlock = null; - if (sender instanceof Player) + if (cSender instanceof Player) { - user = getUser(sender); + user = getUser((Player)cSender); } - else if (sender instanceof BlockCommandSender) + else if (cSender instanceof BlockCommandSender) { - BlockCommandSender bsender = (BlockCommandSender)sender; + BlockCommandSender bsender = (BlockCommandSender)cSender; bSenderBlock = bsender.getBlock(); } @@ -421,10 +422,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { Bukkit.getLogger().log(Level.INFO, "{0} issued server command: /{1} {2}", new Object[] { - sender.getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0) + cSender.getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0) }); } + CommandSource sender = new CommandSource(cSender); // New mail notification if (user != null && !getSettings().isCommandDisabled("mail") && !command.getName().equals("mail") && user.isAuthorized("essentials.mail")) @@ -452,7 +454,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { if (cmd.matches(commandLabel)) { - cmd.execute(sender, commandLabel, args); + cmd.execute(cSender, commandLabel, args); } } } @@ -559,7 +561,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials } @Override - public void showError(final CommandSender sender, final Throwable exception, final String commandLabel) + public void showError(final CommandSource sender, final Throwable exception, final String commandLabel) { sender.sendMessage(_("errorWithMessage", exception.getMessage())); if (getSettings().isDebug()) @@ -608,18 +610,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials this.metrics = metrics; } + @Override - public User getUser(final Object base) - { - if (base instanceof Player) - { - return getUser((Player)base); - } - if (base instanceof String) - { - return getOfflineUser((String)base); - } - return null; + public User getUser(final String base) + { + return getOfflineUser((String)base); } @Override @@ -633,18 +628,14 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials return user; } - private User getUser(final T base) + @Override + public User getUser(final Player base) { if (base == null) { return null; } - if (base instanceof User) - { - return (User)base; - } - if (userMap == null) { LOGGER.log(Level.WARNING, "Essentials userMap not initialized"); @@ -746,7 +737,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { if (keywords) { - broadcast = new KeywordReplacer(broadcast, player, this, false); + broadcast = new KeywordReplacer(broadcast, new CommandSource(player), this, false); } for (String messageText : broadcast.getLines()) { diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java index a521cd927..883b310a9 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java @@ -35,7 +35,7 @@ public class EssentialsEntityListener implements Listener final Entity eDefend = event.getEntity(); if (eAttack instanceof Player) { - final User attacker = ess.getUser(eAttack); + final User attacker = ess.getUser((Player)eAttack); if (eDefend instanceof Player) { onPlayerVsPlayerDamage(event, (Player)eDefend, attacker); @@ -59,7 +59,7 @@ public class EssentialsEntityListener implements Listener Entity shooter = ((Projectile)event.getDamager()).getShooter(); if (shooter instanceof Player) { - final User attacker = ess.getUser(shooter); + final User attacker = ess.getUser((Player)shooter); onPlayerVsPlayerDamage(event, (Player)eDefend, attacker); attacker.updateActivity(true); } @@ -124,7 +124,7 @@ public class EssentialsEntityListener implements Listener @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onEntityDamage(final EntityDamageEvent event) { - if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) + if (event.getEntity() instanceof Player && ess.getUser((Player)event.getEntity()).isGodModeEnabled()) { final Player player = (Player)event.getEntity(); player.setFireTicks(0); @@ -136,7 +136,7 @@ public class EssentialsEntityListener implements Listener @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onEntityCombust(final EntityCombustEvent event) { - if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) + if (event.getEntity() instanceof Player && ess.getUser((Player)event.getEntity()).isGodModeEnabled()) { event.setCancelled(true); } @@ -173,7 +173,7 @@ public class EssentialsEntityListener implements Listener { if (event.getEntity() instanceof Player) { - final User user = ess.getUser(event.getEntity()); + final User user = ess.getUser((Player)event.getEntity()); if (user.isGodModeEnabled()) { if (user.isGodModeEnabledRaw()) @@ -190,7 +190,7 @@ public class EssentialsEntityListener implements Listener public void onEntityRegainHealth(final EntityRegainHealthEvent event) { if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player - && ess.getUser(event.getEntity()).isAfk() && ess.getSettings().getFreezeAfkPlayers()) + && ess.getUser((Player)event.getEntity()).isAfk() && ess.getSettings().getFreezeAfkPlayers()) { event.setCancelled(true); } @@ -201,7 +201,7 @@ public class EssentialsEntityListener implements Listener { for (LivingEntity entity : event.getAffectedEntities()) { - if (entity instanceof Player && ess.getUser(entity).isGodModeEnabled()) + if (entity instanceof Player && ess.getUser((Player)entity).isGodModeEnabled()) { event.setIntensity(entity, 0d); } @@ -213,7 +213,7 @@ public class EssentialsEntityListener implements Listener { if (event.getEntity() instanceof Player) { - final User user = ess.getUser(event.getEntity()); + final User user = ess.getUser((Player)event.getEntity()); if (user.isAfk()) { user.updateActivity(true); diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 8040d42ae..fcf99355f 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -235,10 +235,10 @@ public class EssentialsPlayerListener implements Listener { try { - final IText input = new TextInput(user.getBase(), "motd", true, ess); - final IText output = new KeywordReplacer(input, user.getBase(), ess); + final IText input = new TextInput(user.getSource(), "motd", true, ess); + final IText output = new KeywordReplacer(input, user.getSource(), ess); final TextPager pager = new TextPager(output, true); - pager.showPage("1", null, "motd", user.getBase()); + pager.showPage("1", null, "motd", user.getSource()); } catch (IOException ex) { @@ -595,11 +595,11 @@ public class EssentialsPlayerListener implements Listener if (type == InventoryType.PLAYER) { - final User user = ess.getUser(event.getWhoClicked()); + final User user = ess.getUser((Player)event.getWhoClicked()); final InventoryHolder invHolder = top.getHolder(); if (invHolder != null && invHolder instanceof HumanEntity) { - final User invOwner = ess.getUser((HumanEntity)invHolder); + final User invOwner = ess.getUser((Player)invHolder); if (user.isInvSee() && (!user.isAuthorized("essentials.invsee.modify") || invOwner.isAuthorized("essentials.invsee.preventmodify") || !invOwner.isOnline())) @@ -611,7 +611,7 @@ public class EssentialsPlayerListener implements Listener } else if (type == InventoryType.ENDER_CHEST) { - final User user = ess.getUser(event.getWhoClicked()); + final User user = ess.getUser((Player)event.getWhoClicked()); if (user.isEnderSee() && (!user.isAuthorized("essentials.enderchest.modify"))) { event.setCancelled(true); @@ -619,7 +619,7 @@ public class EssentialsPlayerListener implements Listener } else if (type == InventoryType.WORKBENCH) { - User user = ess.getUser(event.getWhoClicked()); + User user = ess.getUser((Player)event.getWhoClicked()); if (user.isRecipeSee()) { event.setCancelled(true); @@ -627,7 +627,7 @@ public class EssentialsPlayerListener implements Listener } else if (type == InventoryType.CHEST && top.getSize() == 9) { - final User user = ess.getUser(event.getWhoClicked()); + final User user = ess.getUser((Player)event.getWhoClicked()); final InventoryHolder invHolder = top.getHolder(); if (invHolder != null && invHolder instanceof HumanEntity && user.isInvSee()) { @@ -643,19 +643,19 @@ public class EssentialsPlayerListener implements Listener final InventoryType type = top.getType(); if (type == InventoryType.PLAYER) { - final User user = ess.getUser(event.getPlayer()); + final User user = ess.getUser((Player)event.getPlayer()); user.setInvSee(false); user.updateInventory(); } else if (type == InventoryType.ENDER_CHEST) { - final User user = ess.getUser(event.getPlayer()); + final User user = ess.getUser((Player)event.getPlayer()); user.setEnderSee(false); user.updateInventory(); } else if (type == InventoryType.WORKBENCH) { - final User user = ess.getUser(event.getPlayer()); + final User user = ess.getUser((Player)event.getPlayer()); if (user.isRecipeSee()) { user.setRecipeSee(false); @@ -668,7 +668,7 @@ public class EssentialsPlayerListener implements Listener final InventoryHolder invHolder = top.getHolder(); if (invHolder != null && invHolder instanceof HumanEntity) { - final User user = ess.getUser(event.getPlayer()); + final User user = ess.getUser((Player)event.getPlayer()); user.setInvSee(false); user.updateInventory(); } diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java index 6c1ba3715..73b462939 100644 --- a/Essentials/src/com/earth2me/essentials/IEssentials.java +++ b/Essentials/src/com/earth2me/essentials/IEssentials.java @@ -10,6 +10,7 @@ import java.util.List; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; @@ -23,7 +24,9 @@ public interface IEssentials extends Plugin boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath, String permissionPrefix, IEssentialsModule module); - User getUser(Object base); + User getUser(String base); + + User getUser(Player base); I18n getI18n(); @@ -67,7 +70,7 @@ public interface IEssentials extends Plugin AlternativeCommandsHandler getAlternativeCommandsHandler(); - void showError(final CommandSender sender, final Throwable exception, final String commandLabel); + void showError(final CommandSource sender, final Throwable exception, final String commandLabel); IItemDb getItemDb(); diff --git a/Essentials/src/com/earth2me/essentials/IReplyTo.java b/Essentials/src/com/earth2me/essentials/IReplyTo.java index 429fd7584..ee8e80b4c 100644 --- a/Essentials/src/com/earth2me/essentials/IReplyTo.java +++ b/Essentials/src/com/earth2me/essentials/IReplyTo.java @@ -1,18 +1,16 @@ package com.earth2me.essentials; -import org.bukkit.command.CommandSender; - public interface IReplyTo { /** * Sets the user to reply to * @param user */ - public void setReplyTo(CommandSender user); + public void setReplyTo(CommandSource user); /** * Gets the user the sender should reply to * @return */ - public CommandSender getReplyTo(); + public CommandSource getReplyTo(); } diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java index fbd0e355d..cc5806022 100644 --- a/Essentials/src/com/earth2me/essentials/IUser.java +++ b/Essentials/src/com/earth2me/essentials/IUser.java @@ -7,7 +7,6 @@ import java.util.Map; import java.util.Set; import net.ess3.api.ITeleport; import org.bukkit.Location; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -23,13 +22,13 @@ public interface IUser void giveMoney(BigDecimal value); - void giveMoney(final BigDecimal value, final CommandSender initiator); + void giveMoney(final BigDecimal value, final CommandSource initiator); void payUser(final User reciever, final BigDecimal value) throws Exception; void takeMoney(BigDecimal value); - void takeMoney(final BigDecimal value, final CommandSender initiator); + void takeMoney(final BigDecimal value, final CommandSource initiator); boolean canAfford(BigDecimal value); @@ -93,9 +92,8 @@ public interface IUser public void sendMessage(String message); /* - * UserData - */ - + * UserData + */ Location getHome(String name) throws Exception; Location getHome(Location loc) throws Exception; @@ -107,25 +105,25 @@ public interface IUser void delHome(String name) throws Exception; boolean hasHome(); - + Location getLastLocation(); - + Location getLogoutLocation(); - + long getLastTeleportTimestamp(); void setLastTeleportTimestamp(long time); - + String getJail(); void setJail(String jail); - + List getMails(); - + void addMail(String mail); - + boolean isAfk(); - + void setConfigProperty(String node, Object object); Set getConfigKeys(); @@ -133,12 +131,13 @@ public interface IUser Map getConfigMap(); Map getConfigMap(String node); - + /* * PlayerExtension */ - Player getBase(); + CommandSource getSource(); + public String getName(); } diff --git a/Essentials/src/com/earth2me/essentials/Jails.java b/Essentials/src/com/earth2me/essentials/Jails.java index 8acf04195..303de169c 100644 --- a/Essentials/src/com/earth2me/essentials/Jails.java +++ b/Essentials/src/com/earth2me/essentials/Jails.java @@ -12,6 +12,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -236,7 +237,7 @@ public class Jails extends AsyncStorageObjectHolder parts, final List data, int mobCount) throws Exception + public static void spawnmob(final IEssentials ess, final Server server, final CommandSource sender, final User target, final List parts, final List data, int mobCount) throws Exception { spawnmob(ess, server, sender, target, target.getLocation(), parts, data, mobCount); } // This method spawns a mob at loc, owned by target - public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final User target, final Location loc, final List parts, final List data, int mobCount) throws Exception + public static void spawnmob(final IEssentials ess, final Server server, final CommandSource sender, final User target, final Location loc, final List parts, final List data, int mobCount) throws Exception { final Location sloc = LocationUtil.getSafeDestination(loc); @@ -152,7 +151,7 @@ public class SpawnMob } } - private static void spawnMob(final IEssentials ess, final Server server, final CommandSender sender, final User target, final Location sloc, List parts, List data) throws Exception + private static void spawnMob(final IEssentials ess, final Server server, final CommandSource sender, final User target, final Location sloc, List parts, List data) throws Exception { Mob mob; Entity spawnedMob = null; @@ -191,7 +190,7 @@ public class SpawnMob } } - private static void checkSpawnable(IEssentials ess, CommandSender sender, Mob mob) throws Exception + private static void checkSpawnable(IEssentials ess, CommandSource sender, Mob mob) throws Exception { if (mob == null) { @@ -203,13 +202,13 @@ public class SpawnMob throw new Exception(_("disabledToSpawnMob")); } - if (sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.spawnmob." + mob.name.toLowerCase(Locale.ENGLISH))) + if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.spawnmob." + mob.name.toLowerCase(Locale.ENGLISH))) { throw new Exception(_("noPermToSpawnMob")); } } - private static void changeMobData(final CommandSender sender, final EntityType type, final Entity spawned, final String inputData, final User target) throws Exception + private static void changeMobData(final CommandSource sender, final EntityType type, final Entity spawned, final String inputData, final User target) throws Exception { String data = inputData; @@ -217,14 +216,15 @@ public class SpawnMob { sender.sendMessage(_("mobDataList", StringUtil.joinList(MobData.getValidHelp(spawned)))); } - + MobData newData = MobData.fromData(spawned, data); - while (newData != null) { + while (newData != null) + { newData.setData(spawned, target.getBase(), data); data = data.replace(newData.getMatched(), ""); newData = MobData.fromData(spawned, data); } - + if (spawned instanceof Zombie || type == EntityType.SKELETON) { if (inputData.contains("armor") || inputData.contains("armour")) diff --git a/Essentials/src/com/earth2me/essentials/TimedTeleport.java b/Essentials/src/com/earth2me/essentials/TimedTeleport.java index 15e5642f3..5287feaf1 100644 --- a/Essentials/src/com/earth2me/essentials/TimedTeleport.java +++ b/Essentials/src/com/earth2me/essentials/TimedTeleport.java @@ -114,7 +114,7 @@ public class TimedTeleport implements Runnable } catch (Throwable ex) { - ess.showError(teleportOwner.getBase(), ex, "teleport"); + ess.showError(teleportOwner.getSource(), ex, "teleport"); } } catch (Exception ex) diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index ddc158c3f..c4e22fe86 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -14,7 +14,6 @@ import java.util.logging.Logger; import net.ess3.api.IEssentials; import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.potion.PotionEffect; @@ -23,7 +22,7 @@ import org.bukkit.potion.PotionEffectType; public class User extends UserData implements Comparable, IReplyTo, net.ess3.api.IUser { - private CommandSender replyTo = null; + private CommandSource replyTo = null; private transient String teleportRequester; private transient boolean teleportRequestHere; private transient Location teleportLocation; @@ -137,7 +136,7 @@ public class User extends UserData implements Comparable, IReplyTo, net.es } @Override - public void giveMoney(final BigDecimal value, final CommandSender initiator) + public void giveMoney(final BigDecimal value, final CommandSource initiator) { if (value.signum() == 0) { @@ -178,7 +177,7 @@ public class User extends UserData implements Comparable, IReplyTo, net.es } @Override - public void takeMoney(final BigDecimal value, final CommandSender initiator) + public void takeMoney(final BigDecimal value, final CommandSource initiator) { if (value.signum() == 0) { @@ -799,13 +798,13 @@ public class User extends UserData implements Comparable, IReplyTo, net.es } @Override - public void setReplyTo(final CommandSender user) + public void setReplyTo(final CommandSource user) { replyTo = user; } @Override - public CommandSender getReplyTo() + public CommandSource getReplyTo() { return replyTo; } @@ -832,4 +831,9 @@ public class User extends UserData implements Comparable, IReplyTo, net.es { return this.getName().hashCode(); } + + public CommandSource getSource() + { + return new CommandSource(getBase()); + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java index 6d9016a31..e14b02a80 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandafk extends EssentialsCommand @@ -28,7 +28,7 @@ public class Commandafk extends EssentialsCommand } @Override - public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + public void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { if (args.length > 0) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java index 38644c680..4da00e26e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Backup; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandbackup extends EssentialsCommand @@ -14,7 +14,7 @@ public class Commandbackup extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { final Backup backup = ess.getBackup(); if (backup == null) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java index ce0d03437..09b661191 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.NumberUtil; import java.math.BigDecimal; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandbalance extends EssentialsCommand @@ -16,7 +16,7 @@ public class Commandbalance extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index 87063bdd8..64ba74c91 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.textreader.SimpleTextInput; @@ -11,7 +12,6 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.locks.ReentrantReadWriteLock; import org.bukkit.Server; -import org.bukkit.command.CommandSender; //TODO: Remove op and replace with perm public class Commandbalancetop extends EssentialsCommand @@ -27,7 +27,7 @@ public class Commandbalancetop extends EssentialsCommand private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { int page = 0; boolean force = false; @@ -39,7 +39,7 @@ public class Commandbalancetop extends EssentialsCommand } catch (NumberFormatException ex) { - if (args[0].equalsIgnoreCase("force") && sender.isOp()) + if (args[0].equalsIgnoreCase("force") && sender.getSender().isOp()) { force = true; } @@ -77,7 +77,7 @@ public class Commandbalancetop extends EssentialsCommand } - private static void outputCache(final CommandSender sender, int page) + private static void outputCache(final CommandSource sender, int page) { final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(cacheage); @@ -163,11 +163,11 @@ public class Commandbalancetop extends EssentialsCommand private class Viewer implements Runnable { - private final transient CommandSender sender; + private final transient CommandSource sender; private final transient int page; private final transient boolean force; - public Viewer(final CommandSender sender, final int page, final boolean force) + public Viewer(final CommandSource sender, final int page, final boolean force) { this.sender = sender; this.page = page; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index 0cf353094..6d0efced5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; @@ -7,7 +8,6 @@ import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import java.util.logging.Level; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -19,7 +19,7 @@ public class Commandban extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { boolean nomatch = false; if (args.length < 1) @@ -38,8 +38,7 @@ public class Commandban extends EssentialsCommand } if (!user.isOnline()) { - if (sender instanceof Player - && !ess.getUser(sender).isAuthorized("essentials.ban.offline")) + if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.ban.offline")) { throw new Exception(_("banExempt")); } @@ -52,7 +51,7 @@ public class Commandban extends EssentialsCommand } } - final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; + final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; String banReason; if (args.length > 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java index e8ac16bdb..9246f89ad 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java @@ -1,13 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import java.util.logging.Level; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandbanip extends EssentialsCommand @@ -18,14 +17,14 @@ public class Commandbanip extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; + final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; String ipAddress; if (FormatUtil.validIP(args[0])) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java index c68ed5000..a97ed54c9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandbroadcast extends EssentialsCommand @@ -21,9 +21,9 @@ public class Commandbroadcast extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { - sendBroadcast(sender.getName(), args); + sendBroadcast(sender.getSender().getName(), args); } private void sendBroadcast(final String name, final String[] args) throws NotEnoughArgumentsException diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandburn.java b/Essentials/src/com/earth2me/essentials/commands/Commandburn.java index dad96dee7..019768750 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandburn.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandburn.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandburn extends EssentialsCommand @@ -14,7 +14,7 @@ public class Commandburn extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index 1d4d82dcf..140831bb4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.NumberUtil; @@ -8,7 +9,6 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -25,23 +25,23 @@ public class Commandclearinventory extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - parseCommand(server, user.getBase(), args, user.isAuthorized("essentials.clearinventory.others"), user.isAuthorized("essentials.clearinventory.all")); + parseCommand(server, user.getSource(), args, user.isAuthorized("essentials.clearinventory.others"), user.isAuthorized("essentials.clearinventory.all")); } @Override - protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + protected void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { parseCommand(server, sender, args, true, true); } - private void parseCommand(Server server, CommandSender sender, String[] args, boolean allowOthers, boolean allowAll) throws Exception + private void parseCommand(Server server, CommandSource sender, String[] args, boolean allowOthers, boolean allowAll) throws Exception { List players = new ArrayList(); int offset = 0; - if (sender instanceof Player) + if (sender.isPlayer()) { - players.add((Player)sender); + players.add(sender.getPlayer()); } if (allowAll && args.length > 0 && args[0].contentEquals("*")) @@ -66,7 +66,7 @@ public class Commandclearinventory extends EssentialsCommand } } - protected void clearHandler(CommandSender sender, Player player, String[] args, int offset, boolean showExtended) throws Exception + protected void clearHandler(CommandSource sender, Player player, String[] args, int offset, boolean showExtended) throws Exception { short data = -1; int type = -1; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandcustomtext.java b/Essentials/src/com/earth2me/essentials/commands/Commandcustomtext.java index 4d56fa705..6c2601823 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandcustomtext.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandcustomtext.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.TextInput; import com.earth2me.essentials.textreader.TextPager; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandcustomtext extends EssentialsCommand @@ -16,7 +16,7 @@ public class Commandcustomtext extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { final IText input = new TextInput(sender, "custom", true, ess); final IText output = new KeywordReplacer(input, sender, ess); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java index 3faf1c80a..555bcd4a2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import java.util.Locale; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commanddelhome extends EssentialsCommand @@ -15,14 +15,14 @@ public class Commanddelhome extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - User user = ess.getUser(sender); + User user = ess.getUser(sender.getPlayer()); String name; String[] expandedArg; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java index e224cbe7b..17e0411ad 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commanddeljail extends EssentialsCommand @@ -13,7 +13,7 @@ public class Commanddeljail extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java index 7a053b449..754f62118 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commanddelwarp extends EssentialsCommand @@ -13,7 +13,7 @@ public class Commanddelwarp extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java index f66004d17..37f94e5b6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java @@ -1,13 +1,13 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.ChargeException; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.NumberUtil; import java.math.BigDecimal; import java.util.Locale; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandeco extends EssentialsLoopCommand @@ -21,7 +21,7 @@ public class Commandeco extends EssentialsLoopCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -56,7 +56,7 @@ public class Commandeco extends EssentialsLoopCommand } @Override - protected void updatePlayer(final Server server, final CommandSender sender, final User player, final String[] args) throws NotEnoughArgumentsException, ChargeException + protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws NotEnoughArgumentsException, ChargeException { switch (cmd) { @@ -75,7 +75,7 @@ public class Commandeco extends EssentialsLoopCommand } } - private void take(BigDecimal amount, final User player, final CommandSender sender) throws ChargeException + private void take(BigDecimal amount, final User player, final CommandSource sender) throws ChargeException { BigDecimal money = player.getMoney(); BigDecimal minBalance = ess.getSettings().getMinMoney(); @@ -94,7 +94,7 @@ public class Commandeco extends EssentialsLoopCommand } } - private void set(BigDecimal amount, final User player, final CommandSender sender) + private void set(BigDecimal amount, final User player, final CommandSource sender) { BigDecimal minBalance = ess.getSettings().getMinMoney(); boolean underMinimum = (amount.compareTo(minBalance) < 0); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java index 88d76e573..d26833041 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java @@ -63,7 +63,7 @@ public class Commandenchant extends EssentialsCommand final MetaItemStack metaStack = new MetaItemStack(stack); final Enchantment enchantment = metaStack.getEnchantment(user, args[0]); - metaStack.addEnchantment(user.getBase(), allowUnsafe, enchantment, level); + metaStack.addEnchantment(user.getSource(), allowUnsafe, enchantment, level); user.getInventory().setItemInHand(metaStack.getItemStack()); user.updateInventory(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index f4655212f..50dc8ad1e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.UserMap; @@ -13,8 +14,6 @@ import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.Sound; import org.bukkit.block.Block; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; // This command has 4 undocumented behaviours #EasterEgg @@ -28,7 +27,7 @@ public class Commandessentials extends EssentialsCommand private final transient Map noteBlocks = new HashMap(); @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length == 0) { @@ -65,7 +64,7 @@ public class Commandessentials extends EssentialsCommand } //If you do not supply an argument this command will list 'overridden' commands. - private void run_disabled(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + private void run_disabled(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { sender.sendMessage("/ "); @@ -85,7 +84,7 @@ public class Commandessentials extends EssentialsCommand } } - private void run_reset(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + private void run_reset(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -96,19 +95,19 @@ public class Commandessentials extends EssentialsCommand sender.sendMessage("Reset Essentials userdata for player: " + user.getDisplayName()); } - private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + private void run_debug(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { ess.getSettings().setDebug(!ess.getSettings().isDebug()); sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled")); } - private void run_reload(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + private void run_reload(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { ess.reload(); sender.sendMessage(_("essentialsReload", ess.getDescription().getVersion())); } - private void run_nya(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + private void run_nya(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { final Map noteMap = new HashMap(); noteMap.put("1F#", 0.5f); @@ -174,36 +173,36 @@ public class Commandessentials extends EssentialsCommand } noteBlocks.clear(); } - - - private final String[] consoleMoo = new String[] { - " (__)", - " (oo)", - " /------\\/", - " / | ||", - " * /\\---/\\", - " ~~ ~~", - "....\"Have you mooed today?\"..." - }; - - private final String[] playerMoo = new String[] { - " (__)", - " (oo)", - " /------\\/", - " / | | |", - " * /\\---/\\", - " ~~ ~~", - "....\"Have you mooed today?\"..." - }; - private void run_moo(final Server server, final CommandSender sender, final String command, final String args[]) + private final String[] consoleMoo = new String[] { - if(args.length == 2 && args[1].equals("moo")) + " (__)", + " (oo)", + " /------\\/", + " / | ||", + " * /\\---/\\", + " ~~ ~~", + "....\"Have you mooed today?\"..." + }; + private final String[] playerMoo = new String[] + { + " (__)", + " (oo)", + " /------\\/", + " / | | |", + " * /\\---/\\", + " ~~ ~~", + "....\"Have you mooed today?\"..." + }; + + private void run_moo(final Server server, final CommandSource sender, final String command, final String args[]) + { + if (args.length == 2 && args[1].equals("moo")) { - for(String s : consoleMoo) + for (String s : consoleMoo) { logger.info(s); } - for(Player player : ess.getServer().getOnlinePlayers()) + for (Player player : ess.getServer().getOnlinePlayers()) { player.sendMessage(playerMoo); player.playSound(player.getLocation(), Sound.COW_IDLE, 1, 1.0f); @@ -211,20 +210,21 @@ public class Commandessentials extends EssentialsCommand } else { - if (sender instanceof ConsoleCommandSender) + if (sender.isPlayer()) { - sender.sendMessage(consoleMoo); + sender.getSender().sendMessage(playerMoo); + final Player player = (Player)sender; + player.playSound(player.getLocation(), Sound.COW_IDLE, 1, 1.0f); + } else { - sender.sendMessage(playerMoo); - final Player player = (Player)sender; - player.playSound(player.getLocation(), Sound.COW_IDLE, 1, 1.0f); + sender.getSender().sendMessage(consoleMoo); } } } - private void run_optout(final Server server, final CommandSender sender, final String command, final String args[]) + private void run_optout(final Server server, final CommandSource sender, final String command, final String args[]) { final Metrics metrics = ess.getMetrics(); try @@ -246,7 +246,7 @@ public class Commandessentials extends EssentialsCommand } } - private void run_cleanup(final Server server, final CommandSender sender, final String command, final String args[]) throws Exception + private void run_cleanup(final Server server, final CommandSource sender, final String command, final String args[]) throws Exception { if (args.length < 2 || !NumberUtil.isInt(args[1])) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java index 09c325481..2f301fb34 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.craftbukkit.SetExpFix; @@ -7,7 +8,6 @@ import com.earth2me.essentials.utils.NumberUtil; import java.util.List; import java.util.Locale; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -23,28 +23,28 @@ public class Commandexp extends EssentialsCommand { if (args.length == 0) { - showExp(user.getBase(), user); + showExp(user.getSource(), user); } else if (args.length > 1 && args[0].equalsIgnoreCase("set") && user.isAuthorized("essentials.exp.set")) { if (args.length == 3 && user.isAuthorized("essentials.exp.set.others")) { - expMatch(server, user.getBase(), args[1], args[2], false); + expMatch(server, user.getSource(), args[1], args[2], false); } else { - setExp(user.getBase(), user, args[1], false); + setExp(user.getSource(), user, args[1], false); } } else if (args.length > 1 && args[0].equalsIgnoreCase("give") && user.isAuthorized("essentials.exp.give")) { if (args.length == 3 && user.isAuthorized("essentials.exp.give.others")) { - expMatch(server, user.getBase(), args[1], args[2], true); + expMatch(server, user.getSource(), args[1], args[2], true); } else { - setExp(user.getBase(), user, args[1], true); + setExp(user.getSource(), user, args[1], true); } } else if (args[0].equalsIgnoreCase("show")) @@ -52,11 +52,11 @@ public class Commandexp extends EssentialsCommand if (args.length >= 2 && user.isAuthorized("essentials.exp.others")) { String match = args[1].trim(); - showMatch(server, user.getBase(), match); + showMatch(server, user.getSource(), match); } else { - showExp(user.getBase(), user); + showExp(user.getSource(), user); } } else @@ -65,27 +65,27 @@ public class Commandexp extends EssentialsCommand { if (args.length >= 2 && user.isAuthorized("essentials.exp.give.others")) { - expMatch(server, user.getBase(), args[1], args[0], true); + expMatch(server, user.getSource(), args[1], args[0], true); } else { - setExp(user.getBase(), user, args[0], true); + setExp(user.getSource(), user, args[0], true); } } else if (args.length >= 1 && user.isAuthorized("essentials.exp.others")) { String match = args[0].trim(); - showMatch(server, user.getBase(), match); + showMatch(server, user.getSource(), match); } else { - showExp(user.getBase(), user); + showExp(user.getSource(), user); } } } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -115,9 +115,9 @@ public class Commandexp extends EssentialsCommand } } - private void showMatch(final Server server, final CommandSender sender, final String match) throws PlayerNotFoundException + private void showMatch(final Server server, final CommandSource sender, final String match) throws PlayerNotFoundException { - boolean skipHidden = sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.vanish.interact"); + boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact"); boolean foundUser = false; final List matchedPlayers = server.matchPlayer(match); for (Player matchPlayer : matchedPlayers) @@ -136,9 +136,9 @@ public class Commandexp extends EssentialsCommand } } - private void expMatch(final Server server, final CommandSender sender, final String match, String amount, final boolean give) throws NotEnoughArgumentsException, PlayerNotFoundException + private void expMatch(final Server server, final CommandSource sender, final String match, String amount, final boolean give) throws NotEnoughArgumentsException, PlayerNotFoundException { - boolean skipHidden = sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.vanish.interact"); + boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact"); boolean foundUser = false; final List matchedPlayers = server.matchPlayer(match); for (Player matchPlayer : matchedPlayers) @@ -157,13 +157,13 @@ public class Commandexp extends EssentialsCommand } } - private void showExp(final CommandSender sender, final User target) + private void showExp(final CommandSource sender, final User target) { sender.sendMessage(_("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target.getBase()), target.getLevel(), SetExpFix.getExpUntilNextLevel(target.getBase()))); } //TODO: Limit who can give negative exp? - private void setExp(final CommandSender sender, final User target, String strAmount, final boolean give) throws NotEnoughArgumentsException + private void setExp(final CommandSource sender, final User target, String strAmount, final boolean give) throws NotEnoughArgumentsException { long amount; strAmount = strAmount.toLowerCase(Locale.ENGLISH); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandext.java b/Essentials/src/com/earth2me/essentials/commands/Commandext.java index 338a214cf..23ab6ac40 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandext.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandext.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,7 +15,7 @@ public class Commandext extends EssentialsLoopCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -35,11 +35,11 @@ public class Commandext extends EssentialsLoopCommand return; } - loopOnlinePlayers(server, user.getBase(), true, args[0], null); + loopOnlinePlayers(server, user.getSource(), true, args[0], null); } @Override - protected void updatePlayer(final Server server, final CommandSender sender, final User player, final String[] args) + protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) { extPlayer(player.getBase()); sender.sendMessage(_("extinguishOthers", player.getDisplayName())); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java index 7460d2238..f2df07f3c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.entity.FoodLevelChangeEvent; @@ -25,7 +25,7 @@ public class Commandfeed extends EssentialsLoopCommand if (args.length > 0 && user.isAuthorized("essentials.feed.others")) { - loopOnlinePlayers(server, user.getBase(), true, args[0], null); + loopOnlinePlayers(server, user.getSource(), true, args[0], null); return; } @@ -34,7 +34,7 @@ public class Commandfeed extends EssentialsLoopCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -45,7 +45,7 @@ public class Commandfeed extends EssentialsLoopCommand } @Override - protected void updatePlayer(final Server server, final CommandSender sender, final User player, final String[] args) throws PlayerExemptException + protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws PlayerExemptException { try { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java b/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java index d01e5bf85..ecf0561e1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java @@ -113,7 +113,7 @@ public class Commandfirework extends EssentialsCommand { try { - mStack.addFireworkMeta(user.getBase(), true, arg, ess); + mStack.addFireworkMeta(user.getSource(), true, arg, ess); } catch (Exception e) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfly.java b/Essentials/src/com/earth2me/essentials/commands/Commandfly.java index 8036ba57c..8d38f08dd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfly.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfly.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandfly extends EssentialsToggleCommand @@ -14,7 +14,7 @@ public class Commandfly extends EssentialsToggleCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { toggleOtherPlayers(server, sender, args); } @@ -27,25 +27,25 @@ public class Commandfly extends EssentialsToggleCommand Boolean toggle = matchToggleArgument(args[0]); if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getBase(), args); + toggleOtherPlayers(server, user.getSource(), args); } else { - togglePlayer(user.getBase(), user, toggle); + togglePlayer(user.getSource(), user, toggle); } } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getBase(), args); + toggleOtherPlayers(server, user.getSource(), args); } else { - togglePlayer(user.getBase(), user, null); + togglePlayer(user.getSource(), user, null); } } @Override - void togglePlayer(CommandSender sender, User user, Boolean enabled) + void togglePlayer(CommandSource sender, User user, Boolean enabled) { if (enabled == null) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java index c96a6116f..c24a08a9c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import java.util.List; import java.util.Locale; import org.bukkit.GameMode; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -18,7 +18,7 @@ public class Commandgamemode extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { GameMode gameMode; if (args.length == 0) @@ -49,7 +49,7 @@ public class Commandgamemode extends EssentialsCommand else if (args.length > 1 && args[1].trim().length() > 2 && user.isAuthorized("essentials.gamemode.others")) { gameMode = matchGameMode(args[0].toLowerCase(Locale.ENGLISH)); - gamemodeOtherPlayers(server, user.getBase(), gameMode, args[1]); + gamemodeOtherPlayers(server, user.getSource(), gameMode, args[1]); return; } else @@ -63,7 +63,7 @@ public class Commandgamemode extends EssentialsCommand if (user.isAuthorized("essentials.gamemode.others")) { gameMode = matchGameMode(commandLabel); - gamemodeOtherPlayers(server, user.getBase(), gameMode, args[0]); + gamemodeOtherPlayers(server, user.getSource(), gameMode, args[0]); return; } throw new NotEnoughArgumentsException(); @@ -77,7 +77,7 @@ public class Commandgamemode extends EssentialsCommand user.sendMessage(_("gameMode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName())); } - private void gamemodeOtherPlayers(final Server server, final CommandSender sender, final GameMode gameMode, final String name) throws NotEnoughArgumentsException, PlayerNotFoundException + private void gamemodeOtherPlayers(final Server server, final CommandSource sender, final GameMode gameMode, final String name) throws NotEnoughArgumentsException, PlayerNotFoundException { //TODO: TL this if (name.trim().length() < 2 || gameMode == null) @@ -85,7 +85,7 @@ public class Commandgamemode extends EssentialsCommand throw new NotEnoughArgumentsException("You need to specify a valid player/mode."); } - boolean skipHidden = sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.vanish.interact"); + boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact"); boolean foundUser = false; final List matchedPlayers = server.matchPlayer(name); for (Player matchPlayer : matchedPlayers) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java index 9f15c18fd..0faf037e5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.NumberUtil; @@ -9,7 +10,6 @@ import org.bukkit.ChatColor; import org.bukkit.Chunk; import org.bukkit.Server; import org.bukkit.World; -import org.bukkit.command.CommandSender; public class Commandgc extends EssentialsCommand @@ -20,7 +20,7 @@ public class Commandgc extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { double tps = ess.getTimer().getAverageTPS(); ChatColor color; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java index 021d711a8..0a9959461 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Location; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandgetpos extends EssentialsCommand @@ -20,14 +20,14 @@ public class Commandgetpos extends EssentialsCommand if (args.length > 0 && user.isAuthorized("essentials.getpos.others")) { final User otherUser = getPlayer(server, user, args, 0); - outputPosition(user.getBase(), otherUser.getLocation(), user.getLocation()); + outputPosition(user.getSource(), otherUser.getLocation(), user.getLocation()); return; } - outputPosition(user.getBase(), user.getLocation(), null); + outputPosition(user.getSource(), user.getLocation(), null); } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -37,7 +37,7 @@ public class Commandgetpos extends EssentialsCommand outputPosition(sender, user.getLocation(), null); } - private void outputPosition(final CommandSender sender, final Location coords, final Location distance) + private void outputPosition(final CommandSource sender, final Location coords, final Location distance) { sender.sendMessage(_("currentWorld", coords.getWorld().getName())); sender.sendMessage(_("posX", coords.getBlockX())); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index ce0258108..54c5a0afb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.User; @@ -9,8 +10,6 @@ import java.util.Locale; import java.util.Map; import org.bukkit.Material; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -22,7 +21,7 @@ public class Commandgive extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -32,13 +31,13 @@ public class Commandgive extends EssentialsCommand ItemStack stack = ess.getItemDb().get(args[1]); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); - if (sender instanceof Player + if (sender.isPlayer() && (ess.getSettings().permissionBasedItemSpawn() - ? (!ess.getUser(sender).isAuthorized("essentials.itemspawn.item-all") - && !ess.getUser(sender).isAuthorized("essentials.itemspawn.item-" + itemname) - && !ess.getUser(sender).isAuthorized("essentials.itemspawn.item-" + stack.getTypeId())) - : (!ess.getUser(sender).isAuthorized("essentials.itemspawn.exempt") - && !ess.getUser(sender).canSpawnItem(stack.getTypeId())))) + ? (!ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.item-all") + && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.item-" + itemname) + && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.item-" + stack.getTypeId())) + : (!ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.exempt") + && !ess.getUser(sender.getPlayer()).canSpawnItem(stack.getTypeId())))) { throw new Exception(_("cantSpawnItem", itemname)); } @@ -74,7 +73,7 @@ public class Commandgive extends EssentialsCommand { MetaItemStack metaStack = new MetaItemStack(stack); boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments(); - if (allowUnsafe && sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.enchantments.allowunsafe")) + if (allowUnsafe && sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.enchantments.allowunsafe")) { allowUnsafe = false; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java index c1c561d6e..439584667 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java @@ -1,11 +1,10 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import net.ess3.api.events.GodStatusChangeEvent; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandgod extends EssentialsToggleCommand @@ -16,7 +15,7 @@ public class Commandgod extends EssentialsToggleCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { toggleOtherPlayers(server, sender, args); } @@ -29,32 +28,32 @@ public class Commandgod extends EssentialsToggleCommand Boolean toggle = matchToggleArgument(args[0]); if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getBase(), args); + toggleOtherPlayers(server, user.getSource(), args); } else { - togglePlayer(user.getBase(), user, toggle); + togglePlayer(user.getSource(), user, toggle); } } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getBase(), args); + toggleOtherPlayers(server, user.getSource(), args); } else { - togglePlayer(user.getBase(), user, null); + togglePlayer(user.getSource(), user, null); } } @Override - void togglePlayer(CommandSender sender, User user, Boolean enabled) + void togglePlayer(CommandSource sender, User user, Boolean enabled) { if (enabled == null) { enabled = !user.isGodModeEnabled(); } - final User controller = sender instanceof Player ? ess.getUser(sender) : null; + final User controller = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null; final GodStatusChangeEvent godEvent = new GodStatusChangeEvent(controller, user, enabled); ess.getServer().getPluginManager().callEvent(godEvent); if (!godEvent.isCancelled()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java index b579ba16a..fb4477331 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; @@ -27,7 +27,7 @@ public class Commandheal extends EssentialsLoopCommand if (args.length > 0 && user.isAuthorized("essentials.heal.others")) { - loopOnlinePlayers(server, user.getBase(), true, args[0], null); + loopOnlinePlayers(server, user.getSource(), true, args[0], null); return; } @@ -35,7 +35,7 @@ public class Commandheal extends EssentialsLoopCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -46,7 +46,7 @@ public class Commandheal extends EssentialsLoopCommand } @Override - protected void updatePlayer(final Server server, final CommandSender sender, final User player, final String[] args) throws PlayerExemptException + protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws PlayerExemptException { try { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java index 36b93e82b..03cd37374 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.textreader.*; import com.earth2me.essentials.utils.NumberUtil; import java.util.Locale; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandhelp extends EssentialsCommand @@ -23,7 +23,7 @@ public class Commandhelp extends EssentialsCommand String pageStr = args.length > 0 ? args[0] : null; String chapterPageStr = args.length > 1 ? args[1] : null; String command = commandLabel; - final IText input = new TextInput(user.getBase(), "help", false, ess); + final IText input = new TextInput(user.getSource(), "help", false, ess); if (input.getLines().isEmpty()) { @@ -45,14 +45,14 @@ public class Commandhelp extends EssentialsCommand } else { - output = new KeywordReplacer(input, user.getBase(), ess); + output = new KeywordReplacer(input, user.getSource(), ess); } final TextPager pager = new TextPager(output); - pager.showPage(pageStr, chapterPageStr, command, user.getBase()); + pager.showPage(pageStr, chapterPageStr, command, user.getSource()); } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { sender.sendMessage(_("helpConsole")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java index d1dec09a0..7f4647de5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; @@ -20,16 +21,16 @@ public class Commandhelpop extends EssentialsCommand public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { user.setDisplayNick(); - sendMessage(server, user.getBase(), user.getDisplayName(), args); + sendMessage(server, user.getSource(), user.getDisplayName(), args); } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { sendMessage(server, sender, Console.NAME, args); } - private void sendMessage(final Server server, final CommandSender sender, final String from, final String[] args) throws Exception + private void sendMessage(final Server server, final CommandSource sender, final String from, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java index afe1add72..a8b10cf36 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.TextInput; import com.earth2me.essentials.textreader.TextPager; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandinfo extends EssentialsCommand @@ -16,7 +16,7 @@ public class Commandinfo extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { final IText input = new TextInput(sender, "info", true, ess); final IText output = new KeywordReplacer(input, sender, ess); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index 869028af4..09715dff1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -60,7 +60,7 @@ public class Commanditem extends EssentialsCommand MetaItemStack metaStack = new MetaItemStack(stack); final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchantments.allowunsafe"); - metaStack.parseStringMeta(user.getBase(), allowUnsafe, args, 2, ess); + metaStack.parseStringMeta(user.getSource(), allowUnsafe, args, 2, ess); stack = metaStack.getItemStack(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java b/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java index 11d633286..e0b87dca5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import org.bukkit.Material; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -16,13 +16,13 @@ public class Commanditemdb extends EssentialsCommand } @Override - protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + protected void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { ItemStack itemStack = null; boolean itemHeld = false; if (args.length < 1) { - if (sender instanceof Player) + if (sender.isPlayer()) { itemHeld = true; itemStack = ((Player)sender).getItemInHand(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java index b7eccdba3..5fe61032d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.utils.StringUtil; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandjails extends EssentialsCommand @@ -13,7 +13,7 @@ public class Commandjails extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { sender.sendMessage("§7" + StringUtil.joinList(" ", ess.getJails().getList())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index 3825d7865..316b50300 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -1,13 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import java.util.logging.Level; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandkick extends EssentialsCommand @@ -18,7 +17,7 @@ public class Commandkick extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -26,9 +25,9 @@ public class Commandkick extends EssentialsCommand } final User target = getPlayer(server, args, 0, true, false); - if (sender instanceof Player) + if (sender.isPlayer()) { - User user = ess.getUser(sender); + User user = ess.getUser(sender.getPlayer()); if (target.isHidden() && !user.isAuthorized("essentials.vanish.interact")) { throw new PlayerNotFoundException(); @@ -44,7 +43,7 @@ public class Commandkick extends EssentialsCommand kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); target.kickPlayer(kickReason); - final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; + final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; server.getLogger().log(Level.INFO, _("playerKicked", senderName, target.getName(), kickReason)); ess.broadcastMessage("essentials.kick.notify", _("playerKicked", senderName, target.getName(), kickReason)); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java index e8453d90b..f789cfe32 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,14 +15,14 @@ public class Commandkickall extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { String kickReason = args.length > 0 ? getFinalArg(args, 0) : _("kickDefault"); kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); for (Player onlinePlayer : server.getOnlinePlayers()) { - if (sender instanceof Player && onlinePlayer.getName().equalsIgnoreCase(((Player)sender).getName())) + if (sender.isPlayer() && onlinePlayer.getName().equalsIgnoreCase(((Player)sender).getName())) { continue; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkill.java b/Essentials/src/com/earth2me/essentials/commands/Commandkill.java index 0bbb3562e..36698f0b2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkill.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkill.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; @@ -16,7 +16,7 @@ public class Commandkill extends EssentialsLoopCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -27,16 +27,16 @@ public class Commandkill extends EssentialsLoopCommand } @Override - protected void updatePlayer(final Server server, final CommandSender sender, final User user, final String[] args) throws PlayerExemptException + protected void updatePlayer(final Server server, final CommandSource sender, final User user, final String[] args) throws PlayerExemptException { final Player matchPlayer = user.getBase(); - if (sender instanceof Player && user.isAuthorized("essentials.kill.exempt") && !ess.getUser(sender).isAuthorized("essentials.kill.force")) + if (sender.isPlayer() && user.isAuthorized("essentials.kill.exempt") && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) { throw new PlayerExemptException(_("killExempt", matchPlayer.getDisplayName())); } final EntityDamageEvent ede = new EntityDamageEvent(matchPlayer, sender instanceof Player && ((Player)sender).getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Short.MAX_VALUE); server.getPluginManager().callEvent(ede); - if (ede.isCancelled() && sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.kill.force")) + if (ede.isCancelled() && sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) { return; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java index 014d4d4e9..1ce8aecc0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Mob; import java.util.ArrayList; @@ -7,7 +8,6 @@ import java.util.Locale; import org.bukkit.Chunk; import org.bukkit.Server; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.*; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; @@ -22,12 +22,12 @@ public class Commandkillall extends EssentialsCommand //TODO: Tidy - missed this during command cleanup @Override - public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + public void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { String type = "all"; int radius = -1; World world; - if (sender instanceof Player) + if (sender.isPlayer()) { world = ((Player)sender).getWorld(); if (args.length == 1) @@ -96,7 +96,7 @@ public class Commandkillall extends EssentialsCommand { for (Entity entity : chunk.getEntities()) { - if (sender instanceof Player) + if (sender.isPlayer()) { if (radius >= 0 && ((Player)sender).getLocation().distanceSquared(entity.getLocation()) > radius) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index ccc58c224..a7fc4e2e5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Kit; import com.earth2me.essentials.Trade; @@ -9,7 +10,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandkit extends EssentialsCommand @@ -42,7 +42,7 @@ public class Commandkit extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java index 12381a330..254058eb2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.LightningStrike; import org.bukkit.entity.Player; @@ -18,10 +18,10 @@ public class Commandlightning extends EssentialsLoopCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { User user = null; - if (sender instanceof Player) + if (sender.isPlayer()) { user = ess.getUser(((Player)sender)); if ((args.length < 1 || user != null && !user.isAuthorized("essentials.lightning.others"))) @@ -45,7 +45,7 @@ public class Commandlightning extends EssentialsLoopCommand } @Override - protected void updatePlayer(final Server server, final CommandSender sender, final User matchUser, final String[] args) + protected void updatePlayer(final Server server, final CommandSource sender, final User matchUser, final String[] args) { sender.sendMessage(_("lightningUse", matchUser.getDisplayName())); final LightningStrike strike = matchUser.getBase().getWorld().strikeLightningEffect(matchUser.getBase().getLocation()); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index ef7911d12..c9bc864cf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.PlayerList; import com.earth2me.essentials.User; @@ -7,8 +8,6 @@ import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.NumberUtil; import java.util.*; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandlist extends EssentialsCommand @@ -19,12 +18,12 @@ public class Commandlist extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { boolean showHidden = true; - if (sender instanceof Player) + if (sender.isPlayer()) { - showHidden = ess.getUser(sender).isAuthorized("essentials.list.hidden") || ess.getUser(sender).isAuthorized("essentials.vanish.interact"); + showHidden = ess.getUser(sender.getPlayer()).isAuthorized("essentials.list.hidden") || ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact"); } sender.sendMessage(PlayerList.listSummary(ess, showHidden)); final Map> playerList = PlayerList.getPlayerLists(ess, showHidden); @@ -40,7 +39,7 @@ public class Commandlist extends EssentialsCommand } // Output the standard /list output, when no group is specified - private void sendGroupedList(CommandSender sender, String commandLabel, Map> playerList) + private void sendGroupedList(CommandSource sender, String commandLabel, Map> playerList) { final Set configGroups = ess.getSettings().getListGroupConfig().keySet(); final List asterisk = new ArrayList(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index 70310cf2a..cb7ba174f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.StringUtil; import java.util.List; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandmail extends EssentialsCommand @@ -97,7 +97,7 @@ public class Commandmail extends EssentialsCommand } @Override - protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + protected void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { if (args.length >= 1 && "read".equalsIgnoreCase(args[0])) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index fe552f598..382bbf06a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandme extends EssentialsCommand @@ -35,7 +35,7 @@ public class Commandme extends EssentialsCommand } @Override - public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + public void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java b/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java index 0031504e8..bbab26ab0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.TextInput; import com.earth2me.essentials.textreader.TextPager; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandmotd extends EssentialsCommand @@ -16,7 +16,7 @@ public class Commandmotd extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { final IText input = new TextInput(sender, "motd", true, ess); final IText output = new KeywordReplacer(input, sender, ess); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index 5749bb667..31156813b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IReplyTo; @@ -8,7 +9,6 @@ import static com.earth2me.essentials.commands.EssentialsCommand.getFinalArg; import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandmsg extends EssentialsLoopCommand @@ -21,7 +21,7 @@ public class Commandmsg extends EssentialsLoopCommand } @Override - public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + public void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { if (args.length < 2 || args[0].trim().length() < 2 || args[1].trim().isEmpty()) { @@ -29,9 +29,9 @@ public class Commandmsg extends EssentialsLoopCommand } String message = getFinalArg(args, 1); - if (sender instanceof Player) + if (sender.isPlayer()) { - User user = ess.getUser(sender); + User user = ess.getUser(sender.getPlayer()); if (user.isMuted()) { throw new Exception(_("voiceSilenced")); @@ -45,13 +45,13 @@ public class Commandmsg extends EssentialsLoopCommand if (args[0].equalsIgnoreCase(Console.NAME)) { - final IReplyTo replyTo = sender instanceof Player ? ess.getUser(sender) : Console.getConsoleReplyTo(); - final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; + final IReplyTo replyTo = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : Console.getConsoleReplyTo(); + final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; sender.sendMessage(_("msgFormat", translatedMe, Console.NAME, message)); CommandSender cs = Console.getCommandSender(server); cs.sendMessage(_("msgFormat", senderName, translatedMe, message)); - replyTo.setReplyTo(cs); + replyTo.setReplyTo(new CommandSource(cs)); Console.getConsoleReplyTo().setReplyTo(sender); return; } @@ -60,10 +60,10 @@ public class Commandmsg extends EssentialsLoopCommand } @Override - protected void updatePlayer(final Server server, final CommandSender sender, final User matchedUser, final String[] args) + protected void updatePlayer(final Server server, final CommandSource sender, final User matchedUser, final String[] args) { - final IReplyTo replyTo = sender instanceof Player ? ess.getUser(sender) : Console.getConsoleReplyTo(); - final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; + final IReplyTo replyTo = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : Console.getConsoleReplyTo(); + final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; if (matchedUser.isAfk()) { @@ -71,13 +71,13 @@ public class Commandmsg extends EssentialsLoopCommand } sender.sendMessage(_("msgFormat", translatedMe, matchedUser.getDisplayName(), args[0])); - if (sender instanceof Player && matchedUser.isIgnoredPlayer(ess.getUser(sender))) + if (sender.isPlayer() && matchedUser.isIgnoredPlayer(ess.getUser(sender.getPlayer()))) { return; } matchedUser.sendMessage(_("msgFormat", senderName, translatedMe, args[0])); - replyTo.setReplyTo(matchedUser.getBase()); + replyTo.setReplyTo(matchedUser.getSource()); matchedUser.setReplyTo(sender); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index 9ef7f5662..201768e8c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DateUtil; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -17,7 +17,7 @@ public class Commandmute extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { boolean nomatch = false; if (args.length < 1) @@ -36,8 +36,7 @@ public class Commandmute extends EssentialsCommand } if (!user.isOnline()) { - if (sender instanceof Player - && !ess.getUser(sender).isAuthorized("essentials.mute.offline")) + if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.mute.offline")) { throw new Exception(_("muteExempt")); } @@ -83,7 +82,7 @@ public class Commandmute extends EssentialsCommand sender.sendMessage(_("mutedPlayer", user.getDisplayName())); user.sendMessage(_("playerMuted")); } - ess.broadcastMessage("essentials.mute.notify", _("muteNotify", sender.getName(), user.getName(), muteTime)); + ess.broadcastMessage("essentials.mute.notify", _("muteNotify", sender.getSender().getName(), user.getName(), muteTime)); } else { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java index b79ee93f9..71205cdb8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -72,7 +72,7 @@ public class Commandnear extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length == 0) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index d6346e71c..0a5665b33 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import java.util.Locale; import net.ess3.api.events.NickChangeEvent; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -32,18 +32,18 @@ public class Commandnick extends EssentialsLoopCommand if (args.length > 1 && user.isAuthorized("essentials.nick.others")) { final String[] nickname = formatNickname(user, args[1]).split(" "); - loopOfflinePlayers(server, user.getBase(), false, args[0], nickname); + loopOfflinePlayers(server, user.getSource(), false, args[0], nickname); user.sendMessage(_("nickChanged")); } else { final String[] nickname = formatNickname(user, args[0]).split(" "); - updatePlayer(server, user.getBase(), user, nickname); + updatePlayer(server, user.getSource(), user, nickname); } } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -59,7 +59,7 @@ public class Commandnick extends EssentialsLoopCommand } @Override - protected void updatePlayer(final Server server, final CommandSender sender, final User target, final String[] args) throws NotEnoughArgumentsException + protected void updatePlayer(final Server server, final CommandSource sender, final User target, final String[] args) throws NotEnoughArgumentsException { final String nick = args[0]; if (target.getName().equalsIgnoreCase(nick)) @@ -123,9 +123,9 @@ public class Commandnick extends EssentialsLoopCommand return false; } - private void setNickname(final Server server, final CommandSender sender, final User target, final String nickname) + private void setNickname(final Server server, final CommandSource sender, final User target, final String nickname) { - final User controller = sender instanceof Player ? ess.getUser(sender) : null; + final User controller = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null; final NickChangeEvent nickEvent = new NickChangeEvent(controller, target, nickname); server.getPluginManager().callEvent(nickEvent); if (!nickEvent.isCancelled()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java b/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java index de365a89a..173e28b5c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import java.util.ArrayList; import java.util.Arrays; @@ -7,7 +8,6 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -20,7 +20,7 @@ public class Commandnuke extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws NoSuchFieldException, NotEnoughArgumentsException + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NoSuchFieldException, NotEnoughArgumentsException { List targets; if (args.length > 0) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java index c229d1a2b..c6826717b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.ChargeException; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import java.math.BigDecimal; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandpay extends EssentialsLoopCommand @@ -26,13 +26,13 @@ public class Commandpay extends EssentialsLoopCommand } amount = new BigDecimal(args[1].replaceAll("[^0-9\\.]", "")); - loopOnlinePlayers(server, user.getBase(), false, args[0], args); + loopOnlinePlayers(server, user.getSource(), false, args[0], args); } @Override - protected void updatePlayer(final Server server, final CommandSender sender, final User player, final String[] args) throws ChargeException + protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws ChargeException { - User user = ess.getUser(sender); + User user = ess.getUser(sender.getPlayer()); user.payUser(player, amount); Trade.log("Command", "Pay", "Player", user.getName(), new Trade(amount, ess), player.getName(), new Trade(amount, ess), user.getLocation(), ess); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandping.java b/Essentials/src/com/earth2me/essentials/commands/Commandping.java index 72b5beca0..0597ae6e5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandping.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandping.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; -import org.bukkit.command.CommandSender; // This command can be used to echo messages to the users screen, mostly useless but also an #EasterEgg public class Commandping extends EssentialsCommand @@ -14,7 +14,7 @@ public class Commandping extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpotion.java b/Essentials/src/com/earth2me/essentials/commands/Commandpotion.java index 52ab627ae..73a6157b9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpotion.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpotion.java @@ -69,7 +69,7 @@ public class Commandpotion extends EssentialsCommand final MetaItemStack mStack = new MetaItemStack(stack); for (String arg : args) { - mStack.addPotionMeta(user.getBase(), true, arg, ess); + mStack.addPotionMeta(user.getSource(), true, arg, ess); } if (mStack.completePotion()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index 33b69565f..582a8fe99 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.StringUtil; @@ -8,8 +9,6 @@ import java.util.List; import java.util.Locale; import org.bukkit.Material; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -25,11 +24,11 @@ public class Commandpowertool extends EssentialsCommand { final String command = getFinalArg(args, 0); final ItemStack itemStack = user.getItemInHand(); - powertool(server, user.getBase(), user, commandLabel, itemStack, command); + powertool(server, user.getSource(), user, commandLabel, itemStack, command); } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 3) //running from console means inserting a player and item before the standard syntax { @@ -42,7 +41,7 @@ public class Commandpowertool extends EssentialsCommand powertool(server, sender, user, commandLabel, itemStack, command); } - protected void powertool(final Server server, final CommandSender sender, final User user, final String commandLabel, final ItemStack itemStack, String command) throws Exception + protected void powertool(final Server server, final CommandSource sender, final User user, final String commandLabel, final ItemStack itemStack, String command) throws Exception { // check to see if this is a clear all command if (command != null && command.equalsIgnoreCase("d:")) @@ -88,7 +87,7 @@ public class Commandpowertool extends EssentialsCommand { if (command.startsWith("a:")) { - if (sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.powertool.append")) + if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.powertool.append")) { throw new Exception(_("noPerm", "essentials.powertool.append")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java index 8c0fd7dfa..050a012ad 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DescParseTickFormat; import java.util.*; import org.bukkit.Server; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -28,7 +28,7 @@ public class Commandptime extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { // Which Players(s) / Users(s) are we interested in? String userSelector = null; @@ -45,11 +45,14 @@ public class Commandptime extends EssentialsCommand return; } - User user = ess.getUser(sender); - if (user != null && (!users.contains(user) || users.size() > 1)&& !user.isAuthorized("essentials.ptime.others")) + if (sender.isPlayer()) { - user.sendMessage(_("pTimeOthersPermission")); - return; + User user = ess.getUser(sender.getPlayer()); + if (user != null && (!users.contains(user) || users.size() > 1) && !user.isAuthorized("essentials.ptime.others")) + { + user.sendMessage(_("pTimeOthersPermission")); + return; + } } Long ticks; @@ -89,7 +92,7 @@ public class Commandptime extends EssentialsCommand /** * Used to get the time and inform */ - private void getUsersTime(final CommandSender sender, final Collection users) + private void getUsersTime(final CommandSource sender, final Collection users) { if (users.size() > 1) { @@ -120,7 +123,7 @@ public class Commandptime extends EssentialsCommand /** * Used to set the time and inform of the change */ - private void setUsersTime(final CommandSender sender, final Collection users, final Long ticks, Boolean relative) + private void setUsersTime(final CommandSource sender, final Collection users, final Long ticks, Boolean relative) { // Update the time if (ticks == null) @@ -181,24 +184,24 @@ public class Commandptime extends EssentialsCommand /** * Used to parse an argument of the type "users(s) selector" */ - private Set getUsers(final Server server, final CommandSender sender, final String selector) throws Exception + private Set getUsers(final Server server, final CommandSource sender, final String selector) throws Exception { final Set users = new TreeSet(new UserNameComparator()); // If there is no selector we want the sender itself. Or all users if sender isn't a user. if (selector == null) { - final User user = ess.getUser(sender); - if (user == null) + if (sender.isPlayer()) + { + final User user = ess.getUser(sender.getPlayer()); + users.add(user); + } + else { for (Player player : server.getOnlinePlayers()) { users.add(ess.getUser(player)); } } - else - { - users.add(user); - } return users; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java index c410bcdfa..0c067b682 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import java.util.*; import org.bukkit.Server; import org.bukkit.WeatherType; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -32,7 +32,7 @@ public class Commandpweather extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { // Which Players(s) / Users(s) are we interested in? String userSelector = null; @@ -54,11 +54,14 @@ public class Commandpweather extends EssentialsCommand return; } - User user = ess.getUser(sender); - if (user != null && (!users.contains(user) || users.size() > 1) && !user.isAuthorized("essentials.pweather.others")) + if (sender.isPlayer()) { - user.sendMessage(_("pWeatherOthersPermission")); - return; + User user = ess.getUser(sender.getPlayer()); + if (user != null && (!users.contains(user) || users.size() > 1) && !user.isAuthorized("essentials.pweather.others")) + { + user.sendMessage(_("pWeatherOthersPermission")); + return; + } } setUsersWeather(sender, users, args[0].toLowerCase()); @@ -67,7 +70,7 @@ public class Commandpweather extends EssentialsCommand /** * Used to get the time and inform */ - private void getUsersWeather(final CommandSender sender, final Collection users) + private void getUsersWeather(final CommandSource sender, final Collection users) { if (users.size() > 1) { @@ -90,7 +93,7 @@ public class Commandpweather extends EssentialsCommand /** * Used to set the time and inform of the change */ - private void setUsersWeather(final CommandSender sender, final Collection users, final String weatherType) throws Exception + private void setUsersWeather(final CommandSource sender, final Collection users, final String weatherType) throws Exception { final StringBuilder msg = new StringBuilder(); @@ -131,24 +134,24 @@ public class Commandpweather extends EssentialsCommand /** * Used to parse an argument of the type "users(s) selector" */ - private Set getUsers(final Server server, final CommandSender sender, final String selector) throws Exception + private Set getUsers(final Server server, final CommandSource sender, final String selector) throws Exception { final Set users = new TreeSet(new UserNameComparator()); // If there is no selector we want the sender itself. Or all users if sender isn't a user. if (selector == null) { - final User user = ess.getUser(sender); - if (user == null) + if (sender.isPlayer()) + { + final User user = ess.getUser(sender.getPlayer()); + users.add(user); + } + else { for (Player player : server.getOnlinePlayers()) { users.add(ess.getUser(player)); } } - else - { - users.add(user); - } return users; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index a011540b1..82b74d7bd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IReplyTo; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -18,7 +18,7 @@ public class Commandr extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -29,9 +29,9 @@ public class Commandr extends EssentialsCommand IReplyTo replyTo; String senderName; - if (sender instanceof Player) + if (sender.isPlayer()) { - User user = ess.getUser(sender); + User user = ess.getUser(sender.getPlayer()); message = FormatUtil.formatMessage(user, "essentials.msg", message); replyTo = user; senderName = user.getDisplayName(); @@ -43,7 +43,7 @@ public class Commandr extends EssentialsCommand senderName = Console.NAME; } - final CommandSender target = replyTo.getReplyTo(); + final CommandSource target = replyTo.getReplyTo(); final String targetName = target instanceof Player ? ((Player)target).getDisplayName() : Console.NAME; if (target == null || ((target instanceof Player) && !((Player)target).isOnline())) @@ -52,10 +52,10 @@ public class Commandr extends EssentialsCommand } sender.sendMessage(_("msgFormat", _("me"), targetName, message)); - if (target instanceof Player) + if (target.isPlayer()) { - User player = ess.getUser(target); - if (sender instanceof Player && player.isIgnoredPlayer(ess.getUser(sender))) + User player = ess.getUser(target.getPlayer()); + if (sender.isPlayer() && player.isIgnoredPlayer(ess.getUser(sender.getPlayer()))) { return; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index cadc0e652..6a4f600cc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import java.util.Locale; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -17,14 +17,14 @@ public class Commandrealname extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } final String whois = args[0].toLowerCase(Locale.ENGLISH); - boolean skipHidden = sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.vanish.interact"); + boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact"); boolean foundUser = false; for (Player onlinePlayer : server.getOnlinePlayers()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java index 6661233ac..565067a5e 100755 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.NumberUtil; @@ -9,8 +10,6 @@ import java.util.Locale; import java.util.Map; import org.bukkit.Material; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.inventory.*; @@ -22,7 +21,7 @@ public class Commandrecipe extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -77,18 +76,18 @@ public class Commandrecipe extends EssentialsCommand } } - public void furnaceRecipe(final CommandSender sender, final FurnaceRecipe recipe) + public void furnaceRecipe(final CommandSource sender, final FurnaceRecipe recipe) { sender.sendMessage(_("recipeFurnace", getMaterialName(recipe.getInput()))); } - public void shapedRecipe(final CommandSender sender, final ShapedRecipe recipe) + public void shapedRecipe(final CommandSource sender, final ShapedRecipe recipe) { final Map recipeMap = recipe.getIngredientMap(); - if (sender instanceof Player) + if (sender.isPlayer()) { - final User user = ess.getUser(sender); + final User user = ess.getUser(sender.getPlayer()); user.closeInventory(); user.setRecipeSee(true); final InventoryView view = user.openWorkbench(null, true); @@ -142,12 +141,12 @@ public class Commandrecipe extends EssentialsCommand } } - public void shapelessRecipe(final CommandSender sender, final ShapelessRecipe recipe) + public void shapelessRecipe(final CommandSource sender, final ShapelessRecipe recipe) { final List ingredients = recipe.getIngredientList(); - if (sender instanceof Player) + if (sender.isPlayer()) { - final User user = ess.getUser(sender); + final User user = ess.getUser(sender.getPlayer()); user.setRecipeSee(true); final InventoryView view = user.openWorkbench(null, true); for (int i = 0; i < ingredients.size(); i++) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandremove.java b/Essentials/src/com/earth2me/essentials/commands/Commandremove.java index 1f1dfef77..f466f2b66 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandremove.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandremove.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import java.util.Locale; import org.bukkit.Chunk; import org.bukkit.Server; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.*; //Todo: Fix this up @@ -74,11 +74,11 @@ public class Commandremove extends EssentialsCommand } } - removeEntities(user.getBase(), world, toRemove, radius); + removeEntities(user.getSource(), world, toRemove, radius); } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -105,7 +105,7 @@ public class Commandremove extends EssentialsCommand removeEntities(sender, world, toRemove, 0); } - protected void removeEntities(final CommandSender sender, final World world, final ToRemove toRemove, int radius) throws Exception + protected void removeEntities(final CommandSource sender, final World world, final ToRemove toRemove, int radius) throws Exception { int removed = 0; if (radius > 0) @@ -173,7 +173,7 @@ public class Commandremove extends EssentialsCommand } else if (toRemove == ToRemove.ITEMFRAMES) { - if (e instanceof ItemFrame) + if (e instanceof ItemFrame) { e.remove(); removed++; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrules.java b/Essentials/src/com/earth2me/essentials/commands/Commandrules.java index d87c4f41b..2a3e7a464 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrules.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrules.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.TextInput; import com.earth2me.essentials.textreader.TextPager; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandrules extends EssentialsCommand @@ -16,7 +16,7 @@ public class Commandrules extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { final IText input = new TextInput(sender, "rules", true, ess); final IText output = new KeywordReplacer(input, sender, ess); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java index 6393b2e4e..c63671e1f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.UserMap; @@ -10,8 +11,6 @@ import java.util.ArrayList; import java.util.List; import org.bukkit.Location; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandseen extends EssentialsCommand @@ -22,7 +21,7 @@ public class Commandseen extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { seen(server, sender, args, true, true, true); } @@ -30,10 +29,10 @@ public class Commandseen extends EssentialsCommand @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - seen(server, user.getBase(), args, user.isAuthorized("essentials.seen.banreason"), user.isAuthorized("essentials.seen.extra"), user.isAuthorized("essentials.seen.ipsearch")); + seen(server, user.getSource(), args, user.isAuthorized("essentials.seen.banreason"), user.isAuthorized("essentials.seen.extra"), user.isAuthorized("essentials.seen.ipsearch")); } - protected void seen(final Server server, final CommandSender sender, final String[] args, final boolean showBan, final boolean extra, final boolean ipLookup) throws Exception + protected void seen(final Server server, final CommandSource sender, final String[] args, final boolean showBan, final boolean extra, final boolean ipLookup) throws Exception { if (args.length < 1) { @@ -67,7 +66,7 @@ public class Commandseen extends EssentialsCommand } } - private void seenOnline(final Server server, final CommandSender sender, final User user, final boolean showBan, final boolean extra) throws Exception + private void seenOnline(final Server server, final CommandSource sender, final User user, final boolean showBan, final boolean extra) throws Exception { user.setDisplayNick(); @@ -89,7 +88,7 @@ public class Commandseen extends EssentialsCommand : _("true")))); } final String location = user.getGeoLocation(); - if (location != null && (!(sender instanceof Player) || ess.getUser(sender).isAuthorized("essentials.geoip.show"))) + if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) { sender.sendMessage(_("whoisGeoLocation", location)); } @@ -99,7 +98,7 @@ public class Commandseen extends EssentialsCommand } } - private void seenOffline(final Server server, final CommandSender sender, User user, final boolean showBan, final boolean extra) throws Exception + private void seenOffline(final Server server, final CommandSource sender, User user, final boolean showBan, final boolean extra) throws Exception { user.setDisplayNick(); if (user.getLastLogout() > 0) @@ -115,7 +114,7 @@ public class Commandseen extends EssentialsCommand sender.sendMessage(_("whoisBanned", showBan ? user.getBanReason() : _("true"))); } final String location = user.getGeoLocation(); - if (location != null && (!(sender instanceof Player) || ess.getUser(sender).isAuthorized("essentials.geoip.show"))) + if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) { sender.sendMessage(_("whoisGeoLocation", location)); } @@ -133,7 +132,7 @@ public class Commandseen extends EssentialsCommand } } - private void seenIP(final Server server, final CommandSender sender, final String ipAddress) throws Exception + private void seenIP(final Server server, final CommandSource sender, final String ipAddress) throws Exception { final UserMap userMap = ess.getUserMap(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java index 91a1dd657..ecc11cd52 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.inventory.ItemStack; @@ -41,7 +41,7 @@ public class Commandsetworth extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java index 54344124a..e288a5cb0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandsocialspy extends EssentialsToggleCommand @@ -14,7 +14,7 @@ public class Commandsocialspy extends EssentialsToggleCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { toggleOtherPlayers(server, sender, args); } @@ -27,25 +27,25 @@ public class Commandsocialspy extends EssentialsToggleCommand Boolean toggle = matchToggleArgument(args[0]); if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getBase(), args); + toggleOtherPlayers(server, user.getSource(), args); } else { - togglePlayer(user.getBase(), user, toggle); + togglePlayer(user.getSource(), user, toggle); } } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getBase(), args); + toggleOtherPlayers(server, user.getSource(), args); } else { - togglePlayer(user.getBase(), user, null); + togglePlayer(user.getSource(), user, null); } } @Override - void togglePlayer(CommandSender sender, User user, Boolean enabled) throws NotEnoughArgumentsException + void togglePlayer(CommandSource sender, User user, Boolean enabled) throws NotEnoughArgumentsException { if (enabled == null) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index 3722d6412..4c37e35bb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Mob; import com.earth2me.essentials.SpawnMob; @@ -7,7 +8,6 @@ import com.earth2me.essentials.User; import com.earth2me.essentials.utils.StringUtil; import java.util.List; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandspawnmob extends EssentialsCommand @@ -43,7 +43,7 @@ public class Commandspawnmob extends EssentialsCommand if (args.length >= 3) { final User target = getPlayer(ess.getServer(), user, args, 2); - SpawnMob.spawnmob(ess, server, user.getBase(), target, mobParts, mobData, mobCount); + SpawnMob.spawnmob(ess, server, user.getSource(), target, mobParts, mobData, mobCount); return; } @@ -51,7 +51,7 @@ public class Commandspawnmob extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 3) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java index f4bc6e597..ce361e786 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import java.util.List; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,7 +16,7 @@ public class Commandspeed extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -53,7 +53,7 @@ public class Commandspeed extends EssentialsCommand { throw new PlayerNotFoundException(); } - speedOtherPlayers(server, user.getBase(), isFly, isBypass, speed, args[2]); + speedOtherPlayers(server, user.getSource(), isFly, isBypass, speed, args[2]); return; } } @@ -70,9 +70,9 @@ public class Commandspeed extends EssentialsCommand } } - private void speedOtherPlayers(final Server server, final CommandSender sender, final boolean isFly, final boolean isBypass, final float speed, final String name) throws PlayerNotFoundException + private void speedOtherPlayers(final Server server, final CommandSource sender, final boolean isFly, final boolean isBypass, final float speed, final String name) throws PlayerNotFoundException { - boolean skipHidden = sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.vanish.interact"); + boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact"); boolean foundUser = false; final List matchedPlayers = server.matchPlayer(name); for (Player matchPlayer : matchedPlayers) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java b/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java index 7067eef4a..61e31c1a3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; @@ -20,7 +20,7 @@ public class Commandsudo extends EssentialsCommand private static final Logger LOGGER = Logger.getLogger("Minecraft"); @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java index dc9bc67c0..f2d39929a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DateUtil; import java.util.GregorianCalendar; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -18,7 +18,7 @@ public class Commandtempban extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -27,8 +27,8 @@ public class Commandtempban extends EssentialsCommand final User user = getPlayer(server, args, 0, true, true); if (!user.isOnline()) { - if (sender instanceof Player - && !ess.getUser(sender).isAuthorized("essentials.tempban.offline")) + if (sender.isPlayer() + && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.tempban.offline")) { sender.sendMessage(_("tempbanExempt")); return; @@ -47,13 +47,13 @@ public class Commandtempban extends EssentialsCommand final long maxBanLength = ess.getSettings().getMaxTempban() * 1000; if (maxBanLength > 0 && ((banTimestamp - GregorianCalendar.getInstance().getTimeInMillis()) > maxBanLength) - && sender instanceof Player && !(ess.getUser(sender).isAuthorized("essentials.tempban.unlimited"))) + && sender.isPlayer() && !(ess.getUser(sender.getPlayer()).isAuthorized("essentials.tempban.unlimited"))) { sender.sendMessage(_("oversizedTempban")); throw new NoChargeException(); } - final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; + final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; final String banReason = _("tempBanned", DateUtil.formatDateDiff(banTimestamp), senderName); user.setBanReason(banReason); user.setBanTimeout(banTimestamp); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java index b0099ada5..e29be16f5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DescParseTickFormat; @@ -7,7 +8,6 @@ import com.earth2me.essentials.utils.NumberUtil; import java.util.*; import org.bukkit.Server; import org.bukkit.World; -import org.bukkit.command.CommandSender; public class Commandtime extends EssentialsCommand @@ -18,7 +18,7 @@ public class Commandtime extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { boolean add = false; final List argList = new ArrayList(Arrays.asList(args)); @@ -59,11 +59,12 @@ public class Commandtime extends EssentialsCommand return; } } - else { + else + { setTime = validArgs[0]; } - final User user = ess.getUser(sender); + final User user = ess.getUser(sender.getPlayer()); if (user != null && !user.isAuthorized("essentials.time.set")) { user.sendMessage(_("timeSetPermission")); @@ -87,7 +88,7 @@ public class Commandtime extends EssentialsCommand /** * Used to get the time and inform */ - private void getWorldsTime(final CommandSender sender, final Collection worlds) + private void getWorldsTime(final CommandSource sender, final Collection worlds) { if (worlds.size() == 1) { @@ -105,7 +106,7 @@ public class Commandtime extends EssentialsCommand /** * Used to set the time and inform of the change */ - private void setWorldsTime(final CommandSender sender, final Collection worlds, final long ticks, final boolean add) + private void setWorldsTime(final CommandSource sender, final Collection worlds, final long ticks, final boolean add) { // Update the time for (World world : worlds) @@ -135,21 +136,22 @@ public class Commandtime extends EssentialsCommand /** * Used to parse an argument of the type "world(s) selector" */ - private Set getWorlds(final Server server, final CommandSender sender, final String selector) throws Exception + private Set getWorlds(final Server server, final CommandSource sender, final String selector) throws Exception { final Set worlds = new TreeSet(new WorldNameComparator()); // If there is no selector we want the world the user is currently in. Or all worlds if it isn't a user. if (selector == null) { - final User user = ess.getUser(sender); - if (user == null) + if (sender.isPlayer()) { - worlds.addAll(server.getWorlds()); + + final User user = ess.getUser(sender.getPlayer()); + worlds.add(user.getWorld()); } else { - worlds.add(user.getWorld()); + worlds.addAll(server.getWorlds()); } return worlds; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java index 4aed22fd1..ba1f0f3a2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java @@ -1,11 +1,10 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DateUtil; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandtogglejail extends EssentialsCommand @@ -16,7 +15,7 @@ public class Commandtogglejail extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -29,8 +28,8 @@ public class Commandtogglejail extends EssentialsCommand { if (!player.isOnline()) { - if (sender instanceof Player - && !ess.getUser(sender).isAuthorized("essentials.togglejail.offline")) + if (sender.isPlayer() + && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.togglejail.offline")) { sender.sendMessage(_("mayNotJail")); return; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java index fc2c1302c..119e45f5d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import org.bukkit.Location; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -92,7 +92,7 @@ public class Commandtp extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java index 03672ddd5..689fdcc57 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,13 +15,13 @@ public class Commandtpaall extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { - if (sender instanceof Player) + if (sender.isPlayer()) { - teleportAAllPlayers(server, sender, ess.getUser(sender)); + teleportAAllPlayers(server, sender, ess.getUser(sender.getPlayer())); return; } throw new NotEnoughArgumentsException(); @@ -31,7 +31,7 @@ public class Commandtpaall extends EssentialsCommand teleportAAllPlayers(server, sender, target); } - private void teleportAAllPlayers(final Server server, final CommandSender sender, final User target) + private void teleportAAllPlayers(final Server server, final CommandSource sender, final User target) { sender.sendMessage(_("teleportAAll")); for (Player onlinePlayer : server.getOnlinePlayers()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java index 39fd58550..65930cca2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java @@ -69,7 +69,7 @@ public class Commandtpaccept extends EssentialsCommand catch (Exception ex) { user.sendMessage(_("pendingTeleportCancelled")); - ess.showError(requester.getBase(), ex, commandLabel); + ess.showError(requester.getSource(), ex, commandLabel); } user.requestTeleport(null, false); throw new NoChargeException(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java index 1b9ca7553..74a0136e7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -16,13 +16,13 @@ public class Commandtpall extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { - if (sender instanceof Player) + if (sender.isPlayer()) { - teleportAllPlayers(server, sender, ess.getUser(sender)); + teleportAllPlayers(server, sender, ess.getUser(sender.getPlayer())); return; } throw new NotEnoughArgumentsException(); @@ -32,7 +32,7 @@ public class Commandtpall extends EssentialsCommand teleportAllPlayers(server, sender, target); } - private void teleportAllPlayers(Server server, CommandSender sender, User target) + private void teleportAllPlayers(Server server, CommandSource sender, User target) { sender.sendMessage(_("teleportAll")); for (Player onlinePlayer : server.getOnlinePlayers()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java index b1a41fc4c..2b8ce49e3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import org.bukkit.Location; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -48,7 +48,7 @@ public class Commandtppos extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 4) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java index 7d8028353..442f53554 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandtptoggle extends EssentialsToggleCommand @@ -14,7 +14,7 @@ public class Commandtptoggle extends EssentialsToggleCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { toggleOtherPlayers(server, sender, args); } @@ -27,25 +27,25 @@ public class Commandtptoggle extends EssentialsToggleCommand Boolean toggle = matchToggleArgument(args[0]); if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getBase(), args); + toggleOtherPlayers(server, user.getSource(), args); } else { - togglePlayer(user.getBase(), user, toggle); + togglePlayer(user.getSource(), user, toggle); } } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getBase(), args); + toggleOtherPlayers(server, user.getSource(), args); } else { - togglePlayer(user.getBase(), user, null); + togglePlayer(user.getSource(), user, null); } } @Override - void togglePlayer(CommandSender sender, User user, Boolean enabled) + void togglePlayer(CommandSource sender, User user, Boolean enabled) { if (enabled == null) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java index 49ddd0b97..eeb60985d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java @@ -1,13 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import java.util.logging.Level; import org.bukkit.OfflinePlayer; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandunban extends EssentialsCommand @@ -18,7 +17,7 @@ public class Commandunban extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -43,7 +42,7 @@ public class Commandunban extends EssentialsCommand player.setBanned(false); } - final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; + final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; server.getLogger().log(Level.INFO, _("playerUnbanned", senderName, name)); ess.broadcastMessage("essentials.ban.notify", _("playerUnbanned", senderName, name)); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java index 8d6c5909d..c3de1b48e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java @@ -1,13 +1,12 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import java.util.logging.Level; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandunbanip extends EssentialsCommand @@ -18,7 +17,7 @@ public class Commandunbanip extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -49,7 +48,7 @@ public class Commandunbanip extends EssentialsCommand } ess.getServer().unbanIP(ipAddress); - final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; + final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; server.getLogger().log(Level.INFO, _("playerUnbanIpAddress", senderName, ipAddress)); ess.broadcastMessage("essentials.ban.notify", _("playerUnbanIpAddress", senderName, ipAddress)); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java b/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java index c44563325..588c17883 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Commandvanish extends EssentialsToggleCommand @@ -14,7 +14,7 @@ public class Commandvanish extends EssentialsToggleCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { toggleOtherPlayers(server, sender, args); } @@ -27,25 +27,25 @@ public class Commandvanish extends EssentialsToggleCommand Boolean toggle = matchToggleArgument(args[0]); if (toggle == null && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getBase(), args); + toggleOtherPlayers(server, user.getSource(), args); } else { - togglePlayer(user.getBase(), user, toggle); + togglePlayer(user.getSource(), user, toggle); } } else if (args.length == 2 && user.isAuthorized(othersPermission)) { - toggleOtherPlayers(server, user.getBase(), args); + toggleOtherPlayers(server, user.getSource(), args); } else { - togglePlayer(user.getBase(), user, null); + togglePlayer(user.getSource(), user, null); } } @Override - void togglePlayer(CommandSender sender, User user, Boolean enabled) throws NotEnoughArgumentsException + void togglePlayer(CommandSource sender, User user, Boolean enabled) throws NotEnoughArgumentsException { if (enabled == null) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index 430c36220..501aca36c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; @@ -13,7 +14,6 @@ import java.util.List; import java.util.Locale; import net.ess3.api.IUser; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -35,7 +35,7 @@ public class Commandwarp extends EssentialsCommand { throw new Exception(_("warpListPermission")); } - warpList(user.getBase(), args, user); + warpList(user.getSource(), args, user); throw new NoChargeException(); } if (args.length > 0) @@ -54,7 +54,7 @@ public class Commandwarp extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2 || NumberUtil.isInt(args[0])) { @@ -68,7 +68,7 @@ public class Commandwarp extends EssentialsCommand } //TODO: Use one of the new text classes, like /help ? - private void warpList(final CommandSender sender, final String[] args, final IUser user) throws Exception + private void warpList(final CommandSource sender, final String[] args, final IUser user) throws Exception { final IWarps warps = ess.getWarps(); if (warps.isEmpty()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java index dc9f767d5..e193a4913 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; import org.bukkit.World; -import org.bukkit.command.CommandSender; public class Commandweather extends EssentialsCommand @@ -60,7 +60,7 @@ public class Commandweather extends EssentialsCommand //TODO: Translate these @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) //running from console means inserting a world arg before other args { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index b89a4d7f7..4d4b5df7a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.craftbukkit.SetExpFix; @@ -7,8 +8,6 @@ import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.NumberUtil; import java.util.Locale; import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandwhois extends EssentialsCommand @@ -19,7 +18,7 @@ public class Commandwhois extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -42,7 +41,7 @@ public class Commandwhois extends EssentialsCommand sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString())); final String location = user.getGeoLocation(); if (location != null - && (sender instanceof Player ? ess.getUser(sender).isAuthorized("essentials.geoip.show") : true)) + && (sender.isPlayer() ? ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show") : true)) { sender.sendMessage(_("whoisGeoLocation", location)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java index fa2e106f7..eeea2d7e3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.NumberUtil; @@ -7,7 +8,6 @@ import java.math.BigDecimal; import java.util.List; import java.util.Locale; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.inventory.ItemStack; @@ -35,7 +35,7 @@ public class Commandworth extends EssentialsCommand { if (stack.getAmount() > 0) { - totalWorth = totalWorth.add(itemWorth(user.getBase(), user, stack, args)); + totalWorth = totalWorth.add(itemWorth(user.getSource(), user, stack, args)); stack = stack.clone(); count++; for (ItemStack zeroStack : is) @@ -70,7 +70,7 @@ public class Commandworth extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { String type = ""; if (args.length < 1) @@ -83,7 +83,7 @@ public class Commandworth extends EssentialsCommand itemWorth(sender, null, stack, args); } - private BigDecimal itemWorth(CommandSender sender, User user, ItemStack is, String[] args) throws Exception + private BigDecimal itemWorth(CommandSource sender, User user, ItemStack is, String[] args) throws Exception { int amount = 1; if (user == null) diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index b3005d869..ccb348a57 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -9,7 +9,6 @@ import java.util.logging.Logger; import net.ess3.api.IEssentials; import org.bukkit.Server; import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -44,11 +43,11 @@ public abstract class EssentialsCommand implements IEssentialsCommand } // Get online players - only show vanished if source has permission - protected User getPlayer(final Server server, final CommandSender sender, final String[] args, final int pos) throws PlayerNotFoundException, NotEnoughArgumentsException + protected User getPlayer(final Server server, final CommandSource sender, final String[] args, final int pos) throws PlayerNotFoundException, NotEnoughArgumentsException { - if (sender instanceof Player) + if (sender.isPlayer()) { - User user = ess.getUser(sender); + User user = ess.getUser(sender.getPlayer()); return getPlayer(server, user, args, pos); } return getPlayer(server, args, pos, true, false); @@ -153,16 +152,16 @@ public abstract class EssentialsCommand implements IEssentialsCommand protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - run(server, (CommandSender)(user.getBase()), commandLabel, args); + run(server, user.getSource(), commandLabel, args); } @Override - public final void run(final Server server, final CommandSender sender, final String commandLabel, final Command cmd, final String[] args) throws Exception + public final void run(final Server server, final CommandSource sender, final String commandLabel, final Command cmd, final String[] args) throws Exception { run(server, sender, commandLabel, args); } - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { throw new Exception(_("onlyPlayers", commandLabel)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java index 854385f04..2a7ebddde 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.ChargeException; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; import java.util.List; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,7 +15,7 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand super(command); } - protected void loopOfflinePlayers(final Server server, final CommandSender sender, final boolean multipleStringMatches, final String searchTerm, final String[] commandArgs) + protected void loopOfflinePlayers(final Server server, final CommandSource sender, final boolean multipleStringMatches, final String searchTerm, final String[] commandArgs) throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException { if (searchTerm.isEmpty()) @@ -33,7 +33,7 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand } else if (searchTerm.contentEquals("*")) { - boolean skipHidden = sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.vanish.interact"); + boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact"); for (Player onlinePlayer : server.getOnlinePlayers()) { final User onlineUser = ess.getUser(onlinePlayer); @@ -69,7 +69,7 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand } } - protected void loopOnlinePlayers(final Server server, final CommandSender sender, final boolean multipleStringMatches, final String searchTerm, final String[] commandArgs) + protected void loopOnlinePlayers(final Server server, final CommandSource sender, final boolean multipleStringMatches, final String searchTerm, final String[] commandArgs) throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException { if (searchTerm.isEmpty()) @@ -77,7 +77,7 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand throw new PlayerNotFoundException(); } - boolean skipHidden = sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.vanish.interact"); + boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact"); if (searchTerm.contentEquals("**") || searchTerm.contentEquals("*")) { @@ -121,6 +121,6 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand } } - protected abstract void updatePlayer(Server server, CommandSender sender, User user, String[] args) + protected abstract void updatePlayer(Server server, CommandSource sender, User user, String[] args) throws NotEnoughArgumentsException, PlayerExemptException, ChargeException; } diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java index 8bc4cb91e..062441dda 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; import java.util.List; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -30,14 +30,14 @@ public abstract class EssentialsToggleCommand extends EssentialsCommand return null; } - protected void toggleOtherPlayers(final Server server, final CommandSender sender, final String[] args) throws PlayerNotFoundException, NotEnoughArgumentsException + protected void toggleOtherPlayers(final Server server, final CommandSource sender, final String[] args) throws PlayerNotFoundException, NotEnoughArgumentsException { if (args.length < 1 || args[0].trim().length() < 2) { throw new PlayerNotFoundException(); } - boolean skipHidden = sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.vanish.interact"); + boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact"); boolean foundUser = false; final List matchedPlayers = server.matchPlayer(args[0]); for (Player matchPlayer : matchedPlayers) @@ -72,5 +72,5 @@ public abstract class EssentialsToggleCommand extends EssentialsCommand } // Make sure when implementing this method that all 3 Boolean states are handled, 'null' should toggle the existing state. - abstract void togglePlayer(CommandSender sender, User user, Boolean enabled) throws NotEnoughArgumentsException; + abstract void togglePlayer(CommandSource sender, User user, Boolean enabled) throws NotEnoughArgumentsException; } diff --git a/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java index 4a946d814..1eb241888 100644 --- a/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.IEssentialsModule; import com.earth2me.essentials.User; import net.ess3.api.IEssentials; import org.bukkit.Server; import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; public interface IEssentialsCommand @@ -15,7 +15,7 @@ public interface IEssentialsCommand void run(Server server, User user, String commandLabel, Command cmd, String[] args) throws Exception; - void run(Server server, CommandSender sender, String commandLabel, Command cmd, String[] args) + void run(Server server, CommandSource sender, String commandLabel, Command cmd, String[] args) throws Exception; void setEssentials(IEssentials ess); diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index a0e862730..482b66fcb 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -51,11 +51,11 @@ public class EssentialsSign } catch (ChargeException ex) { - ess.showError(user.getBase(), ex, signName); + ess.showError(user.getSource(), ex, signName); } catch (SignException ex) { - ess.showError(user.getBase(), ex, signName); + ess.showError(user.getSource(), ex, signName); } // Return true, so the player sees the wrong sign. return true; @@ -97,12 +97,12 @@ public class EssentialsSign } catch (ChargeException ex) { - ess.showError(user.getBase(), ex, signName); + ess.showError(user.getSource(), ex, signName); return false; } catch (SignException ex) { - ess.showError(user.getBase(), ex, signName); + ess.showError(user.getSource(), ex, signName); return false; } } @@ -119,7 +119,7 @@ public class EssentialsSign } catch (SignException ex) { - ess.showError(user.getBase(), ex, signName); + ess.showError(user.getSource(), ex, signName); return false; } } @@ -148,11 +148,11 @@ public class EssentialsSign } catch (ChargeException ex) { - ess.showError(user.getBase(), ex, signName); + ess.showError(user.getSource(), ex, signName); } catch (SignException ex) { - ess.showError(user.getBase(), ex, signName); + ess.showError(user.getSource(), ex, signName); } return false; } @@ -166,11 +166,11 @@ public class EssentialsSign } catch (ChargeException ex) { - ess.showError(user.getBase(), ex, signName); + ess.showError(user.getSource(), ex, signName); } catch (SignException ex) { - ess.showError(user.getBase(), ex, signName); + ess.showError(user.getSource(), ex, signName); } return false; } @@ -184,7 +184,7 @@ public class EssentialsSign } catch (SignException ex) { - ess.showError(user.getBase(), ex, signName); + ess.showError(user.getSource(), ex, signName); } return false; } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignInfo.java b/Essentials/src/com/earth2me/essentials/signs/SignInfo.java index 050cc3d57..9d6ef8da0 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignInfo.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignInfo.java @@ -37,10 +37,10 @@ public class SignInfo extends EssentialsSign final IText input; try { - input = new TextInput(player.getBase(), "info", true, ess); - final IText output = new KeywordReplacer(input, player.getBase(), ess); + input = new TextInput(player.getSource(), "info", true, ess); + final IText output = new KeywordReplacer(input, player.getSource(), ess); final TextPager pager = new TextPager(output); - pager.showPage(chapter, page, null, player.getBase()); + pager.showPage(chapter, page, null, player.getSource()); } catch (IOException ex) diff --git a/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java b/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java index b271b8951..4916d131b 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java @@ -30,7 +30,7 @@ public class SignSpawnmob extends EssentialsSign { List mobParts = SpawnMob.mobParts(sign.getLine(2)); List mobData = SpawnMob.mobData(sign.getLine(2)); - SpawnMob.spawnmob(ess, ess.getServer(), player.getBase(), player, mobParts, mobData, Integer.parseInt(sign.getLine(1))); + SpawnMob.spawnmob(ess, ess.getServer(), player.getSource(), player, mobParts, mobData, Integer.parseInt(sign.getLine(1))); } catch (Exception ex) { diff --git a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java index b8c1a13a3..def72e2ae 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.textreader; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.ExecuteTimer; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.PlayerList; @@ -24,7 +25,6 @@ import java.util.regex.Pattern; import net.ess3.api.IEssentials; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -40,7 +40,7 @@ public class KeywordReplacer implements IText private final static Pattern KEYWORDSPLIT = Pattern.compile("\\:"); private final EnumMap keywordCache = new EnumMap(KeywordType.class); - public KeywordReplacer(final IText input, final CommandSender sender, final IEssentials ess) + public KeywordReplacer(final IText input, final CommandSource sender, final IEssentials ess) { this.input = input; this.replaced = new ArrayList(this.input.getLines().size()); @@ -49,7 +49,7 @@ public class KeywordReplacer implements IText replaceKeywords(sender); } - public KeywordReplacer(final IText input, final CommandSender sender, final IEssentials ess, final boolean showPrivate) + public KeywordReplacer(final IText input, final CommandSource sender, final IEssentials ess, final boolean showPrivate) { this.input = input; this.replaced = new ArrayList(this.input.getLines().size()); @@ -58,14 +58,14 @@ public class KeywordReplacer implements IText replaceKeywords(sender); } - private void replaceKeywords(final CommandSender sender) + private void replaceKeywords(final CommandSource sender) { execTimer = new ExecuteTimer(); execTimer.start(); User user = null; - if (sender instanceof Player) + if (sender.isPlayer()) { - user = ess.getUser(sender); + user = ess.getUser(sender.getPlayer()); //This is just so any displayname lookups below show the correct nickname user.setDisplayNick(); } @@ -122,8 +122,9 @@ public class KeywordReplacer implements IText } } } - - if (validKeyword.isPrivate() && !includePrivate) { + + if (validKeyword.isPrivate() && !includePrivate) + { replacer = ""; } @@ -199,10 +200,12 @@ public class KeywordReplacer implements IText else { final boolean showHidden; - if (user == null) { + if (user == null) + { showHidden = true; } - else { + else + { showHidden = user.isAuthorized("essentials.list.hidden") || user.isAuthorized("essentials.vanish.interact"); } @@ -381,10 +384,9 @@ enum KeywordType ADDRESS(KeywordCachable.CACHEABLE, true), PLUGINS(KeywordCachable.CACHEABLE, true), VERSION(KeywordCachable.CACHEABLE, true); - private final KeywordCachable type; private final boolean isPrivate; - + KeywordType(KeywordCachable type) { this.type = type; @@ -401,12 +403,14 @@ enum KeywordType { return type; } - - public boolean isPrivate() { + + public boolean isPrivate() + { return isPrivate; } } + enum KeywordCachable { CACHEABLE, // This keyword can be cached as a string diff --git a/Essentials/src/com/earth2me/essentials/textreader/SimpleTextPager.java b/Essentials/src/com/earth2me/essentials/textreader/SimpleTextPager.java index 5376abbd2..2556201f1 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/SimpleTextPager.java +++ b/Essentials/src/com/earth2me/essentials/textreader/SimpleTextPager.java @@ -1,8 +1,7 @@ package com.earth2me.essentials.textreader; +import com.earth2me.essentials.CommandSource; import java.util.List; -import org.bukkit.command.CommandSender; - public class SimpleTextPager { @@ -13,7 +12,7 @@ public class SimpleTextPager this.text = text; } - public void showPage(final CommandSender sender) + public void showPage(final CommandSource sender) { for (String line : text.getLines()) { diff --git a/Essentials/src/com/earth2me/essentials/textreader/TextInput.java b/Essentials/src/com/earth2me/essentials/textreader/TextInput.java index 7d3bb02cf..f375a3072 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/TextInput.java +++ b/Essentials/src/com/earth2me/essentials/textreader/TextInput.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.textreader; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.StringUtil; @@ -7,8 +8,6 @@ import java.io.*; import java.lang.ref.SoftReference; import java.util.*; import net.ess3.api.IEssentials; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class TextInput implements IText @@ -19,13 +18,13 @@ public class TextInput implements IText private final transient long lastChange; private final static HashMap> cache = new HashMap>(); - public TextInput(final CommandSender sender, final String filename, final boolean createFile, final IEssentials ess) throws IOException + public TextInput(final CommandSource sender, final String filename, final boolean createFile, final IEssentials ess) throws IOException { File file = null; - if (sender instanceof Player) + if (sender.isPlayer()) { - final User user = ess.getUser(sender); + final User user = ess.getUser(sender.getPlayer()); file = new File(ess.getDataFolder(), filename + "_" + StringUtil.sanitizeFileName(user.getName()) + ".txt"); if (!file.exists()) { @@ -78,7 +77,8 @@ public class TextInput implements IText { String[] titles = line.substring(1).trim().replace(" ", "_").split(","); chapters.add(FormatUtil.replaceFormat(titles[0])); - for (String title : titles) { + for (String title : titles) + { bookmarks.put(FormatUtil.stripEssentialsFormat(title.toLowerCase(Locale.ENGLISH)), lineNumber); } } diff --git a/Essentials/src/com/earth2me/essentials/textreader/TextPager.java b/Essentials/src/com/earth2me/essentials/textreader/TextPager.java index b07e0b233..d2f18984f 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/TextPager.java +++ b/Essentials/src/com/earth2me/essentials/textreader/TextPager.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.textreader; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.I18n; import static com.earth2me.essentials.I18n._; import java.util.List; import java.util.Locale; import java.util.Map; -import org.bukkit.command.CommandSender; public class TextPager @@ -24,7 +24,7 @@ public class TextPager this.onePage = onePage; } - public void showPage(final String pageStr, final String chapterPageStr, final String commandName, final CommandSender sender) + public void showPage(final String pageStr, final String chapterPageStr, final String commandName, final CommandSource sender) { List lines = text.getLines(); List chapters = text.getChapters(); diff --git a/Essentials/test/com/earth2me/essentials/ToggleTest.java b/Essentials/test/com/earth2me/essentials/ToggleTest.java index e5555e9fc..e66d7a9c7 100644 --- a/Essentials/test/com/earth2me/essentials/ToggleTest.java +++ b/Essentials/test/com/earth2me/essentials/ToggleTest.java @@ -64,7 +64,7 @@ public class ToggleTest extends TestCase { cmd = (IEssentialsCommand)Essentials.class.getClassLoader().loadClass("com.earth2me.essentials.commands.Command" + command).newInstance(); cmd.setEssentials(ess); - cmd.run(server, sender, command, null, args); + cmd.run(server, new CommandSource(sender), command, null, args); } catch (NoChargeException ex) { diff --git a/EssentialsAntiBuild/EssentialsAntiBuild.iml b/EssentialsAntiBuild/EssentialsAntiBuild.iml new file mode 100644 index 000000000..df12eff90 --- /dev/null +++ b/EssentialsAntiBuild/EssentialsAntiBuild.iml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java index 7f5acd56f..c81a38ab2 100644 --- a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java +++ b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java @@ -151,7 +151,7 @@ public class EssentialsAntiBuildListener implements Listener final Entity entity = event.getRemover(); if (entity instanceof Player) { - final User user = ess.getUser(entity); + final User user = ess.getUser((Player)entity); final EntityType type = event.getEntity().getType(); final boolean warn = ess.getSettings().warnOnBuildDisallow(); if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")) @@ -259,7 +259,7 @@ public class EssentialsAntiBuildListener implements Listener if (entity instanceof Player) { - final User user = ess.getUser(entity); + final User user = ess.getUser((Player)entity); final ItemStack item = event.getRecipe().getResult(); if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) diff --git a/EssentialsChat/EssentialsChat.iml b/EssentialsChat/EssentialsChat.iml new file mode 100644 index 000000000..df12eff90 --- /dev/null +++ b/EssentialsChat/EssentialsChat.iml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java index 7fff85ff8..78b9d1a7f 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -82,7 +82,7 @@ public abstract class EssentialsChatPlayer implements Listener } catch (ChargeException e) { - ess.showError(chatStore.getUser().getBase(), e, chatStore.getLongType()); + ess.showError(chatStore.getUser().getSource(), e, chatStore.getLongType()); event.setCancelled(true); return false; } diff --git a/EssentialsGeoIP/EssentialsGeoIP.iml b/EssentialsGeoIP/EssentialsGeoIP.iml new file mode 100644 index 000000000..df12eff90 --- /dev/null +++ b/EssentialsGeoIP/EssentialsGeoIP.iml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index d8657fef5..1336f3e07 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -37,7 +37,12 @@ public class EssentialsProtectEntityListener implements Listener return; } - final User user = ess.getUser(target); + User user = null; + if (target instanceof Player) + { + user = ess.getUser((Player)target); + } + final DamageCause cause = event.getCause(); if (event instanceof EntityDamageByBlockEvent) @@ -69,7 +74,12 @@ public class EssentialsProtectEntityListener implements Listener { final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event; final Entity eAttack = edEvent.getDamager(); - final User attacker = ess.getUser(eAttack); + + User attacker = null; + if (eAttack instanceof Player) + { + attacker = ess.getUser((Player)eAttack); + } //Creeper explode prevention if (eAttack instanceof Creeper @@ -126,7 +136,7 @@ public class EssentialsProtectEntityListener implements Listener || (((Projectile)edEvent.getDamager()).getShooter() instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && (!user.isAuthorized("essentials.protect.pvp") - || !ess.getUser(((Projectile)edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp"))))) + || !ess.getUser((Player)((Projectile)edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp"))))) { event.setCancelled(true); return; @@ -275,7 +285,7 @@ public class EssentialsProtectEntityListener implements Listener { return; } - final User user = ess.getUser(event.getTarget()); + final User user = ess.getUser((Player)event.getTarget()); if ((event.getReason() == TargetReason.CLOSEST_PLAYER || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY || event.getReason() == TargetReason.PIG_ZOMBIE_TARGET diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java index 35edd172c..2317e774c 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.spawn; +import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Console; import com.earth2me.essentials.Trade; @@ -9,7 +10,6 @@ import com.earth2me.essentials.commands.NoChargeException; import com.earth2me.essentials.commands.NotEnoughArgumentsException; import org.bukkit.Location; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -43,7 +43,7 @@ public class Commandspawn extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java index 6fcabe6e0..668294970 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -108,7 +108,7 @@ public class EssentialsSpawnPlayerListener implements Listener //This method allows for multiple line player announce messages using multiline yaml syntax #EasterEgg if (ess.getSettings().getAnnounceNewPlayers()) { - final IText output = new KeywordReplacer(ess.getSettings().getAnnounceNewPlayerFormat(), user.getBase(), ess); + final IText output = new KeywordReplacer(ess.getSettings().getAnnounceNewPlayerFormat(), user.getSource(), ess); final SimpleTextPager pager = new SimpleTextPager(output); for (String line : pager.getLines()) diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java index e7dd01670..529b4a1c2 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.xmpp; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.NotEnoughArgumentsException; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,7 +16,7 @@ public class Commandxmpp extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException { if (args.length < 2) { @@ -31,7 +31,7 @@ public class Commandxmpp extends EssentialsCommand else { final String message = getFinalArg(args, 1); - final String senderName = sender instanceof Player ? ess.getUser(sender).getDisplayName() : Console.NAME; + final String senderName = sender.isPlayer() ? ess.getUser(sender.getPlayer()).getDisplayName() : Console.NAME; sender.sendMessage("[" + senderName + ">" + address + "] " + message); if (!EssentialsXMPP.getInstance().sendMessage(address, "[" + senderName + "] " + message)) { diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java index 4f276c3b9..a3f8ee83e 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.xmpp; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.NotEnoughArgumentsException; import java.util.List; import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,7 +16,7 @@ public class Commandxmppspy extends EssentialsCommand } @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException { if (args.length < 1) {