Adds a lot of this. in some files

This commit is contained in:
Christian Koop 2023-06-24 12:57:57 +02:00
parent 49eb5437e9
commit b09338f78f
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
5 changed files with 67 additions and 67 deletions

View File

@ -182,31 +182,31 @@ public class SongodaCore {
}
SongodaCore() {
commandManager = null;
this.commandManager = null;
}
SongodaCore(JavaPlugin javaPlugin) {
piggybackedPlugin = javaPlugin;
commandManager = new CommandManager(piggybackedPlugin);
loginListener = new EventListener();
this.piggybackedPlugin = javaPlugin;
this.commandManager = new CommandManager(this.piggybackedPlugin);
this.loginListener = new EventListener();
}
private void init() {
shadingListener = new ShadedEventListener();
commandManager.registerCommandDynamically(new SongodaCoreCommand())
this.shadingListener = new ShadedEventListener();
this.commandManager.registerCommandDynamically(new SongodaCoreCommand())
.addSubCommands(new SongodaCoreDiagCommand(), new SongodaCoreUUIDCommand(), new SongodaCoreLicenseCommand());
Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin);
Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin);
Bukkit.getPluginManager().registerEvents(this.loginListener, this.piggybackedPlugin);
Bukkit.getPluginManager().registerEvents(this.shadingListener, this.piggybackedPlugin);
// we aggressively want to own this command
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
10 * 60));
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
20 * 60));
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
20 * 60 * 2));
}
@ -216,17 +216,17 @@ public class SongodaCore {
private void destroy() {
Bukkit.getServicesManager().unregister(SongodaCore.class, INSTANCE);
tasks.stream().filter(Objects::nonNull)
this.tasks.stream().filter(Objects::nonNull)
.forEach(task -> Bukkit.getScheduler().cancelTask(task.getTaskId()));
HandlerList.unregisterAll(loginListener);
HandlerList.unregisterAll(this.loginListener);
if (!hasShading()) {
HandlerList.unregisterAll(shadingListener);
HandlerList.unregisterAll(this.shadingListener);
}
registeredPlugins.clear();
commandManager = null;
loginListener = null;
this.commandManager = null;
this.loginListener = null;
}
private ArrayList<BukkitTask> tasks = new ArrayList<>();
@ -247,7 +247,7 @@ public class SongodaCore {
// don't forget to check for language pack updates ;)
info.addModule(new LocaleModule());
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;
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()));
return;
}
proto = Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
if (proto) {
this.proto = Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
if (this.proto) {
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
}
}
@EventHandler
void onLogin(PlayerLoginEvent event) {
if (via) {
if (this.via) {
ClientVersion.onLoginVia(event.getPlayer(), getHijackedPlugin());
return;
}
if (proto) {
if (this.proto) {
ClientVersion.onLoginProtocol(event.getPlayer(), getHijackedPlugin());
}
}
@EventHandler
void onLogout(PlayerQuitEvent event) {
if (via) {
if (this.via) {
ClientVersion.onLogout(event.getPlayer());
}
}
@ -396,9 +396,9 @@ public class SongodaCore {
@EventHandler
void onEnable(PluginEnableEvent event) {
// 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()));
} 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()));
}
}
@ -413,13 +413,13 @@ public class SongodaCore {
// don't spam players with update checks
long now = System.currentTimeMillis();
Long last = lastCheck.get(player.getUniqueId());
Long last = this.lastCheck.get(player.getUniqueId());
if (last != null && now - 10000 < last) {
return;
}
lastCheck.put(player.getUniqueId(), now);
this.lastCheck.put(player.getUniqueId(), now);
// is this player good to revieve update notices?
if (!event.getPlayer().isOp() && !player.hasPermission("songoda.updatecheck")) return;
@ -441,19 +441,19 @@ public class SongodaCore {
registeredPlugins.remove(pi);
}
if (event.getPlugin() == piggybackedPlugin) {
if (event.getPlugin() == SongodaCore.this.piggybackedPlugin) {
// uh-oh! Abandon ship!!
Bukkit.getServicesManager().unregisterAll(piggybackedPlugin);
Bukkit.getServicesManager().unregisterAll(SongodaCore.this.piggybackedPlugin);
// can we move somewhere else?
if ((pi = registeredPlugins.stream().findFirst().orElse(null)) != null) {
// move ourselves to this plugin
piggybackedPlugin = pi.getJavaPlugin();
SongodaCore.this.piggybackedPlugin = pi.getJavaPlugin();
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, piggybackedPlugin, ServicePriority.Normal);
Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin);
Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin);
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, SongodaCore.this.piggybackedPlugin, ServicePriority.Normal);
Bukkit.getPluginManager().registerEvents(SongodaCore.this.loginListener, SongodaCore.this.piggybackedPlugin);
Bukkit.getPluginManager().registerEvents(SongodaCore.this.shadingListener, SongodaCore.this.piggybackedPlugin);
CommandManager.registerCommandDynamically(SongodaCore.this.piggybackedPlugin, "songoda", SongodaCore.this.commandManager, SongodaCore.this.commandManager);
}
}
}

