Tempban command

Discussion in 'Spigot Plugin Development' started by fdsfa, May 28, 2017.

  1. hello other plugin developers
    i have a quistion.

    i am making an admin plugin.
    but i hav som broblem with tempban
    i wrote some codes and both of them didnt work
    the were all with a time loop but when the time stopped it didnt unban them
    so my quistion is can you guys make somting

    on this
    the config must be bans

    Code (Text):
    import me.bobby.plugin.com.commands.*;
    import me.bobby.plugin.com.config.ConfigFile;
    import me.bobby.plugin.com.event.PlayerJoin;
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;

    /**
    * This class was created on 1/12/2017 in the project Bukkit Tutorials by DeveloperB.
    */
    public class Main extends JavaPlugin {

        private static ConfigFile bans;

        @Override
        public void onEnable() {

            Bukkit.getServer().getLogger().info("plugin gemaakt door Bobby");
            Bukkit.getServer().getLogger().info("minecraft ItzAPranko");

            bans = new ConfigFile(this, "Bans");
            getCommand("kick").setExecutor(new KickCommand());
            new BanCommand(this);
            new AntiCurse(this);
            new PlayerJoin(this);
            new UnbanCommand(this);

            getConfig().options().copyDefaults(true);
            saveConfig();

        }

        public static ConfigFile getBans() {
            return bans;
        }
    }
     
    Code (Text):
    import me.bobby.plugin.com.Main;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    /**
    * This class was created on 1/8/2017 in the project Bukkit Tutorials by DeveloperB.
    */
    public class PlayerJoin implements Listener {

        private Main plugin;

        public PlayerJoin(Main plugin) {
            this.plugin = plugin;
            Bukkit.getPluginManager().registerEvents(this, plugin);
        }

        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player player = e.getPlayer();

            if (plugin.getConfig().getConfigurationSection("banned_players") != null) {
                for (String section : plugin.getConfig().getConfigurationSection("banned_players").getKeys(false)) {
                    if (section.equals(player.getName())) {
                        player.kickPlayer(ChatColor.RED + "You are banned from the server!\nBy: " + plugin.getConfig().getString("banned_players." + player.getName() + ".banner") + "\nReason: " + plugin.getConfig().getString("banned_players." + player.getName() + ".reason"));
                    }
                }
            }
        }
    }
     
    Code (Text):
    public class ConfigFile {

        private File file;
        private FileConfiguration config;

        public ConfigFile(Plugin plugin, String fileName) {
            if (!plugin.getDataFolder().exists()) {
                plugin.getDataFolder().mkdir();
            }

            file = new File(plugin.getDataFolder(), fileName+".yml");

            if(!file.exists()){
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            config = YamlConfiguration.loadConfiguration(file);

        }

        public void set(String path, Object value) {
            config.set(path, value);

        }

        public Object get(String path) {
            return config.get(path);
        }

        public boolean contains(String path) {
            return config.contains(path);
        }

        public ConfigurationSection createSection(String path) {
            ConfigurationSection section =  config.createSection(path);
            save();
            return section;
        }

        public Set<String> getKeys(String path) {
            return config.getConfigurationSection(path).getKeys(false);
        }

        public void save() {
            try {
                config.save(file);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
     
  2. First off, don't kick a player when they join, disallow their login event :/. Also, don't do those null checks on join, do that on enable. And for tempbans, just compare system times.
     
    • Agree Agree x 1
  3. the null checks are fore the unban command