下面列出了net.minecraft.util.ChatStyle#net.minecraft.util.IChatComponent 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @author CCBlueX
*/
@Overwrite
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
Gui.drawRect(2, this.height - (int) fade, this.width - 2, this.height, Integer.MIN_VALUE);
this.inputField.drawTextBox();
if (LiquidBounce.commandManager.getLatestAutoComplete().length > 0 && !inputField.getText().isEmpty() && inputField.getText().startsWith(String.valueOf(LiquidBounce.commandManager.getPrefix()))) {
String[] latestAutoComplete = LiquidBounce.commandManager.getLatestAutoComplete();
String[] textArray = inputField.getText().split(" ");
String trimmedString = latestAutoComplete[0].replaceFirst("(?i)" + textArray[textArray.length - 1], "");
mc.fontRendererObj.drawStringWithShadow(trimmedString, inputField.xPosition + mc.fontRendererObj.getStringWidth(inputField.getText()), inputField.yPosition, new Color(165, 165, 165).getRGB());
}
IChatComponent ichatcomponent =
this.mc.ingameGUI.getChatGUI().getChatComponent(Mouse.getX(), Mouse.getY());
if (ichatcomponent != null)
this.handleComponentHover(ichatcomponent, mouseX, mouseY);
}
@Override
public void handleChat(String s) {
if (s.toLowerCase().contains("reconnecting hyperium connection")) return;
Hyperium.LOGGER.debug("Chat: {}", s);
s = s.replace("&", C.COLOR_CODE_SYMBOL);
IChatComponent chatComponent = new ChatComponentText("");
Arrays.stream(s.split(" ")).forEach(s1 -> {
ChatComponentText iChatComponents = new ChatComponentText(s1 + " ");
if (s1.contains(".") && !s1.startsWith(".") && !s1.endsWith(".")) {
ChatStyle chatStyle = new ChatStyle();
chatStyle.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, s1.startsWith("http") ? s1 : "http://" + s1));
iChatComponents.setChatStyle(chatStyle);
}
chatComponent.appendSibling(iChatComponents);
});
GeneralChatHandler.instance().sendMessage(chatComponent);
}
public IChatComponent getDisplayName() {
if (cachedName == null || System.currentTimeMillis() - lastChangeTime > 50L) {
IChatComponent ichatcomponent = new ChatComponentText(ScorePlayerTeam
.formatPlayerName(parent.getTeam(), displayName));
ichatcomponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + parent.getName() + " "));
//Unneeded for client
if (Minecraft.getMinecraft().isIntegratedServerRunning()) {
ichatcomponent.getChatStyle()
.setChatHoverEvent(((IMixinEntity) parent).callGetHoverEvent());
}
ichatcomponent.getChatStyle().setInsertion(parent.getName());
cachedName = ichatcomponent;
}
return cachedName;
}
@Command(
name = "list",
permission = "mytown.cmd.everyone.ranks.list",
parentName = "mytown.cmd.everyone.ranks",
syntax = "/town ranks list")
public static CommandResponse listRanksCommand(ICommandSender sender, List<String> args) {
Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
Town town = getTownFromResident(res);
IChatComponent root = new ChatComponentList();
root.appendSibling(LocalManager.get("myessentials.format.list.header", new ChatComponentFormatted("{9|RANKS}")));
for (Rank rank : town.ranksContainer) {
root.appendSibling(new ChatComponentFormatted("{7| - }").appendSibling(LocalManager.get("mytown.format.rank.long", rank.getName(), rank.getType())));
}
ChatManager.send(sender, root);
return CommandResponse.DONE;
}
@Command(
name = "info",
permission = "mytown.adm.cmd.plot.info",
parentName = "mytown.adm.cmd.plot",
syntax = "/townadmin plot info <town> <plot>",
completionKeys = {"townCompletion", "plotCompletion"},
console = true)
public static CommandResponse plotInfoCommand(ICommandSender sender, List<String> args) {
if (args.size() < 2) {
return CommandResponse.SEND_SYNTAX;
}
Town town = getTownFromName(args.get(0));
Plot plot = getPlotFromName(town, args.get(1));
IChatComponent header = LocalManager.get("myessentials.format.list.header", new ChatComponentFormatted("{9|%s}", plot.getName()));
ChatManager.send(sender, "mytown.format.plot.long", plot.ownersContainer, plot.toVolume().toChatMessage());
return CommandResponse.DONE;
}
@Command(
name = "res",
permission = "mytown.cmd.outsider.res",
parentName = "mytown.cmd",
syntax = "/town res <resident>",
completionKeys = {"residentCompletion"},
console = true)
public static CommandResponse resCommand(ICommandSender sender, List<String> args) {
if (args.size() < 1) {
return CommandResponse.SEND_SYNTAX;
}
Resident res = getResidentFromName(args.get(0));
if (res == null) {
throw new MyTownCommandException("mytown.cmd.err.resident.missing", args.get(0));
}
IChatComponent header = LocalManager.get("myessentials.format.list.header", res);
ChatManager.send(sender, "mytown.format.resident.long", header, res.townsContainer, Formatter.formatDate(res.getJoinDate()), Formatter.formatDate(res.getLastOnline()), res.getExtraBlocks());
return CommandResponse.DONE;
}
@Command(
name = "prices",
permission = "mytown.cmd.outsider.prices",
parentName = "mytown.cmd",
syntax = "/town prices")
public static CommandResponse pricesCommand(ICommandSender sender, List<String> args) {
Resident res = getUniverse().getOrMakeResident(sender);
IChatComponent header = LocalManager.get("myessentials.format.list.header", new ChatComponentFormatted("{9|PRICES}"));
ChatManager.send(sender, "mytown.notification.prices",
header,
EconomyProxy.getCurrency(Config.instance.costAmountMakeTown.get()),
EconomyProxy.getCurrency(Config.instance.costAmountClaim.get()),
EconomyProxy.getCurrency(Config.instance.costAdditionClaim.get()),
EconomyProxy.getCurrency(Config.instance.costAmountClaimFar.get()),
EconomyProxy.getCurrency(Config.instance.costAmountSpawn.get()),
EconomyProxy.getCurrency(Config.instance.costAmountSetSpawn.get()),
EconomyProxy.getCurrency(Config.instance.costAmountOtherSpawn.get()),
EconomyProxy.getCurrency(Config.instance.costTownUpkeep.get()),
EconomyProxy.getCurrency(Config.instance.costAdditionalUpkeep.get()));
return CommandResponse.DONE;
}
@Override
public IChatComponent toChatMessage() {
IChatComponent header = LocalManager.get("myessentials.format.list.header", new ChatComponentFormatted("{9|%s}", getName()));
IChatComponent hoverComponent = ((ChatComponentFormatted)LocalManager.get("mytown.format.town.long", header, residentsMap.size(), townBlocksContainer.size(), getMaxBlocks(), plotsContainer.size(), residentsMap, ranksContainer)).applyDelimiter("\n");
return LocalManager.get("mytown.format.town.short", name, hoverComponent);
}
public static String getUnformattedText(IChatComponent iChatComponent) {
SkyblockAddons main = SkyblockAddons.getInstance();
ICommandSender player = Minecraft.getMinecraft().thePlayer;
if (main != null && SkyblockAddonsTransformer.isDeobfuscated() || (player != null && player.getName().equals("Biscut"))) {
return iChatComponent.getFormattedText(); // makes it easier for debugging
}
return iChatComponent.getUnformattedText();
}
public static void handleComponentClick(IChatComponent component) {
SkyblockAddons main = SkyblockAddons.getInstance();
if (main.getUtils().isOnSkyblock() && component != null && "§2§l[OPEN MENU]".equals(component.getUnformattedText()) &&
!CooldownManager.isOnCooldown(InventoryUtils.MADDOX_BATPHONE_DISPLAYNAME)) {// The prompt when Maddox picks up the phone.
CooldownManager.put(InventoryUtils.MADDOX_BATPHONE_DISPLAYNAME, MADDOX_BATPHONE_COOLDOWN);
}
}
@Inject(method = "handleComponentHover", at = @At("HEAD"))
private void handleHoverOverComponent(IChatComponent component, int x, int y, final CallbackInfo callbackInfo) {
if (component == null || component.getChatStyle().getChatClickEvent() == null || !LiquidBounce.moduleManager.getModule(ComponentOnHover.class).getState())
return;
final ChatStyle chatStyle = component.getChatStyle();
final ClickEvent clickEvent = chatStyle.getChatClickEvent();
final HoverEvent hoverEvent = chatStyle.getChatHoverEvent();
drawHoveringText(Collections.singletonList("§c§l" + clickEvent.getAction().getCanonicalName().toUpperCase() + ": §a" + clickEvent.getValue()), x, y - (hoverEvent != null ? 17 : 0));
}
@Command(
name = "info",
permission = "mytown.adm.cmd.blocks.info",
parentName = "mytown.adm.cmd.blocks",
syntax = "/townadmin blocks info <town>",
completionKeys = {"townCompletion"},
console = true)
public static CommandResponse blocksInfoCommand(ICommandSender sender, List<String> args) {
if(args.size() < 1) {
return CommandResponse.SEND_SYNTAX;
}
Town town = getTownFromName(args.get(0));
IChatComponent header = LocalManager.get("myessentials.format.list.header", new ChatComponentFormatted("{9|BLOCKS}"));
String blocks = town.townBlocksContainer.size() + "/" + town.getMaxBlocks();
String extraBlocks = town.getExtraBlocks() + "";
String farBlocks = town.townBlocksContainer.getFarClaims() + "/" + town.getMaxFarClaims();
ChatComponentContainer extraBlocksSources = new ChatComponentContainer();
extraBlocksSources.add(LocalManager.get("mytown.notification.blocks.info.extra", new ChatComponentFormatted("{9|TOWN}"), town.townBlocksContainer.getExtraBlocks()));
for(Resident res : town.residentsMap.keySet()) {
extraBlocksSources.add(LocalManager.get("mytown.notification.blocks.info.extra", res, res.getExtraBlocks()));
}
ChatManager.send(sender, "mytown.notification.blocks.info", header, blocks, extraBlocks, extraBlocksSources, farBlocks);
return CommandResponse.DONE;
}
public static void displayChatMessage(final String message) {
if (mc.thePlayer == null) {
getLogger().info("(MCChat)" + message);
return;
}
final JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("text", message);
mc.thePlayer.addChatMessage(IChatComponent.Serializer.jsonToComponent(jsonObject.toString()));
}
@Override
public IChatComponent toChatMessage() {
IChatComponent root = new ChatComponentText("");
for (Rank rank : this) {
if (root.getSiblings().size() > 0) {
root.appendSibling(new ChatComponentFormatted("{7|, }"));
}
root.appendSibling(rank.toChatMessage());
}
return root;
}
/**
* @author CCBlueX
*/
@Overwrite
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
Gui.drawRect(2, this.height - (int) fade, this.width - 2, this.height, Integer.MIN_VALUE);
this.inputField.drawTextBox();
IChatComponent ichatcomponent =
this.mc.ingameGUI.getChatGUI().getChatComponent(Mouse.getX(), Mouse.getY());
if (ichatcomponent != null)
this.handleComponentHover(ichatcomponent, mouseX, mouseY);
}
@Override
public IChatComponent toChatMessage() {
IChatComponent root = new ChatComponentText("");
for (Town town : this) {
if (root.getSiblings().size() > 0) {
root.appendSibling(new ChatComponentFormatted("{7|, }"));
}
root.appendSibling(town.toChatMessage());
}
return root;
}
public static String getUnformattedText(Object component) {
if (component == null) {
return null;
}
String unformattedText = ((IChatComponent) component).getUnformattedText();
return ChatColor.stripColor(unformattedText);
}
public static String getHoverText(Object component) {
IChatComponent chatComponent = (IChatComponent) component;
if (component == null || chatComponent.getChatStyle() == null || chatComponent.getChatStyle().getChatHoverEvent() == null) {
return null;
}
IChatComponent hoverText = chatComponent.getChatStyle().getChatHoverEvent().getValue();
return getUnformattedText(hoverText);
}
public IChatComponent getDisplayName() {
if (cachedName == null || System.currentTimeMillis() - nameCacheTime > 50L) {
ChatComponentText chatcomponenttext = new ChatComponentText(parent.getName());
//not needed otherwise
if (Minecraft.getMinecraft().isIntegratedServerRunning())
chatcomponenttext.getChatStyle().setChatHoverEvent(((IMixinEntity) parent).callGetHoverEvent());
chatcomponenttext.getChatStyle().setInsertion(parent.getUniqueID().toString());
cachedName = chatcomponenttext;
nameCacheTime = System.currentTimeMillis();
}
return cachedName;
}
public void printChatMessage(IChatComponent chatComponent, CallbackInfo ci) {
ChatEvent event = new ChatEvent(chatComponent);
EventBus.INSTANCE.post(event);
if (event.isCancelled()) {
ci.cancel();
} else {
if (event.getChat() != chatComponent) {
parent.printChatMessageWithOptionalDeletion(event.getChat(), 0);
ci.cancel();
}
}
}
@Override
public IChatComponent toChatMessage() {
IChatComponent root = new ChatComponentText("");
for (Resident res : this) {
if (root.getSiblings().size() > 0) {
root.appendSibling(new ChatComponentFormatted("{7|, }"));
}
root.appendSibling(res.toChatMessage());
}
return root;
}
@InvokeEvent
public void serverJoinEvent(ServerJoinEvent event) {
if (asked) return; //If they were already asked, don't even make the new thread.
UpdateUtils updateUtils = new UpdateUtils();
Multithreading.runAsync(() -> {
boolean latest = updateUtils.isAbsoluteLatest();
boolean beta = updateUtils.isBeta();
int version = Metadata.getVersionID();
Hyperium.LOGGER.info("version is: " + version);
if (beta) return; // dont alert beta users
if (latest) return; //If they're on the latest version, I don't want to mess with them.
Hyperium.INSTANCE.getNotification().display("You have an update pending.",
"Click here to be sent to the installer.",
10f,
null, () -> {
try {
Desktop.getDesktop().browse(new URI("https://hyperium.cc/downloads"));
} catch (IOException | URISyntaxException e) {
IChatComponent urlComponent = new
ChatComponentText(ChatColor.RED + "[Hyperium] " +
ChatColor.GRAY + "Click to be sent to update Hyperium");
urlComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://hyperium.cc/downloads"));
Hyperium.INSTANCE.getHandlers().getGeneralChatHandler().sendMessage(urlComponent);
}
}, new Color(200, 150, 50));
asked = true;
});
}
/**
* Returns the message to be displayed on player death.
*/
@Override
public IChatComponent func_151519_b(EntityLivingBase par1EntityLivingBase){
String messageMeta = "";
int messageNumber = par1EntityLivingBase.getRNG().nextInt(deathMessages) + 1;
messageMeta = messageNumber + "";
EntityLivingBase entitylivingbase1 = par1EntityLivingBase.func_94060_bK();
String s = "death.attack." + damageType + messageMeta;
String s1 = s + ".player";
return entitylivingbase1 != null && StatCollector.canTranslate(s1) ? new ChatComponentTranslation(s1, new Object[]{par1EntityLivingBase.func_145748_c_(), entitylivingbase1.func_145748_c_()}) : new ChatComponentTranslation(s, new Object[]{par1EntityLivingBase.func_145748_c_()});
}
@Override
public boolean chatReceived(IChatComponent component, String text) {
String playerJoinEndStr = " joined the guild!";
if (text.endsWith(playerJoinEndStr) && Settings.SEND_GUILD_WELCOME_MESSAGE) {
int rankHeader = 0;
if (text.contains("[")) rankHeader = text.indexOf("]") + 1;
String playerName = String.valueOf(text.subSequence(rankHeader, text.length() - playerJoinEndStr.length())).trim();
String message = "/gc Welcome to the guild " + playerName + "!";
Minecraft.getMinecraft().thePlayer.sendChatMessage(message);
}
return false;
}
@Override
public boolean chatReceived(IChatComponent component, String text) {
Matcher matcher = regexPatterns.get(ChatRegexType.QUEST_COMPLETE).matcher(text);
if (matcher.matches()) {
JsonObject record = new JsonObject();
record.add("name", new JsonPrimitive(matcher.group("name")));
record.add("type", new JsonPrimitive(matcher.group("type")));
record.add("timestamp", new JsonPrimitive(System.currentTimeMillis()));
json.add(record);
save();
}
return false;
}
@SubscribeEvent
public void onPlayerJoin(TickEvent.PlayerTickEvent event){
if(event.player.worldObj.isRemote && event.player == FMLClientHandler.instance().getClientPlayerEntity()) {
event.player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a("[\"" + EnumChatFormatting.GOLD + "The mod " + supportingMod + " is supporting In-Game Wiki mod. " + EnumChatFormatting.GOLD + "However, In-Game Wiki isn't installed! " + "[\"," + "{\"text\":\"Download Latest\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/igwmod_download\"}}," + "\"]\"]"));
FMLCommonHandler.instance().bus().unregister(this);
}
}
@Inject(
method = "handleComponentClick",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiScreen;sendChatMessage(Ljava/lang/String;Z)V")
)
private void runCommand(IChatComponent chatComponent, CallbackInfoReturnable<Boolean> cir) {
Hyperium.INSTANCE.getHandlers().getHyperiumCommandHandler().runningCommand = true;
}
/**
* Invoked once the player is disconnecting from a server
*/
@Inject(method = "<init>", at = @At("RETURN"))
private void init(GuiScreen screen,
String reasonLocalizationKey,
IChatComponent chatComp,
CallbackInfo ci) {
EventBus.INSTANCE.post(new ServerLeaveEvent());
}
@Override
public IChatComponent toChatMessage() {
IChatComponent root = new ChatComponentText("");
for (Plot plot : this) {
if (root.getSiblings().size() > 0) {
root.appendSibling(new ChatComponentFormatted("{7|, }"));
}
root.appendSibling(plot.toChatMessage());
}
return root;
}
@Override
public IChatComponent toChatMessage() {
IChatComponent root = new ChatComponentText("");
for (TownBlock block : values()) {
root.appendSibling(block.toChatMessage());
root.appendSibling(new ChatComponentText(" "));
}
return root;
}