V1.0.2 for CB 1.2.5-R4.1

This commit is contained in:
Olof Larsson 2012-06-20 11:12:28 +02:00
parent 10ff054323
commit 56828bc3e6
5 changed files with 143 additions and 4 deletions

View File

@ -1,4 +1,4 @@
name: mcore3 name: mcore3
version: 1.0.1 version: 1.0.2
main: com.massivecraft.mcore3.MCore main: com.massivecraft.mcore3.MCore
load: startup load: startup

View File

@ -1,5 +1,6 @@
package com.massivecraft.mcore3.cmd; package com.massivecraft.mcore3.cmd;
import java.lang.reflect.Field;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -7,6 +8,7 @@ import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap; import org.bukkit.command.SimpleCommandMap;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -57,4 +59,19 @@ public class Cmd
CraftServer craftServer = (CraftServer)Bukkit.getServer(); CraftServer craftServer = (CraftServer)Bukkit.getServer();
return craftServer.getCommandMap(); return craftServer.getCommandMap();
} }
@SuppressWarnings("unchecked")
public static Map<String, Command> getKnownCommandsFromSimpleCommandMap(SimpleCommandMap scm)
{
try
{
Field field = SimpleCommandMap.class.getDeclaredField("knownCommands");
field.setAccessible(true);
return (Map<String, Command>) field.get(scm);
}
catch (Exception e)
{
return null;
}
}
} }

View File

@ -4,7 +4,9 @@ import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.mcore3.Lang; import com.massivecraft.mcore3.Lang;
@ -148,9 +150,23 @@ public abstract class MCommand
public boolean register() public boolean register()
{ {
// TODO: Save this somewhere? And update it on changes to the aliases? return register(false);
}
public boolean register(boolean override)
{
BukkitGlueCommand bgc = new BukkitGlueCommand(this); BukkitGlueCommand bgc = new BukkitGlueCommand(this);
return Cmd.getBukkitCommandMap().register("mcore", bgc); SimpleCommandMap scm = Cmd.getBukkitCommandMap();
if (override)
{
// Our commands are more important than your commands :P
Map<String, Command> knownCommands = Cmd.getKnownCommandsFromSimpleCommandMap(scm);
String lowerLabel = bgc.getName().trim().toLowerCase();
knownCommands.remove(lowerLabel);
}
return scm.register("mcore", bgc);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -0,0 +1,107 @@
package com.massivecraft.mcore3.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.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

@ -8,7 +8,6 @@ import java.util.regex.Pattern;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.TextWrapper;
public class Txt public class Txt
{ {