Java Code Examples for codechicken.core.ServerUtils

The following examples show how to use codechicken.core.ServerUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ChickenChunks   Source File: BlockChunkLoader.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
    int meta = world.getBlockMetadata(x, y, z);
    if (meta != 0 || player.isSneaking())
        return false;

    if (!world.isRemote) {
        TileChunkLoader tile = (TileChunkLoader) world.getTileEntity(x, y, z);
        if (tile.owner == null || tile.owner.equals(player.getCommandSenderName()) ||
                ChunkLoaderManager.opInteract() && ServerUtils.isPlayerOP(player.getCommandSenderName())) {
            PacketCustom packet = new PacketCustom(ChunkLoaderSPH.channel, 12);
            packet.writeCoord(x, y, z);
            packet.sendToPlayer(player);
        } else
            player.addChatMessage(new ChatComponentTranslation("chickenchunks.accessdenied"));
    }
    return true;
}
 
Example 2
Source Project: ChickenChunks   Source File: ChunkLoaderManager.java    License: MIT License 6 votes vote down vote up
private static void updateLoginTimes() {
    long time = System.currentTimeMillis();
    for (EntityPlayer player : ServerUtils.getPlayers())
        loginTimes.put(player.getCommandSenderName(), time);

    try {
        File saveFile = new File(saveDir, "loginTimes.dat");
        if (!saveFile.exists())
            saveFile.createNewFile();

        DataOutputStream dataout = new DataOutputStream(new FileOutputStream(saveFile));
        dataout.writeInt(loginTimes.size());
        for (Entry<String, Long> entry : loginTimes.entrySet()) {
            dataout.writeUTF(entry.getKey());
            dataout.writeLong(entry.getValue());
        }
        dataout.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    for (PlayerOrganiser organiser : playerOrganisers.values())
        if (!organiser.isDormant() && !loggedInRecently(organiser.username))
            ReviveChange.PlayerDevive.list.add(organiser);
}
 
Example 3
Source Project: WirelessRedstone   Source File: RedstoneEtherServerAddons.java    License: MIT License 6 votes vote down vote up
public void tickTriangs() {
    for (Entry<String, AddonPlayerInfo> entry : playerInfos.entrySet()) {
        EntityPlayer player = ServerUtils.getPlayer(entry.getKey());

        for (Integer freq : entry.getValue().triangSet) {
            double spinto;
            if (!RedstoneEther.server().isFreqOn(freq)) {
                spinto = -1;
            } else if (isRemoteOn(player, freq)) {
                spinto = -2;
            } else {
                Vector3 strengthvec = getBroadcastVector(player, freq);
                if (strengthvec == null)//in another dimension
                {
                    spinto = -2;//spin to a random place
                } else {
                    spinto = (player.rotationYaw + 180) * MathHelper.torad - Math.atan2(-strengthvec.x, strengthvec.z);//spin to the transmitter vec
                }
            }
            WRAddonSPH.sendTriangAngleTo(player, freq, (float) spinto);
        }
    }
}
 
Example 4
Source Project: ChickenChunks   Source File: ChunkLoaderEventHandler.java    License: MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldUnload(Unload event) {
    if (!event.world.isRemote) {
        if (ServerUtils.mc().isServerRunning()) {
            ChunkLoaderManager.unloadWorld(event.world);
            PlayerChunkViewerManager.instance().dimChanges.add(new DimensionChange((WorldServer) event.world, false));
        } else {
            PlayerChunkViewerManager.serverShutdown();
            ChunkLoaderManager.serverShutdown();
        }
    }
}
 
Example 5
Source Project: ChickenChunks   Source File: ChunkLoaderManager.java    License: MIT License 5 votes vote down vote up
public static boolean allowOffline(String username) {
    ConfigTag config = ChickenChunks.config.getTag("allowoffline");
    if (config.containsTag(username))
        return config.getTag(username).getBooleanValue(true);

    if (ServerUtils.isPlayerOP(username))
        return config.getTag("OP").getBooleanValue(true);

    return config.getTag("DEFAULT").getBooleanValue(true);
}
 
Example 6
Source Project: ChickenChunks   Source File: ChunkLoaderManager.java    License: MIT License 5 votes vote down vote up
public static boolean allowChunkViewer(String username) {
    ConfigTag config = ChickenChunks.config.getTag("allowchunkviewer");
    if (config.containsTag(username))
        return config.getTag(username).getBooleanValue(true);

    if (ServerUtils.isPlayerOP(username))
        return config.getTag("OP").getBooleanValue(true);

    return config.getTag("DEFAULT").getBooleanValue(true);
}
 
Example 7
Source Project: ChickenChunks   Source File: ChunkLoaderManager.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void cleanChunks(WorldServer world) {
    int dim = CommonUtils.getDimension(world);
    int viewdist = ServerUtils.mc().getConfigurationManager().getViewDistance();

    HashSet<ChunkCoordIntPair> loadedChunks = new HashSet<ChunkCoordIntPair>();
    for (EntityPlayer player : ServerUtils.getPlayersInDimension(dim)) {
        int playerChunkX = (int) player.posX >> 4;
        int playerChunkZ = (int) player.posZ >> 4;

        for (int cx = playerChunkX - viewdist; cx <= playerChunkX + viewdist; cx++)
            for (int cz = playerChunkZ - viewdist; cz <= playerChunkZ + viewdist; cz++)
                loadedChunks.add(new ChunkCoordIntPair(cx, cz));
    }

    ImmutableSetMultimap<ChunkCoordIntPair, Ticket> persistantChunks = world.getPersistentChunks();
    PlayerManager manager = world.getPlayerManager();

    for (Chunk chunk : (List<Chunk>) world.theChunkProviderServer.loadedChunks) {
        ChunkCoordIntPair coord = chunk.getChunkCoordIntPair();
        if (!loadedChunks.contains(coord) && !persistantChunks.containsKey(coord) && world.theChunkProviderServer.chunkExists(coord.chunkXPos, coord.chunkZPos)) {
            PlayerInstance instance = manager.getOrCreateChunkWatcher(coord.chunkXPos, coord.chunkZPos, false);
            if (instance == null) {
                world.theChunkProviderServer.unloadChunksIfNotNearSpawn(coord.chunkXPos, coord.chunkZPos);
            } else {
                while (instance.playersWatchingChunk.size() > 0)
                    instance.removePlayer((EntityPlayerMP) instance.playersWatchingChunk.get(0));
            }
        }
    }

    if (ServerUtils.getPlayersInDimension(dim).isEmpty() && world.getPersistentChunks().isEmpty() && !DimensionManager.shouldLoadSpawn(dim)) {
        DimensionManager.unloadWorld(dim);
    }
}
 
Example 8
Source Project: NotEnoughItems   Source File: NEIServerUtils.java    License: MIT License 5 votes vote down vote up
public static void toggleRaining(World world, boolean notify) {
    boolean raining = !world.isRaining();
    if (!raining)//turn off
        ((WorldServer) world).provider.resetRainAndThunder();
    else
        world.getWorldInfo().setRaining(!isRaining(world));

    if (notify)
        ServerUtils.sendChatToAll(new ChatComponentTranslation("nei.chat.rain." + (raining ? "on" : "off")));
}
 
Example 9
Source Project: NotEnoughItems   Source File: NEIServerUtils.java    License: MIT License 5 votes vote down vote up
public static void setHourForward(World world, int hour, boolean notify) {
    long day = (getTime(world) / 24000L) * 24000L;
    long newTime = day + 24000L + hour * 1000;
    setTime(newTime, world);
    if (notify)
        ServerUtils.sendChatToAll(new ChatComponentTranslation("nei.chat.time", getTime(world) / 24000L, hour));
}
 
Example 10
Source Project: NotEnoughItems   Source File: NEIServerUtils.java    License: MIT License 5 votes vote down vote up
public static void sendNotice(ICommandSender sender, IChatComponent msg, String permission) {
    ChatComponentTranslation notice = new ChatComponentTranslation("chat.type.admin", sender.getCommandSenderName(), msg.createCopy());
    notice.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true);

    if (NEIServerConfig.canPlayerPerformAction("CONSOLE", permission))
        MinecraftServer.getServer().addChatMessage(notice);

    for (EntityPlayer p : ServerUtils.getPlayers())
        if(p == sender)
            p.addChatComponentMessage(msg);
        else if (NEIServerConfig.canPlayerPerformAction(p.getCommandSenderName(), permission))
            p.addChatComponentMessage(notice);
}
 
