-
-
Save EdGruberman/3074230 to your computer and use it in GitHub Desktop.
SimpleSave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.sonarbeserk.simplesave; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
import org.bukkit.Bukkit; | |
import org.bukkit.ChatColor; | |
import org.bukkit.configuration.ConfigurationSection; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class SimpleSave extends JavaPlugin { | |
private final static long TICKS_PER_SECOND = 20; | |
private final static long INITIAL_DELAY = 40; | |
@Override | |
public void onEnable() { | |
this.getConfig().options().copyDefaults(true); | |
this.getConfig().options().copyHeader(true); | |
this.saveConfig(); | |
final ConfigurationSection config = this.getConfig(); | |
final TimeUnit unit = TimeUnit.valueOf(config.getString("delayUnit", TimeUnit.SECONDS.name())); | |
final long delayTime = unit.toSeconds(config.getLong("delay")) * SimpleSave.TICKS_PER_SECOND; | |
final List<String> msgs = config.getStringList("messages"); | |
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BroadcastMessage(msgs), SimpleSave.INITIAL_DELAY, delayTime); | |
} | |
private class BroadcastMessage implements Runnable { | |
private final List<String> msgs; | |
BroadcastMessage(final List<String> msgs) { | |
this.msgs = msgs; | |
} | |
@Override | |
public void run() { | |
for(final String savemsg: this.msgs) { | |
final String formatedmsg = ChatColor.translateAlternateColorCodes('&', savemsg); | |
Bukkit.broadcastMessage(formatedmsg); | |
} | |
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "save-all"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment