Search in sources :

Example 1 with GlobalWaystones

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) GlobalWaystones(net.blay09.mods.waystones.GlobalWaystones) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) TileWaystone(net.blay09.mods.waystones.block.TileWaystone) Nullable(javax.annotation.Nullable)

Example 2 with GlobalWaystones

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);
}
Also used : MessageConfig(net.blay09.mods.waystones.network.message.MessageConfig) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

WaystoneEntry (net.blay09.mods.waystones.util.WaystoneEntry)2 Nullable (javax.annotation.Nullable)1 GlobalWaystones (net.blay09.mods.waystones.GlobalWaystones)1 TileWaystone (net.blay09.mods.waystones.block.TileWaystone)1 MessageConfig (net.blay09.mods.waystones.network.message.MessageConfig)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1