[STILL NOT SOLVED] Small bug, need help

Discussion in 'Plugin Development' started by TheFl4me, Feb 25, 2015.

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

    TheFl4me

    Basically on my plugin each time a new player joins the server it will generate a file with his name and inside will also be his UUID.

    If a player gets banned it will add a string in that file: "banned: true"
    the problem im having is that im trying to make it so that when a player joins and is not banned it will set a string "banned: false" but im having problems with this.

    here are all my classes:

    JoinQuitListener:

    Code:
    package Listeners;
    
    import java.io.File;
    import java.io.IOException;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    
    import AdminMode.Admin;
    import AdminMode.Invis;
    import AdminMode.Watch;
    import KitPvP.AFK;
    import KitPvP.Fly;
    import Main.Utils;
    
    public class JoinQuitListener implements Listener {
      
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            File spawnfile = new File("plugins//KitPvP//spawn.yml");
            if(!spawnfile.exists()){
                return;
            }
            YamlConfiguration cfg = YamlConfiguration.loadConfiguration(spawnfile);
            Location loc = p.getLocation();
            double x = cfg.getDouble("X");
            double y = cfg.getDouble("Y");
            double z = cfg.getDouble("Z");
            double yaw = cfg.getDouble("Yaw");
            double pitch = cfg.getDouble("Pitch");
            String worldname = cfg.getString("Worldname");
          
            World world = Bukkit.getWorld(worldname);
          
            loc.setX(x);
            loc.setY(y);
            loc.setZ(z);
            loc.setYaw((float) yaw);
            loc.setPitch((float) pitch);
            loc.setWorld(world);
          
            p.teleport(loc);
          
            try {
                File file = new File("plugins//KitPvP//userdata//"+p.getName()+".yml");
                if(!file.exists()) {
                    file.createNewFile();
                }
                YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file);
                cfg1.set("UUID", p.getUniqueId().toString());
                cfg1.save(file);
            }
            catch (IOException event) {
                p.sendMessage("§4Directory was not found");
            }
        }
    }
    Code:
    package Listeners;
    
    import java.io.File;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    public class BanListener implements Listener {
    
        @EventHandler
        public void onBannedJoin(PlayerJoinEvent e) {
            File file = new File("plugins//KitPvP//userdata//"+e.getPlayer().getName()+".yml");
            if(!file.exists()) {
                return;
            }
            YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
            if(cfg.getString("UUID").equals(e.getPlayer().getUniqueId().toString())) {
                if(cfg.getString("banned").equals("true")) {
                    if(cfg.getString("hacking").equals("true")) {
                        e.getPlayer().kickPlayer("You have been banned for cheating \n \n§7UUID: " + e.getPlayer().getUniqueId().toString());
                    }
                    else {
                        e.getPlayer().kickPlayer("You have been banned for " + cfg.getString("reason") + "\n\n §7UUID: " + cfg.getString("UUID"));
                    }
                }
            }
            if(cfg.getString("banned").equals("true")) {
                if(cfg.getString("hacking").equals("true")) {
                    e.getPlayer().kickPlayer("You have been banned for cheating \n \n§7UUID: " + e.getPlayer().getUniqueId().toString());
                }
                else {
                    e.getPlayer().kickPlayer("You have been banned for " + cfg.getString("reason") + "\n\n §7UUID: " + cfg.getString("UUID"));
                }      
            }
        }
    }

    EDIT: also everytime a non-banned player joined a error appears in the console
     
  2. Offline

    tomudding

    First generate a file with the players UUID as name instead of his name because of name changes etc...
     
  3. Offline

    TheFl4me

    No need, the plugin checks if the player is banned based on if the players UUID matches the one in his file at the UUID string.

    check in the BanListener at line 18
     
  4. @TheFl4me When creating the file, just set the Boolean banned to false.
     
  5. Offline

    RainoBoy97

    @TheFl4me
    If a player changes name after being banned, they will be able to log in. Because you're using the players name as the file name, meaning if they change their name it wont get the same file.
     
  6. Offline

    TheFl4me

    how could i fix this? is there a way besides renaming the file? because i already know the renaming the file would work but the reason i tried doing it this way is because when alot of people are banned i just want to be able to fin there file quickly :/

    btw thanks @CodePlaysMinecraft it worked :) im still gonna keep this as a ongoing problem though because of the new UUID problem :/
     
  7. Offline

    SuperOriginal

    This is just from off the top of my head, but you could format the file names to be user readable friendly as well as contain their uuid, (ex. 155131-1235435-021354[notch]), and you could implement something that changes the name if their uuid doesn't match the name in the file etc
     
  8. Offline

    TheFl4me

    but how would i do it so that the ban listener knows the difference between the name and the UUID?
     
  9. Offline

    SuperOriginal

    It doesn't need to know if the exact file name is the uuid, it just needs to know if it contains() it
     
  10. Offline

    RainoBoy97

    @TheFl4me
    Use the UUID as the file name instead of the name.
     
  11. Offline

    TheFl4me

    i really like the idea of @SuperOriginal but i am still trying to find out how to make the plugin check if the UUID is contained in the file name. (i did not find anything called contains())

    EDIT: i did find contains() but when i do:

    Code:
    if(file.getName().contains(p.getUniqueId())) {
    it puts an error saying:
    The method contains(CharSequence) in the type String is not applicable for the arguments (UUID)

    EDIT NUMBER 2: i fixed that problem with simply add .toString() behind and it works :) but now i have another problem for my unban and offlineban cmds since previoulsy they would get args[0] and check if a file equal to args[0] existed but now that wont work anymore (args[0] is the playername)
     
    Last edited: Feb 26, 2015
Thread Status:
Not open for further replies.

Share This Page