mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-05 18:32:28 +01:00
Merge branch 'master' of https://github.com/Minestom/Minestom
This commit is contained in:
commit
aa689d0df0
@ -51,7 +51,7 @@ dependencies {
|
||||
api 'com.github.TheMode:CommandBuilder:f893cfbfe4'
|
||||
|
||||
// https://jitpack.io/#Articdive/Jnoise
|
||||
api 'com.github.Articdive:Jnoise:1.0-SNAPSHOT'
|
||||
api 'com.github.Articdive:Jnoise:145c910a1e'
|
||||
|
||||
// https://mvnrepository.com/artifact/org.rocksdb/rocksdbjni
|
||||
api group: 'org.rocksdb', name: 'rocksdbjni', version: '6.8.1'
|
||||
|
@ -16,7 +16,7 @@ import java.util.Random;
|
||||
public class NoiseTestGenerator extends ChunkGenerator {
|
||||
|
||||
private Random random = new Random();
|
||||
private JNoise jNoise = JNoise.newBuilder().perlin().setInterpolationType(InterpolationType.LINEAR).setSeed(141414).setFrequency(0.5).build();
|
||||
private JNoise jNoise = JNoise.newBuilder().perlin().setInterpolation(InterpolationType.LINEAR).setSeed(141414).setFrequency(0.5).build();
|
||||
|
||||
@Override
|
||||
public void generateChunkData(ChunkBatch batch, int chunkX, int chunkZ) {
|
||||
|
@ -18,7 +18,9 @@ import net.minestom.server.instance.block.BlockManager;
|
||||
import net.minestom.server.listener.manager.PacketListenerManager;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.PacketProcessor;
|
||||
import net.minestom.server.network.PacketWriterUtils;
|
||||
import net.minestom.server.network.netty.NettyServer;
|
||||
import net.minestom.server.network.packet.server.play.PluginMessagePacket;
|
||||
import net.minestom.server.network.packet.server.play.ServerDifficultyPacket;
|
||||
import net.minestom.server.ping.ResponseDataConsumer;
|
||||
import net.minestom.server.recipe.RecipeManager;
|
||||
@ -28,11 +30,11 @@ import net.minestom.server.storage.StorageFolder;
|
||||
import net.minestom.server.storage.StorageManager;
|
||||
import net.minestom.server.timer.SchedulerManager;
|
||||
import net.minestom.server.utils.thread.MinestomThread;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import net.minestom.server.world.Difficulty;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.Proxy;
|
||||
import java.security.KeyPair;
|
||||
@ -106,6 +108,7 @@ public class MinecraftServer {
|
||||
|
||||
// Data
|
||||
private static ResponseDataConsumer responseDataConsumer;
|
||||
private static String brandName = "Minestom";
|
||||
private static Difficulty difficulty = Difficulty.NORMAL;
|
||||
private static LootTableManager lootTableManager;
|
||||
private static TagManager tagManager;
|
||||
@ -153,6 +156,28 @@ public class MinecraftServer {
|
||||
return minecraftServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current server brand name
|
||||
*
|
||||
* @return the server brand name
|
||||
*/
|
||||
public static String getBrandName() {
|
||||
return brandName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the server brand name, update the name to all connected players
|
||||
*
|
||||
* @param brandName
|
||||
*/
|
||||
public static void setBrandName(String brandName) {
|
||||
Check.notNull(brandName, "The brand name cannot be null");
|
||||
MinecraftServer.brandName = brandName;
|
||||
|
||||
PluginMessagePacket brandMessage = PluginMessagePacket.getBrandPacket();
|
||||
PacketWriterUtils.writeAndSend(connectionManager.getOnlinePlayers(), brandMessage);
|
||||
}
|
||||
|
||||
public static Difficulty getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
@ -39,13 +39,15 @@ import net.minestom.server.scoreboard.Team;
|
||||
import net.minestom.server.sound.Sound;
|
||||
import net.minestom.server.sound.SoundCategory;
|
||||
import net.minestom.server.stat.PlayerStatistic;
|
||||
import net.minestom.server.utils.*;
|
||||
import net.minestom.server.utils.ArrayUtils;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import net.minestom.server.world.Dimension;
|
||||
import net.minestom.server.world.LevelType;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
@ -180,7 +182,10 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
joinGamePacket.reducedDebugInfo = false;
|
||||
playerConnection.sendPacket(joinGamePacket);
|
||||
|
||||
// TODO minecraft:brand plugin message
|
||||
// Server brand name
|
||||
{
|
||||
playerConnection.sendPacket(PluginMessagePacket.getBrandPacket());
|
||||
}
|
||||
|
||||
ServerDifficultyPacket serverDifficultyPacket = new ServerDifficultyPacket();
|
||||
serverDifficultyPacket.difficulty = MinecraftServer.getDifficulty();
|
||||
@ -241,7 +246,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
tagManager.addRequiredTagsToPacket(tags);
|
||||
|
||||
UpdateTagListEvent event = new UpdateTagListEvent(tags);
|
||||
callEvent(UpdateTagListEvent.class,event);
|
||||
callEvent(UpdateTagListEvent.class, event);
|
||||
|
||||
getPlayerConnection().sendPacket(tags);
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class PlayerSkin {
|
||||
|
||||
try {
|
||||
final String response = URLUtils.getText(url);
|
||||
JsonObject jsonObject = (new JsonParser()).parse(response).getAsJsonObject();
|
||||
JsonObject jsonObject = JsonParser.parseString(response).getAsJsonObject();
|
||||
JsonArray propertiesArray = jsonObject.get("properties").getAsJsonArray();
|
||||
|
||||
Iterator<JsonElement> iterator = propertiesArray.iterator();
|
||||
@ -82,7 +82,7 @@ public class PlayerSkin {
|
||||
|
||||
try {
|
||||
final String response = URLUtils.getText(url);
|
||||
JsonObject jsonObject = (new JsonParser()).parse(response).getAsJsonObject();
|
||||
JsonObject jsonObject = JsonParser.parseString(response).getAsJsonObject();
|
||||
final String uuid = jsonObject.get("id").getAsString();
|
||||
return fromUuid(uuid);
|
||||
} catch (IOException e) {
|
||||
|
@ -277,7 +277,8 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
}
|
||||
|
||||
// Refresh slot
|
||||
refreshSlot(slot); // Use #update() if any problem occurs
|
||||
update();
|
||||
//refreshSlot(slot); problem with ghost item when clicking on a slot which has a different internal id
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,90 +1,52 @@
|
||||
package net.minestom.server.network.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.SerializerUtils;
|
||||
import net.minestom.server.utils.Utils;
|
||||
import net.minestom.server.utils.buffer.BufferWrapper;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
// TODO delete
|
||||
public class PacketWriter {
|
||||
|
||||
private ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
private DataOutputStream data = new DataOutputStream(output);
|
||||
|
||||
public PacketWriter() {
|
||||
}
|
||||
private ByteBuf buffer = Unpooled.buffer();
|
||||
|
||||
public void writeBoolean(boolean b) {
|
||||
try {
|
||||
data.writeBoolean(b);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buffer.writeBoolean(b);
|
||||
}
|
||||
|
||||
public void writeByte(byte b) {
|
||||
try {
|
||||
data.writeByte(b);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buffer.writeByte(b);
|
||||
}
|
||||
|
||||
public void writeChar(char s) {
|
||||
try {
|
||||
data.writeChar(s);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buffer.writeChar(s);
|
||||
}
|
||||
|
||||
public void writeShort(short s) {
|
||||
try {
|
||||
data.writeShort(s);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buffer.writeShort(s);
|
||||
}
|
||||
|
||||
public void writeInt(int i) {
|
||||
try {
|
||||
data.writeInt(i);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buffer.writeInt(i);
|
||||
}
|
||||
|
||||
public void writeLong(long l) {
|
||||
try {
|
||||
data.writeLong(l);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buffer.writeLong(l);
|
||||
}
|
||||
|
||||
public void writeFloat(float f) {
|
||||
try {
|
||||
data.writeFloat(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buffer.writeFloat(f);
|
||||
}
|
||||
|
||||
public void writeDouble(double d) {
|
||||
try {
|
||||
data.writeDouble(d);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buffer.writeDouble(d);
|
||||
}
|
||||
|
||||
public void writeVarInt(int i) {
|
||||
@ -121,11 +83,7 @@ public class PacketWriter {
|
||||
}
|
||||
|
||||
public void writeBytes(byte[] bytes) {
|
||||
try {
|
||||
data.write(bytes);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buffer.writeBytes(bytes);
|
||||
}
|
||||
|
||||
public void writeStringArray(String[] array) {
|
||||
@ -171,7 +129,10 @@ public class PacketWriter {
|
||||
}
|
||||
|
||||
public byte[] toByteArray() {
|
||||
return output.toByteArray();
|
||||
byte[] bytes = new byte[buffer.readableBytes()];
|
||||
int readerIndex = buffer.readerIndex();
|
||||
buffer.getBytes(readerIndex, bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.network.packet.PacketWriter;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
@ -19,4 +20,23 @@ public class PluginMessagePacket implements ServerPacket {
|
||||
public int getId() {
|
||||
return ServerPacketIdentifier.PLUGIN_MESSAGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current server brand name packet
|
||||
* <p>
|
||||
* Sent to all players when the name changes
|
||||
*
|
||||
* @return the current brand name packet
|
||||
*/
|
||||
public static PluginMessagePacket getBrandPacket() {
|
||||
PluginMessagePacket brandMessage = new PluginMessagePacket();
|
||||
brandMessage.channel = "minecraft:brand";
|
||||
|
||||
PacketWriter writer = new PacketWriter();
|
||||
writer.writeSizedString(MinecraftServer.getBrandName());
|
||||
|
||||
brandMessage.data = writer.toByteArray();
|
||||
|
||||
return brandMessage;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user