[Urgent!] getting from config does not work... or it does in the wrong way!

Discussion in 'Plugin Development' started by ChipDev, Jun 18, 2014.

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

    ChipDev

    Hi guys, I am making a plugin which disables/enables pvp messages with /pvpmsg,
    I am doing /pvpmsg and it gives me the text that it enables, then it disables really fast..
    code:
    Code:java
    1. package Com.chip;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.entity.PlayerDeathEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class PvpDisabler extends JavaPlugin implements Listener {
    12. String Prefix = ChatColor.GREEN + "[" + ChatColor.BLUE + "NoPvpMsg" + ChatColor.GREEN + "] ";
    13. String blue = ChatColor.BLUE + "";
    14. String red = ChatColor.RED + "";
    15. String green = ChatColor.GREEN + "";
    16. String bold = ChatColor.BOLD + "";
    17. String reset = ChatColor.RESET + "";
    18. public void onEnable() {
    19. getServer().getConsoleSender().sendMessage(Prefix + "Enabled!");
    20. getServer().getPluginCommand("pvpmsg").setPermissionMessage(Prefix + green + "You do not have permission!");
    21. }
    22. public void onDisable() {
    23. getServer().getConsoleSender().sendMessage(Prefix + "Disabled!");
    24. }
    25. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    26. if(cmd.getName().equalsIgnoreCase("pvpmsg")) {
    27. Player player = (Player) sender;
    28. if(getConfig().contains(player.getWorld().getName())) {
    29. getConfig().set(player.getWorld().getName(), null);
    30. saveConfig();
    31. player.sendMessage(Prefix + green + "Pvp message enabled in:" + red + bold + player.getWorld().getName() + reset + green + "!");
    32. }
    33. if(!getConfig().contains(player.getWorld().getName())) {
    34. getConfig().set(player.getWorld().getName(), 1);
    35. saveConfig();
    36. player.sendMessage(Prefix + green + "Pvp message disabled in:" + red + bold + player.getWorld().getName() + reset + green + "!");
    37. }
    38. }
    39. return true;
    40. }
    41. public void onPlayerDeathEvent(PlayerDeathEvent e) {
    42. Player player = e.getEntity();
    43. if (e.getEntity() instanceof Player){
    44. if(!player.hasPermission("pvpmessage.bypass")) {
    45. if(getConfig().contains(player.getWorld().toString())) {
    46. e.setDeathMessage(null);
    47. }
    48.  
    49. }
    50. }
    51. }
    52. }
    53.  

    Thanks !
     
  2. Offline

    teej107

    ChipDev You could try using if/else statements in your command. Your 2 if statements is basically mimicking that except that the second if statement could execute it's code if the first does something to make the test true.
     
  3. Offline

    ChipDev

    Hmm use else.
    Hah I used scratch before bukkit, Never used else's , I just used more If's .. heh k.
     
  4. Offline

    teej107

    remove your second if statement and replace it with "else".
    EDIT: Just your if test. Don't remove the code inside it.
    Code:java
    1. if(test)
    2. {
    3.  
    4. }
    5. else
    6. {
    7.  
    8. }


    The else will execute if the if test returns false
     
    ChipDev likes this.
  5. Offline

    techboy291

    Please don't put urgent tags in your post title; your problems aren't more important than anybody else's. I don't mean to be harsh, but all it does is make people (at least me) want to help less.
     
    ZodiacTheories likes this.
  6. Offline

    nzkiwi.5000

    getWorld().toString() won't give you the information which you need to identify world. You should get (and save to config) it's name or UUID.
     
  7. Offline

    Konkz

    How does one get UUID of a world?
     
  8. Konkz World#getUID()

    I'm surprised you didn't read the JavaDocs, I thought you knew better than that ;)
     
  9. Offline

    Konkz

    #getUID() and #getUUID are not the same, one is for user (Unique User Identification) other is for just general use (Unique Identification) - that's why I picked him up on UUID. ;)

    Also, when I read JavaDocs I read for what I need, not everything. I gotta life you know :p
     
  10. Konkz I think that's the real problem - what with 1.8 we're forgetting that UUID is actually a Java thing for identifying objects, not a Minecraft/Bukkit/Player specific and actually stands for Universally Unique IDentifier. As such, getUID returns a UUID :)

    Pah, I don't!
     
    Rocoty likes this.
  11. Offline

    nzkiwi.5000

    Konkz
    Code:java
    1. world.getName();
    2. world.getUUID();
     
Thread Status:
Not open for further replies.

Share This Page