Command does not work (Question goes to Pro's)

Discussion in 'Plugin Development' started by Cammeritz, Jan 26, 2014.

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

    Cammeritz

    Hey Guys,

    this is Cammeritz. I am making a new Plugin for a friend. I want to create Regions. It works. But if i try to perform the command to set/define them, i get the permission.message :O

    I will add here my Region constructor, plugin.yml, Main Class and my Region Set Class.

    I hope you can help me.

    Yours sincerely

    Cammeritz :)

    Main (ProGameZ.class) :

    Code:java
    1. package de.Cammeritz.ProGameZ;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.util.HashMap;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.Location;
    9. import org.bukkit.World;
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.configuration.file.YamlConfiguration;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. import de.Cammeritz.ProGameZ.Regionen.ItemDropCommand;
    15. import de.Cammeritz.ProGameZ.Regionen.Regionen;
    16. import de.Cammeritz.ProGameZ.Regionen.RegionenCommand;
    17.  
    18. public class ProGameZ extends JavaPlugin{
    19.  
    20. public HashMap<String, Regionen> regionen = new HashMap<String, Regionen>();
    21.  
    22. public void onEnable(){
    23. System.out.println("[ProGameZ] hat geladen!");
    24.  
    25.  
    26. this.getCommand("itemdrop").setExecutor(new ItemDropCommand());
    27. this.getCommand("location").setExecutor(new RegionenCommand(this));
    28.  
    29.  
    30. File file = new File("plugins/ProGameZ", "regionen.yml");
    31. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    32.  
    33. for (String region : cfg.getConfigurationSection("").getKeys(false)){
    34.  
    35. String world = cfg.getString(region + ".world");
    36.  
    37. World w = Bukkit.getWorld(world);
    38.  
    39. if(w != null){
    40. int minX = cfg.getInt(region + ".minX");
    41. int minY = cfg.getInt(region + ".minY");
    42. int minZ = cfg.getInt(region + ".minZ");
    43.  
    44. int maxX = cfg.getInt(region + ".maxX");
    45. int maxY = cfg.getInt(region + ".maxY");
    46. int maxZ = cfg.getInt(region + ".maxZ");
    47.  
    48. this.regionen.put(region.toLowerCase(), new Regionen(new Location(w, minX, minY, minZ), new Location(w, maxX, maxY, maxZ)));
    49.  
    50. }
    51.  
    52. }
    53. }
    54.  
    55.  
    56.  
    57. public void onDisable(){
    58. System.out.println("[ProGameZ] wurde ausgeschaltet!");
    59.  
    60. File file = new File("plugins/ProGameZ", "regionen.yml");
    61. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    62.  
    63. for (String region : this.regionen.keySet()){
    64. cfg.set(region, this.regionen.get(region).serialize());
    65. }
    66.  
    67. try {
    68. cfg.save(file);
    69. System.out.println("[ProGameZ] " + this.regionen.size() + " Regionen gespeichert.");
    70. } catch (IOException e) {
    71. e.printStackTrace();
    72. }
    73. }
    74.  
    75.  
    76. }
    77.  


    The Region Constructor (Regionen.class) :

    Code:java
    1. package de.Cammeritz.ProGameZ.Regionen;
    2.  
    3. import java.util.HashMap;
    4. import java.util.Map;
    5.  
    6. import org.bukkit.Location;
    7. import org.bukkit.World;
    8. import org.bukkit.configuration.serialization.ConfigurationSerializable;
    9.  
    10. public class Regionen implements ConfigurationSerializable{
    11.  
    12. private int minX, minY, minZ;
    13. private int maxX, maxY, maxZ;
    14. private World world;
    15.  
    16. public Regionen(Location loca1, Location loca2){
    17. this.minX = Math.min(loca1.getBlockX(), loca2.getBlockX());
    18. this.minY = Math.min(loca1.getBlockY(), loca2.getBlockY());
    19. this.minZ = Math.min(loca1.getBlockZ(), loca2.getBlockZ());
    20.  
    21. this.maxX = Math.max(loca1.getBlockX(), loca2.getBlockX());
    22. this.maxY = Math.max(loca1.getBlockY(), loca2.getBlockY());
    23. this.maxZ = Math.max(loca1.getBlockZ(), loca2.getBlockZ());
    24.  
    25. this.world = loca1.getWorld();
    26. }
    27.  
    28. @Override
    29. public Map<String, Object> serialize() {
    30. Map<String, Object> o = new HashMap<String, Object>();
    31.  
    32. o.put("minX", this.minX);
    33. o.put("minY", this.minY);
    34. o.put("minZ", this.minZ);
    35.  
    36.  
    37. o.put("maxX", this.maxX);
    38. o.put("maxY", this.maxY);
    39. o.put("maxZ", this.maxZ);
    40.  
    41. o.put("world", this.world.getName());
    42.  
    43. return o;
    44. }
    45.  
    46. }
    47.  


    The RegionSet class (RegionCommand.class) (don't wonder about the language i used , i am not english :) ):

    Code:java
    1. package de.Cammeritz.ProGameZ.Regionen;
    2.  
    3. import java.io.File;
    4. import java.io.FileNotFoundException;
    5. import java.io.IOException;
    6. import java.util.HashMap;
    7.  
    8. import org.bukkit.Location;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandExecutor;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.configuration.InvalidConfigurationException;
    13. import org.bukkit.configuration.file.FileConfiguration;
    14. import org.bukkit.configuration.file.YamlConfiguration;
    15. import org.bukkit.entity.Player;
    16.  
    17. import de.Cammeritz.ProGameZ.ProGameZ;
    18.  
    19. public class RegionenCommand implements CommandExecutor {
    20.  
    21. private HashMap<String, Location> loc1 = new HashMap<String, Location>();
    22. private HashMap<String, Location> loc2 = new HashMap<String, Location>();
    23.  
    24. private ProGameZ plugin;
    25.  
    26. public RegionenCommand(ProGameZ plugin){
    27. this.plugin = plugin;
    28. }
    29.  
    30. File file = new File("plugins/ProGameZ", "regionen.yml");
    31. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    32.  
    33.  
    34. @Override
    35. public boolean onCommand(CommandSender cs, Command cmd, String label,
    36. String[] args) {
    37.  
    38. if(!(cs instanceof Player)){
    39. cs.sendMessage("[ProGameZ] Du musst ein Spieler sein um dies zu machen!");
    40. return true;
    41. }
    42.  
    43. Player p = (Player) cs;
    44. String name = p.getName();
    45. Location loc = p.getLocation();
    46. Location cloc = p.getEyeLocation();
    47.  
    48. if(p.hasPermission("progamez.location")){
    49.  
    50. try {
    51. if(args.length >= 1){
    52.  
    53. if(args[0].equalsIgnoreCase("loc1")){
    54. this.loc1.put(name, loc);
    55. p.sendMessage("§3Position 1 wurde gesetzt!");
    56. return true;
    57. } else if (args[0].equalsIgnoreCase("loc2")){
    58. this.loc2.put(name, loc);
    59. p.sendMessage("§3Position 2 wurde gesetzt!");
    60. return true;
    61. } else if (args[0].equalsIgnoreCase("cloc1")){
    62. p.sendMessage("§3Position 1 wurde gesetzt!");
    63. this.loc1.put(name, cloc);
    64. return true;
    65. } else if (args[0].equalsIgnoreCase("cloc2")){
    66. this.loc2.put(name, cloc);
    67. p.sendMessage("§3Position 2 wurde gesetzt!");
    68. return true;
    69. } else if (args[0].equalsIgnoreCase("create")){
    70. if(args.length == 2){
    71. Location loca1 = this.loc1.get(p.getName());
    72. Location loca2 = this.loc2.get(p.getName());
    73. if(loca1 == null){
    74. p.sendMessage("§cDu musst erst noch Punkt 1 setzen!");
    75. return true;
    76. }
    77. if(loca2 == null){
    78. p.sendMessage("§cDu musst erst noch Punkt 2 setzen!");
    79. return true;
    80. }
    81. if(!(loca1.getWorld().getName() == loca2.getWorld().getName())){
    82. p.sendMessage("§cDie Punkte müssen in der gleichen Welt liegen!");
    83. return true;
    84. }
    85. if(loca1.getWorld() == null || loca2.getWorld() == null){
    86. p.sendMessage("§cDie gesetzten Punkte liegen in einer unbekannten Welt!");
    87. return true;
    88. }
    89.  
    90. String welt = args[1].toLowerCase();
    91.  
    92. if(this.plugin.regionen.containsKey(name)){
    93. p.sendMessage("§cDie Region §6" + welt + " §cexestiert schon, wähle einen anderen Namen!");
    94. return true;
    95. }
    96.  
    97. this.plugin.regionen.put(welt, new Regionen(loca1, loca2));
    98. p.sendMessage("§3Die Region " + welt + " wurde gesetzt!");
    99. try {
    100. cfg.save(file);
    101. System.out.println("[ProGameZ] Die neue Region wurde erfolgreich gespeichert!");
    102. } catch (IOException e) {
    103. e.printStackTrace();
    104. }
    105.  
    106. try {
    107. cfg.load(file);
    108. } catch (FileNotFoundException e) {
    109. System.out.println("[ProGameZ] die regionen.yml exestiert nicht!");
    110. e.printStackTrace();
    111. } catch (IOException e) {
    112. e.printStackTrace();
    113. } catch (InvalidConfigurationException e) {
    114. e.printStackTrace();
    115. }
    116. return true;
    117. } else if (args.length >= 1){
    118. p.sendMessage("§cDu musst noch einen Namen angeben! /location create [name]!");
    119. return true;
    120. } else {
    121. p.sendMessage("§cDie Welt kann nur einen Namen haben! /location create [name]");
    122. return true;
    123. }
    124. } else {
    125. p.sendMessage("§cFalsche Verwendung!");
    126. p.sendMessage("§c/location <create|loc1|loc2> [name(optional)]");
    127. return true;
    128. }
    129.  
    130. } else {
    131. p.sendMessage("§cFalsche Verwendung!");
    132. p.sendMessage("§c/location <create|loc1|loc2> [name(optional)]");
    133. return true;
    134. }
    135. } catch (NullPointerException e) {
    136. e.printStackTrace();
    137. }
    138.  
    139. } else {
    140. cs.sendMessage("§cDu hast keine Permissions dazu!");
    141. return true;
    142. }
    143. return true;
    144. }
    145.  
    146. }
    147.  


    Plugin.yml (plugin.yml) :

    Code:
    author: Cammeritz
    name: ProGameZ
    version: 1.0
    description: ProGameZ
     
    database: false
     
    main: de.Cammeritz.ProGameZ.ProGameZ
     
    commands:
      location:
        description: Setze Regionen
        usage: /location
        aliases: [loc]
        permission: progamez.location
    permissions:
      progamez.*:
        description: Alle Permissions
        children:
          progamez.location: true
      progamez.location:
        description: Permission Regionen zu setzen
    Thanks to all trying to help me :)

    The Error:

    [​IMG]

    And i get no Stacktrace >.<

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    L33m4n123

    you nowhere check if the command is location o.o
     
  3. Offline

    Cammeritz

    I don't need to do that, because i registered the command in my Main class ;) the only thing i need to do is checking for the labels, if i want to use them
     
  4. Offline

    ase34

    Cammeritz Do you get any stack-traces during startup of the plugin?
     
  5. Offline

    DeGambler

    ase34
    Cammeritz
    Mind changing your usage message to something else to see if that's actually what's being returned? I can't really see why it would return false from that onCommand method...
     
  6. Offline

    ase34

    DeGambler I thought he means he gets no stack-traces during command-execution, because of the image.
     
  7. Offline

    DeGambler

    ase34
    Ahhh, well that wasn't meant to come across rude or anything, sorry if it did! :)
     
  8. Offline

    ase34

    Absolutely no problem! :D
     
  9. Offline

    Cammeritz

    DeGambler Same problem if i change the usage message
     
  10. Offline

    Th3Br1x

    Is there a StackTrace in the console? (Nice writing mistakes in the messages of the plugin btw :p)
     
  11. Offline

    Dako

  12. Offline

    Th3Br1x

    Yes, i did. I thought he only watched into the chat, cause there can occur stacktraces too.
    Sorry, if i misunderstood it.
     
  13. Offline

    DeGambler

    Cammeritz
    So it's returning the usage you set in the plugin.yml or just /location ?
     
  14. Offline

    Th3Br1x

    Cammeritz May i am wrong, but it looks like your file "regionen.yml" just doesn't exist. You can create it like this:
    Code:java
    1. if(!file.exists){
    2. file.createNewFile();
    3. }
     
  15. Offline

    ItsLeoFTW

    I know what's happening. You can't have the usage message if you're using arguments!! Remove the usage message from the plugin.yml file, build the jar again, and use the new jar. THEN try.
     
  16. Offline

    Th3Br1x

    That's wrong.
    Sure you can have one. The usage message is only displayed on a "return false;" so it doesn't matter here.
    It can even be "Wrong usage!", it really doesn't matter.

    Edit:
    Cammeritz Maybe this is the problem:
    Code:java
    1. public RegionenCommand(ProGameZ plugin){
    2. this.plugin = plugin;
    3. }
    4.  
    5. File file = new File("plugins/ProGameZ", "regionen.yml");
    6. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);


    In general, there should be a stacktrace, but try to do this:

    Code:java
    1. public RegionenCommand(ProGameZ plugin){
    2. this.plugin = plugin;
    3.  
    4. File file = new File(plugin.getDataFolffer(), "regionen.yml");
    5. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    6. }
    7.  
    8.  
     
Thread Status:
Not open for further replies.

Share This Page