mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 10:35:18 +01:00
Adds a lot of this.
in some files
This commit is contained in:
parent
49eb5437e9
commit
b09338f78f
@ -182,31 +182,31 @@ public class SongodaCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SongodaCore() {
|
SongodaCore() {
|
||||||
commandManager = null;
|
this.commandManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
SongodaCore(JavaPlugin javaPlugin) {
|
SongodaCore(JavaPlugin javaPlugin) {
|
||||||
piggybackedPlugin = javaPlugin;
|
this.piggybackedPlugin = javaPlugin;
|
||||||
commandManager = new CommandManager(piggybackedPlugin);
|
this.commandManager = new CommandManager(this.piggybackedPlugin);
|
||||||
loginListener = new EventListener();
|
this.loginListener = new EventListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
shadingListener = new ShadedEventListener();
|
this.shadingListener = new ShadedEventListener();
|
||||||
commandManager.registerCommandDynamically(new SongodaCoreCommand())
|
this.commandManager.registerCommandDynamically(new SongodaCoreCommand())
|
||||||
.addSubCommands(new SongodaCoreDiagCommand(), new SongodaCoreUUIDCommand(), new SongodaCoreLicenseCommand());
|
.addSubCommands(new SongodaCoreDiagCommand(), new SongodaCoreUUIDCommand(), new SongodaCoreLicenseCommand());
|
||||||
Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin);
|
Bukkit.getPluginManager().registerEvents(this.loginListener, this.piggybackedPlugin);
|
||||||
Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin);
|
Bukkit.getPluginManager().registerEvents(this.shadingListener, this.piggybackedPlugin);
|
||||||
|
|
||||||
// we aggressively want to own this command
|
// we aggressively want to own this command
|
||||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
|
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
|
||||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
|
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
|
||||||
10 * 60));
|
10 * 60));
|
||||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
|
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
|
||||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
|
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
|
||||||
20 * 60));
|
20 * 60));
|
||||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
|
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
|
||||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
|
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
|
||||||
20 * 60 * 2));
|
20 * 60 * 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,17 +216,17 @@ public class SongodaCore {
|
|||||||
private void destroy() {
|
private void destroy() {
|
||||||
Bukkit.getServicesManager().unregister(SongodaCore.class, INSTANCE);
|
Bukkit.getServicesManager().unregister(SongodaCore.class, INSTANCE);
|
||||||
|
|
||||||
tasks.stream().filter(Objects::nonNull)
|
this.tasks.stream().filter(Objects::nonNull)
|
||||||
.forEach(task -> Bukkit.getScheduler().cancelTask(task.getTaskId()));
|
.forEach(task -> Bukkit.getScheduler().cancelTask(task.getTaskId()));
|
||||||
|
|
||||||
HandlerList.unregisterAll(loginListener);
|
HandlerList.unregisterAll(this.loginListener);
|
||||||
if (!hasShading()) {
|
if (!hasShading()) {
|
||||||
HandlerList.unregisterAll(shadingListener);
|
HandlerList.unregisterAll(this.shadingListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
registeredPlugins.clear();
|
registeredPlugins.clear();
|
||||||
commandManager = null;
|
this.commandManager = null;
|
||||||
loginListener = null;
|
this.loginListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<BukkitTask> tasks = new ArrayList<>();
|
private ArrayList<BukkitTask> tasks = new ArrayList<>();
|
||||||
@ -247,7 +247,7 @@ public class SongodaCore {
|
|||||||
// don't forget to check for language pack updates ;)
|
// don't forget to check for language pack updates ;)
|
||||||
info.addModule(new LocaleModule());
|
info.addModule(new LocaleModule());
|
||||||
registeredPlugins.add(info);
|
registeredPlugins.add(info);
|
||||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> update(info), 60L));
|
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> update(info), 60L));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -361,34 +361,34 @@ public class SongodaCore {
|
|||||||
boolean proto = false;
|
boolean proto = false;
|
||||||
|
|
||||||
ShadedEventListener() {
|
ShadedEventListener() {
|
||||||
via = Bukkit.getPluginManager().isPluginEnabled("ViaVersion");
|
this.via = Bukkit.getPluginManager().isPluginEnabled("ViaVersion");
|
||||||
|
|
||||||
if (via) {
|
if (this.via) {
|
||||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p, getHijackedPlugin()));
|
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p, getHijackedPlugin()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
proto = Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
|
this.proto = Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
|
||||||
if (proto) {
|
if (this.proto) {
|
||||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
|
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onLogin(PlayerLoginEvent event) {
|
void onLogin(PlayerLoginEvent event) {
|
||||||
if (via) {
|
if (this.via) {
|
||||||
ClientVersion.onLoginVia(event.getPlayer(), getHijackedPlugin());
|
ClientVersion.onLoginVia(event.getPlayer(), getHijackedPlugin());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proto) {
|
if (this.proto) {
|
||||||
ClientVersion.onLoginProtocol(event.getPlayer(), getHijackedPlugin());
|
ClientVersion.onLoginProtocol(event.getPlayer(), getHijackedPlugin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onLogout(PlayerQuitEvent event) {
|
void onLogout(PlayerQuitEvent event) {
|
||||||
if (via) {
|
if (this.via) {
|
||||||
ClientVersion.onLogout(event.getPlayer());
|
ClientVersion.onLogout(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -396,9 +396,9 @@ public class SongodaCore {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
void onEnable(PluginEnableEvent event) {
|
void onEnable(PluginEnableEvent event) {
|
||||||
// technically shouldn't have online players here, but idk
|
// technically shouldn't have online players here, but idk
|
||||||
if (!via && (via = event.getPlugin().getName().equals("ViaVersion"))) {
|
if (!this.via && (this.via = event.getPlugin().getName().equals("ViaVersion"))) {
|
||||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p, getHijackedPlugin()));
|
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p, getHijackedPlugin()));
|
||||||
} else if (!proto && (proto = event.getPlugin().getName().equals("ProtocolSupport"))) {
|
} else if (!this.proto && (this.proto = event.getPlugin().getName().equals("ProtocolSupport"))) {
|
||||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
|
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,13 +413,13 @@ public class SongodaCore {
|
|||||||
|
|
||||||
// don't spam players with update checks
|
// don't spam players with update checks
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Long last = lastCheck.get(player.getUniqueId());
|
Long last = this.lastCheck.get(player.getUniqueId());
|
||||||
|
|
||||||
if (last != null && now - 10000 < last) {
|
if (last != null && now - 10000 < last) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastCheck.put(player.getUniqueId(), now);
|
this.lastCheck.put(player.getUniqueId(), now);
|
||||||
|
|
||||||
// is this player good to revieve update notices?
|
// is this player good to revieve update notices?
|
||||||
if (!event.getPlayer().isOp() && !player.hasPermission("songoda.updatecheck")) return;
|
if (!event.getPlayer().isOp() && !player.hasPermission("songoda.updatecheck")) return;
|
||||||
@ -441,19 +441,19 @@ public class SongodaCore {
|
|||||||
registeredPlugins.remove(pi);
|
registeredPlugins.remove(pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getPlugin() == piggybackedPlugin) {
|
if (event.getPlugin() == SongodaCore.this.piggybackedPlugin) {
|
||||||
// uh-oh! Abandon ship!!
|
// uh-oh! Abandon ship!!
|
||||||
Bukkit.getServicesManager().unregisterAll(piggybackedPlugin);
|
Bukkit.getServicesManager().unregisterAll(SongodaCore.this.piggybackedPlugin);
|
||||||
|
|
||||||
// can we move somewhere else?
|
// can we move somewhere else?
|
||||||
if ((pi = registeredPlugins.stream().findFirst().orElse(null)) != null) {
|
if ((pi = registeredPlugins.stream().findFirst().orElse(null)) != null) {
|
||||||
// move ourselves to this plugin
|
// move ourselves to this plugin
|
||||||
piggybackedPlugin = pi.getJavaPlugin();
|
SongodaCore.this.piggybackedPlugin = pi.getJavaPlugin();
|
||||||
|
|
||||||
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, piggybackedPlugin, ServicePriority.Normal);
|
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, SongodaCore.this.piggybackedPlugin, ServicePriority.Normal);
|
||||||
Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin);
|
Bukkit.getPluginManager().registerEvents(SongodaCore.this.loginListener, SongodaCore.this.piggybackedPlugin);
|
||||||
Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin);
|
Bukkit.getPluginManager().registerEvents(SongodaCore.this.shadingListener, SongodaCore.this.piggybackedPlugin);
|
||||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);
|
CommandManager.registerCommandDynamically(SongodaCore.this.piggybackedPlugin, "songoda", SongodaCore.this.commandManager, SongodaCore.this.commandManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,22 +53,22 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
return config.getFileConfig();
|
return this.config.getFileConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Config getCoreConfig() {
|
public Config getCoreConfig() {
|
||||||
return config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadConfig() {
|
public void reloadConfig() {
|
||||||
config.load();
|
this.config.load();
|
||||||
onConfigReload();
|
onConfigReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveConfig() {
|
public void saveConfig() {
|
||||||
config.save();
|
this.config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,7 +47,7 @@ public class DecentHologramsHolograms extends Holograms {
|
|||||||
DecentHologramsAPI.get().getHologramManager().removeHologram(id);
|
DecentHologramsAPI.get().getHologramManager().removeHologram(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ourHolograms.remove(id);
|
this.ourHolograms.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,7 +68,7 @@ public class DecentHologramsHolograms extends Holograms {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllHolograms() {
|
public void removeAllHolograms() {
|
||||||
for (String id : ourHolograms) {
|
for (String id : this.ourHolograms) {
|
||||||
Hologram hologram = DHAPI.getHologram(id);
|
Hologram hologram = DHAPI.getHologram(id);
|
||||||
|
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
@ -77,7 +77,7 @@ public class DecentHologramsHolograms extends Holograms {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ourHolograms.clear();
|
this.ourHolograms.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -93,6 +93,6 @@ public class DecentHologramsHolograms extends Holograms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DHAPI.createHologram(id, location, lines);
|
DHAPI.createHologram(id, location, lines);
|
||||||
ourHolograms.add(id);
|
this.ourHolograms.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class HologramsHolograms extends Holograms {
|
|||||||
public HologramsHolograms(Plugin plugin) {
|
public HologramsHolograms(Plugin plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
|
||||||
hologramPlugin = (HologramPlugin) Bukkit.getPluginManager().getPlugin("Holograms");
|
this.hologramPlugin = (HologramPlugin) Bukkit.getPluginManager().getPlugin("Holograms");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -30,7 +30,7 @@ public class HologramsHolograms extends Holograms {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return hologramPlugin.isEnabled();
|
return this.hologramPlugin.isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -45,38 +45,38 @@ public class HologramsHolograms extends Holograms {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeHologram(String id) {
|
public void removeHologram(String id) {
|
||||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
|
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
|
||||||
|
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
hologram.despawn();
|
hologram.despawn();
|
||||||
hologramPlugin.getHologramManager().removeActiveHologram(hologram);
|
this.hologramPlugin.getHologramManager().removeActiveHologram(hologram);
|
||||||
}
|
}
|
||||||
|
|
||||||
ourHolograms.remove(id);
|
this.ourHolograms.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllHolograms() {
|
public void removeAllHolograms() {
|
||||||
for (String id : ourHolograms) {
|
for (String id : this.ourHolograms) {
|
||||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
|
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
|
||||||
|
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
hologram.despawn();
|
hologram.despawn();
|
||||||
hologramPlugin.getHologramManager().removeActiveHologram(hologram);
|
this.hologramPlugin.getHologramManager().removeActiveHologram(hologram);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ourHolograms.clear();
|
this.ourHolograms.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isHologramLoaded(String id) {
|
public boolean isHologramLoaded(String id) {
|
||||||
return hologramPlugin.getHologramManager().getHologram(id) != null;
|
return this.hologramPlugin.getHologramManager().getHologram(id) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateHologram(String id, List<String> lines) {
|
public void updateHologram(String id, List<String> lines) {
|
||||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
|
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
|
||||||
|
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
hologram.spawn();
|
hologram.spawn();
|
||||||
@ -118,8 +118,8 @@ public class HologramsHolograms extends Holograms {
|
|||||||
hologram.addLine(new TextLine(hologram, line));
|
hologram.addLine(new TextLine(hologram, line));
|
||||||
}
|
}
|
||||||
|
|
||||||
hologramPlugin.getHologramManager().addActiveHologram(hologram);
|
this.hologramPlugin.getHologramManager().addActiveHologram(hologram);
|
||||||
|
|
||||||
ourHolograms.add(id);
|
this.ourHolograms.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class HolographicDisplaysHolograms extends Holograms {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeHologram(String id) {
|
public void removeHologram(String id) {
|
||||||
Hologram hologram = holograms.remove(id);
|
Hologram hologram = this.holograms.remove(id);
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
hologram.delete();
|
hologram.delete();
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ public class HolographicDisplaysHolograms extends Holograms {
|
|||||||
String id = entry.getKey();
|
String id = entry.getKey();
|
||||||
List<String> lines = entry.getValue();
|
List<String> lines = entry.getValue();
|
||||||
|
|
||||||
Hologram hologram = holograms.get(id);
|
Hologram hologram = this.holograms.get(id);
|
||||||
|
|
||||||
// only update if there is a change to the text
|
// only update if there is a change to the text
|
||||||
boolean isChanged = lines.size() != hologram.size();
|
boolean isChanged = lines.size() != hologram.size();
|
||||||
@ -70,7 +70,7 @@ public class HolographicDisplaysHolograms extends Holograms {
|
|||||||
if (!isChanged) {
|
if (!isChanged) {
|
||||||
// double-check the lines
|
// double-check the lines
|
||||||
for (int i = 0; !isChanged && i < lines.size(); ++i) {
|
for (int i = 0; !isChanged && i < lines.size(); ++i) {
|
||||||
isChanged = !hologram.getLine(i).toString().equals(String.format(textLineFormat, lines.get(i)));
|
isChanged = !hologram.getLine(i).toString().equals(String.format(this.textLineFormat, lines.get(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,27 +85,27 @@ public class HolographicDisplaysHolograms extends Holograms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createAt(String id, Location location, List<String> lines) {
|
private void createAt(String id, Location location, List<String> lines) {
|
||||||
if (holograms.containsKey(id)) {
|
if (this.holograms.containsKey(id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
location = fixLocation(location);
|
location = fixLocation(location);
|
||||||
Hologram hologram = HologramsAPI.createHologram(plugin, location);
|
Hologram hologram = HologramsAPI.createHologram(this.plugin, location);
|
||||||
|
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
hologram.appendTextLine(line);
|
hologram.appendTextLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
holograms.put(id, hologram);
|
this.holograms.put(id, hologram);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllHolograms() {
|
public void removeAllHolograms() {
|
||||||
holograms.values().forEach(Hologram::delete);
|
this.holograms.values().forEach(Hologram::delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isHologramLoaded(String id) {
|
public boolean isHologramLoaded(String id) {
|
||||||
return holograms.get(id) != null;
|
return this.holograms.get(id) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user