下面列出了net.minecraft.util.StringUtils 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Listener
public void recievePacket(EventReceivePacket event) {
if (event.getStage() == EventStageable.EventStage.PRE) {
if(event.getPacket() instanceof SPacketChat && Minecraft.getMinecraft().player != null) {
final SPacketChat packet = (SPacketChat) event.getPacket();
if (packet.getChatComponent() instanceof TextComponentString) {
final TextComponentString component = (TextComponentString) packet.getChatComponent();
final String message = StringUtils.stripControlCodes(component.getUnformattedText());
final boolean serverMessage = message.startsWith("\247c") || message.startsWith("\2475");
if (!serverMessage && message.length() > 0) {
final String[] split = message.split(" ");
if (split != null) {
final Ignored ignored = Seppuku.INSTANCE.getIgnoredManager().find(split[0].replace("<", "").replace(">", ""));
if (ignored != null) {
event.setCanceled(true);
}
}
}
}
}
}
}
@Listener
public void recievePacket(EventReceivePacket event) {
if (event.getStage() == EventStageable.EventStage.PRE) {
if (event.getPacket() instanceof SPacketChat) {
final SPacketChat packet = (SPacketChat) event.getPacket();
if (packet.getChatComponent() instanceof TextComponentString) {
final TextComponentString component = (TextComponentString) packet.getChatComponent();
final String message = StringUtils.stripControlCodes(component.getUnformattedText());
final boolean serverMessage = message.startsWith("\247c") || message.startsWith("\2475");
if (!serverMessage && this.blacklistContains(message)) {
final String[] split = message.split(" ");
if (split != null) {
final String username = split[0].replace("<", "").replace(">", "");
final Ignored ignored = Seppuku.INSTANCE.getIgnoredManager().find(username);
if (ignored == null && !username.equalsIgnoreCase(Minecraft.getMinecraft().session.getUsername())) {
switch (this.mode.getValue()) {
case CLIENT:
Seppuku.INSTANCE.getIgnoredManager().add(username);
Seppuku.INSTANCE.logChat("Added \247c" + username + "\247f to your ignore list");
break;
case SERVER:
Seppuku.INSTANCE.getChatManager().add("/ignore " + username);
break;
case BOTH:
Seppuku.INSTANCE.getChatManager().add("/ignore " + username);
Seppuku.INSTANCE.getIgnoredManager().add(username);
Seppuku.INSTANCE.logChat("Added \247c" + username + "\247f to your ignore list");
break;
}
}
}
event.setCanceled(true);
}
}
}
}
}
@Override
public void drawPanel(int mouseX, int mouseY, Panel panel) {
RenderUtils.drawBorderedRect((float) panel.getX(), (float) panel.getY() - 3, (float) panel.getX() + panel.getWidth(), (float) panel.getY() + 17, 3, new Color(42, 57, 79).getRGB(), new Color(42, 57, 79).getRGB());
if (panel.getFade() > 0) {
RenderUtils.drawBorderedRect((float) panel.getX(), (float) panel.getY() + 17, (float) panel.getX() + panel.getWidth(), panel.getY() + 19 + panel.getFade(), 3, new Color(54, 71, 96).getRGB(), new Color(54, 71, 96).getRGB());
RenderUtils.drawBorderedRect((float) panel.getX(), panel.getY() + 17 + panel.getFade(), (float) panel.getX() + panel.getWidth(), panel.getY() + 19 + panel.getFade() + 5, 3, new Color(42, 57, 79).getRGB(), new Color(42, 57, 79).getRGB());
}
GlStateManager.resetColor();
float textWidth = Fonts.font35.getStringWidth("§f" + StringUtils.stripControlCodes(panel.getName()));
Fonts.font35.drawString(panel.getName(), (int) (panel.getX() - (textWidth - 100.0F) / 2F), panel.getY() + 7 - 3, Color.WHITE.getRGB());
}
@Override
public void drawPanel(int mouseX, int mouseY, Panel panel) {
RenderUtils.drawBorderedRect((float) panel.getX() - (panel.getScrollbar() ? 4 : 0), (float) panel.getY(), (float) panel.getX() + panel.getWidth(), (float) panel.getY() + 19 + panel.getFade(), 1F, new Color(255, 255, 255, 90).getRGB(), Integer.MIN_VALUE);
float textWidth = Fonts.font35.getStringWidth("§f" + StringUtils.stripControlCodes(panel.getName()));
Fonts.font35.drawString("§f" + panel.getName(), (int) (panel.getX() - (textWidth - 100.0F) / 2F), panel.getY() + 7, -16777216);
if(panel.getScrollbar() && panel.getFade() > 0) {
RenderUtils.drawRect(panel.getX() - 2, panel.getY() + 21, panel.getX(), panel.getY() + 16 + panel.getFade(), Integer.MAX_VALUE);
RenderUtils.drawRect(panel.getX() - 2, panel.getY() + 30 + (panel.getFade() - 24F) / (panel.getElements().size() - ((ClickGUI) LiquidBounce.moduleManager.getModule(ClickGUI.class)).maxElementsValue.get()) * panel.getDragged() - 10.0f, panel.getX(), panel.getY() + 40 + (panel.getFade() - 24.0f) / (panel.getElements().size() - ((ClickGUI) LiquidBounce.moduleManager.getModule(ClickGUI.class)).maxElementsValue.get()) * panel.getDragged(), Integer.MIN_VALUE);
}
}
@Override
public void drawPanel(int mouseX, int mouseY, Panel panel) {
RenderUtils.drawRect((float) panel.getX() - 3, (float) panel.getY(), (float) panel.getX() + panel.getWidth() + 3, (float) panel.getY() + 19, ClickGUI.generateColor().getRGB());
if(panel.getFade() > 0)
RenderUtils.drawBorderedRect((float) panel.getX(), (float) panel.getY() + 19, (float) panel.getX() + panel.getWidth(), panel.getY() + 19 + panel.getFade(), 1, Integer.MIN_VALUE, Integer.MIN_VALUE);
GlStateManager.resetColor();
float textWidth = Fonts.font35.getStringWidth("§f" + StringUtils.stripControlCodes(panel.getName()));
Fonts.font35.drawString("§f" + panel.getName(), (int) (panel.getX() - (textWidth - 100.0F) / 2F), panel.getY() + 7, Integer.MAX_VALUE);
}
/**
* @author Sk1er
* @reason Not proper null checks
*/
@Overwrite
public static GameProfile readGameProfileFromNBT(NBTTagCompound compound) {
String s = null;
String s1 = null;
if (compound.hasKey("Name", 8)) s = compound.getString("Name");
if (compound.hasKey("Id", 8)) s1 = compound.getString("Id");
if (StringUtils.isNullOrEmpty(s) && StringUtils.isNullOrEmpty(s1)) {
return null;
} else {
UUID uuid = null;
if (s1 != null)
try {
uuid = UUID.fromString(s1);
} catch (Throwable ignored) {
}
GameProfile gameprofile = new GameProfile(uuid, s);
if (compound.hasKey("Properties", 10)) {
NBTTagCompound nbttagcompound = compound.getCompoundTag("Properties");
for (String s2 : nbttagcompound.getKeySet()) {
NBTTagList nbttaglist = nbttagcompound.getTagList(s2, 10);
int bound = nbttaglist.tagCount();
for (int i = 0; i < bound; i++) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
String s3 = nbttagcompound1.getString("Value");
gameprofile.getProperties().put(s2, nbttagcompound1.hasKey("Signature", 8) ?
new Property(s2, s3, nbttagcompound1.getString("Signature")) : new Property(s2, s3));
}
}
}
return gameprofile;
}
}
/**
* Copies the objective and scores that are being displayed on a scoreboard's sidebar.
*
* @param scoreboard the {@link Scoreboard} to copy the sidebar from
* @param stripControlCodes if {@code true}, the control codes will be removed, otherwise they will be copied
*/
public static void copyScoreboardSidebar(Scoreboard scoreboard, boolean stripControlCodes) {
Utils utils = SkyblockAddons.getInstance().getUtils();
if (scoreboard == null) {
utils.sendErrorMessage("No scoreboard found!");
return;
}
ScoreObjective sideBarObjective = scoreboard.getObjectiveInDisplaySlot(1);
if (sideBarObjective == null) {
utils.sendErrorMessage("Nothing is being displayed in the sidebar!");
return;
}
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb, Locale.CANADA);
String objectiveName = sideBarObjective.getDisplayName();
List<Score> scores = (List<Score>) scoreboard.getSortedScores(sideBarObjective);
if (scores == null || scores.isEmpty()) {
SkyblockAddons.getInstance().getUtils().sendErrorMessage("No scores were found!");
}
else {
int width = SIDEBAR_COPY_WIDTH;
if (stripControlCodes) {
objectiveName = StringUtils.stripControlCodes(objectiveName);
}
// Remove scores that aren't rendered.
scores = scores.stream().filter(input -> input.getPlayerName() != null && !input.getPlayerName().startsWith("#"))
.skip(Math.max(scores.size() - 15, 0)).collect(Collectors.toList());
/*
Minecraft renders the scoreboard from bottom to top so to keep the same order when writing it from top
to bottom, we need to reverse the scores' order.
*/
Collections.reverse(scores);
for (Score score:
scores) {
ScorePlayerTeam scoreplayerteam = scoreboard.getPlayersTeam(score.getPlayerName());
String playerName = ScorePlayerTeam.formatPlayerName(scoreplayerteam, score.getPlayerName());
// Strip colours and emoji player names.
playerName = RegexUtil.strip(playerName, RegexUtil.SIDEBAR_PLAYER_NAME_PATTERN);
if (stripControlCodes) {
playerName = StringUtils.stripControlCodes(playerName);
}
int points = score.getScorePoints();
width = Math.max(width, (playerName + " " + points).length());
formatter.format("%-" + width + "." +
width + "s %d%n", playerName, points);
}
// Insert the objective name at the top of the sidebar string.
sb.insert(0, "\n").insert(0, org.apache.commons.lang3.StringUtils.center(objectiveName, width));
copyStringToClipboard(sb.toString(), "Sidebar copied to clipboard!");
}
}
boolean isHovering(int mouseX, int mouseY) {
final float textWidth = mc.fontRendererObj.getStringWidth(StringUtils.stripControlCodes(name)) - 100F;
return mouseX >= x - textWidth / 2F - 19F && mouseX <= x - textWidth / 2F + mc.fontRendererObj.getStringWidth(StringUtils.stripControlCodes(name)) + 19F && mouseY >= y && mouseY <= y + height - (open ? 2 : 0);
}
public WrapperStringUtils(StringUtils var1) {
this.real = var1;
}
public static String ticksToElapsedTime(int var0) {
return StringUtils.ticksToElapsedTime(var0);
}
public static String stripControlCodes(String var0) {
return StringUtils.stripControlCodes(var0);
}
public static boolean isNullOrEmpty(String var0) {
return StringUtils.isNullOrEmpty(var0);
}
public StringUtils unwrap() {
return this.real;
}
public int drawStringWithShadow(String text, float x, float y, int color) {
drawString(StringUtils.stripControlCodes(text), x + 0.5F, y + 0.5F, 0x000000);
return drawString(text, x, y, color);
}
public void drawCenteredStringWithShadow(String text, float x, float y, int color) {
drawCenteredString(StringUtils.stripControlCodes(text), x + 0.5F, y + 0.5F, color);
drawCenteredString(text, x, y, color);
}
public ToggleSprintStatus(JsonHolder data, int ordinal) {
super(data, ordinal);
sprintEnabledText = data.optString("sprintEnabledText");
if (StringUtils.isNullOrEmpty(sprintEnabledText)) sprintEnabledText = "ToggleSprint Enabled";
height = 10;
}