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;
}
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();
}
}
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;
}
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;
}
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();
}
}
Aggregations