Solved Fixed <3

Discussion in 'Plugin Development' started by Monkey_Swag, Nov 5, 2014.

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

    Monkey_Swag

  2. Offline

    Europia79

    Monkey_Swag

    Use the config to make the Deathban length configurable. But I wouldn't save any player information in the config. Also, I don't really think you need to persist this data. So just save it in memory. Server restarts shouldn't happen too frequently... And if a server reset does happen, then players who are Deathbanned just get a lucky break imo.

    Code:java
    1. package tld.yourdomain.yourproject;
    2.  
    3. import java.util.HashMap;
    4. import java.util.Map;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.entity.PlayerDeathEvent;
    9. import org.bukkit.event.player.PlayerJoinEvent;
    10.  
    11. /**
    12. *
    13. * @author Nikolai
    14. */
    15. public class Listeners implements Listener {
    16.  
    17. /**
    18.   * A list of banned players and the time that they were banned. <br/>
    19.   */
    20. private final Map<String, Long> players = new HashMap<String, Long>();
    21. private final long SECONDS;
    22.  
    23. /**
    24.   * Constructor. <br/>
    25.   *
    26.   * @param duration in seconds.
    27.   */
    28. public Listeners(long duration) {
    29. this.SECONDS = duration;
    30. }
    31.  
    32. @EventHandler
    33. public void onPlayerDeath(PlayerDeathEvent e) {
    34. Player player = e.getEntity();
    35. String name = e.getEntity().getName();
    36. long start = System.currentTimeMillis();
    37. players.put(name, start);
    38. player.kickPlayer("§cDeathbanned: §l" + (SECONDS / 60) + " minutes.");
    39. }
    40.  
    41. @EventHandler
    42. public void onPlayerJoin(PlayerJoinEvent e) {
    43. Player p = e.getPlayer();
    44. if (players.containsKey(p.getName())) {
    45. long start = players.get(p.getName());
    46. long end = System.currentTimeMillis();
    47. long duration = (end - start) / 1000;
    48. if (duration < SECONDS) {
    49. long minutes = (SECONDS - duration) / 60;
    50. p.kickPlayer("§cYou are still Deathbanned for §l"
    51. + minutes + " minutes.");
    52. } else {
    53. players.remove(p.getName());
    54. }
    55. }
    56. }
    57.  
    58. }
    59.  
     
  3. Offline

    Barinade

    Move the line that kicks them to the end of the event handler, and store their time at which they will be unbanned instead
     
  4. Offline

    Monkey_Swag

    So... I went to sleep, got up, tried to fix it myself, fixed it, aaaaand now I'm here. Hi :3

    SLEEPING MAKES YOU WISE
     
  5. Offline

    teej107

    Sometimes it helps to just get away from coding and unwind a bit. It's how I solve some of my programming issues and I wonder how I even missed my mistake in the first place.
     
  6. Offline

    Rocoty

    Don't do that please. What if someone else with a similar problem came around? Would you deny them help? Instead of removing the entire post, how about editing it with your solution at the bottom? That way people with the same problem will immediately find a solution and the help comes from you.
     
    Europia79 likes this.
Thread Status:
Not open for further replies.

Share This Page