Search in sources :

Example 16 with GlowServer

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

the class PardonCommand method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
    if (!testPermission(sender, commandMessages.getPermissionMessage())) {
        return true;
    }
    if (args.length != 1) {
        sendUsageMessage(sender, commandMessages);
        return false;
    }
    String name = args[0];
    final GlowServer server = (GlowServer) ServerProvider.getServer();
    // asynchronously lookup player
    server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
        if (ex != null) {
            new LocalizedStringImpl("pardon.exception", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, name, ex.getMessage());
            ex.printStackTrace();
            return;
        }
        BanList banList = server.getBanList(BanList.Type.NAME);
        String exactName = player.getName();
        if (!banList.isBanned(exactName)) {
            new LocalizedStringImpl("pardon.not-banned", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, exactName);
            return;
        }
        banList.pardon(exactName);
        new LocalizedStringImpl("pardon.done", commandMessages.getResourceBundle()).send(sender, exactName);
    });
    // todo: asynchronous command callbacks?
    return true;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) GlowServer(net.glowstone.GlowServer) BanList(org.bukkit.BanList)

Example 17 with GlowServer

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

the class CompoundTag method tryGetMaterial.

/**
 * Reads a material from a string ID or numeric ID, depending on the tag type. Returns null if
 * the tag isn't present, its type is neither string nor any integral type, or its value isn't
 * a valid material ID.
 *
 * @param key the key to look up
 * @return the Material denoted by that key, if present and readable; an empty Optional otherwise
 */
public Optional<Material> tryGetMaterial(@NonNls String key) {
    if (!containsKey(key)) {
        return Optional.empty();
    }
    BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
    switch(value.get(key).getType()) {
        case STRING:
            @NonNls String id = getString(key);
            if (id.isEmpty()) {
                return Optional.empty();
            }
            if (!id.contains(":")) {
                // There is no namespace, so prepend the default minecraft: namespace
                id = "minecraft:" + id;
            }
            Material type = ItemIds.getBlock(id);
            if (type == null) {
                // Not a block, might be an item
                type = ItemIds.getItem(id);
            }
            return Optional.ofNullable(type);
        case INT:
            return Optional.of(blockDataManager.convertToBlockData(getInt(key)).getMaterial());
        case SHORT:
            return Optional.of(blockDataManager.convertToBlockData(getShort(key)).getMaterial());
        case BYTE:
            return Optional.of(blockDataManager.convertToBlockData(getByte(key)).getMaterial());
        default:
            return Optional.empty();
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) Material(org.bukkit.Material) GlowServer(net.glowstone.GlowServer) BlockDataManager(net.glowstone.block.data.BlockDataManager)

Example 18 with GlowServer

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

the class GlowTeam method getPlayers.

@Override
@Deprecated
public Set<OfflinePlayer> getPlayers() throws IllegalStateException {
    Set<OfflinePlayer> playerObjectSet = new HashSet<>(players.size());
    playerObjectSet.addAll(players.stream().map(s -> new GlowOfflinePlayer((GlowServer) Bukkit.getServer(), s)).collect(Collectors.toList()));
    return playerObjectSet;
}
Also used : GlowOfflinePlayer(net.glowstone.GlowOfflinePlayer) OfflinePlayer(org.bukkit.OfflinePlayer) GlowOfflinePlayer(net.glowstone.GlowOfflinePlayer) GlowServer(net.glowstone.GlowServer) HashSet(java.util.HashSet)

Example 19 with GlowServer

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

the class GlowBlock method setTypeIdAndData.

@Deprecated
public boolean setTypeIdAndData(int type, byte data, boolean applyPhysics) {
    Material oldTypeId = getType();
    byte oldData = getData();
    GlowChunk chunk = (GlowChunk) world.getChunkAt(this);
    Material material = ((GlowServer) Bukkit.getServer()).getBlockDataManager().convertToBlockData(type).getMaterial();
    chunk.setType(x & 0xf, z & 0xf, y, material);
    chunk.setMetaData(x & 0xf, z & 0xf, y, data);
    if (applyPhysics) {
        applyPhysics(oldTypeId, material, oldData, data);
    }
    GlowChunk.Key key = GlowChunk.Key.of(x >> 4, z >> 4);
    BlockChangeMessage bcmsg = new BlockChangeMessage(x, y, z, type, data);
    world.broadcastBlockChangeInRange(key, bcmsg);
    return true;
}
Also used : Material(org.bukkit.Material) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) GlowServer(net.glowstone.GlowServer) GlowChunk(net.glowstone.chunk.GlowChunk)

Example 20 with GlowServer

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

the class FurnaceEntity method burn.