Example 11
Source Project: NotEnoughItems   Source File: NEIServerConfig.java    License: MIT License 5 votes vote down vote up
public static boolean isPlayerInList(String playername, Set<String> list, boolean allowCards) {
    if (playername.equals("CONSOLE"))
        return list.contains(playername);

    playername = playername.toLowerCase();

    if (allowCards) {
        if (list.contains("ALL"))
            return true;
        if ((ServerUtils.isPlayerOP(playername) || ServerUtils.isPlayerOwner(playername)) && list.contains("OP"))
            return true;
    }

    return list.contains(playername);
}
 
Example 12
Source Project: WirelessRedstone   Source File: WRAddonEventHandler.java    License: MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldUnload(net.minecraftforge.event.world.WorldEvent.Unload event) {
    if (event.world.isRemote)
        return;

    if (!ServerUtils.mc().isServerRunning())
        RedstoneEtherAddons.unloadServer();
}
 
Example 13
Source Project: WirelessRedstone   Source File: EntityWirelessTracker.java    License: MIT License 5 votes vote down vote up
private void findAttachedEntity()
{
    if(attachmentCounter == 0)
    {
        detachFromEntity();
        return;
    }
    
    if(attachedPlayerName != null)
    {
        EntityPlayer player = ServerUtils.getPlayer(attachedPlayerName);
        if(player != null)
        {
            attachedEntity = player;
            moveToEntityExterior();
            RedstoneEther.server().addTransmittingDevice(this);
            attachmentCounter = 0;
            return;
        }
    }
    else
    {
        for(Entity entity : (List<Entity>)worldObj.getEntitiesWithinAABBExcludingEntity(this, AxisAlignedBB.getBoundingBox(-10, -10, -10, 10, 10, 10).offset(posX, posY, posZ)))
        {
            if(tryAttach(entity, 0.4, 0.2))
            {
                attachmentCounter = 0;
                return;
            }
        }
        
        attachmentCounter--;
    }
}
 
