Hello, im currently working on a login plugin, but i have something which isnt working. when the player joins, it should receive a message, but instead it does nothing. as far as i know, ive registered the events. this is the code: Code:java package me.jkctech.JKCLogin; import java.util.ArrayList;import java.util.List; import org.bukkit.ChatColor;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerJoinEvent;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin implements Listener{ List<Player> hasLoggedIn = new ArrayList<Player>(); List<Player> needToLogin = new ArrayList<Player>(); public void loadConfiguration(){ getConfig().options().copyDefaults(true); saveConfig(); } @Override public void onEnable(){ PluginDescriptionFile ymlFile = this.getDescription(); this.getLogger().info(ymlFile.getName() + " Version " + ymlFile.getVersion() + " is enabled!"); this.getLogger().info("This plugin is made by jkctech!"); this.getServer().getPluginManager().registerEvents(this, this); loadConfiguration(); } @Override public void onDisable(){ PluginDescriptionFile ymlFile = this.getDescription(); this.getLogger().info(ymlFile.getName() + ymlFile.getVersion() + " is now disabled!"); } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { final Player p = (Player) sender; if(label.equalsIgnoreCase("register") || label.equalsIgnoreCase("login")){ if(args.length == 1){ if(label.equalsIgnoreCase("register")){ if(getConfig().contains("players."+p.getName())){ p.sendMessage(ChatColor.GOLD+"[JKC Login] "+ChatColor.DARK_RED+"You are already registered!"); } else { getConfig().set("players."+p.getName(), p.getName()); getConfig().set("players."+p.getName()+".password", args[0]); saveConfig(); p.sendMessage(ChatColor.GOLD+"[JKC Login] "+ChatColor.GREEN+"You are now registered!"); } }else if(label.equalsIgnoreCase("login")){ String configValue = getConfig().getString("players."+p.getName()+".password"); if(configValue != null && configValue.equals(args[0])) { hasLoggedIn.add(p); p.sendMessage(ChatColor.GOLD+"[JKC Login] "+ChatColor.GREEN+"You are now logged in!"); this.getLogger().info(p.getName()+" has logged in!"); } else { p.sendMessage(ChatColor.GOLD+"[JKC Login] "+ChatColor.DARK_RED+"Incorrect password!"); } } } } return true; } @EventHandler public void onplayerjoin(PlayerJoinEvent event){ Player p = event.getPlayer(); if(getConfig().getString("players").contains(p.getName())){ p.sendMessage(ChatColor.GOLD+"[JKC Login] "+ChatColor.DARK_RED+"You need to login!"); } } } i also want that if the player is in the config and not in array, all his events are canceled. i know i have to do this for every single event, but im not sure what events there are and what their syntaxes are. could somebody maybe create a macro-like thingy which i can copy? thanks in advance!
jkctech You need to register the events. http://wiki.bukkit.org/Event_API_Reference#Adding_the_listener The event list can be found in the javadocs http://jd.bukkit.org/dev/apidocs/
Gecco1234 AdamQpzm It's cute how you guys didn't even read the code. Hint: line 32 Not sure if you can register every single event - you could try with just the base Event and see if it gets captured with an @EventHandler.
jkctech getConfig().getString("players").contains(p.getName()) is your problem. You are returning a string, not a string list. use getStringList or similar EDIT: Also, the way you register players, you need to seek the path "players."+event.getName() or whatever it is you set it to. Please read up on how YML data is stored and how to access it.
Zethariel AdamQpzm ive added this debug code: Code:java p.sendMessage(ChatColor.GREEN+getConfig().getString("players")); p.sendMessage(ChatColor.GREEN+p.getName()); the getconfig part returns a strange thing: MemorySection[path='players', root='YamlConfiguration'] the second part returns jkctech, which is correct. what am i doing wrong? also, im an autistic 14 YO XD, can somebody make an example code for me?
jkctech Who you are and what age is kinda irrelevant, but whatevs >.> MemorySection means that the path you are accessing does not contain a value, and instead contains child nodes. You need to access the child nodes and read those values. As said before, read the documentation about YamlConfiguration, storing data in YML files in general. The Bukkit Wiki is a good place to start.
Zethariel AdamQpzm this is my YAML code: Code: players: Notch: password: HELLEU! jkctech: password: lolz please, i cant seem to get it working, can somebody help me with this?
jkctech Try this, instead of your if: Code: if(getConfig().contains("players." + p.getName()) { //your code } Then read this and switch to UUIDs.
AdamQpzm hello, ive got this code: Code: @EventHandler public void onplayerjoin(PlayerJoinEvent event){ Player p = event.getPlayer(); if(getConfig().contains("players." + p.getName())){ hasToLogin.add(p); p.sendMessage(ChatColor.GOLD+"[JKC Login] "+ChatColor.DARK_RED+"You need to login!"); } } //Alle Events @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); String name = player.getName(); Location from = event.getFrom(); Location to = event.getTo().clone(); if (hasToLogin.contains(name)) { to.setX(from.getX()); to.setZ(from.getZ()); event.setTo(to); } } but they both only partialy work, the onplayerjoin works, if i am in the config, i will get a message and i will be added to array.(im not sure if im actually added to array, because i dont know how to debug it.) the onmoveevent also works, but only if i remove the if statement. so i think i messed up the array. what am i doing wrong with the array? ive created it like this: Code: List<Player> hasLoggedIn = new ArrayList<Player>(); List<Player> hasToLogin = new ArrayList<Player>(); thanks in advance!