Java 类net.minecraft.util.text.TextComponentUtils 实例源码
项目:Backmemed
文件:CommandMessageRaw.java
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 2)
{
throw new WrongUsageException("commands.tellraw.usage", new Object[0]);
}
else
{
EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
String s = buildString(args, 1);
try
{
ITextComponent itextcomponent = ITextComponent.Serializer.jsonToComponent(s);
entityplayer.addChatMessage(TextComponentUtils.processComponent(sender, itextcomponent, entityplayer));
}
catch (JsonParseException jsonparseexception)
{
throw toSyntaxException(jsonparseexception);
}
}
}
项目:CustomWorldGen
文件:CommandMessageRaw.java
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 2)
{
throw new WrongUsageException("commands.tellraw.usage", new Object[0]);
}
else
{
EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
String s = buildString(args, 1);
try
{
ITextComponent itextcomponent = ITextComponent.Serializer.jsonToComponent(s);
entityplayer.addChatMessage(TextComponentUtils.processComponent(sender, itextcomponent, entityplayer));
}
catch (JsonParseException jsonparseexception)
{
/**
* Convert a JsonParseException into a user-friendly exception
*/
throw toSyntaxException(jsonparseexception);
}
}
}
项目:wizards-of-lua
文件:TestResults.java
@Override
public void fireTestStarted(Description description) throws StoppedByUserException {
super.fireTestStarted(description);
String message = "Running " + description.getDisplayName();
logger.info(message);
try {
EntityPlayerMP player = server.getPlayerList().getPlayerByUsername(playerName);
ITextComponent itextcomponent = new TextComponentString(message);
SPacketTitle packet = new SPacketTitle(SPacketTitle.Type.ACTIONBAR,
TextComponentUtils.processComponent(player, itextcomponent, player));
player.connection.sendPacket(packet);
} catch (CommandException e) {
throw new RuntimeException(e);
}
}
项目:ExpandedRailsMod
文件:CommandMessageRaw.java
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 2)
{
throw new WrongUsageException("commands.tellraw.usage", new Object[0]);
}
else
{
EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
String s = buildString(args, 1);
try
{
ITextComponent itextcomponent = ITextComponent.Serializer.jsonToComponent(s);
entityplayer.addChatMessage(TextComponentUtils.processComponent(sender, itextcomponent, entityplayer));
}
catch (JsonParseException jsonparseexception)
{
/**
* Convert a JsonParseException into a user-friendly exception
*/
throw toSyntaxException(jsonparseexception);
}
}
}
项目:Backmemed
文件:TileEntitySign.java
public void readFromNBT(NBTTagCompound compound)
{
this.isEditable = false;
super.readFromNBT(compound);
ICommandSender icommandsender = new ICommandSender()
{
public String getName()
{
return "Sign";
}
public ITextComponent getDisplayName()
{
return new TextComponentString(this.getName());
}
public void addChatMessage(ITextComponent component)
{
}
public boolean canCommandSenderUseCommand(int permLevel, String commandName)
{
return true;
}
public BlockPos getPosition()
{
return TileEntitySign.this.pos;
}
public Vec3d getPositionVector()
{
return new Vec3d((double)TileEntitySign.this.pos.getX() + 0.5D, (double)TileEntitySign.this.pos.getY() + 0.5D, (double)TileEntitySign.this.pos.getZ() + 0.5D);
}
public World getEntityWorld()
{
return TileEntitySign.this.world;
}
public Entity getCommandSenderEntity()
{
return null;
}
public boolean sendCommandFeedback()
{
return false;
}
public void setCommandStat(CommandResultStats.Type type, int amount)
{
}
public MinecraftServer getServer()
{
return TileEntitySign.this.world.getMinecraftServer();
}
};
for (int i = 0; i < 4; ++i)
{
String s = compound.getString("Text" + (i + 1));
ITextComponent itextcomponent = ITextComponent.Serializer.jsonToComponent(s);
try
{
this.signText[i] = TextComponentUtils.processComponent(icommandsender, itextcomponent, (Entity)null);
}
catch (CommandException var7)
{
this.signText[i] = itextcomponent;
}
}
this.stats.readStatsFromNBT(compound);
}
项目:Backmemed
文件:CommandTitle.java
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 2)
{
throw new WrongUsageException("commands.title.usage", new Object[0]);
}
else
{
if (args.length < 3)
{
if ("title".equals(args[1]) || "subtitle".equals(args[1]) || "actionbar".equals(args[1]))
{
throw new WrongUsageException("commands.title.usage.title", new Object[0]);
}
if ("times".equals(args[1]))
{
throw new WrongUsageException("commands.title.usage.times", new Object[0]);
}
}
EntityPlayerMP entityplayermp = getPlayer(server, sender, args[0]);
SPacketTitle.Type spackettitle$type = SPacketTitle.Type.byName(args[1]);
if (spackettitle$type != SPacketTitle.Type.CLEAR && spackettitle$type != SPacketTitle.Type.RESET)
{
if (spackettitle$type == SPacketTitle.Type.TIMES)
{
if (args.length != 5)
{
throw new WrongUsageException("commands.title.usage", new Object[0]);
}
else
{
int i = parseInt(args[2]);
int j = parseInt(args[3]);
int k = parseInt(args[4]);
SPacketTitle spackettitle2 = new SPacketTitle(i, j, k);
entityplayermp.connection.sendPacket(spackettitle2);
notifyCommandListener(sender, this, "commands.title.success", new Object[0]);
}
}
else if (args.length < 3)
{
throw new WrongUsageException("commands.title.usage", new Object[0]);
}
else
{
String s = buildString(args, 2);
ITextComponent itextcomponent;
try
{
itextcomponent = ITextComponent.Serializer.jsonToComponent(s);
}
catch (JsonParseException jsonparseexception)
{
throw toSyntaxException(jsonparseexception);
}
SPacketTitle spackettitle1 = new SPacketTitle(spackettitle$type, TextComponentUtils.processComponent(sender, itextcomponent, entityplayermp));
entityplayermp.connection.sendPacket(spackettitle1);
notifyCommandListener(sender, this, "commands.title.success", new Object[0]);
}
}
else if (args.length != 2)
{
throw new WrongUsageException("commands.title.usage", new Object[0]);
}
else
{
SPacketTitle spackettitle = new SPacketTitle(spackettitle$type, (ITextComponent)null);
entityplayermp.connection.sendPacket(spackettitle);
notifyCommandListener(sender, this, "commands.title.success", new Object[0]);
}
}
}
项目:ExpandedRailsMod
文件:ItemWrittenBook.java
private void resolveContents(ItemStack stack, EntityPlayer player)
{
if (stack != null && stack.getTagCompound() != null)
{
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (!nbttagcompound.getBoolean("resolved"))
{
nbttagcompound.setBoolean("resolved", true);
if (validBookTagContents(nbttagcompound))
{
NBTTagList nbttaglist = nbttagcompound.getTagList("pages", 8);
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
String s = nbttaglist.getStringTagAt(i);
ITextComponent lvt_7_1_;
try
{
lvt_7_1_ = ITextComponent.Serializer.fromJsonLenient(s);
lvt_7_1_ = TextComponentUtils.processComponent(player, lvt_7_1_, player);
}
catch (Exception var9)
{
lvt_7_1_ = new TextComponentString(s);
}
nbttaglist.set(i, new NBTTagString(ITextComponent.Serializer.componentToJson(lvt_7_1_)));
}
nbttagcompound.setTag("pages", nbttaglist);
if (player instanceof EntityPlayerMP && player.getHeldItemMainhand() == stack)
{
Slot slot = player.openContainer.getSlotFromInventory(player.inventory, player.inventory.currentItem);
((EntityPlayerMP)player).connection.sendPacket(new SPacketSetSlot(0, slot.slotNumber, stack));
}
}
}
}
}