From f4b6d4e44e6aac85ad827cc7088e7592f2850dba Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Wed, 22 Apr 2015 16:06:38 -0400 Subject: [PATCH] Starting on converting to 1.8 --- .../core/common/jsonchat/JsonMessage.java | 24 +- .../mineplex/core/common/util/UtilPlayer.java | 14 +- .../mineplex/core/common/util/WorldUtil.java | 211 +++++++++--------- 3 files changed, 115 insertions(+), 134 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java index 0d8f6fb01..0e5311230 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java @@ -1,11 +1,10 @@ package mineplex.core.common.jsonchat; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.minecraft.server.v1_7_R4.ChatSerializer; -import net.minecraft.server.v1_7_R4.PacketPlayOutChat; +import net.minecraft.server.v1_8_R2.IChatBaseComponent; +import net.minecraft.server.v1_8_R2.PacketPlayOutChat; -import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; public class JsonMessage @@ -119,25 +118,12 @@ public class JsonMessage */ public void send(MessageType messageType, Player... players) { - send(messageType, false, players); - } - - /** - * Send a message to players using the new 1.8 message types - * - * @param messageType Message type to send - * @param defaultToChat Only applies to MessageType.ABOVE_HOTBAR. If true, it will send this to chat for 1.7 clients - * @param players Players to send to - */ - public void send(MessageType messageType, boolean defaultToChat, Player... players) - { - PacketPlayOutChat chatPacket = new PacketPlayOutChat(ChatSerializer.a(toString())); + PacketPlayOutChat chatPacket = new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(toString())); chatPacket.setChatType(messageType.getId()); for (Player player : players) { - if (defaultToChat || messageType != MessageType.ABOVE_HOTBAR || UtilPlayer.is1_8(player)) - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(chatPacket); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(chatPacket); } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index 322a55134..21ce78908 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -7,18 +7,17 @@ import java.util.List; import java.util.UUID; import org.bukkit.ChatColor; -import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.minecraft.server.v1_7_R4.Packet; -import net.minecraft.server.v1_7_R4.PlayerConnection; +import net.minecraft.server.v1_8_R2.Packet; +import net.minecraft.server.v1_8_R2.PlayerConnection; public class UtilPlayer { @@ -587,11 +586,6 @@ public class UtilPlayer return (((CraftEntity) player).getHandle().getDataWatcher().getByte(0) & 1 << 4) != 0; } - public static boolean is1_8(Player player) - { - return ((CraftPlayer) player).getHandle().playerConnection.networkManager.getVersion() >= 47; - } - public static void sendPacket(Player player, Packet... packets) { PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/WorldUtil.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/WorldUtil.java index 8df6595b3..a4a27f77c 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/WorldUtil.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/WorldUtil.java @@ -2,23 +2,22 @@ package mineplex.core.common.util; import java.io.File; -import net.minecraft.server.v1_7_R4.ConvertProgressUpdater; -import net.minecraft.server.v1_7_R4.Convertable; -import net.minecraft.server.v1_7_R4.EntityTracker; -import net.minecraft.server.v1_7_R4.EnumDifficulty; -import net.minecraft.server.v1_7_R4.EnumGamemode; -import net.minecraft.server.v1_7_R4.IWorldAccess; -import net.minecraft.server.v1_7_R4.ServerNBTManager; -import net.minecraft.server.v1_7_R4.WorldLoaderServer; -import net.minecraft.server.v1_7_R4.WorldManager; -import net.minecraft.server.v1_7_R4.WorldServer; -import net.minecraft.server.v1_7_R4.WorldSettings; -import net.minecraft.server.v1_7_R4.WorldType; +import net.minecraft.server.v1_8_R2.Convertable; +import net.minecraft.server.v1_8_R2.EntityTracker; +import net.minecraft.server.v1_8_R2.EnumDifficulty; +import net.minecraft.server.v1_8_R2.IWorldAccess; +import net.minecraft.server.v1_8_R2.ServerNBTManager; +import net.minecraft.server.v1_8_R2.WorldData; +import net.minecraft.server.v1_8_R2.WorldLoaderServer; +import net.minecraft.server.v1_8_R2.WorldManager; +import net.minecraft.server.v1_8_R2.WorldServer; +import net.minecraft.server.v1_8_R2.WorldSettings; +import net.minecraft.server.v1_8_R2.WorldType; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; -import org.bukkit.craftbukkit.v1_7_R4.CraftServer; +import org.bukkit.craftbukkit.v1_8_R2.CraftServer; import org.bukkit.event.world.WorldInitEvent; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.generator.ChunkGenerator; @@ -28,107 +27,109 @@ public class WorldUtil public static World LoadWorld(WorldCreator creator) { CraftServer server = (CraftServer)Bukkit.getServer(); - if (creator == null) - { - throw new IllegalArgumentException("Creator may not be null"); - } + if (creator == null) + { + throw new IllegalArgumentException("Creator may not be null"); + } - String name = creator.name(); - System.out.println("Loading world '" + name + "'"); - ChunkGenerator generator = creator.generator(); - File folder = new File(server.getWorldContainer(), name); - World world = server.getWorld(name); - WorldType type = WorldType.getType(creator.type().getName()); - boolean generateStructures = creator.generateStructures(); + String name = creator.name(); + System.out.println("Loading world '" + name + "'"); + ChunkGenerator generator = creator.generator(); + File folder = new File(server.getWorldContainer(), name); + World world = server.getWorld(name); + WorldType type = WorldType.getType(creator.type().getName()); + boolean generateStructures = creator.generateStructures(); - if (world != null) - { - return world; - } + if (world != null) + { + return world; + } - if ((folder.exists()) && (!folder.isDirectory())) - { - throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder"); - } + if ((folder.exists()) && (!folder.isDirectory())) + { + throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder"); + } - if (generator == null) - { - generator = server.getGenerator(name); - } + if (generator == null) + { + generator = server.getGenerator(name); + } - Convertable converter = new WorldLoaderServer(server.getWorldContainer()); - if (converter.isConvertable(name)) - { - server.getLogger().info("Converting world '" + name + "'"); - converter.convert(name, new ConvertProgressUpdater(server.getServer())); - } + // TODO - +// Convertable converter = new WorldLoaderServer(server.getWorldContainer()); +// if (converter.isConvertable(name)) +// { +// server.getLogger().info("Converting world '" + name + "'"); +// converter.convert(name, new ConvertProgressUpdater(server.getServer())); +// } - int dimension = server.getWorlds().size() + 1; - boolean used = false; - do - { - for (WorldServer worldServer : server.getServer().worlds) - { - used = worldServer.dimension == dimension; - if (used) - { - dimension++; - break; - } - } - } while(used); - boolean hardcore = false; + int dimension = server.getWorlds().size() + 1; + boolean used = false; + do + { + for (WorldServer worldServer : server.getServer().worlds) + { + used = worldServer.dimension == dimension; + if (used) + { + dimension++; + break; + } + } + } while(used); + boolean hardcore = false; - System.out.println("Loaded world with dimension : " + dimension); - - WorldServer internal = new WorldServer(server.getServer(), new ServerNBTManager(server.getWorldContainer(), name, true), name, dimension, new WorldSettings(creator.seed(), EnumGamemode.getById(server.getDefaultGameMode().getValue()), generateStructures, hardcore, type), server.getServer().methodProfiler, creator.environment(), generator); - - boolean containsWorld = false; - for (World otherWorld : server.getWorlds()) - { - if (otherWorld.getName().equalsIgnoreCase(name.toLowerCase())) - { - containsWorld = true; - break; - } - } - - if (!containsWorld) - return null; + System.out.println("Loaded world with dimension : " + dimension); - System.out.println("Created world with dimension : " + dimension); - - internal.scoreboard = server.getScoreboardManager().getMainScoreboard().getHandle(); - internal.worldMaps = server.getServer().worlds.get(0).worldMaps; - internal.tracker = new EntityTracker(internal); // CraftBukkit - internal.addIWorldAccess((IWorldAccess) new WorldManager(server.getServer(), internal)); - internal.difficulty = EnumDifficulty.HARD; - internal.setSpawnFlags(true, true); - internal.savingDisabled = true; - server.getServer().worlds.add(internal); + WorldData worldData = new WorldData(new WorldSettings(creator.seed(), WorldSettings.EnumGamemode.getById(server.getDefaultGameMode().getValue()), generateStructures, hardcore, type), name); + WorldServer internal = new WorldServer(server.getServer(), new ServerNBTManager(server.getWorldContainer(), name, true), worldData, dimension, server.getServer().methodProfiler, creator.environment(), generator); - /* - for (WorldServer worlder : server.getServer().worlds) - { - System.out.println(worlder.getWorldData().getName() + " with dimension: " + worlder.dimension); - } - */ - - if (generator != null) - { - internal.getWorld().getPopulators().addAll(generator.getDefaultPopulators(internal.getWorld())); - } + boolean containsWorld = false; + for (World otherWorld : server.getWorlds()) + { + if (otherWorld.getName().equalsIgnoreCase(name.toLowerCase())) + { + containsWorld = true; + break; + } + } - server.getPluginManager().callEvent(new WorldInitEvent(internal.getWorld())); - server.getPluginManager().callEvent(new WorldLoadEvent(internal.getWorld())); - - /* - for (WorldServer worlder : server.getServer().worlds) - { - System.out.println(worlder.getWorldData().getName() + " with dimension: " + worlder.dimension); - } - */ - - return internal.getWorld(); + if (!containsWorld) + return null; + + System.out.println("Created world with dimension : " + dimension); + + internal.scoreboard = server.getScoreboardManager().getMainScoreboard().getHandle(); + internal.worldMaps = server.getServer().worlds.get(0).worldMaps; + internal.tracker = new EntityTracker(internal); // CraftBukkit + internal.addIWorldAccess((IWorldAccess) new WorldManager(server.getServer(), internal)); + internal.worldData.setDifficulty(EnumDifficulty.HARD); + internal.setSpawnFlags(true, true); + internal.savingDisabled = true; + server.getServer().worlds.add(internal); + + /* + for (WorldServer worlder : server.getServer().worlds) + { + System.out.println(worlder.getWorldData().getName() + " with dimension: " + worlder.dimension); + } + */ + + if (generator != null) + { + internal.getWorld().getPopulators().addAll(generator.getDefaultPopulators(internal.getWorld())); + } + + server.getPluginManager().callEvent(new WorldInitEvent(internal.getWorld())); + server.getPluginManager().callEvent(new WorldLoadEvent(internal.getWorld())); + + /* + for (WorldServer worlder : server.getServer().worlds) + { + System.out.println(worlder.getWorldData().getName() + " with dimension: " + worlder.dimension); + } + */ + + return internal.getWorld(); } }