/**
 * Advances the cooking process for the tick.
 */
// TODO: Change block on burning
public void burn() {
    GlowFurnaceInventory inv = (GlowFurnaceInventory) getInventory();
    boolean sendChange = false;
    if (burnTime > 0) {
        burnTime--;
        sendChange = true;
    }
    boolean isBurnable = isBurnable();
    if (cookTime > 0 && isBurnable) {
        cookTime++;
        sendChange = true;
    } else if (burnTime != 0) {
        cookTime = 0;
        sendChange = true;
    }
    if (cookTime == 0 && isBurnable) {
        cookTime = 1;
        sendChange = true;
    }
    if (burnTime == 0) {
        if (isBurnable) {
            FuelManager fm = ((GlowServer) ServerProvider.getServer()).getFuelManager();
            FurnaceBurnEvent burnEvent = new FurnaceBurnEvent(block, inv.getFuel(), fm.getFuelTime(inv.getFuel().getType()));
            EventFactory.getInstance().callEvent(burnEvent);
            if (!burnEvent.isCancelled() && burnEvent.isBurning()) {
                burnTime = (short) burnEvent.getBurnTime();
                burnTimeFuel = burnTime;
                if (inv.getFuel().getAmount() == 1) {
                    if (inv.getFuel().getType().equals(Material.LAVA_BUCKET)) {
                        inv.setFuel(new ItemStack(Material.BUCKET));
                    } else {
                        inv.setFuel(null);
                    }
                } else {
                    inv.getFuel().setAmount(inv.getFuel().getAmount() - 1);
                }
                sendChange = true;
            } else if (cookTime != 0) {
                if (cookTime % 2 == 0) {
                    cookTime = (short) (cookTime - 2);
                } else {
                    cookTime--;
                }
                sendChange = true;
            }
        } else if (cookTime != 0) {
            if (cookTime % 2 == 0) {
                cookTime = (short) (cookTime - 2);
            } else {
                cookTime--;
            }
            sendChange = true;
        }
    }
    if (cookTime == 200) {
        RecipeManager rm = ((GlowServer) ServerProvider.getServer()).getRecipeManager();
        Recipe recipe = rm.getRecipe(inv);
        if (recipe != null) {
            FurnaceSmeltEvent smeltEvent = new FurnaceSmeltEvent(block, inv.getSmelting(), recipe.getResult());
            EventFactory.getInstance().callEvent(smeltEvent);
            if (!smeltEvent.isCancelled()) {
                if (inv.getSmelting().getType().equals(Material.SPONGE) && inv.getSmelting().getData().getData() == 1 && inv.getFuel() != null && inv.getFuel().getType().equals(Material.BUCKET) && inv.getFuel().getAmount() == 1) {
                    inv.setFuel(new ItemStack(Material.WATER_BUCKET));
                }
                if (inv.getResult() == null || inv.getResult().getType().equals(Material.AIR)) {
                    inv.setResult(smeltEvent.getResult());
                } else if (inv.getResult().getType().equals(smeltEvent.getResult().getType())) {
                    inv.getResult().setAmount(inv.getResult().getAmount() + smeltEvent.getResult().getAmount());
                }
                if (inv.getSmelting().getAmount() == 1) {
                    inv.setSmelting(null);
                } else {
                    inv.getSmelting().setAmount(inv.getSmelting().getAmount() - 1);
                }
            }
            cookTime = 0;
            sendChange = true;
        }
    }
    inv.getViewersSet().forEach(human -> {
        human.setWindowProperty(Property.BURN_TIME, burnTime);
        human.setWindowProperty(Property.TICKS_FOR_CURRENT_FUEL, burnTimeFuel);
        human.setWindowProperty(Property.COOK_TIME, cookTime);
        human.setWindowProperty(Property.TICKS_FOR_CURRENT_SMELTING, 200);
    });
    if (!isBurnable && burnTime == 0 && cookTime == 0) {
        getState().getBlock().getWorld().cancelPulse(getState().getBlock());
        sendChange = true;
    }
    if (sendChange) {
        updateInRange();
    }
}
Also used : FurnaceBurnEvent(org.bukkit.event.inventory.FurnaceBurnEvent) GlowFurnaceInventory(net.glowstone.inventory.GlowFurnaceInventory) Recipe(org.bukkit.inventory.Recipe) RecipeManager(net.glowstone.datapack.RecipeManager) GlowServer(net.glowstone.GlowServer) ItemStack(org.bukkit.inventory.ItemStack) FurnaceSmeltEvent(org.bukkit.event.inventory.FurnaceSmeltEvent) FuelManager(net.glowstone.datapack.FuelManager)

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