use of net.blay09.mods.waystones.GlobalWaystones in project Waystones by blay09.
the class HandlerEditWaystone method onMessage.
@Override
@Nullable
public IMessage onMessage(final MessageEditWaystone message, final MessageContext ctx) {
NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
EntityPlayer entityPlayer = ctx.getServerHandler().player;
if (WaystoneConfig.general.creativeModeOnly && !entityPlayer.capabilities.isCreativeMode) {
return;
}
World world = entityPlayer.getEntityWorld();
BlockPos pos = message.getPos();
if (entityPlayer.getDistance(pos.getX(), pos.getY(), pos.getZ()) > 10) {
return;
}
GlobalWaystones globalWaystones = GlobalWaystones.get(ctx.getServerHandler().player.world);
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof TileWaystone) {
TileWaystone tileWaystone = ((TileWaystone) tileEntity).getParent();
if (globalWaystones.getGlobalWaystone(tileWaystone.getWaystoneName()) != null && !ctx.getServerHandler().player.capabilities.isCreativeMode && !WaystoneConfig.general.allowEveryoneGlobal) {
return;
}
if (WaystoneConfig.general.restrictRenameToOwner && !tileWaystone.isOwner(ctx.getServerHandler().player)) {
ctx.getServerHandler().player.sendMessage(new TextComponentTranslation("waystones:notTheOwner"));
return;
}
if (globalWaystones.getGlobalWaystone(message.getName()) != null && !ctx.getServerHandler().player.capabilities.isCreativeMode) {
ctx.getServerHandler().player.sendMessage(new TextComponentTranslation("waystones:nameOccupied", message.getName()));
return;
}
WaystoneEntry oldWaystone = new WaystoneEntry(tileWaystone);
globalWaystones.removeGlobalWaystone(oldWaystone);
tileWaystone.setWaystoneName(message.getName());
WaystoneEntry newWaystone = new WaystoneEntry(tileWaystone);
if (message.isGlobal() && (ctx.getServerHandler().player.capabilities.isCreativeMode || WaystoneConfig.general.allowEveryoneGlobal)) {
tileWaystone.setGlobal(true);
newWaystone.setGlobal(true);
globalWaystones.addGlobalWaystone(newWaystone);
for (Object obj : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayers()) {
WaystoneManager.sendPlayerWaystones((EntityPlayer) obj);
}
}
}
});
return null;
}
use of net.blay09.mods.waystones.GlobalWaystones 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);
}
Aggregations