[Not Solved] Signs not working

Discussion in 'Spigot Plugin Development' started by Dartanman, Jun 7, 2016.

  1. Hey guys! Basically, when you right click a sign that says
    Line 1: [FrostPvP]
    Line 2: [Start]
    Lines 3 and 4 don't matter
    it should teleport you (assuming you are on a team).
    For some reason, no matter what, it tells you "You are not in a game", regardless of the fact that they might be on a team. Please help!
    The code you need is at:
    #1 Dartanman, Jun 7, 2016
    Last edited: Jun 7, 2016
  2. Make return statements + Else if statements.
  3. Code (Text):

    public void onInteract(PlayerInteractEvent event){
    FileConfiguration config = plugin.getConfig();
    Player player = (Player) event.getPlayer();
    if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if(event.getClickedBlock().getType() == Material.SIGN ||
    event.getClickedBlock().getType() == Material.WALL_SIGN ||
    event.getClickedBlock().getType() == Material.SIGN_POST){
    Sign sign = (Sign) event.getClickedBlock().getState();
    if(sign.getLine(0).equalsIgnoreCase("[FrostPvP]") && sign.getLine(1).equalsIgnoreCase("[Start]")){
    Location newLoc3 = new Location(Bukkit.getWorld((String) config.get("location3.World")), config.getDouble("location3.X"), config.getDouble("location3.Y"), config.getDouble("location3.Z"));
    player.sendMessage(ChatColor.GREEN + "The game is starting");
    else if(blue.contains(player)){
    Location newLoc4 = new Location(Bukkit.getWorld((String) config.get("location4.World")), config.getDouble("location4.X"), config.getDouble("location4.Y"), config.getDouble("location4.Z"));
    player.sendMessage(ChatColor.GREEN + "The game is starting");
    } else{
    player.sendMessage(ChatColor.RED + "You are not in a game!");
    That doesn't work either
  4. Still not working
  5. Try having the console broadcast messages after each if-statement to see which lines of code are and are not firing. Then you'll know if you have an if-statement that isn't working as intended.
  6. I did that, it's the if(blue.contains...... and the if(red.contains......
  7. Do you get any console errors after clicking the sign?
  8. Oh, I see you issue (I think). You are having your data and event handler in the same class. Java is an OOP language, so it likes to make objects whenever something gets created. When your onEnable creates the class that contains your data, commands, and event handler, it creates them as separate objects, one for the commands, and one for the events. This means the data in the class, ie. the two ArrayLists of players, is separated in different objects. Firstly, create a couple new classes, one for commands, and one for events. Then put your two ArrayLists in your main class or somewhere that will be created once and never deleted with some getter and setter methods. In your command and events class just pass you main class to them like you already have and have them add/check the ArrayLists from your main. I may not bee 100% right in terms of the Java theory, but if you try what I said I think your problem should be solved. I know it might be a bit hard to understand what I mean exactly (hard to get thoughts on paper), so if you don't quite understand I'll try and reword it.
  9. May I also add @Dartanman you should probably try to use HashMaps instead of ArrayLists.
  10. No, I don't.

    I'll try that.
  11. tell me what exactly you wanna do with a few words i might be able to help
  12. @Dartanman Or, you know, create a single instance of Game, rather than two. Also
    1. Sets might be better for the job (and faster) than Lists
    2. You should use interfaces and abstract types as field types, rather than concrete classes. F.e. List vs ArrayList and Set vs HashSet.
    You do realise those are two completely different data structures, right? If he can manage with a Collection (List/Set), then there's not really a reason to start using (Hash)Maps. (unless there's a compelling reason to do so, but in the current snippet, I doubt that)