2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2015-10-19 17:43:46 +00:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2016-03-01 16:47:01 +00:00
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class Announcer extends FreedomService
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
private final List<String> announcements = Lists.newArrayList();
|
|
|
|
private boolean enabled;
|
|
|
|
private long interval;
|
|
|
|
private String prefix;
|
2016-03-01 16:47:01 +00:00
|
|
|
private BukkitTask announcer;
|
2015-10-19 17:43:46 +00:00
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
|
|
|
enabled = ConfigEntry.ANNOUNCER_ENABLED.getBoolean();
|
|
|
|
interval = ConfigEntry.ANNOUNCER_INTERVAL.getInteger() * 20L;
|
|
|
|
prefix = FUtil.colorize(ConfigEntry.ANNOUNCER_PREFIX.getString());
|
|
|
|
|
|
|
|
announcements.clear();
|
|
|
|
for (Object announcement : ConfigEntry.ANNOUNCER_ANNOUNCEMENTS.getList())
|
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
announcements.add(FUtil.colorize((String)announcement));
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
announcer = new BukkitRunnable()
|
|
|
|
{
|
|
|
|
private int current = 0;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
current++;
|
|
|
|
|
|
|
|
if (current >= announcements.size())
|
|
|
|
{
|
|
|
|
current = 0;
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
announce(announcements.get(current));
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
2016-05-12 19:40:39 +00:00
|
|
|
}.runTaskTimer(plugin, interval, interval);
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
|
|
|
if (announcer == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
FUtil.cancel(announcer);
|
|
|
|
announcer = null;
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> getAnnouncements()
|
|
|
|
{
|
|
|
|
return Collections.unmodifiableList(announcements);
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
public void announce(String message)
|
|
|
|
{
|
|
|
|
FUtil.bcastMsg(prefix + message);
|
|
|
|
}
|
|
|
|
|
2020-12-25 19:46:43 +00:00
|
|
|
public boolean isEnabled()
|
|
|
|
{
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getInterval()
|
|
|
|
{
|
|
|
|
return interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPrefix()
|
|
|
|
{
|
|
|
|
return prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BukkitTask getAnnouncer()
|
|
|
|
{
|
|
|
|
return announcer;
|
|
|
|
}
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|