Array users multicomand.

Discussion in 'Plugin Development' started by MrNice, Jul 11, 2013.

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

    MrNice

    Hi i am trying to make a plugin that will extend some other plugins and features. My basic problem is i wana have a command qc enterd in console with parameters, and parametr g set on creative mode, part t disable. The worst problem ist that args array [0]=g/t, and rest of array must be player nick, but when i started in foreach to give creative mod it gave me cannot cast string to object. Transfering string into object didnt help, Can smby help me create a list of players array so i could cast on them comands ?? PLZ
    I am new to java thx.


    Code:java
    1. package pl.MrNice.PluginFactory;
    2. import org.bukkit.command.Command;
    3. import org.bukkit.command.CommandSender;
    4. import org.bukkit.command.ConsoleCommandSender;
    5. import org.bukkit.entity.HumanEntity;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.Plugin;
    8. import java.util.List;
    9. import java.io.Console;
    10. import java.util.ArrayList;
    11. import java.util.logging.Level;
    12. import java.util.logging.Logger;
    13.  
    14.  
    15. import pl.MrNice.PluginFactory.LocalComponent;
    16.  
    17.  
    18. import org.bukkit.Bukkit;
    19. import org.bukkit.ChatColor;
    20. import org.bukkit.GameMode;
    21. import org.bukkit.plugin.PluginDescriptionFile;
    22. import org.bukkit.plugin.java.JavaPlugin;
    23.  
    24.  
    25. public final class PluginFactory extends JavaPlugin{
    26. private static PluginFactory instance = null;
    27. private List<LocalComponent> components = new ArrayList<LocalComponent>();
    28. private Plugin PluginFactory;
    29.  
    30. public void onEnable() {
    31. instance=this;
    32. PluginDescriptionFile pdfFile = getDescription();
    33. this.getLogger().log(Level.INFO,"Hello World!");
    34. System.out.println("\033[32;1m" + "[" + pdfFile.getName() +" wersja " + pdfFile.getVersion() + " jest wlaczony/ENABELD\033[0;39m");
    35.  
    36. startComponents();
    37.  
    38.  
    39. }
    40.  
    41.  
    42.  
    43. public void onDisable(){
    44. instance=null;
    45. PluginDescriptionFile pdfFile = getDescription();
    46. this.getLogger().log(Level.INFO, "\033[31;22m" + "[" + pdfFile.getName() +" wersja " + pdfFile.getVersion() + " jest teraz wylaczony/DISABELD\033[0;39m");
    47. //for (LocalComponent component : components) {
    48. // component.disable();
    49. //}
    50.  
    51. }
    52. private void startComponents() {
    53. ComandCore comandCore = new ComandCore();
    54. comandCore.enable();
    55. components.add(comandCore);
    56.  
    57. ComandExtend comandExtend = new ComandExtend();
    58. comandExtend.enable();
    59. components.add(comandExtend);
    60.  
    61. FactoryCore factoryCore = new FactoryCore();
    62. factoryCore.enable();
    63. components.add(factoryCore);
    64.  
    65. }
    66. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    67. if(cmd.getName().equalsIgnoreCase("qc"))
    68. {
    69. if (sender instanceof Player){
    70. Player player= (Player) sender;
    71. if(player.getGameMode().getValue()==0)
    72. {
    73. player.setGameMode(GameMode.CREATIVE);
    74. }else{
    75. player.setGameMode(GameMode.SURVIVAL);
    76. }
    77. return true;
    78. }
    79. else if(sender instanceof ConsoleCommandSender){
    80. if(args.length!=0 && args.length>1&&args[0].equalsIgnoreCase("g")){
    81. //ArrayList<Player> QCPlayers = new ArrayList<Player>();
    82. int i = 1;
    83. for( Object playtoqc:args){
    84.  
    85.  
    86.  
    87.  
    88. Bukkit.getPlayer(playtoqc).setGameMode(GameMode.CREATIVE);
    89. //String a= playtoqc.getPlayer;
    90. //System.out.println(a);
    91.  
    92. }
    93. }
    94. else if(args.length!=0 && args.length>1&&args[0]=="t"){
    95. for( String playtoqc:args){
    96. };
    97. }else
    98. {sender.sendMessage("Wrong arguments [g/t] nicks (g-give/t-take)!!!");}
    99. }else{
    100. sender.sendMessage("Cannot run in console!!!");
    101. return false;
    102. }
    103. }return false;
    104. }
    105.  
    106.  
    107.  
    108. }
    109.  


    Code:java
    1. Player player= (Player) playtoqc;
    2.  
    3.  
    4.  
    5.  
    6. player.setGameMode(GameMode.CREATIVE);


    gives

    2013-07-11 19:29:39 [INFO] MrNice issued server command: /qc
    2013-07-11 19:29:51 [WARNING] Unexpected exception while parsing console command "qc g mrnice"
    org.bukkit.command.CommandException: Unhandled exception executing command 'qc' in plugin PluginFactory v0.0.1

    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)

    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)

    at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)

    at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchServerCommand(CraftServer.java:512)

    at net.minecraft.server.v1_6_R2.DedicatedServer.ar(DedicatedServer.java:262)

    at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:227)

    at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)

    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)

    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)

    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to org.bukkit.entity.Player

    at pl.MrNice.PluginFactory.PluginFactory.onCommand(PluginFactory.java:84)

    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)

    ... 8 more

    2013-07-11 19:30:45 [INFO] MrNice issued server command: /qc
     
Thread Status:
Not open for further replies.

Share This Page