2022-04-24 12:15:45 +00:00
|
|
|
package dev.plex;
|
|
|
|
|
2022-04-27 23:44:25 +00:00
|
|
|
import dev.plex.handler.CommandHandler;
|
|
|
|
import dev.plex.handler.ListenerHandler;
|
2022-04-24 12:15:45 +00:00
|
|
|
import dev.plex.permission.PermissionHandlerImpl;
|
2022-04-24 13:51:12 +00:00
|
|
|
import dev.plex.player.ISunburstPlayer;
|
2022-04-24 12:15:45 +00:00
|
|
|
import dev.plex.player.PlayerCache;
|
2022-04-24 13:51:12 +00:00
|
|
|
import dev.plex.player.SunburstPlayer;
|
2022-04-24 14:23:59 +00:00
|
|
|
import dev.plex.plugin.SunburstPlugin;
|
2022-04-24 12:15:45 +00:00
|
|
|
import dev.plex.storage.FileStorage;
|
2022-04-24 14:23:59 +00:00
|
|
|
import dev.plex.util.ComponentUtil;
|
2022-04-24 12:15:45 +00:00
|
|
|
import dev.plex.util.Configuration;
|
2022-04-24 23:34:42 +00:00
|
|
|
import dev.plex.util.Logger;
|
2022-04-25 03:02:39 +00:00
|
|
|
import dev.plex.world.JsonWorldManager;
|
|
|
|
import lombok.AccessLevel;
|
2022-04-24 12:15:45 +00:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2022-04-24 14:23:59 +00:00
|
|
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
2022-04-24 13:51:12 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2022-04-24 12:15:45 +00:00
|
|
|
|
|
|
|
@Getter
|
|
|
|
@Setter
|
2022-04-24 14:23:59 +00:00
|
|
|
public final class Sunburst extends SunburstPlugin
|
2022-04-24 12:15:45 +00:00
|
|
|
{
|
|
|
|
private static Sunburst plugin;
|
|
|
|
|
|
|
|
private final PlayerCache playerCache = new PlayerCache();
|
|
|
|
|
|
|
|
private Configuration configuration;
|
2022-04-24 13:51:12 +00:00
|
|
|
private Configuration messages;
|
2022-04-24 12:15:45 +00:00
|
|
|
|
2022-04-25 03:02:39 +00:00
|
|
|
@Getter(AccessLevel.NONE)
|
|
|
|
private JsonWorldManager jsonWorldManager;
|
2022-04-24 12:15:45 +00:00
|
|
|
|
|
|
|
@Override
|
2022-04-24 14:23:59 +00:00
|
|
|
public void load()
|
2022-04-24 12:15:45 +00:00
|
|
|
{
|
|
|
|
plugin = this;
|
|
|
|
this.configuration = new Configuration(this, "config.yml");
|
2022-04-24 13:51:12 +00:00
|
|
|
this.messages = new Configuration(this, "messages.yml");
|
|
|
|
|
|
|
|
this.configuration.load();
|
|
|
|
this.messages.load();
|
|
|
|
|
2022-04-24 14:23:59 +00:00
|
|
|
this.getObjectHolder().setPermissionHandler(new PermissionHandlerImpl());
|
2022-04-27 23:44:25 +00:00
|
|
|
this.getObjectHolder().setChatRenderer((source, sourceDisplayName, message, viewer) ->
|
|
|
|
{
|
2022-04-24 23:34:42 +00:00
|
|
|
Logger.log("Spokenz");
|
|
|
|
Logger.log(ComponentUtil.mmCustom(sourceDisplayName, ComponentUtil.REGULAR_TAGS));
|
|
|
|
return ComponentUtil.configComponent("chatFormat",
|
|
|
|
ComponentUtil.REGULAR_TAGS,
|
|
|
|
ComponentUtil.mmCustom(sourceDisplayName, ComponentUtil.REGULAR_TAGS),
|
|
|
|
PlainTextComponentSerializer.plainText().serialize(message));
|
|
|
|
});
|
|
|
|
|
|
|
|
Logger.debug("Loading");
|
2022-04-24 12:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2022-04-27 23:44:25 +00:00
|
|
|
new ListenerHandler();
|
|
|
|
new CommandHandler();
|
|
|
|
|
2022-04-24 14:23:59 +00:00
|
|
|
this.getObjectHolder().setStorageSystem(new FileStorage());
|
2022-04-25 03:02:39 +00:00
|
|
|
this.jsonWorldManager = new JsonWorldManager();
|
2022-04-24 13:51:12 +00:00
|
|
|
|
|
|
|
Bukkit.getOnlinePlayers().forEach(player ->
|
|
|
|
{
|
2022-04-24 14:23:59 +00:00
|
|
|
ISunburstPlayer sunburstPlayer = plugin.getObjectHolder().getStorageSystem().getPlayer(player.getUniqueId());
|
2022-04-24 13:51:12 +00:00
|
|
|
if (sunburstPlayer == null)
|
|
|
|
{
|
|
|
|
sunburstPlayer = new SunburstPlayer(player.getUniqueId(), player.getName(), player.getAddress().getAddress().getHostAddress());
|
2022-04-24 14:23:59 +00:00
|
|
|
plugin.getObjectHolder().getStorageSystem().createPlayer(sunburstPlayer);
|
2022-04-24 13:51:12 +00:00
|
|
|
}
|
|
|
|
plugin.getPlayerCache().addPlayer(sunburstPlayer);
|
|
|
|
if (sunburstPlayer.displayName() != null)
|
|
|
|
{
|
|
|
|
player.displayName(sunburstPlayer.displayName());
|
|
|
|
}
|
|
|
|
});
|
2022-04-24 12:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable()
|
|
|
|
{
|
2022-04-27 23:44:25 +00:00
|
|
|
plugin.getPlayerCache().getPlayers().forEach(sunburstPlayer ->
|
|
|
|
{
|
2022-04-24 14:23:59 +00:00
|
|
|
plugin.getObjectHolder().getStorageSystem().updatePlayer(sunburstPlayer);
|
2022-04-24 13:51:12 +00:00
|
|
|
});
|
2022-04-24 12:15:45 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 03:02:39 +00:00
|
|
|
@Override
|
|
|
|
public JsonWorldManager getWorldManager()
|
|
|
|
{
|
|
|
|
return jsonWorldManager;
|
|
|
|
}
|
|
|
|
|
2022-04-24 12:15:45 +00:00
|
|
|
public static Sunburst inst()
|
|
|
|
{
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
}
|