View File

@ -53,22 +53,22 @@ public abstract class SongodaPlugin extends JavaPlugin {
@Override
public FileConfiguration getConfig() {
return config.getFileConfig();
return this.config.getFileConfig();
}
public Config getCoreConfig() {
return config;
return this.config;
}
@Override
public void reloadConfig() {
config.load();
this.config.load();
onConfigReload();
}
@Override
public void saveConfig() {
config.save();
this.config.save();
}
@Override

View File

@ -47,7 +47,7 @@ public class DecentHologramsHolograms extends Holograms {
DecentHologramsAPI.get().getHologramManager().removeHologram(id);
}
ourHolograms.remove(id);
this.ourHolograms.remove(id);
}
@Override
@ -68,7 +68,7 @@ public class DecentHologramsHolograms extends Holograms {
@Override
public void removeAllHolograms() {
for (String id : ourHolograms) {
for (String id : this.ourHolograms) {
Hologram hologram = DHAPI.getHologram(id);
if (hologram != null) {
@ -77,7 +77,7 @@ public class DecentHologramsHolograms extends Holograms {
}
}
ourHolograms.clear();
this.ourHolograms.clear();
}
@Override
@ -93,6 +93,6 @@ public class DecentHologramsHolograms extends Holograms {
}
DHAPI.createHologram(id, location, lines);
ourHolograms.add(id);
this.ourHolograms.add(id);
}
}

View File

@ -20,7 +20,7 @@ public class HologramsHolograms extends Holograms {
public HologramsHolograms(Plugin plugin) {
super(plugin);
hologramPlugin = (HologramPlugin) Bukkit.getPluginManager().getPlugin("Holograms");
this.hologramPlugin = (HologramPlugin) Bukkit.getPluginManager().getPlugin("Holograms");
}
@Override
@ -30,7 +30,7 @@ public class HologramsHolograms extends Holograms {
@Override
public boolean isEnabled() {
return hologramPlugin.isEnabled();
return this.hologramPlugin.isEnabled();
}
@Override
@ -45,38 +45,38 @@ public class HologramsHolograms extends Holograms {
@Override
public void removeHologram(String id) {
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
if (hologram != null) {
hologram.despawn();
hologramPlugin.getHologramManager().removeActiveHologram(hologram);
this.hologramPlugin.getHologramManager().removeActiveHologram(hologram);
}
ourHolograms.remove(id);
this.ourHolograms.remove(id);
}
@Override
public void removeAllHolograms() {
for (String id : ourHolograms) {
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
for (String id : this.ourHolograms) {
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
if (hologram != null) {
hologram.despawn();
hologramPlugin.getHologramManager().removeActiveHologram(hologram);
this.hologramPlugin.getHologramManager().removeActiveHologram(hologram);
}
}
ourHolograms.clear();
this.ourHolograms.clear();
}
@Override
public boolean isHologramLoaded(String id) {
return hologramPlugin.getHologramManager().getHologram(id) != null;
return this.hologramPlugin.getHologramManager().getHologram(id) != null;
}
@Override
public void updateHologram(String id, List<String> lines) {
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
if (hologram != null) {
hologram.spawn();
@ -118,8 +118,8 @@ public class HologramsHolograms extends Holograms {
hologram.addLine(new TextLine(hologram, line));
}
hologramPlugin.getHologramManager().addActiveHologram(hologram);
this.hologramPlugin.getHologramManager().addActiveHologram(hologram);
ourHolograms.add(id);
this.ourHolograms.add(id);
}
}

View File

@ -45,7 +45,7 @@ public class HolographicDisplaysHolograms extends Holograms {
@Override
public void removeHologram(String id) {
Hologram hologram = holograms.remove(id);
Hologram hologram = this.holograms.remove(id);
if (hologram != null) {
hologram.delete();
}
@ -62,7 +62,7 @@ public class HolographicDisplaysHolograms extends Holograms {
String id = entry.getKey();
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
boolean isChanged = lines.size() != hologram.size();
@ -70,7 +70,7 @@ public class HolographicDisplaysHolograms extends Holograms {
if (!isChanged) {
// double-check the lines
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) {
if (holograms.containsKey(id)) {
if (this.holograms.containsKey(id)) {
return;
}
location = fixLocation(location);
Hologram hologram = HologramsAPI.createHologram(plugin, location);
Hologram hologram = HologramsAPI.createHologram(this.plugin, location);
for (String line : lines) {
hologram.appendTextLine(line);
}
holograms.put(id, hologram);
this.holograms.put(id, hologram);
}
@Override
public void removeAllHolograms() {
holograms.values().forEach(Hologram::delete);
this.holograms.values().forEach(Hologram::delete);
}
@Override
public boolean isHologramLoaded(String id) {
return holograms.get(id) != null;
return this.holograms.get(id) != null;
}
}