This commit is contained in:
parent
afa69c059b
commit
2ded40ca0f
2 changed files with 14 additions and 5 deletions
|
@ -96,4 +96,8 @@ public class TweaksPlugin extends JavaPlugin {
|
||||||
|
|
||||||
getLogger().info("Took %.3f milliseconds".formatted((System.nanoTime() - start) / 1000000.0));
|
getLogger().info("Took %.3f milliseconds".formatted((System.nanoTime() - start) / 1000000.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasResource(String resource) {
|
||||||
|
return this.getClassLoader().getResource(resource) != null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import com.comphenix.protocol.events.*;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
import eu.m724.tweaks.TweaksConfig;
|
||||||
|
import eu.m724.tweaks.TweaksPlugin;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.SharedConstants;
|
||||||
|
@ -28,11 +29,11 @@ import java.util.Optional;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class MotdManager {
|
public class MotdManager {
|
||||||
private final Plugin plugin;
|
private final TweaksPlugin plugin;
|
||||||
|
|
||||||
private Component[] motds;
|
private Component[] motds;
|
||||||
|
|
||||||
public MotdManager(Plugin plugin) {
|
public MotdManager(TweaksPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,14 +41,18 @@ public class MotdManager {
|
||||||
// TODO adding more MOTD features would require checking whether to enable set
|
// TODO adding more MOTD features would require checking whether to enable set
|
||||||
|
|
||||||
String motdSetName = TweaksConfig.getConfig().motdSet();
|
String motdSetName = TweaksConfig.getConfig().motdSet();
|
||||||
File motdSetsFile = new File(plugin.getDataFolder() + "/motd sets/" + motdSetName + ".txt");
|
String motdSetPath = "motd sets/" + motdSetName + ".txt";
|
||||||
|
File motdSetsFile = new File(plugin.getDataFolder(), motdSetPath);
|
||||||
|
|
||||||
|
// create "motd sets" directory
|
||||||
motdSetsFile.getParentFile().mkdirs();
|
motdSetsFile.getParentFile().mkdirs();
|
||||||
|
|
||||||
// if this is a builtin set
|
// if this is a builtin set
|
||||||
plugin.saveResource("motd sets/" + motdSetName + ".txt", false);
|
if (!motdSetsFile.exists() && plugin.hasResource(motdSetPath))
|
||||||
|
plugin.saveResource(motdSetPath, false);
|
||||||
|
|
||||||
if (!motdSetsFile.exists()) {
|
if (!motdSetsFile.exists()) {
|
||||||
throw new RuntimeException("MOTD set \"%s\" doesn't exist (%s)".formatted(motdSetName, motdSetsFile.getPath()));
|
throw new RuntimeException("MOTD set \"%s\" doesn't exist".formatted(motdSetName));
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileContent = Files.readString(motdSetsFile.toPath());
|
String fileContent = Files.readString(motdSetsFile.toPath());
|
||||||
|
|
Loading…
Reference in a new issue