forum Forumsplay_arrow Minecraft fiber_manual_record Mods

1

Bukkit Plugin

1 emerald7 replies237 views
created 08/29/2015 1:07 pm by pieterx12
last reply 08/30/2015 12:40 pm
Dear people,
I'm programming a plugin with a config. But when I try to put the config system into a command it doesn't want to work. Can someone help me please ? :'(

public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
if(CommandLabel.equalsIgnoreCase("vip")){
Player p = (Player) sender;
if (getConfig().getString("vips." + p.getName()) == null) {
getConfig().addDefault("vips." + p.getName(), 0);
saveConfig();

}else {
p.sendMessage("wrong");
saveConfig();
}


}
return false;
Posted by avatar
pieterx12
Level 8 : Apprentice Miner
1

7 replies

1
08/30/2015 12:40 pm
Level 2 : Apprentice Miner
jeeperscreeper77
avatar
If your trying to get to use the config in another class file, you have to use the proper constructors. https://bukkit.org/threads/tutorial-how ... rs.166618/
1
08/30/2015 12:26 pm
Level 30 : Artisan Toast
Vector10f
avatar
This is not related, but if you looked at https://docs.oracle.com/javase/tutorial/ or any other decent java tutorial, you most likely wouldn't have to create this thread.

https://hub.spigotmc.org/javadocs/bukkit/ The Bukkit/Spigot java docs is also your friend.
1
08/30/2015 10:29 am
Level 3 : Apprentice Engineer
Killstrike Gamer
avatar
Do not use implements CommandExecuter in your main class, it is mainly for other classes, And if your going to register events, you need to implement Listener
1
08/30/2015 5:33 am
Level 12 : Journeyman Artist
supermankyle
avatar
idk i dont know how to code xD
1
08/30/2015 5:12 am
Level 3 : Apprentice Network
weakwizardsucks2
avatar
unrelated but make sure you call registerCommands() and registerEvents() in your onEnable() (or where needed)
1
08/30/2015 3:42 am
Level 8 : Apprentice Miner
pieterx12
avatar
package EnvyGames.VIPSystem.com;

import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import EnvyGames.VIPSystem.com.Commands.Goodbye;
import EnvyGames.VIPSystem.com.Commands.Hello;
import EnvyGames.VIPSystem.com.Commands.VipRemoveCommand;
import EnvyGames.VIPSystem.com.event.block.BlockBreak;


public class Main extends JavaPlugin implements CommandExecutor {

public void onEnable() {


getConfig().options().copyDefaults(true);
saveDefaultConfig();
}

public void onDisable() {
getConfig().options().copyDefaults(true);
saveConfig();
}

public void registerCommands(){
getCommand("Hello").setExecutor(new Hello());
getCommand("Goodbye").setExecutor(new Goodbye());


}
public void registerEvents(){
PluginManager pm = getServer().getPluginManager();

pm.registerEvents(new BlockBreak(), this);

}


public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
if(CommandLabel.equalsIgnoreCase("vips")){
Player p = (Player) sender;
if (getConfig().getString("vips." + p.getName()) == null) {
getConfig().addDefault("vips." + p.getName(), 0);
saveConfig();
p.sendMessage("fout");
}else {

saveConfig();
}


}
return false;
}
1
08/29/2015 2:03 pm
Level 52 : Grandmaster Programmer
Willsr71
avatar
Context please. If possible include the entire class.

Planet Minecraft

Browse

Site

© 2010 - 2019
planetminecraft.com

Welcome