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;
|
2026-01-23 21:53:12 -05:00
|
|
|
import noppes.npcs.controllers.AuctionController;
|
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.world.WorldServer;
|
2025-12-15 10:28:17 +02:00
|
|
|
import noppes.npcs.controllers.ScriptController;
|
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;
|
2026-01-22 23:07:38 -05:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
2023-01-12 21:33:06 -05:00
|
|
|
|
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();
|
2026-01-23 21:53:12 -05:00
|
|
|
|
|
|
|
|
// Process auction system tick
|
|
|
|
|
if (AuctionController.Instance != null) {
|
|
|
|
|
AuctionController.Instance.onServerTick();
|
|
|
|
|
}
|
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-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-10-19 22:06:11 -04:00
|
|
|
SyncController.beginLogin(player);
|
2025-02-10 21:41:54 -05:00
|
|
|
SyncController.syncEffects(player);
|
2025-12-15 10:28:17 +02:00
|
|
|
ScriptController.Instance.syncClientScripts(player);
|
2026-01-23 21:53:12 -05:00
|
|
|
|
|
|
|
|
// Send auction notifications on login
|
|
|
|
|
if (AuctionController.Instance != null) {
|
|
|
|
|
AuctionController.Instance.onPlayerLogin(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-12-30 23:20:54 +00:00
|
|
|
// Dismount player from NPC mount before logout to prevent orphaned mount state
|
|
|
|
|
if (event.player.ridingEntity instanceof EntityNPCInterface) {
|
|
|
|
|
event.player.mountEntity(null);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|