TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/Announcer.java
Paldiu 5c0f77c7c5 Removal of Lombok
Lombok implementation removal.

I have also gone through and replaced things with inline methods and variables, lambdas, and simplified loops down, removed unnecessary guard clauses, and overall cleaned up every single class. This took a long time, please do remember to follow proper naming conventions, don't include unnecessary guard clauses, follow exception rules and comment rules, and please PLEASE remember to use the DIAMOND OPERATOR rather than just inferring RAW TYPES!!!

Thank you!!
2020-12-25 14:46:43 -05:00

99 lines
2.1 KiB
Java

package me.totalfreedom.totalfreedommod;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
public class Announcer extends FreedomService
{
private final List<String> announcements = Lists.newArrayList();
private boolean enabled;
private long interval;
private String prefix;
private BukkitTask announcer;
@Override
public void onStart()
{
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())
{
announcements.add(FUtil.colorize((String)announcement));
}
if (!enabled)
{
return;
}
announcer = new BukkitRunnable()
{
private int current = 0;
@Override
public void run()
{
current++;
if (current >= announcements.size())
{
current = 0;
}
announce(announcements.get(current));
}
}.runTaskTimer(plugin, interval, interval);
}
@Override
public void onStop()
{
if (announcer == null)
{
return;
}
FUtil.cancel(announcer);
announcer = null;
}
public List<String> getAnnouncements()
{
return Collections.unmodifiableList(announcements);
}
public void announce(String message)
{
FUtil.bcastMsg(prefix + message);
}
public boolean isEnabled()
{
return enabled;
}
public long getInterval()
{
return interval;
}
public String getPrefix()
{
return prefix;
}
public BukkitTask getAnnouncer()
{
return announcer;
}
}