Untested version for 1.7.2

This commit is contained in:
Olof Larsson 2013-12-04 12:16:03 +01:00
parent 8e0362172d
commit e6d98e4e15
13 changed files with 56 additions and 157 deletions

View File

@ -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;

View File

@ -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")

View File

@ -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?

View File

@ -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<String> lines = new ArrayList<String>();
for (Aspect aspect : AspectColl.get().getAllRegistered())
{
lines.add("<h>"+aspect.getId()+" <white>--> <h>"+aspect.getMultiverse().getId());
String line = Txt.parse("<h>"+aspect.getId()+" <white>--> <h>"+aspect.getMultiverse().getId());
lines.add(line);
}
// Send them
lines = Txt.parseWrap(lines);
this.sendMessage(Txt.getPage(lines, pageHumanBased, "Aspect List", sender));
}

View File

@ -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<String> lines = new ArrayList<String>();
for (Multiverse multiverse : MultiverseColl.get().getAll())
{
lines.add("<h>"+multiverse.getId()+" <i>has "+Txt.implodeCommaAndDot(multiverse.getUniverses(), "<aqua>%s", "<i>, ", " <i>and ", "<i>."));
String line = Txt.parse("<h>"+multiverse.getId()+" <i>has "+Txt.implodeCommaAndDot(multiverse.getUniverses(), "<aqua>%s", "<i>, ", " <i>and ", "<i>."));
lines.add(line);
}
// Send them
lines = Txt.parseWrap(lines);
this.sendMessage(Txt.getPage(lines, pageHumanBased, "Multiverse List", sender));
}

View File

@ -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<Integer, String> getBiomeIdNames()
{
Map<Integer, String> ret = new LinkedHashMap<Integer, String>();
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<Integer, String>(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);

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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()));
}
}

View File

@ -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;

View File

@ -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");
}
}

View File

@ -172,19 +172,20 @@ public class Txt
}
// -------------------------------------------- //
// Wrapping the Craftbukkit TextWrapper
// SPLIT AT LINEBREAKS
// -------------------------------------------- //
public static ArrayList<String> wrap(final String string)
{
return wrap(Arrays.asList(string.split("\\r?\\n")));
return new ArrayList<String>(Arrays.asList(string.split("\\r?\\n")));
}
public static ArrayList<String> wrap(final Collection<String> strings)
{
ArrayList<String> ret = new ArrayList<String>();
for (String line : strings)
for (String string : strings)
{
ret.addAll(Arrays.asList(TextWrapper.wrapText(line)));
ret.addAll(wrap(string));
}
return ret;
}