Help with redirecting commands

Discussion in 'Plugin Development' started by josh7554, Mar 30, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    josh7554

    Hello, I am currently making a plugin directly for my server which when the Command is executed sets them to either a modified Playable rank or a Commanding rank which has all commands using the PermissionsEx plugin and sets them into vanish mode using the BetterVanish plugin. Here's my code.
    Code:java
    1. package me.josh7554.AdminToPlayer;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Main extends JavaPlugin implements Listener {
    16.  
    17.  
    18.  
    19.  
    20.  
    21. @Override
    22. public void onEnable() {
    23. getLogger().info("Has Now Been Enabled!");
    24. try{
    25. saveConfig();
    26. setupConfig(getConfig());
    27. saveConfig();
    28. }catch(Exception e){
    29. e.printStackTrace();
    30. }
    31. }
    32.  
    33. public void onDisable() {
    34. getLogger().info("Has Now Been Disabled! :(");
    35. saveConfig();
    36. }
    37.  
    38.  
    39. private void setupConfig(FileConfiguration config) throws IOException {
    40. if(!new File(getDataFolder(), "DeleteToReset.file").exists()) {
    41. new File(getDataFolder(), "DeleteToReset.file").createNewFile();
    42. config.set("PermissionsPlugin", "none");
    43. config.set("GroupsToSwap", "none");
    44.  
    45. }
    46. }
    47.  
    48. public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) {
    49. if(sender instanceof Player) {
    50. if(getConfig().getString("PermissionsPlugin").equals("none"));
    51. if(getConfig().getString("PermissionsPlugin").equalsIgnoreCase("Pex") || getConfig().getString("PermissionsPlugin").equalsIgnoreCase("PermissionsEx") ){
    52. Player p = (Player) sender;
    53. String pn = p.getName();
    54. if(cmd.getName().equalsIgnoreCase("Owner")) {
    55. String Owner = "pex user " + pn + " group set Owner";
    56. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), Owner);
    57. Owner = "v ";
    58. p.sendMessage(ChatColor.BLUE + "Bukkit is just about to execute /v");
    59. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), Owner);
    60. p.sendMessage(ChatColor.BLUE + "Bukkit executed /v");
    61. p.sendMessage(ChatColor.BLUE + "You are now in 'Admin' mode. You have been vanished, Mods and below will not be able to see you. ");
    62. // Command that Owners would use to turn into a commanding rank.
    63. }
    64. }else if(cmd.getName().equalsIgnoreCase("Player")) {
    65. if(sender instanceof Player) {
    66. Player p = (Player) sender;
    67. String pn = p.getName();
    68. String Player = "pex user " + pn + " group set POwner";
    69. // NOTE: the set rank command works.
    70. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), Player);
    71. Player = "uv";
    72. p.sendMessage(ChatColor.BLUE + "Bukkit is just about to execute the unvanish");
    73. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), Player);
    74. p.sendMessage(ChatColor.BLUE + "You are now in 'Player' mode. If you were in vanish, you have now been unvanished.");
    75. // Command that Owners would use to turn into a Player.
    76. }else if(cmd.getName().equalsIgnoreCase("COwner")) {
    77. if(sender instanceof Player) {
    78. Player p = (Player) sender;
    79. String pn = p.getName();
    80. String COwner = "pex user " + pn + " group set Co-Owner";
    81. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), COwner);
    82. COwner = "v";
    83. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), COwner);
    84. p.sendMessage(ChatColor.BLUE + "You are now in 'Admin' mode. You have been vanished, Mods and below will not be able to see you. ");
    85. // Command that Co-Owners would use to turn into a commanding rank.
    86. }else if(cmd.getName().equalsIgnoreCase("PlayerC")) {
    87. if(sender instanceof Player) {
    88. Player p = (Player) sender;
    89. String pn = p.getName();
    90. String PlayerC = "pex user " + pn + "group set PCo-Owner";
    91. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), PlayerC);
    92. PlayerC = "uv";
    93. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), PlayerC);
    94. p.sendMessage(ChatColor.BLUE + "You are now in 'Player' mode. If you were in vanish, you have now been unvanished.");
    95. // Command that Co-Owners would use to turn into a Player.
    96. }
    97.  
    98. }
    99. }
    100. }
    101. }
    102.  
    103.  
    104. return false;
    105. }
    106.  
    107.  
    108.  
    109.  
    110.  
    111. }
    112.  
    113. // Written by josh7554



    When I execute "/Owner" on my server, nothing comes up, in game or in the console. When I execute "/Player" It switches me to the Player-Owner rank (POwner in my Permissions.yml) but it also has a problem and the unvanish (uv) command doesn't work and says, "An internal error occurred while attempting to perform this command." /player does give me some console output though which I will put now.

    Code:
    29.03 14:41:49 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at tk.dallen6.vanishcloak.Main.onCommand(Main.java:35) ~[?:?]
    29.03 14:41:49 [Server] INFO Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R1.command.ColouredConsoleSender cannot be cast to org.bukkit.entity.Player
    29.03 14:41:49 [Server] INFO ... 13 more
    29.03 14:41:49 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at me.josh7554.AdminToPlayer.Main.onCommand(Main.java:75) ~[?:?]
    29.03 14:41:49 [Server] INFO at org.bukkit.Bukkit.dispatchCommand(Bukkit.java:307) ~[craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO Caused by: org.bukkit.command.CommandException: Unhandled exception executing command 'uv' in plugin BetterVanish v3.1
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:952) [craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.7.2-3020.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    29.03 14:41:49 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'player' in plugin AdminToPlayer v1.0
    29.03 14:41:49 [Server] ERROR null
    29.03 14:41:49 [Server] INFO User groups set!
    Also, like the command "/Owner", when I type "/COwner" (supposed to set to Co-Owner) it does nothing. And gives no console output. With the command "/PlayerC" Which is supposed to set a Co
    -Owner to a playable Co-Owner rank, it gives me the unknown command message. Oh, and I was wondering like, I have 4 different commands, would there be a way to be able to check if whoever is sending the command has which rank and depending on which rank changes them to Player mode or Owner/Co-Owner mode. I was thinking maybe a permission?

    If anyone can help me thank you in advance.
    - Josh
     
Thread Status:
Not open for further replies.

Share This Page