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