Search in sources :

Example 1 with GlowServer

use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.

the class BlockRedstone method receivePulse.

@Override
public void receivePulse(GlowBlock me) {
    GlowChunk.Key key = GlowChunk.Key.of(me.getX() >> 4, me.getZ() >> 4);
    BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
    BlockChangeMessage bcmsg = new BlockChangeMessage(me.getX(), me.getY(), me.getZ(), blockDataManager.convertToBlockId(blockDataManager.createBlockData(me.getType())), me.getData());
    me.getWorld().broadcastBlockChangeInRange(key, bcmsg);
}
Also used : BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) GlowServer(net.glowstone.GlowServer) BlockDataManager(net.glowstone.block.data.BlockDataManager) GlowChunk(net.glowstone.chunk.GlowChunk)

Example 2 with GlowServer

use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.

the class LoginStartHandler method handle.

@Override
public void handle(GlowSession session, LoginStartMessage message) {
    String name = message.getUsername();
    int length = name.length();
    if (length > 16 || !usernamePattern.matcher(name).find()) {
        session.disconnect("Invalid username provided.", true);
    }
    GlowServer server = session.getServer();
    if (server.getOnlineMode()) {
        // Get necessary information to create our request message
        String sessionId = session.getSessionId();
        byte[] publicKey = SecurityUtils.generateX509Key(server.getKeyPair().getPublic()).getEncoded();
        byte[] verifyToken = SecurityUtils.generateVerifyToken();
        // Set verify data on session for use in the response handler
        session.setVerifyToken(verifyToken);
        session.setVerifyUsername(name);
        // Send created request message and wait for the response
        session.send(new EncryptionKeyRequestMessage(sessionId, publicKey, verifyToken));
    } else {
        GlowPlayerProfile profile;
        ProxyData proxy = session.getProxyData();
        if (proxy == null) {
            UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8));
            profile = new GlowPlayerProfile(name, uuid, true);
        } else {
            profile = proxy.getProfile(name);
        }
        AsyncPlayerPreLoginEvent event = EventFactory.getInstance().onPlayerPreLogin(profile.getName(), session.getAddress(), profile.getId());
        if (event.getLoginResult() != Result.ALLOWED) {
            session.disconnect(event.getKickMessage(), true);
            return;
        }
        GlowPlayerProfile finalProfile = profile;
        server.getScheduler().runTask(null, () -> session.setPlayer(finalProfile));
    }
}
Also used : ProxyData(net.glowstone.net.ProxyData) EncryptionKeyRequestMessage(net.glowstone.net.message.login.EncryptionKeyRequestMessage) AsyncPlayerPreLoginEvent(org.bukkit.event.player.AsyncPlayerPreLoginEvent) GlowPlayerProfile(net.glowstone.entity.meta.profile.GlowPlayerProfile) GlowServer(net.glowstone.GlowServer) UUID(java.util.UUID)

Example 3 with GlowServer

use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.

the class FurnaceEntity method isBurnable.

private boolean isBurnable() {
    GlowFurnaceInventory inv = (GlowFurnaceInventory) getInventory();
    if ((burnTime != 0 || !InventoryUtil.isEmpty(inv.getFuel())) && !InventoryUtil.isEmpty(inv.getSmelting())) {
        if ((InventoryUtil.isEmpty(inv.getFuel()) || InventoryUtil.isEmpty(inv.getSmelting())) && burnTime == 0) {
            return false;
        }
        RecipeManager rm = ((GlowServer) ServerProvider.getServer()).getRecipeManager();
        FuelManager fm = ((GlowServer) ServerProvider.getServer()).getFuelManager();
        if (burnTime != 0 || fm.isFuel(inv.getFuel().getType())) {
            Recipe recipe = rm.getRecipe(inv);
            if (recipe != null && (InventoryUtil.isEmpty(inv.getResult()) || inv.getResult().getType().equals(recipe.getResult().getType()) && inv.getResult().getAmount() + recipe.getResult().getAmount() <= recipe.getResult().getMaxStackSize())) {
                return true;
            }
        }
    }
    return false;
}
Also used : GlowFurnaceInventory(net.glowstone.inventory.GlowFurnaceInventory) Recipe(org.bukkit.inventory.Recipe) RecipeManager(net.glowstone.datapack.RecipeManager) GlowServer(net.glowstone.GlowServer) FuelManager(net.glowstone.datapack.FuelManager)

