2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs;
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
|
|
|
|
import cpw.mods.fml.common.gameevent.TickEvent;
|
|
|
|
|
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
2025-01-29 13:20:04 -05:00
|
|
|
import kamkeel.npcs.controllers.ProfileController;
|
2025-01-30 09:26:04 -05:00
|
|
|
import kamkeel.npcs.controllers.SyncController;
|
2024-03-07 22:22:39 -05:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2023-01-12 21:33:06 -05:00
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
|
import net.minecraft.world.WorldServer;
|
|
|
|
|
import noppes.npcs.client.AnalyticsTracking;
|
2024-01-22 00:57:59 -06:00
|
|
|
import noppes.npcs.controllers.data.PlayerData;
|
2025-07-08 14:34:39 +03:00
|
|
|
import noppes.npcs.controllers.data.action.ActionManager;
|
2023-01-12 21:33:06 -05:00
|
|
|
|
|
|
|
|
import java.net.InetAddress;
|
|
|
|
|
import java.net.UnknownHostException;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
public class ServerTickHandler {
|
2025-06-28 10:06:14 +03:00
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onServerTick(TickEvent.ServerTickEvent event) {
|
|
|
|
|
if (event.phase == Phase.END) {
|
2025-07-23 14:22:52 -04:00
|
|
|
ActionManager.GLOBAL.tick();
|
2025-06-28 10:06:14 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
@SubscribeEvent
|
2025-06-28 10:06:14 +03:00
|
|
|
public void onWorldTick(TickEvent.WorldTickEvent event) {
|
2025-03-13 17:14:45 -04:00
|
|
|
if (event.phase == Phase.START) {
|
|
|
|
|
NPCSpawning.findChunksForSpawning((WorldServer) event.world);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-07 22:22:39 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
private String serverName = null;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void playerLogin(PlayerEvent.PlayerLoggedInEvent event) {
|
2024-03-07 22:22:39 -05:00
|
|
|
EntityPlayerMP player = (EntityPlayerMP) event.player;
|
2025-08-27 15:47:16 -04:00
|
|
|
// Temporary Disabled
|
|
|
|
|
// if (serverName == null) {
|
|
|
|
|
// String e = "local";
|
|
|
|
|
// MinecraftServer server = MinecraftServer.getServer();
|
|
|
|
|
// if (server.isDedicatedServer()) {
|
|
|
|
|
// try {
|
|
|
|
|
// e = InetAddress.getByName(server.getServerHostname()).getCanonicalHostName();
|
|
|
|
|
// } catch (UnknownHostException e1) {
|
|
|
|
|
// e = MinecraftServer.getServer().getServerHostname();
|
|
|
|
|
// }
|
|
|
|
|
// if (server.getPort() != 25565)
|
|
|
|
|
// e += ":" + server.getPort();
|
|
|
|
|
// }
|
|
|
|
|
// if (e == null || e.startsWith("192.168") || e.contains("127.0.0.1") || e.startsWith("localhost"))
|
|
|
|
|
// e = "local";
|
|
|
|
|
// serverName = e;
|
|
|
|
|
// }
|
|
|
|
|
// AnalyticsTracking.sendData(event.player, "join", serverName);
|
2024-01-22 00:57:59 -06:00
|
|
|
|
2025-04-08 22:48:32 -04:00
|
|
|
PlayerData playerData = PlayerData.get(event.player);
|
2025-03-13 17:14:45 -04:00
|
|
|
if (playerData != null) {
|
|
|
|
|
playerData.onLogin();
|
|
|
|
|
}
|
2024-03-07 22:22:39 -05:00
|
|
|
|
2025-08-27 16:27:40 -04:00
|
|
|
ProfileController.Instance.login(player);
|
2025-01-30 09:26:04 -05:00
|
|
|
SyncController.syncPlayer(player);
|
2025-02-10 21:41:54 -05:00
|
|
|
SyncController.syncEffects(player);
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
2024-01-22 00:57:59 -06:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void playerLogout(PlayerEvent.PlayerLoggedOutEvent event) {
|
2025-04-08 22:48:32 -04:00
|
|
|
PlayerData playerData = PlayerData.get(event.player);
|
2025-03-13 17:14:45 -04:00
|
|
|
if (playerData != null) {
|
|
|
|
|
playerData.onLogout();
|
|
|
|
|
}
|
2025-08-27 16:27:40 -04:00
|
|
|
|
|
|
|
|
// Save and unload the player's profile data on logout
|
|
|
|
|
ProfileController.Instance.logout(event.player);
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|