Solved [URGENT]Config help And Banning using codes help

Discussion in 'Plugin Development' started by jekeke123, Mar 20, 2013.

Thread Status:
Not open for further replies.
  1. How can i ban someone using a code:
    Something like this:
    Code:
    Ban(target, "You have been warned 3times!", "See ya!");
    And another question about Configs:
    How can i make a config say a number for example i want it to count everytime somebody uses a command and trigger an event (ban) when the counter hits 3 this needs to save thats why i wanna use config file or any other yml file

    This is my full code at this moment:
    Code:
    package jasper;
     
    import java.awt.Color;
    import java.util.List;
     
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public final class warnedyou extends JavaPlugin {
     
        @Override
        public void onEnable(){
            // TODO Insert logic to be performed when the plugin is enabled
       getLogger().info("Plugin Warnedyou enabled!");
        }
        @Override
        public void onDisable() {
            // TODO Insert logic to be performed when the plugin is disabled
       getLogger().info("Plugin Warnedyou disabled!");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
       Player player = (Player) sender;
       Player target = (Bukkit.getServer().getPlayer(args[0]));
            String getvalue = this.getConfig().get(target + ".warnings");
       
       if (cmd.getName().equalsIgnoreCase("warn")){ // If the player typed /warn then do the following...
       // do something...
       target.sendMessage(Color.red + "You have been warned, You now have " + getvalue + "/3 Warnings!");
       target.sendMessage(Color.red + "If you have 3 warning points you will get an ban for ever.");
       target.sendMessage(Color.red + "You can go to http://www.funnycraft.nl for more info & Rules!");
       if (getvalue = 3){
       Ban(target, "You are banned because you had 3 warnings, Check Funnycraft.nl for more info!", "See ya!");
       }
       // setting an int value
       String integerValue = getvalue + 1;
       this.getConfig().set(target + ".warnings", integerValue);
       this.saveConfig();
       return true;
       } else if (cmd.getName().equalsIgnoreCase("reload")) {
       // do something
       this.reloadConfig();
       }
       return true;
       }
    }
    I updated my code and can nobody help whit my ban code and this :
    if (getvalue = 3){ //<- this gives error
    String getvalue = this.getConfig().get(target + ".warnings"); //<- this gives error

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

    Barinade

    When you use "=" you are defining something, if you wish to check if it is equal to something else you would use "==", but in this case you want to do (getValue.equals("3"))

    Or just read it as an int instead of a string, making it
    (getValue == 3)

    http://wiki.bukkit.org/Configuration_API_Reference

    Code:
    Getting Values
     
    Reading values from the configuration involves invoking one of the many getter methods. A complete list of getters can be found here. Every getter method takes a configuration path detailed above. Some of the commonly used getter methods are as follows
    getBoolean(String)
    getInt(String) <== this
    getString(String)
    getList(String)
    getStringList(String)
     
  3. Tnx for reply ;)
     
Thread Status:
Not open for further replies.

Share This Page