use of net.blay09.mods.waystones.PlayerWaystoneData in project Waystones by blay09.
the class PlayerWaystoneData method fromPlayer.
public static PlayerWaystoneData fromPlayer(EntityPlayer player) {
NBTTagCompound tagCompound = PlayerWaystoneHelper.getWaystonesTag(player);
NBTTagList tagList = tagCompound.getTagList(PlayerWaystoneHelper.WAYSTONE_LIST, Constants.NBT.TAG_COMPOUND);
WaystoneEntry[] entries = new WaystoneEntry[tagList.tagCount()];
for (int i = 0; i < entries.length; i++) {
entries[i] = WaystoneEntry.read(tagList.getCompoundTagAt(i));
}
long lastFreeWarp = tagCompound.getLong(PlayerWaystoneHelper.LAST_FREE_WARP);
long lastWarpStoneUse = tagCompound.getLong(PlayerWaystoneHelper.LAST_WARP_STONE_USE);
return new PlayerWaystoneData(entries, lastFreeWarp, lastWarpStoneUse);
}
use of net.blay09.mods.waystones.PlayerWaystoneData in project Waystones by blay09.
the class WaystoneManager method sendPlayerWaystones.
public static void sendPlayerWaystones(EntityPlayer player) {
if (player instanceof EntityPlayerMP) {
PlayerWaystoneData waystoneData = PlayerWaystoneData.fromPlayer(player);
NetworkHandler.channel.sendTo(new MessageWaystones(waystoneData.getWaystones(), waystoneData.getLastFreeWarp(), waystoneData.getLastWarpStoneUse()), (EntityPlayerMP) player);
}
}
use of net.blay09.mods.waystones.PlayerWaystoneData in project Waystones by blay09.
the class HandlerRemoveWaystone method onMessage.
@Override
@Nullable
public IMessage onMessage(final MessageRemoveWaystone message, final MessageContext ctx) {
NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
PlayerWaystoneData waystoneData = PlayerWaystoneData.fromPlayer(ctx.getServerHandler().player);
WaystoneEntry[] entries = waystoneData.getWaystones();
int index = message.getIndex();
if (index < 0 || index >= entries.length) {
return;
}
WaystoneManager.removePlayerWaystone(ctx.getServerHandler().player, entries[index]);
WaystoneManager.sendPlayerWaystones(ctx.getServerHandler().player);
});
return null;
}
use of net.blay09.mods.waystones.PlayerWaystoneData in project Waystones by blay09.
the class CommonProxy method onPlayerLoggedIn.
@SubscribeEvent
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
GlobalWaystones globalWaystones = GlobalWaystones.get(event.player.world);
PlayerWaystoneData waystoneData = PlayerWaystoneData.fromPlayer(event.player);
List<WaystoneEntry> validWaystones = Lists.newArrayList();
for (WaystoneEntry waystone : waystoneData.getWaystones()) {
if (waystone.isGlobal()) {
if (globalWaystones.getGlobalWaystone(waystone.getName()) == null) {
continue;
}
}
validWaystones.add(waystone);
}
for (WaystoneEntry waystone : globalWaystones.getGlobalWaystones()) {
if (!validWaystones.contains(waystone)) {
validWaystones.add(waystone);
}
}
PlayerWaystoneHelper.store(event.player, validWaystones.toArray(new WaystoneEntry[validWaystones.size()]), waystoneData.getLastFreeWarp(), waystoneData.getLastWarpStoneUse());
NetworkHandler.channel.sendTo(new MessageConfig(), (EntityPlayerMP) event.player);
WaystoneManager.sendPlayerWaystones(event.player);
}
use of net.blay09.mods.waystones.PlayerWaystoneData in project Waystones by blay09.
the class HandlerSortWaystone method onMessage.
@Override
@Nullable
public IMessage onMessage(final MessageSortWaystone message, final MessageContext ctx) {
NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
PlayerWaystoneData waystoneData = PlayerWaystoneData.fromPlayer(ctx.getServerHandler().player);
WaystoneEntry[] entries = waystoneData.getWaystones();
int index = message.getIndex();
int otherIndex = message.getOtherIndex();
if (index < 0 || index >= entries.length || otherIndex < 0 || otherIndex >= entries.length) {
return;
}
WaystoneEntry swap = entries[index];
entries[index] = entries[otherIndex];
entries[otherIndex] = swap;
waystoneData.store(ctx.getServerHandler().player);
WaystoneManager.sendPlayerWaystones(ctx.getServerHandler().player);
});
return null;
}
Aggregations