diff --git a/src/main/java/net/minecraft/server/GameRules.java b/src/main/java/net/minecraft/server/GameRules.java new file mode 100644 index 000000000..d383c9f46 --- /dev/null +++ b/src/main/java/net/minecraft/server/GameRules.java @@ -0,0 +1,241 @@ +package net.minecraft.server; + +import com.google.common.collect.Maps; +import com.koloboke.collect.map.hash.HashObjObjMap; +import com.koloboke.collect.map.hash.HashObjObjMaps; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; + +import java.util.Collections; +import java.util.Iterator; +import java.util.Set; +import java.util.TreeMap; +import java.util.Map.Entry; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.Supplier; +import javax.annotation.Nullable; + +import org.omg.CORBA.DefinitionKind; + +public class GameRules { + + private static final TreeMap a = (TreeMap) SystemUtils.a(new TreeMap(), (treemap) -> { // Akarin - fixes decompile error + treemap.put("doFireTick", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("mobGriefing", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("keepInventory", new GameRules.GameRuleDefinition("false", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("doMobSpawning", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("doMobLoot", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("doTileDrops", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("doEntityDrops", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("commandBlockOutput", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("naturalRegeneration", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("doDaylightCycle", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("logAdminCommands", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("showDeathMessages", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("randomTickSpeed", new GameRules.GameRuleDefinition("3", GameRules.EnumGameRuleType.NUMERICAL_VALUE)); + treemap.put("sendCommandFeedback", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("reducedDebugInfo", new GameRules.GameRuleDefinition("false", GameRules.EnumGameRuleType.BOOLEAN_VALUE, (minecraftserver, gamerules_gamerulevalue) -> { + int i = gamerules_gamerulevalue.b() ? 22 : 23; + Iterator iterator = minecraftserver.getPlayerList().v().iterator(); + + while (iterator.hasNext()) { + EntityPlayer entityplayer = (EntityPlayer) iterator.next(); + + entityplayer.playerConnection.sendPacket(new PacketPlayOutEntityStatus(entityplayer, (byte) i)); + } + + })); + treemap.put("spectatorsGenerateChunks", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("spawnRadius", new GameRules.GameRuleDefinition("10", GameRules.EnumGameRuleType.NUMERICAL_VALUE)); + treemap.put("disableElytraMovementCheck", new GameRules.GameRuleDefinition("false", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("maxEntityCramming", new GameRules.GameRuleDefinition("24", GameRules.EnumGameRuleType.NUMERICAL_VALUE)); + treemap.put("doWeatherCycle", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("doLimitedCrafting", new GameRules.GameRuleDefinition("false", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + treemap.put("maxCommandChainLength", new GameRules.GameRuleDefinition("65536", GameRules.EnumGameRuleType.NUMERICAL_VALUE)); + treemap.put("announceAdvancements", new GameRules.GameRuleDefinition("true", GameRules.EnumGameRuleType.BOOLEAN_VALUE)); + }); + private final HashObjObjMap b = HashObjObjMaps.newImmutableMap(Maps.transformValues(GameRules.a, GameRules.GameRuleDefinition::a)); // Akarin + + public GameRules() { + // Akarin start + /* + Iterator iterator = GameRules.a.entrySet().iterator(); + + while (iterator.hasNext()) { + Entry entry = (Entry) iterator.next(); + + this.b.put(entry.getKey(), ((GameRules.GameRuleDefinition) entry.getValue()).a()); + } + */ + // Akarin end + + } + + public void set(String s, String s1, @Nullable MinecraftServer minecraftserver) { + GameRules.GameRuleValue gamerules_gamerulevalue = (GameRules.GameRuleValue) this.b.get(s); + + if (gamerules_gamerulevalue != null) { + gamerules_gamerulevalue.a(s1, minecraftserver); + } + + } + + public boolean getBoolean(String s) { + GameRules.GameRuleValue gamerules_gamerulevalue = (GameRules.GameRuleValue) this.b.get(s); + + return gamerules_gamerulevalue != null ? gamerules_gamerulevalue.b() : false; + } + + public int c(String s) { + GameRules.GameRuleValue gamerules_gamerulevalue = (GameRules.GameRuleValue) this.b.get(s); + + return gamerules_gamerulevalue != null ? gamerules_gamerulevalue.c() : 0; + } + + public NBTTagCompound a() { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + Iterator iterator = this.b.keySet().iterator(); + + while (iterator.hasNext()) { + String s = (String) iterator.next(); + GameRules.GameRuleValue gamerules_gamerulevalue = (GameRules.GameRuleValue) this.b.get(s); + + nbttagcompound.setString(s, gamerules_gamerulevalue.a()); + } + + return nbttagcompound; + } + + public void a(NBTTagCompound nbttagcompound) { + Set set = nbttagcompound.getKeys(); + Iterator iterator = set.iterator(); + + while (iterator.hasNext()) { + String s = (String) iterator.next(); + + this.set(s, nbttagcompound.getString(s), (MinecraftServer) null); + } + + } + + public GameRules.GameRuleValue get(String s) { + return (GameRules.GameRuleValue) this.b.get(s); + } + + public static TreeMap getGameRules() { + return GameRules.a; + } + + public static enum EnumGameRuleType { + + ANY_VALUE(StringArgumentType::greedyString, (commandcontext, s) -> { + return (String) commandcontext.getArgument(s, String.class); + }), BOOLEAN_VALUE(BoolArgumentType::bool, (commandcontext, s) -> { + return ((Boolean) commandcontext.getArgument(s, Boolean.class)).toString(); + }), NUMERICAL_VALUE(IntegerArgumentType::integer, (commandcontext, s) -> { + return ((Integer) commandcontext.getArgument(s, Integer.class)).toString(); + }); + + private final Supplier> d; + private final BiFunction, String, String> e; + + private EnumGameRuleType(Supplier supplier, BiFunction, String, String> bifunction) { // Akarin - fixes decompile error + this.d = supplier; + this.e = bifunction; + } + + public RequiredArgumentBuilder a(String s) { + return CommandDispatcher.a(s, (ArgumentType) this.d.get()); + } + + public void a(CommandContext commandcontext, String s, GameRules.GameRuleValue gamerules_gamerulevalue) { + gamerules_gamerulevalue.a((String) this.e.apply(commandcontext, s), ((CommandListenerWrapper) commandcontext.getSource()).getServer()); + } + } + + public static class GameRuleValue { + + private String a; + private boolean b; + private int c; + private double d; + private final GameRules.EnumGameRuleType e; + private final BiConsumer f; + + public GameRuleValue(String s, GameRules.EnumGameRuleType gamerules_enumgameruletype, BiConsumer biconsumer) { + this.e = gamerules_enumgameruletype; + this.f = biconsumer; + this.a(s, (MinecraftServer) null); + } + + public void a(String s, @Nullable MinecraftServer minecraftserver) { + this.a = s; + this.b = Boolean.parseBoolean(s); + this.c = this.b ? 1 : 0; + + try { + this.c = Integer.parseInt(s); + } catch (NumberFormatException numberformatexception) { + ; + } + + try { + this.d = Double.parseDouble(s); + } catch (NumberFormatException numberformatexception1) { + ; + } + + if (minecraftserver != null) { + this.f.accept(minecraftserver, this); + } + + } + + public String a() { + return this.a; + } + + public boolean b() { + return this.b; + } + + public int c() { + return this.c; + } + + public GameRules.EnumGameRuleType getType() { + return this.e; + } + } + + public static class GameRuleDefinition { + + private final GameRules.EnumGameRuleType a; + private final String b; + private final BiConsumer c; + + public GameRuleDefinition(String s, GameRules.EnumGameRuleType gamerules_enumgameruletype) { + this(s, gamerules_enumgameruletype, (minecraftserver, gamerules_gamerulevalue) -> { + }); + } + + public GameRuleDefinition(String s, GameRules.EnumGameRuleType gamerules_enumgameruletype, BiConsumer biconsumer) { + this.a = gamerules_enumgameruletype; + this.b = s; + this.c = biconsumer; + } + + public GameRules.GameRuleValue a() { + return new GameRules.GameRuleValue(this.b, this.a, this.c); + } + + public GameRules.EnumGameRuleType b() { + return this.a; + } + } +} diff --git a/src/test/java/org/bukkit/GameRuleTest.java b/src/test/java/org/bukkit/GameRuleTest.java index 1ed0f4cf2..410b2485c 100644 --- a/src/test/java/org/bukkit/GameRuleTest.java +++ b/src/test/java/org/bukkit/GameRuleTest.java @@ -3,9 +3,13 @@ package org.bukkit; import java.util.Map; import java.util.TreeMap; import net.minecraft.server.GameRules; +import net.minecraft.server.GameRules.GameRuleDefinition; + import org.junit.Assert; import org.junit.Test; +import com.koloboke.collect.map.hash.HashObjObjMap; + public class GameRuleTest { @Test @@ -21,7 +25,7 @@ public class GameRuleTest { @Test public void testMinecraftRules() { - TreeMap minecraftRules = GameRules.getGameRules(); + TreeMap minecraftRules = GameRules.getGameRules(); for (Map.Entry entry : minecraftRules.entrySet()) { GameRule bukkitRule = GameRule.getByName(entry.getKey()); diff --git a/work/Paper b/work/Paper index c5ef31cb0..e8bbfbfdd 160000 --- a/work/Paper +++ b/work/Paper @@ -1 +1 @@ -Subproject commit c5ef31cb0d5ca1c65727682b3dc1fbc3e98ea250 +Subproject commit e8bbfbfddf682fd10cee5f039c11fdacf70eafed