Files
CustomNPC-Plus/src/main/java/noppes/npcs/ServerTickHandler.java
T

79 lines
2.7 KiB
Java
Raw Normal View History

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;
import net.minecraft.entity.player.EntityPlayerMP;
2023-01-12 21:33:06 -05:00
import net.minecraft.world.WorldServer;
2026-02-18 05:13:51 -05:00
import noppes.npcs.controllers.AuctionController;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.controllers.data.action.ActionManager;
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);
}
}
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) {
EntityPlayerMP player = (EntityPlayerMP) event.player;
PlayerData playerData = PlayerData.get(event.player);
2025-03-13 17:14:45 -04:00
if (playerData != null) {
playerData.onLogin();
}
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);
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
}
2025-03-13 17:14:45 -04:00
@SubscribeEvent
public void playerLogout(PlayerEvent.PlayerLoggedOutEvent event) {
// Dismount player from NPC mount before logout to prevent orphaned mount state
if (event.player.ridingEntity instanceof EntityNPCInterface) {
event.player.mountEntity(null);
}
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
2026-01-24 15:11:50 -05:00
// Clear auction permission cache on logout
if (AuctionController.Instance != null) {
AuctionController.Instance.onPlayerLogout(event.player.getUniqueID());
}
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
}