Skip to content

Commit

Permalink
一批问题修改与调整
Browse files Browse the repository at this point in the history
  • Loading branch information
wode490390 committed Feb 14, 2024
1 parent 9d9b62c commit f3c51c9
Show file tree
Hide file tree
Showing 9 changed files with 414 additions and 166 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/command/defaults/TellCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class TellCommand extends VanillaCommand {

public TellCommand(String name) {
super(name, "%commands.tell.description", "%nukkit.command.message.usage", "w"/*, "msg"*/); //FIXME: msg 与插件的 FriendChat 冲突
super(name, "%commands.tell.description", "%nukkit.command.message.usage", "w", "msg");
this.setPermission("nukkit.command.tell");
this.commandData.flags.add(CommandFlag.NOT_CHEAT);
this.commandParameters.clear();
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/cn/nukkit/inventory/CraftingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ protected void initialize() {

@SuppressWarnings("unchecked")
private void loadRecipes(Config config) {
List<Map> recipes = config.getMapList("recipes");
List<Map<?, ?>> recipes = config.getMapList("recipes");
log.info("Loading recipes...");
for (Map<String, Object> recipe : recipes) {
for (Map<?, ?> recipe : recipes) {
try {
int type = Utils.toInt(recipe.get("type"));
switch (type) {
Expand Down Expand Up @@ -216,19 +216,19 @@ private void loadRecipes(Config config) {
}

// Load brewing recipes
List<Map> potionMixes = config.getMapList("potionMixes");
List<Map<?, ?>> potionMixes = config.getMapList("potionMixes");

for (Map potionMix : potionMixes) {
for (Map<?, ?> potionMix : potionMixes) {
int fromPotionId = ((Number) potionMix.get("fromPotionId")).intValue(); // gson returns doubles...
int ingredient = ((Number) potionMix.get("ingredient")).intValue();
int toPotionId = ((Number) potionMix.get("toPotionId")).intValue();

registerBrewingRecipe(new BrewingRecipe(Item.get(ItemID.POTION, fromPotionId), Item.get(ingredient), Item.get(ItemID.POTION, toPotionId)));
}

List<Map> containerMixes = config.getMapList("containerMixes");
List<Map<?, ?>> containerMixes = config.getMapList("containerMixes");

for (Map containerMix : containerMixes) {
for (Map<?, ?> containerMix : containerMixes) {
int fromItemId = ((Number) containerMix.get("fromItemId")).intValue();
int ingredient = ((Number) containerMix.get("ingredient")).intValue();
int toItemId = ((Number) containerMix.get("toItemId")).intValue();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static void initCreativeItems() {

Config config = new Config(Config.JSON);
config.load(Server.class.getClassLoader().getResourceAsStream("creativeitems.json"));
List<Map> list = config.getMapList("items");
List<Map<?, ?>> list = config.getMapList("items");

for (Map map : list) {
try {
Expand Down
37 changes: 35 additions & 2 deletions src/main/java/cn/nukkit/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Predicate;
Expand Down Expand Up @@ -3225,11 +3228,41 @@ public BaseFullChunk getChunk(int chunkX, int chunkZ) {
public BaseFullChunk getChunk(int chunkX, int chunkZ, boolean create) {
long index = Level.chunkHash(chunkX, chunkZ);
boolean isMainThread = server.isPrimaryThread();

BaseFullChunk chunk = this.getChunkFromCache(isMainThread, index);
if (chunk != null) {
return chunk;
} else if (this.loadChunkInternal(index, chunkX, chunkZ, create)) {
return this.getChunkFromCache(isMainThread, index);
}

if (!isMainThread) {
Lock lock = new ReentrantLock();
Condition condition = lock.newCondition();
lock.lock();

BaseFullChunk[] result = new BaseFullChunk[1];
getServer().getScheduler().scheduleTask(null, () -> {
lock.lock();
try {
if (loadChunkInternal(index, chunkX, chunkZ, create)) {
result[0] = getChunkFromCache(true, index);
}
} finally {
condition.signal();
lock.unlock();
}
});

try {
condition.await();
} catch (InterruptedException ignored) {
} finally {
lock.unlock();
}
return result[0];
}

if (this.loadChunkInternal(index, chunkX, chunkZ, create)) {
return this.getChunkFromCache(true, index);
}

return null;
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/cn/nukkit/level/format/generic/BaseFullChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ public ChunkPacketCache getPacketCache() {
public void initChunk() {
if (this.getProvider() != null && !this.isInit) {
boolean changed = false;
if (this.NBTentities != null) {
for (CompoundTag nbt : NBTentities) {
List<CompoundTag> entities = this.NBTentities;
if (entities != null) {
for (CompoundTag nbt : entities) {
if (!nbt.contains("id")) {
this.setChanged();
continue;
Expand All @@ -162,8 +163,9 @@ public void initChunk() {
this.NBTentities = null;
}

if (this.NBTtiles != null) {
for (CompoundTag nbt : NBTtiles) {
List<CompoundTag> blockEntities = this.NBTtiles;
if (blockEntities != null) {
for (CompoundTag nbt : blockEntities) {
if (nbt != null) {
if (!nbt.contains("id")) {
changed = true;
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/cn/nukkit/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import it.unimi.dsi.fastutil.booleans.BooleanList;
import it.unimi.dsi.fastutil.bytes.ByteList;
import it.unimi.dsi.fastutil.chars.CharList;
import it.unimi.dsi.fastutil.doubles.DoubleList;
import it.unimi.dsi.fastutil.floats.FloatList;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.longs.LongList;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntRBTreeMap;
import it.unimi.dsi.fastutil.shorts.ShortList;
import lombok.extern.log4j.Log4j2;
import org.snakeyaml.engine.v2.api.Dump;
import org.snakeyaml.engine.v2.api.DumpSettings;
Expand Down Expand Up @@ -274,6 +282,14 @@ public <T> T get(String key, T defaultValue) {
return this.correct ? this.config.get(key, defaultValue) : defaultValue;
}

public Object getValue(String key) {
return this.getValue(key, null);
}

public Object getValue(String key, Object defaultValue) {
return this.correct ? this.config.getValue(key, defaultValue) : defaultValue;
}

public ConfigSection getSection(String key) {
return this.correct ? this.config.getSection(key) : new ConfigSection();
}
Expand Down Expand Up @@ -366,39 +382,39 @@ public List<String> getStringList(String key) {
return config.getStringList(key);
}

public List<Integer> getIntegerList(String key) {
public IntList getIntegerList(String key) {
return config.getIntegerList(key);
}

public List<Boolean> getBooleanList(String key) {
public BooleanList getBooleanList(String key) {
return config.getBooleanList(key);
}

public List<Double> getDoubleList(String key) {
public DoubleList getDoubleList(String key) {
return config.getDoubleList(key);
}

public List<Float> getFloatList(String key) {
public FloatList getFloatList(String key) {
return config.getFloatList(key);
}

public List<Long> getLongList(String key) {
public LongList getLongList(String key) {
return config.getLongList(key);
}

public List<Byte> getByteList(String key) {
public ByteList getByteList(String key) {
return config.getByteList(key);
}

public List<Character> getCharacterList(String key) {
public CharList getCharacterList(String key) {
return config.getCharacterList(key);
}

public List<Short> getShortList(String key) {
public ShortList getShortList(String key) {
return config.getShortList(key);
}

public List<Map> getMapList(String key) {
public List<Map<?, ?>> getMapList(String key) {
return config.getMapList(key);
}

Expand Down
Loading

0 comments on commit f3c51c9

Please sign in to comment.