Example 4 with GlowServer

use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.

the class HumanEntityStore method load.

// documented at http://minecraft.gamepedia.com/Player.dat_Format
// player data that does not correspond to HumanEntity is in PlayerStore
@Override
public void load(T entity, CompoundTag tag) {
    super.load(entity, tag);
    tag.readInt("XpSeed", entity::setXpSeed);
    tag.readInt("playerGameType", gameType -> {
        GlowServer server = (GlowServer) ServerProvider.getServer();
        if (!server.getConfig().getBoolean(ServerConfig.Key.FORCE_GAMEMODE)) {
            GameMode mode = GameMode.getByValue(gameType);
            if (mode != null) {
                entity.setGameMode(mode);
            }
        } else {
            entity.setGameMode(server.getDefaultGameMode());
        }
    });
    tag.readInt("SelectedItemSlot", entity.getInventory()::setHeldItemSlot);
    // Sleeping and SleepTimer are ignored on load.
    tag.readCompoundList("Inventory", items -> {
        PlayerInventory inventory = entity.getInventory();
        inventory.setStorageContents(NbtSerialization.readInventory(items, 0, inventory.getSize() - 5));
        inventory.setArmorContents(NbtSerialization.readInventory(items, 100, 4));
        inventory.setExtraContents(NbtSerialization.readInventory(items, -106, 1));
    });
    tag.readCompoundList("EnderItems", items -> {
        Inventory inventory = entity.getEnderChest();
        inventory.setContents(NbtSerialization.readInventory(items, 0, inventory.getSize()));
    });
}
Also used : GameMode(org.bukkit.GameMode) PlayerInventory(org.bukkit.inventory.PlayerInventory) GlowServer(net.glowstone.GlowServer) PlayerInventory(org.bukkit.inventory.PlayerInventory) Inventory(org.bukkit.inventory.Inventory)

Example 5 with GlowServer

use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.

the class StructureBuilder method setBlock.

/**
 * Sets the block at a given point, if it is inside this builder's bounding box.
 *
 * @param pos a point relative to this structure's root point
 * @param type the new block type
 * @param data the new block data
 */
public void setBlock(Vector pos, Material type, int data) {
    Vector vec = translate(pos);
    BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
    if (boundingBox.isVectorInside(vec)) {
        delegate.setTypeAndData(world, vec.getBlockX(), vec.getBlockY(), vec.getBlockZ(), type, blockDataManager.createBlockData(type));
    }
}
Also used : GlowServer(net.glowstone.GlowServer) Vector(org.bukkit.util.Vector) BlockDataManager(net.glowstone.block.data.BlockDataManager)

Aggregations

GlowServer (net.glowstone.GlowServer)29 BlockDataManager (net.glowstone.block.data.BlockDataManager)8 Vector (org.bukkit.util.Vector)5 RecipeManager (net.glowstone.datapack.RecipeManager)4 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)4 ByteBuf (io.netty.buffer.ByteBuf)3 GlowChunk (net.glowstone.chunk.GlowChunk)3 FuelManager (net.glowstone.datapack.FuelManager)3 BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)3 Material (org.bukkit.Material)3 ItemStack (org.bukkit.inventory.ItemStack)3 DatagramPacket (io.netty.channel.socket.DatagramPacket)2 UUID (java.util.UUID)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 GlowFurnaceInventory (net.glowstone.inventory.GlowFurnaceInventory)2 HandshakeProtocol (net.glowstone.net.protocol.HandshakeProtocol)2 LoginProtocol (net.glowstone.net.protocol.LoginProtocol)2 PlayProtocol (net.glowstone.net.protocol.PlayProtocol)2 ProtocolProvider (net.glowstone.net.protocol.ProtocolProvider)2 StatusProtocol (net.glowstone.net.protocol.StatusProtocol)2