Example 14
Source Project: WirelessRedstone   Source File: RedstoneEther.java    License: MIT License 5 votes vote down vote up
public void setFrequencyRange(String username, int firstfreq, int lastfreq, boolean jam) {
    if (!remote) {
        EntityPlayer player = ServerUtils.getPlayer(username);
        if (player != null)
            WRCoreSPH.sendSetFrequencyRangeTo(player, firstfreq, lastfreq, jam);
    }

    if (lastfreq > numfreqs)
        lastfreq = numfreqs;

    boolean[] jammedFreqs = getJammedFreqs(username);
    for (int settingfreq = firstfreq; settingfreq <= lastfreq; settingfreq++)
        jammedFreqs[settingfreq - 1] = jam;
}
 
Example 15
Source Project: WirelessRedstone   Source File: RedstoneEtherServer.java    License: MIT License 5 votes vote down vote up
private void unloadJammedMap()
{
    for(Iterator<String> iterator = playerJammedMap.keySet().iterator(); iterator.hasNext();)
    {
        String username = iterator.next();
        if(ServerUtils.getPlayer(username) == null)
        {
            saveJammedFrequencies(username);
            iterator.remove();
        }
    }
}
 
Example 16
Source Project: WirelessRedstone   Source File: WRCoreEventHandler.java    License: MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldUnload(WorldEvent.Unload event) {
    if (event.world.isRemote)
        return;

    RedstoneEther.unloadServerWorld(event.world);

    if (!ServerUtils.mc().isServerRunning())
        RedstoneEther.unloadServer();
}
 
Example 17
Source Project: EnderStorage   Source File: TankSynchroniser.java    License: MIT License 4 votes vote down vote up
@SubscribeEvent
public void onWorldUnload(Unload event)
{
    if(!event.world.isRemote && !ServerUtils.mc().isServerRunning())
        playerItemTankStates = null;
}
 
Example 18
Source Project: CodeChickenCore   Source File: CoreCommand.java    License: MIT License 4 votes vote down vote up
public static void chatOpsT(String s, Object... params) {
    for (EntityPlayerMP player : ServerUtils.getPlayers())
        if (MinecraftServer.getServer().getConfigurationManager().canSendCommands(player.getGameProfile()))
            player.addChatMessage(new ChatComponentTranslation(s, params));
}
 
