mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Merge listeners into one
This commit is contained in:
3 files changed
+34
-47
No files matched your search
@@ -3,8 +3,7 @@ package me.william278.huskhomes2;
|
||||
import me.william278.huskhomes2.api.HuskHomesAPI;
|
||||
import me.william278.huskhomes2.commands.*;
|
||||
import me.william278.huskhomes2.commands.tab.*;
|
||||
import me.william278.huskhomes2.events.onPlayerDeath;
|
||||
import me.william278.huskhomes2.events.onPlayerJoin;
|
||||
import me.william278.huskhomes2.listeners.PlayerListener;
|
||||
import me.william278.huskhomes2.integrations.dynamicMap;
|
||||
import me.william278.huskhomes2.integrations.economy;
|
||||
import me.william278.huskhomes2.migrators.legacyVersionMigrator;
|
||||
@@ -104,8 +103,7 @@ public final class HuskHomes extends JavaPlugin {
|
||||
|
||||
// Register events
|
||||
private static void registerEvents(HuskHomes plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(new onPlayerJoin(), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new onPlayerDeath(), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new PlayerListener(), plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package me.william278.huskhomes2.events;
|
||||
|
||||
import me.william278.huskhomes2.commands.tab.homeTabCompleter;
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.dataManager;
|
||||
import me.william278.huskhomes2.teleportManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class onPlayerJoin implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
// Create player on SQL if they don't exist already
|
||||
if (!dataManager.playerExists(p)) {
|
||||
dataManager.createPlayer(p);
|
||||
if (teleportManager.spawnLocation != null) {
|
||||
p.teleport(teleportManager.spawnLocation.getLocation());
|
||||
}
|
||||
} else {
|
||||
// Check if they've changed their name and update if so
|
||||
dataManager.checkPlayerNameChange(p);
|
||||
|
||||
// Update their TAB cache for /home command
|
||||
homeTabCompleter.updatePlayerHomeCache(p);
|
||||
}
|
||||
|
||||
// If bungee mode, check if the player joined the server from a teleport and act accordingly
|
||||
if (HuskHomes.settings.doBungee()) {
|
||||
if (dataManager.getPlayerTeleporting(p)) {
|
||||
teleportManager.teleportPlayer(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+32
-3
@@ -1,9 +1,11 @@
|
||||
package me.william278.huskhomes2.events;
|
||||
package me.william278.huskhomes2.listeners;
|
||||
|
||||
import me.william278.huskhomes2.commands.tab.homeTabCompleter;
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.objects.TeleportationPoint;
|
||||
import me.william278.huskhomes2.dataManager;
|
||||
import me.william278.huskhomes2.messageManager;
|
||||
import me.william278.huskhomes2.objects.TeleportationPoint;
|
||||
import me.william278.huskhomes2.teleportManager;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
@@ -14,8 +16,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class onPlayerDeath implements Listener {
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
private static ComponentBuilder backButton() {
|
||||
ComponentBuilder backButton = new ComponentBuilder();
|
||||
@@ -39,4 +42,30 @@ public class onPlayerDeath implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
// Create player on SQL if they don't exist already
|
||||
if (!dataManager.playerExists(p)) {
|
||||
dataManager.createPlayer(p);
|
||||
if (teleportManager.spawnLocation != null) {
|
||||
p.teleport(teleportManager.spawnLocation.getLocation());
|
||||
}
|
||||
} else {
|
||||
// Check if they've changed their name and update if so
|
||||
dataManager.checkPlayerNameChange(p);
|
||||
|
||||
// Update their TAB cache for /home command
|
||||
homeTabCompleter.updatePlayerHomeCache(p);
|
||||
}
|
||||
|
||||
// If bungee mode, check if the player joined the server from a teleport and act accordingly
|
||||
if (HuskHomes.settings.doBungee()) {
|
||||
if (dataManager.getPlayerTeleporting(p)) {
|
||||
teleportManager.teleportPlayer(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user