Plugin Help Temportaty Stuff

Discussion in 'Plugin Help/Development/Requests' started by bubblefat_, Feb 17, 2015.

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

    bubblefat_

    I am making a Mute plugin and I need to know how to temporary mute someone. I don't need to know how to make a command like /mute <player> <time> <timeformat> <reason> I need to know how to make a command like /tempmute <number> <player> <reason> basically there there are 2 numbers 1 is 1 hour 2 is 1 day, right now the command I have is /mute <player> <reason> so I don't need to know that.
     
  2. Offline

    pie_flavor

    @bubblefat_ Make an ArrayList<UUID> and store a player's UUID in it. Check for a chat event, and if the list contains their UUID then cancel the event. And when you put the UUID in it, use a BukkitRunnable to take the UUID back out after 1 hour / 1 day (72000L ticks and 1728000 ticks respectively).
     
  3. Offline

    TheEntropy

    The simplest way I can think of temp-muting someone is taking the amount of house/minutes/days/etc. you want to mute that player for and use them with the Calendar class in java.

    Code:
    // create the Calendar and set its time
    Calendar muteUntil = Calendar.getInstance();
    muteUntil.setTime(new Date());
    
    From there you add the amount of time you want to temp ban to be

    Code:
    
    int hours = 1;
    int minutes = 5;
    
    muteUntil.add(Calendar.HOUR_OF_DAY, hours);
    muteUntil.add(Calendar.MINUTE, minutes);
    
    
    Then, you can check to see if the player is unmuted by comparing the date you created (with the calendar class) to the actual date.

    Code:
    
    Date actualDate = new Date();
    
    if (muteUntil.before(actualDate)) {
        // put code here to unmute player
    }
    
    It's up to you on how you want to check if the player is still muted or not
     
  4. Offline

    pie_flavor

    @TheEntropy Actually, schedulers would be simpler. Also, wouldn't that be changing the system time?
     
  5. Offline

    TheEntropy

    @pie_flavor Not entirely sure, I've used it in the past and it has worked fine for long-term temp bans
     
  6. Offline

    pie_flavor

    @TheEntropy I suppose the task might get canceled somehow, but schedulers are part of the api
     
  7. Offline

    TheEntropy

    @pie_flavor I have nothing against schedulers, but I don't find them useful for delaying anything past an hour. If the mutes would only last around 5-10 minutes, then I think it would be appropriate to use schedulers, but there is always the danger of the server getting restarted and those scheduled events being lost. Overall I see no flaw in using your method. Also, it is much simpler.
     
  8. Offline

    pie_flavor

    @TheEntropy If the server reloads, the scheduled events are lost. If the server restarts, then so is the List, so what's the harm there? :)
     
  9. Offline

    TheEntropy

    @pie_flavor You can easily store the date when the player is supposed to be unmuted in a config file at the time of the player mute. You can then have your onEnable() method reload those dates into some type of array or hashmap to continue checking for the player unmute.
     
Thread Status:
Not open for further replies.

Share This Page