From e6d98e4e15a7841129643ca933a1b05f9b3e7401 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 4 Dec 2013 12:16:03 +0100 Subject: [PATCH] Untested version for 1.7.2 --- .../mcore/adapter/InventoryAdapter.java | 4 +- .../mcore/cmd/BukkitCommandDoor.java | 2 +- .../mcore/inventory/MCorePlayerInventory.java | 21 ++-- .../mcorecmd/CmdMCoreUsysAspectList.java | 7 +- .../mcorecmd/CmdMCoreUsysMultiverseList.java | 8 +- .../massivecraft/mcore/util/BiomeUtil.java | 16 +-- .../mcore/util/InventoryUtil.java | 4 +- .../massivecraft/mcore/util/LightUtil.java | 18 +-- src/com/massivecraft/mcore/util/MUtil.java | 4 +- .../massivecraft/mcore/util/PlayerUtil.java | 8 +- .../massivecraft/mcore/util/SenderUtil.java | 4 +- .../massivecraft/mcore/util/TextWrapper.java | 108 ------------------ src/com/massivecraft/mcore/util/Txt.java | 9 +- 13 files changed, 56 insertions(+), 157 deletions(-) delete mode 100644 src/com/massivecraft/mcore/util/TextWrapper.java diff --git a/src/com/massivecraft/mcore/adapter/InventoryAdapter.java b/src/com/massivecraft/mcore/adapter/InventoryAdapter.java index d993f985..acc0897f 100644 --- a/src/com/massivecraft/mcore/adapter/InventoryAdapter.java +++ b/src/com/massivecraft/mcore/adapter/InventoryAdapter.java @@ -2,8 +2,8 @@ package com.massivecraft.mcore.adapter; import java.lang.reflect.Type; -import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventoryCustom; -import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventoryPlayer; +import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventoryCustom; +import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventoryPlayer; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; diff --git a/src/com/massivecraft/mcore/cmd/BukkitCommandDoor.java b/src/com/massivecraft/mcore/cmd/BukkitCommandDoor.java index e11d4854..a639ff37 100644 --- a/src/com/massivecraft/mcore/cmd/BukkitCommandDoor.java +++ b/src/com/massivecraft/mcore/cmd/BukkitCommandDoor.java @@ -8,7 +8,7 @@ import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_6_R3.CraftServer; +import org.bukkit.craftbukkit.v1_7_R1.CraftServer; import org.bukkit.plugin.SimplePluginManager; @SuppressWarnings("unchecked") diff --git a/src/com/massivecraft/mcore/inventory/MCorePlayerInventory.java b/src/com/massivecraft/mcore/inventory/MCorePlayerInventory.java index 0add0672..98b07476 100644 --- a/src/com/massivecraft/mcore/inventory/MCorePlayerInventory.java +++ b/src/com/massivecraft/mcore/inventory/MCorePlayerInventory.java @@ -1,8 +1,8 @@ package com.massivecraft.mcore.inventory; -import net.minecraft.server.v1_6_R3.EntityHuman; -import net.minecraft.server.v1_6_R3.ItemStack; -import net.minecraft.server.v1_6_R3.PlayerInventory; +import net.minecraft.server.v1_7_R1.EntityHuman; +import net.minecraft.server.v1_7_R1.ItemStack; +import net.minecraft.server.v1_7_R1.PlayerInventory; import org.bukkit.inventory.InventoryHolder; @@ -11,13 +11,13 @@ import org.bukkit.inventory.InventoryHolder; * It is extended in such a way that it has a no-arg constructor. * It is mainly used for deserialization of PlayerInventor. * - * What is tricky about the NMS.PlayerInventory is that it does hold a link/field to the holder/player. - * It is however acceptable for this field "public EntityHuman player" to be null as long as some internal methods are rewritten. - * - * NPE evasion is achieved by overriding all internal methods using the player field. + * There is a link/field to the holder/player. + * We override internal methods where necessary. * * How to update: - * Do go to NMS.PlayerInventory and search for references to "player". + * Make sure there is a no-arg constructor. + * Search for references to "public EntityHuman player". + * * As of 1.5.1 these are the references: * * a(EntityHuman) (2 matches) @@ -28,7 +28,7 @@ import org.bukkit.inventory.InventoryHolder; * pickup(ItemStack) (2 matches) * PlayerInventory(EntityHuman) * - * As of 1.6.1 and 1.6.2 and 1.6.4 these are the references: + * As of 1.6.1 and 1.6.2 and 1.6.4 and 1.7.2 these are the references: * * a(EntityHuman) (2 matches) * a(float) @@ -37,6 +37,7 @@ import org.bukkit.inventory.InventoryHolder; * m() (2 matches) * pickup(ItemStack) (2 matches) * PlayerInventory(EntityHuman) + * */ public class MCorePlayerInventory extends PlayerInventory @@ -51,7 +52,7 @@ public class MCorePlayerInventory extends PlayerInventory } // -------------------------------------------- // - // NPE EVASION + // OVERRIDE // -------------------------------------------- // // Is the entityhuman within reach? diff --git a/src/com/massivecraft/mcore/mcorecmd/CmdMCoreUsysAspectList.java b/src/com/massivecraft/mcore/mcorecmd/CmdMCoreUsysAspectList.java index 6f065a53..97fb0057 100644 --- a/src/com/massivecraft/mcore/mcorecmd/CmdMCoreUsysAspectList.java +++ b/src/com/massivecraft/mcore/mcorecmd/CmdMCoreUsysAspectList.java @@ -36,19 +36,20 @@ public class CmdMCoreUsysAspectList extends MCommand @Override public void perform() { + // Args Integer pageHumanBased = this.arg(0, ARInteger.get(), 1); if (pageHumanBased == null) return; - // Create Messages + // Create Lines List lines = new ArrayList(); for (Aspect aspect : AspectColl.get().getAllRegistered()) { - lines.add(""+aspect.getId()+" --> "+aspect.getMultiverse().getId()); + String line = Txt.parse(""+aspect.getId()+" --> "+aspect.getMultiverse().getId()); + lines.add(line); } // Send them - lines = Txt.parseWrap(lines); this.sendMessage(Txt.getPage(lines, pageHumanBased, "Aspect List", sender)); } diff --git a/src/com/massivecraft/mcore/mcorecmd/CmdMCoreUsysMultiverseList.java b/src/com/massivecraft/mcore/mcorecmd/CmdMCoreUsysMultiverseList.java index 758c2974..8e5889af 100644 --- a/src/com/massivecraft/mcore/mcorecmd/CmdMCoreUsysMultiverseList.java +++ b/src/com/massivecraft/mcore/mcorecmd/CmdMCoreUsysMultiverseList.java @@ -36,19 +36,19 @@ public class CmdMCoreUsysMultiverseList extends MCommand @Override public void perform() { + // Args Integer pageHumanBased = this.arg(0, ARInteger.get(), 1); if (pageHumanBased == null) return; - // Create Messages + // Create Lines List lines = new ArrayList(); - for (Multiverse multiverse : MultiverseColl.get().getAll()) { - lines.add(""+multiverse.getId()+" has "+Txt.implodeCommaAndDot(multiverse.getUniverses(), "%s", ", ", " and ", ".")); + String line = Txt.parse(""+multiverse.getId()+" has "+Txt.implodeCommaAndDot(multiverse.getUniverses(), "%s", ", ", " and ", ".")); + lines.add(line); } // Send them - lines = Txt.parseWrap(lines); this.sendMessage(Txt.getPage(lines, pageHumanBased, "Multiverse List", sender)); } diff --git a/src/com/massivecraft/mcore/util/BiomeUtil.java b/src/com/massivecraft/mcore/util/BiomeUtil.java index 2bddab64..dee04219 100644 --- a/src/com/massivecraft/mcore/util/BiomeUtil.java +++ b/src/com/massivecraft/mcore/util/BiomeUtil.java @@ -5,22 +5,22 @@ import java.util.Map; import java.util.Map.Entry; import java.util.AbstractMap.SimpleEntry; -import net.minecraft.server.v1_6_R3.BiomeBase; -import net.minecraft.server.v1_6_R3.Chunk; -import net.minecraft.server.v1_6_R3.WorldServer; +import net.minecraft.server.v1_7_R1.BiomeBase; +import net.minecraft.server.v1_7_R1.Chunk; +import net.minecraft.server.v1_7_R1.WorldServer; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_6_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_7_R1.CraftWorld; public class BiomeUtil { public static Map getBiomeIdNames() { Map ret = new LinkedHashMap(); - for(BiomeBase bb : BiomeBase.biomes) + for (BiomeBase bb : BiomeBase.n()) { if (bb == null) continue; - ret.put(bb.id, bb.y); + ret.put(bb.id, bb.af); } return ret; } @@ -33,7 +33,7 @@ public class BiomeUtil BiomeBase biomeBase = worldServer.getBiome(x, z); Integer id = biomeBase.id; - String name = biomeBase.y; + String name = biomeBase.af; return new SimpleEntry(id, name); } @@ -43,7 +43,7 @@ public class BiomeUtil CraftWorld craftWorld = (CraftWorld)world; WorldServer worldServer = craftWorld.getHandle(); - BiomeBase bb = BiomeBase.biomes[id]; + BiomeBase bb = BiomeBase.getBiome(id); if (craftWorld.loadChunk(x >> 4, z >> 4, false)) { Chunk chunk = worldServer.getChunkAtWorldCoords(x, z); diff --git a/src/com/massivecraft/mcore/util/InventoryUtil.java b/src/com/massivecraft/mcore/util/InventoryUtil.java index 21378923..875fd96f 100644 --- a/src/com/massivecraft/mcore/util/InventoryUtil.java +++ b/src/com/massivecraft/mcore/util/InventoryUtil.java @@ -4,8 +4,8 @@ import java.util.HashMap; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventoryCustom; -import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventoryPlayer; +import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventoryCustom; +import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventoryPlayer; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; diff --git a/src/com/massivecraft/mcore/util/LightUtil.java b/src/com/massivecraft/mcore/util/LightUtil.java index 9f299130..576f9ed9 100644 --- a/src/com/massivecraft/mcore/util/LightUtil.java +++ b/src/com/massivecraft/mcore/util/LightUtil.java @@ -1,21 +1,25 @@ package com.massivecraft.mcore.util; -import net.minecraft.server.v1_6_R3.WorldServer; +import net.minecraft.server.v1_7_R1.WorldServer; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_6_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_7_R1.CraftWorld; /** * Find the method by going through CraftBlock.setTypeId() * The method should look something like this: * - * public void A(int i, int j, int k) { - if (!this.worldProvider.f) { - this.c(EnumSkyBlock.SKY, i, j, k); + * + public boolean t(int i, int j, int k) { + boolean flag = false; + + if (!this.worldProvider.g) { + flag |= this.c(EnumSkyBlock.SKY, i, j, k); } - this.c(EnumSkyBlock.BLOCK, i, j, k); + flag |= this.c(EnumSkyBlock.BLOCK, i, j, k); + return flag; } * */ @@ -36,7 +40,7 @@ public class LightUtil { CraftWorld cworld = (CraftWorld)world; WorldServer worldServer = cworld.getHandle(); - worldServer.A(x, y, z); + worldServer.t(x, y, z); } } diff --git a/src/com/massivecraft/mcore/util/MUtil.java b/src/com/massivecraft/mcore/util/MUtil.java index 2ead319b..da125041 100644 --- a/src/com/massivecraft/mcore/util/MUtil.java +++ b/src/com/massivecraft/mcore/util/MUtil.java @@ -19,7 +19,7 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import net.minecraft.server.v1_6_R3.DedicatedServer; +import net.minecraft.server.v1_7_R1.DedicatedServer; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -27,7 +27,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.v1_6_R3.CraftServer; +import org.bukkit.craftbukkit.v1_7_R1.CraftServer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; diff --git a/src/com/massivecraft/mcore/util/PlayerUtil.java b/src/com/massivecraft/mcore/util/PlayerUtil.java index a08e7438..cad0b263 100644 --- a/src/com/massivecraft/mcore/util/PlayerUtil.java +++ b/src/com/massivecraft/mcore/util/PlayerUtil.java @@ -5,11 +5,11 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentSkipListSet; -import net.minecraft.server.v1_6_R3.EntityPlayer; -import net.minecraft.server.v1_6_R3.Packet8UpdateHealth; +import net.minecraft.server.v1_7_R1.EntityPlayer; +import net.minecraft.server.v1_7_R1.PacketPlayOutUpdateHealth; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -135,7 +135,7 @@ public class PlayerUtil implements Listener { CraftPlayer cplayer = (CraftPlayer)player; EntityPlayer eplayer = cplayer.getHandle(); - eplayer.playerConnection.sendPacket(new Packet8UpdateHealth(eplayer.getHealth(), eplayer.getFoodData().a(), eplayer.getFoodData().e())); + eplayer.playerConnection.sendPacket(new PacketPlayOutUpdateHealth(cplayer.getScaledHealth(), eplayer.getFoodData().a(), eplayer.getFoodData().e())); } } diff --git a/src/com/massivecraft/mcore/util/SenderUtil.java b/src/com/massivecraft/mcore/util/SenderUtil.java index 47892244..9c12d43c 100644 --- a/src/com/massivecraft/mcore/util/SenderUtil.java +++ b/src/com/massivecraft/mcore/util/SenderUtil.java @@ -8,7 +8,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; -import net.minecraft.server.v1_6_R3.MinecraftServer; +import net.minecraft.server.v1_7_R1.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -17,7 +17,7 @@ import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.RemoteConsoleCommandSender; -import org.bukkit.craftbukkit.v1_6_R3.CraftServer; +import org.bukkit.craftbukkit.v1_7_R1.CraftServer; import org.bukkit.entity.Player; import com.massivecraft.mcore.MCore; diff --git a/src/com/massivecraft/mcore/util/TextWrapper.java b/src/com/massivecraft/mcore/util/TextWrapper.java deleted file mode 100644 index edb78b52..00000000 --- a/src/com/massivecraft/mcore/util/TextWrapper.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.massivecraft.mcore.util; - -// This is a modified version of: https://github.com/Bukkit/CraftBukkit/blob/dbd06b46f2bb6a0be4f93642fe0bf57d97d8feb4/src/main/java/org/bukkit/craftbukkit/TextWrapper.java -public class TextWrapper -{ - private static final int[] characterWidths = new int[] { - 1, 9, 9, 8, 8, 8, 8, 7, 9, 8, 9, 9, 8, 9, 9, 9, - 8, 8, 8, 8, 9, 9, 8, 9, 8, 8, 8, 8, 8, 9, 9, 9, - 4, 2, 5, 6, 6, 6, 6, 3, 5, 5, 5, 6, 2, 6, 2, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 2, 5, 6, 5, 6, - 7, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 4, 6, 6, - 3, 6, 6, 6, 6, 6, 5, 6, 6, 2, 6, 5, 3, 6, 6, 6, - 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 5, 2, 5, 7, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 3, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, - 6, 3, 6, 6, 6, 6, 6, 6, 6, 7, 6, 6, 6, 2, 6, 6, - 8, 9, 9, 6, 6, 6, 8, 8, 6, 8, 8, 8, 8, 8, 6, 6, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 9, 9, 9, 5, 9, 9, - 8, 7, 7, 8, 7, 8, 8, 8, 7, 8, 8, 7, 9, 9, 6, 7, - 7, 7, 7, 7, 9, 6, 7, 8, 7, 6, 6, 9, 7, 6, 7, 1 - }; - - private static final char COLOR_CHAR = '\u00A7'; - private static final int CHAT_WINDOW_WIDTH = 320; - private static final int CHAT_STRING_LENGTH = 119; - private static final String allowedChars = net.minecraft.server.v1_6_R3.SharedConstants.allowedCharacters; - - public static int getCharPixelWidth(char ch) - { - // Figure out if it's allowed - int index = allowedChars.indexOf(ch); - if (index == -1) - { - return 9; - } - else - { - // Sadly needed as the allowedChars string misses the first - index += 32; - } - - return characterWidths[index]; - } - - public static String[] wrapText(final String text) - { - final StringBuilder out = new StringBuilder(); - char colorChar = 'f'; - int lineWidth = 0; - int lineLength = 0; - - // Go over the message char by char. - for (int i = 0; i < text.length(); i++) - { - char ch = text.charAt(i); - - // Get the color - if (ch == COLOR_CHAR && i < text.length() - 1) - { - // We might need a linebreak ... so ugly ;( - if (lineLength + 2 > CHAT_STRING_LENGTH) - { - out.append('\n'); - lineLength = 0; - //if (colorChar != 'f' && colorChar != 'F') - //{ - out.append(COLOR_CHAR).append(colorChar); - lineLength += 2; - //} - } - colorChar = text.charAt(++i); - out.append(COLOR_CHAR).append(colorChar); - lineLength += 2; - continue; - } - - // Find the width - final int width = getCharPixelWidth(ch); - - // See if we need a linebreak - if (lineLength + 1 > CHAT_STRING_LENGTH || lineWidth + width >= CHAT_WINDOW_WIDTH) - { - out.append('\n'); - lineLength = 0; - - // Re-apply the last color if it isn't the default - //if (colorChar != 'f' && colorChar != 'F') - //{ - out.append(COLOR_CHAR).append(colorChar); - lineLength += 2; - //} - lineWidth = width; - } - else - { - lineWidth += width; - } - out.append(ch); - lineLength++; - } - - // Return it split - return out.toString().split("\n"); - } - -} diff --git a/src/com/massivecraft/mcore/util/Txt.java b/src/com/massivecraft/mcore/util/Txt.java index 98f31e13..50e6303b 100644 --- a/src/com/massivecraft/mcore/util/Txt.java +++ b/src/com/massivecraft/mcore/util/Txt.java @@ -172,19 +172,20 @@ public class Txt } // -------------------------------------------- // - // Wrapping the Craftbukkit TextWrapper + // SPLIT AT LINEBREAKS // -------------------------------------------- // + public static ArrayList wrap(final String string) { - return wrap(Arrays.asList(string.split("\\r?\\n"))); + return new ArrayList(Arrays.asList(string.split("\\r?\\n"))); } public static ArrayList wrap(final Collection strings) { ArrayList ret = new ArrayList(); - for (String line : strings) + for (String string : strings) { - ret.addAll(Arrays.asList(TextWrapper.wrapText(line))); + ret.addAll(wrap(string)); } return ret; }