Example 19
Source Project: CodeChickenCore   Source File: CoreCommand.java    License: MIT License 4 votes vote down vote up
public final EntityPlayerMP getPlayer(String name) {
    return ServerUtils.getPlayer(name);
}
 
Example 20
Source Project: WirelessRedstone   Source File: RedstoneEtherServerAddons.java    License: MIT License 4 votes vote down vote up
public void processSMPMaps(World world) {
    RedstoneEther.loadServerWorld(world);
    int dimension = CommonUtils.getDimension(world);
    ArrayList<EntityPlayer> players = ServerUtils.getPlayersInDimension(dimension);

    Map<BlockCoord, TXNodeInfo> txnodes = RedstoneEther.server().getTransmittersInDimension(dimension);
    Set<WirelessTransmittingDevice> devices = RedstoneEther.server().getTransmittingDevicesInDimension(dimension);

    for (EntityPlayer player : players) {
        ItemStack helditem = player.getCurrentEquippedItem();

        if (helditem == null || helditem.getItem() != WirelessRedstoneAddons.wirelessMap || RedstoneEther.server().isPlayerJammed(player)) {
            continue;
        }

        ItemWirelessMap map = (ItemWirelessMap) helditem.getItem();
        MapData mapdata = map.getMapData(helditem, world);

        if (mapdata.dimension != player.dimension) {
            continue;
        }

        WirelessMapNodeStorage mapnodes = getMapNodes(player);
        TreeSet<FreqCoord> oldnodes = mapnodes.nodes;
        int lastdevices = mapnodes.devices.size();

        updatePlayerMapData(player, world, mapdata, txnodes, devices);

        TreeSet<FreqCoord> addednodes = new TreeSet<FreqCoord>(mapnodes.nodes);
        TreeSet<FreqCoord> removednodes = new TreeSet<FreqCoord>();

        if (oldnodes.size() != 0) {
            for (Iterator<FreqCoord> nodeiterator = oldnodes.iterator(); nodeiterator.hasNext(); ) {
                FreqCoord node = nodeiterator.next();
                if (!addednodes.remove(node))//remove returns false if the item was not in the set
                {
                    removednodes.add(node);
                }
            }
        }

        if (addednodes.size() != 0 || removednodes.size() != 0 || devices.size() != 0 || lastdevices > 0) {
            WRAddonSPH.sendMapUpdatePacketTo(player, helditem.getItemDamage(), mapdata, addednodes, removednodes, mapnodes.devices);
        }
    }
}
 
Example 21
Source Project: WirelessRedstone   Source File: RedstoneEtherServerAddons.java    License: MIT License 4 votes vote down vote up
public void processTrackers() {
    trackerTicks++;
    HashSet<EntityPlayer> playerEntities = new HashSet<EntityPlayer>(ServerUtils.getPlayers());

    boolean updateFree = trackerTicks % 5 == 0;
    boolean updateAttached = trackerTicks % 100 == 0;

    for (Iterator<Entry<EntityWirelessTracker, HashSet<EntityPlayerMP>>> iterator = trackerPlayerMap.entrySet().iterator(); iterator.hasNext(); ) {
        Entry<EntityWirelessTracker, HashSet<EntityPlayerMP>> entry = iterator.next();

        HashSet<EntityPlayerMP> trackedPlayers = entry.getValue();
        HashSet<EntityPlayerMP> playersToTrack = new HashSet<EntityPlayerMP>();

        EntityWirelessTracker tracker = entry.getKey();
        ChunkCoordIntPair chunk = new ChunkCoordIntPair(tracker.chunkCoordX, tracker.chunkCoordZ);

        for (EntityPlayer entityPlayer : playerEntities) {
            EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
            if (tracker.isDead) {
                WRAddonSPH.sendRemoveTrackerTo(player, tracker);
            } else if (tracker.getDimension() == player.dimension && !player.loadedChunks.contains(chunk) && !tracker.attachedToLogout())//perform update, add to list
            {
                playersToTrack.add(player);
                if (!trackedPlayers.contains(player) || (tracker.isAttachedToEntity() && updateAttached) || (!tracker.isAttachedToEntity() && updateFree)) {
                    WRAddonSPH.sendTrackerUpdatePacketTo(player, tracker);
                }
            } else if (trackedPlayers.contains(player))//no longer in listening range
            {
                WRAddonSPH.sendRemoveTrackerTo(player, tracker);
            }
        }

        if (tracker.isDead) {
            iterator.remove();
            continue;
        }

        trackedPlayers.clear();
        trackedPlayers.addAll(playersToTrack);
    }
}
 
