56 lines
1.7 KiB
Java
56 lines
1.7 KiB
Java
package net.rubeta.legacyping;
|
|
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.logging.Level;
|
|
|
|
public final class LegacyPing extends JavaPlugin {
|
|
private final List<ServerThread> threads = new ArrayList<>();
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
this.saveDefaultConfig();
|
|
this.startThreads();
|
|
}
|
|
|
|
private void startThreads() {
|
|
final FileConfiguration config = this.getConfig();
|
|
final String host = config.getString("host", "0.0.0.0");
|
|
final List<Integer> ports = config.getIntegerList("port");
|
|
final String version = config.getString("displayedVersion", "b1.7.3");
|
|
final int protocol = config.getInt("displayedProtocol", 17);
|
|
for (int port : ports) {
|
|
try {
|
|
this.threads.add(new ServerThread(this, host, port, version, protocol));
|
|
} catch (IOException e) {
|
|
this.getLogger().log(Level.WARNING, "Failed to create ServerSocket", e);
|
|
}
|
|
}
|
|
this.threads.forEach(Thread::start);
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
this.threads.forEach(ServerThread::shutdown);
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
if (!sender.isOp()) {
|
|
return true;
|
|
}
|
|
|
|
this.threads.forEach(ServerThread::shutdown);
|
|
this.threads.clear();
|
|
this.startThreads();
|
|
sender.sendMessage(ChatColor.GOLD + "Restarted");
|
|
return true;
|
|
}
|
|
}
|