Can someone explain/give an example on how to ban players on death and then each time the server restarts unban all the players that were banned last time?
You dont have to unban all players on startup, only unban them when they try to join the server if enough time has passed or whatever reason
Add the player to a list of banned people and then add a listener for when someone joins/logs in. If that player is on the banned list, kick them.
Are you sure as set banned doesn't kick them you have to kick the player first but adding to a list and using a listener is the better option.
If you don't want to restart your server at certain points every time just to unban players, you can use Timers in Java to tick after so many hours/days/etc.
ok, i got this one guys. CHECK A FEW POSTS DOWN Code: onEnable(){ //do some function here that unbans everyone. //you may want so save an array of all the banned players each time a player death occurs. //then access it on load and foreach player execute command /unban playername } public void onPlayerDeath(PlayerDeathEvent event){ Player player = event.getPlayer(); String playername = player.getName(); execute command /ban playername }
@kamikazi3728 The unban should be executed in the disable method instead. Otherwise, he would have to save the list in a file while the server is off and also instead of executing the command, he could just do Code: player.setBanned(false);
Code: //declare the line below outside of any methods, preferably above all of them. //"public" may or may not be needed before String[] List banlist = new ArrayList(); onEnable(){ } onDisable(){ for (string bannedplayer: banlist){ bannedplayer.setBanned(false); } } public void onPlayerDeath(PlayerDeathEvent event){ Player player = event.getPlayer(); String playername = player.getName(); banlist.add(playername); playername.setBanned(true); }
Arrays don't have an add() method. You would need to use a List of some sort. I personally would use an ArrayList.