Example 22
Source Project: WirelessRedstone   Source File: ParamJam.java    License: MIT License 4 votes vote down vote up
public static void jamOpenCommand(String playername, String[] args, WCommandSender listener, boolean jam) {
    RedstoneEtherServer ether = RedstoneEther.server();

    if (args.length == 0) {
        listener.chatT("wrcbe_core.param.invalidno");
        return;
    }

    if ((args.length == 1 && ServerUtils.getPlayer(playername) == null)) {
        listener.chatT("wrcbe_core.param.jam.noplayer");
        return;
    }

    String range = args[args.length - 1];
    String jamPlayer = args.length == 1 ? playername : args[0];

    int startfreq;
    int endfreq;

    if (range.equals("all")) {
        startfreq = 1;
        endfreq = RedstoneEther.numfreqs;
    } else if (range.equals("default")) {
        startfreq = ether.getLastSharedFrequency() + 1;
        endfreq = RedstoneEther.numfreqs;
    } else {
        int[] freqrange = RedstoneEther.parseFrequencyRange(range);
        startfreq = freqrange[0];
        endfreq = freqrange[1];
    }

    if (startfreq < 1 || endfreq > RedstoneEther.numfreqs || endfreq < startfreq) {
        listener.chatT("wrcbe_core.param.invalidfreqrange");
        return;
    }

    ether.setFrequencyRangeCommand(jamPlayer, startfreq, endfreq, jam);

    int publicend = ether.getLastPublicFrequency();
    EntityPlayer player = ServerUtils.getPlayer(jamPlayer);
    String paramName = jam ? "jam" : "open";
    ChatStyle playerStyle = new ChatStyle().setColor(EnumChatFormatting.YELLOW);
    if (startfreq == endfreq) {
        if (startfreq <= publicend) {
            listener.chatT("wrcbe_core.param.jam.errpublic");
            return;
        }
        listener.chatOpsT("wrcbe_core.param."+paramName+".opjammed", playername, jamPlayer, startfreq);
        if (player != null)
            player.addChatComponentMessage(new ChatComponentTranslation("wrcbe_core.param."+paramName+".jammed", startfreq).setChatStyle(playerStyle));
    } else {
        if (startfreq <= publicend && endfreq <= publicend) {
            listener.chatT("wrcbe_core.param.jam.errpublic");
            return;
        }
        if (startfreq <= publicend)
            startfreq = publicend + 1;

        listener.chatOpsT("wrcbe_core.param."+paramName+".opjammed2", playername, jamPlayer, startfreq + "-" + endfreq);
        if (player != null)
            player.addChatComponentMessage(new ChatComponentTranslation("wrcbe_core.param."+paramName+".jammed2", startfreq + "-" + endfreq).setChatStyle(playerStyle));
    }
}
 
Example 23
Source Project: WirelessRedstone   Source File: ParamScan.java    License: MIT License 4 votes vote down vote up
@Override
public void handleCommand(String playername, String[] subArray, WCommandSender listener) {
    RedstoneEther ether = RedstoneEther.get(false);

    if (subArray.length == 1 && ServerUtils.getPlayer(playername) == null) {
        listener.chatT("wrcbe_core.param.invalidno");
        return;
    }

    String scanPlayer = subArray.length == 1 ? playername : subArray[1];

    StringBuilder freqs = new StringBuilder();
    int ranges = 0;
    int startfreq;
    int endfreq = ether.getLastPublicFrequency();
    while (true) {
        int[] freqrange = ether.getNextFrequencyRange(scanPlayer, endfreq + 1, false);
        startfreq = freqrange[0];
        endfreq = freqrange[1];
        if (startfreq == -1) {
            break;
        }

        if (ranges != 0)
            freqs.append(", ");

        if (startfreq == endfreq)
            freqs.append(startfreq);
        else
            freqs.append(startfreq).append("-").append(endfreq);

        ranges++;

        if (endfreq == RedstoneEther.numfreqs) {
            break;
        }
    }

    if (ranges == 0)
        listener.chatT("wrcbe_core.param.scan.onlypublic", scanPlayer);
    else
        listener.chatT("wrcbe_core.param.scan.list", scanPlayer, freqs);
}