Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Clase UpdateEvent.
- package me.gonzalociocca.minelevel.core.updater;
- import me.gonzalociocca.minelevel.core.updater.UpdateType;
- import org.bukkit.event.Event;
- import org.bukkit.event.HandlerList;
- public class UpdateEvent extends Event
- {
- private static final HandlerList handlers = new HandlerList();
- private final UpdateType _type;
- public UpdateEvent(UpdateType example)
- {
- _type = example;
- }
- public UpdateType getType()
- {
- return _type;
- }
- @Override
- public HandlerList getHandlers()
- {
- return handlers;
- }
- public static HandlerList getHandlerList()
- {
- return handlers;
- }
- }
- // Clase Updater
- package me.gonzalociocca.minelevel.core.updater;
- import me.gonzalociocca.minelevel.core.updater.UpdateEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Updater
- implements Runnable
- {
- private JavaPlugin _plugin;
- public Updater(JavaPlugin plugin)
- {
- _plugin = plugin;
- plugin.getServer().getScheduler().scheduleSyncRepeatingTask(_plugin, this, 0L, 20L);
- }
- @Override
- public void run()
- {
- for (UpdateType updateType : UpdateType.values())
- {
- if (updateType.Elapsed())
- {
- _plugin.getServer().getPluginManager().callEvent(new UpdateEvent(updateType));
- }
- }
- }
- }
- //Clase UpdateType
- package me.gonzalociocca.minelevel.core.updater;
- import me.gonzalociocca.minelevel.core.updater.UtilTime;
- public enum UpdateType
- {
- MIN1y2(90000L),
- MIN1(60000L),
- SLOW2(8000L),
- SEC3(3000L),
- SEC(1000L),
- SLOW(750L),
- FAST(150L);
- private final long _time;
- private long _last;
- private long _timeSpent;
- private long _timeCount;
- private UpdateType(long time) { _time = time;
- _last = System.currentTimeMillis();
- }
- public boolean Elapsed()
- {
- if (UtilTime.elapsed(_last, _time))
- {
- _last = System.currentTimeMillis();
- return true;
- }
- return false;
- }
- public void StartTime()
- {
- _timeCount = System.currentTimeMillis();
- }
- public void StopTime()
- {
- _timeSpent += System.currentTimeMillis() - _timeCount;
- }
- public void PrintAndResetTime()
- {
- System.out.println(name() + " in a second: " + _timeSpent);
- _timeSpent = 0L;
- }
- }
- //Evento de prueba
- boolean gameEnabled = false;
- @EventHandler
- public void onEvento(UpdateEvent event){
- if(event.getType().equals(UpdateType.SEC)){
- if(!gameEnabled){
- return;}
- for(Player p : Bukkit.getOnlinePlayers()){
- if(!this.isInside(p.getLocation()){
- this.getEvent().remove(p);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment