Skip to content

Commit

Permalink
Merge branch 'master' into vanilla-tp-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master authored Oct 29, 2024
2 parents 6186b6c + 3e2203b commit da8494a
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 41 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

dependencies {

api("com.github.GTNewHorizons:GTNHLib:0.5.17:dev")
api("com.github.GTNewHorizons:GTNHLib:0.5.18:dev")
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.6.44-GTNH:dev")
compileOnly("com.github.GTNewHorizons:EnderIO:2.8.20:dev")
compileOnly("com.github.GTNewHorizons:Navigator:1.0.15:dev")
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.28'
}


48 changes: 19 additions & 29 deletions src/main/java/serverutils/client/gui/GuiSidebar.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,34 +115,6 @@ public void drawButton(Minecraft mc, int mx, int my) {
}
}

if (mouseOver != null) {
int mx1 = mx + 10;
int my1 = Math.max(3, my - 9);

List<String> list = new ArrayList<>();
list.add(StatCollector.translateToLocal(mouseOver.button.getLangKey()));

if (mouseOver.button.isDisabled()) {
list.add(EnumChatFormatting.RED + ClientUtils.getDisabledTip());
}

if (mouseOver.button.getTooltipHandler() != null) {
mouseOver.button.getTooltipHandler().accept(list);
}

int tw = 0;

for (String s : list) {
tw = Math.max(tw, font.getStringWidth(s));
}

Color4I.DARK_GRAY.draw(mx1 - 3, my1 - 2, tw + 6, 2 + list.size() * 10);

for (int i = 0; i < list.size(); i++) {
font.drawString(list.get(i), mx1, my1 + i * 10, 0xFFFFFFFF);
}
}

GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.disableDepth();
GlStateManager.popMatrix();
Expand All @@ -151,6 +123,12 @@ public void drawButton(Minecraft mc, int mx, int my) {
lastDrawnArea = new Rectangle(xPosition, yPosition, width, height);
}

public void addTooltip(List<String> textLines) {
if (mouseOver != null) {
mouseOver.addTooltip(textLines);
}
}

@Override
public boolean mousePressed(Minecraft mc, int mx, int my) {
if (super.mousePressed(mc, mx, my)) {
Expand Down Expand Up @@ -213,7 +191,7 @@ private void addButtonsToSidebar() {
rx++;
addedAny = true;
}
};
}

if (placement != EnumPlacement.GROUPED) {
if (ry >= max) {
Expand Down Expand Up @@ -286,5 +264,17 @@ public GuiButtonSidebar(int x, int y, SidebarButton b) {
buttonY = y;
button = b;
}

public void addTooltip(List<String> textLines) {
textLines.add(StatCollector.translateToLocal(button.getLangKey()));

if (button.isDisabled()) {
textLines.add(EnumChatFormatting.RED + ClientUtils.getDisabledTip());
}

if (button.getTooltipHandler() != null) {
button.getTooltipHandler().accept(textLines);
}
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/serverutils/command/CmdDumpPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ public void processCommand(ICommandSender sender, String[] args) {
commandList.add(Arrays.asList(EMPTY_ROW));

for (ICommand command : CommandUtils.getAllCommands(sender)) {
ICommandWithPermission commands = (ICommandWithPermission) command;
String node = commands.serverutilities$getPermissionNode();
ICommandWithPermission cmd = (ICommandWithPermission) command;
String node = cmd.serverutilities$getPermissionNode();
DefaultPermissionLevel defaultPermissionLevel = DefaultPermissionHandler.INSTANCE
.getDefaultPermissionLevel(node);
IChatComponent usage = CommandUtils.getTranslatedUsage(command, sender);

commandList.add(
Arrays.asList(
node,
"/" + commands.getCommandName(),
"/" + command.getCommandName(),
defaultPermissionLevel.name(),
usage.getUnformattedText()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.gui.inventory.GuiContainer;
Expand Down Expand Up @@ -61,6 +62,8 @@ public class ServerUtilitiesClientEventHandler {
public static boolean shouldRenderIcons = false;
public static long shutdownTime = 0L;

private static final List<String> sidebarButtonTooltip = new ArrayList<>();

public static void readSyncData(NBTTagCompound nbt) {
shutdownTime = System.currentTimeMillis() + nbt.getLong("ShutdownTime");
}
Expand Down Expand Up @@ -282,6 +285,23 @@ public void onClientTick(TickEvent.ClientTickEvent event) {
}
}

/**
* Renders sidebar button tooltips outside of {@link GuiSidebar#drawButton} so that other screen elements don't draw
* over it.
*/
@SubscribeEvent
public void onGuiScreenDraw(final GuiScreenEvent.DrawScreenEvent.Post event) {
if (ClientUtils.areButtonsVisible(event.gui)) {
event.gui.buttonList.forEach((GuiButton button) -> {
if (button instanceof GuiSidebar sidebar) {
sidebarButtonTooltip.clear();
sidebar.addTooltip(sidebarButtonTooltip);
event.gui.func_146283_a(sidebarButtonTooltip, event.mouseX, event.mouseY);
}
});
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onGameOverlayRender(RenderGameOverlayEvent.Text event) {
if (currentNotification != null && !currentNotification.isImportant()) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/serverutils/mixin/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public enum Mixins {
.addMixinClasses("minecraft.MixinCommandBase", "minecraft.MixinCommandHandler")),
VANILLA_TP_BACK_COMPAT(new Builder("/back compat for the vanilla /tp").addTargetedMod(VANILLA).setSide(Side.BOTH)
.setPhase(Phase.EARLY).setApplyIf(() -> commands.back).addMixinClasses("minecraft.MixinCommandTeleport")),;
.setPhase(Phase.EARLY).setApplyIf(() -> ranks.enabled && ranks.command_permissions).addMixinClasses(
"minecraft.MixinCommandBase",
"minecraft.MixinCommandHandler",
"minecraft.MixinICommand")),;
private final List<String> mixinClasses;
private final Supplier<Boolean> applyIf;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/serverutils/net/MessageRanks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.HashSet;
import java.util.Map;

import net.minecraft.command.ICommand;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
Expand Down Expand Up @@ -137,8 +138,8 @@ public MessageRanks(Ranks r, ForgePlayer p) {
EnumChatFormatting.BLUE + "[" + command.serverutilities$getModName() + "]\n");
ConfigBoolean val = new ConfigBoolean(level == DefaultPermissionLevel.ALL);
commandPermissions.add(node, val, val, StringUtils.FLAG_ID_PERIOD_DEFAULTS)
.setDisplayName(new ChatComponentTranslation(node))
.setInfo(name.appendSibling(CommandUtils.getTranslatedUsage(command, p.getPlayer())));
.setDisplayName(new ChatComponentTranslation(node)).setInfo(
name.appendSibling(CommandUtils.getTranslatedUsage((ICommand) command, p.getPlayer())));
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/serverutils/ranks/ICommandWithPermission.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package serverutils.ranks;

import net.minecraft.command.ICommand;
import java.util.HashMap;
import java.util.Map;

import org.jetbrains.annotations.NotNull;

public interface ICommandWithPermission extends ICommand {
public interface ICommandWithPermission {

Map<String, String> commandOwners = new HashMap<>();

Map<String, String> commandPermissions = new HashMap<>();

String serverutilities$getPermissionNode();

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/serverutil_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ public net.minecraft.util.EnumChatFormatting field_96329_z # formattingCode
public net.minecraft.command.CommandHandler field_71561_b # commandSet
public net.minecraft.server.management.ServerConfigurationManager field_72407_n # commandsAllowedForAll
public net.minecraft.client.gui.FontRenderer field_111274_c # unicodePageLocations
public net.minecraft.client.gui.GuiScreen field_146292_n # buttonList
public net.minecraft.client.gui.GuiScreen func_146283_a(Ljava/util/List;II)V
public net.minecraft.util.ChatStyle field_150248_c # bold
public net.minecraft.util.ChatStyle field_150245_d # italic
public net.minecraft.util.ChatStyle field_150243_f # strikethrough
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public abstract class MixinCommandHandler {
String node = (container == null ? Rank.NODE_COMMAND : (Rank.NODE_COMMAND + '.' + container.getModId())) + "."
+ command.getCommandName();
ICommandWithPermission cmd = (ICommandWithPermission) command;
cmd.serverutilities$setPermissionNode(node);
cmd.serverutilities$setPermissionNode(node.toLowerCase());
cmd.serverutilities$setModName(container == null ? "Minecraft" : container.getName());
serverUtilities$registerPermissions(cmd);
}

@Unique
private DefaultPermissionLevel serverUtilities$getDefaultLevel(ICommand command) {
private DefaultPermissionLevel serverUtilities$getDefaultLevel(ICommandWithPermission command) {
if (command instanceof CommandBase cmdBase) {
return cmdBase.getRequiredPermissionLevel() > 0 ? DefaultPermissionLevel.OP : DefaultPermissionLevel.ALL;
}
Expand All @@ -79,7 +79,7 @@ public abstract class MixinCommandHandler {
if (command instanceof CommandTreeBase tree) {
for (ICommand c : tree.getSubCommands()) {
ICommandWithPermission child = (ICommandWithPermission) c;
child.serverutilities$setPermissionNode(node + '.' + child.getCommandName());
child.serverutilities$setPermissionNode(node.toLowerCase() + '.' + c.getCommandName());
child.serverutilities$setModName(command.serverutilities$getModName());
serverUtilities$registerPermissions(child);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package serverutils.mixins.early.minecraft;

import net.minecraft.command.ICommand;

import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import serverutils.ranks.ICommandWithPermission;

@Mixin(ICommand.class)
public interface MixinICommand extends ICommandWithPermission {

@Shadow
String getCommandName();

@Override
default String serverutilities$getPermissionNode() {
return commandPermissions.get(getCommandName());
}

@Override
default void serverutilities$setPermissionNode(@NotNull String node) {
commandPermissions.put(getCommandName(), node);
}

@Override
default String serverutilities$getModName() {
return commandOwners.get(getCommandName());
}

@Override
default void serverutilities$setModName(@NotNull String modName) {
commandOwners.put(getCommandName(), modName);
}
}

0 comments on commit da8494a

Please sign in to comment.