Skip to content

Commit

Permalink
Merge pull request #48 from Global-Tags/feat/roles
Browse files Browse the repository at this point in the history
Implement admin roles instead of only admin boolean
  • Loading branch information
RappyTV authored Jul 14, 2024
2 parents 65df829 + 14b0020 commit e684811
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Map<String, Object> getBody() {
request.responseBody.tag,
request.responseBody.position,
request.responseBody.icon,
request.responseBody.admin,
request.responseBody.roles,
request.responseBody.ban
));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void sendAsyncRequest(Callback<JsonObject> callback) {
.url(getApiBase() + path)
.method(method)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", key != null ? key : "")
.addHeader("Authorization", key != null ? "LabyConnect " + key : "")
.addHeader("X-Addon-Version", version)
.handleErrorStream()
.async();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class ResponseBody {
public String tag;
public String position;
public String icon;
public boolean admin;
public String[] roles;
public String message;
public Ban ban;

Expand Down
24 changes: 9 additions & 15 deletions api/src/main/java/com/rappytv/globaltags/types/GlobalIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import net.labymod.api.client.gui.icon.Icon;
import net.labymod.api.client.resources.ResourceLocation;
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("unused")
public enum GlobalIcon {
Expand All @@ -26,20 +24,16 @@ public enum GlobalIcon {
XBOX,
YOUTUBE;

private final Map<String, Icon> iconCache = new HashMap<>();
private final Icon icon;

public Icon getIcon() {
String name = name().toLowerCase();
if(iconCache.containsKey(name))
return iconCache.get(name);
ResourceLocation location = ResourceLocation.create(
GlobalIcon() {
this.icon = Icon.texture(ResourceLocation.create(
"globaltags",
"textures/icons/" + name + ".png"
);
iconCache.put(
name,
location.exists() ? Icon.texture(location) : null
);
return getIcon();
"textures/icons/" + this.name().toLowerCase() + ".png"
));
}

public Icon getIcon() {
return icon;
}
}
24 changes: 24 additions & 0 deletions api/src/main/java/com/rappytv/globaltags/types/GlobalRole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.rappytv.globaltags.types;

import net.labymod.api.client.gui.icon.Icon;
import net.labymod.api.client.resources.ResourceLocation;

public enum GlobalRole {
ADMIN("purple"),
DEVELOPER("aqua"),
MODERATOR("orange"),
SUPPORTER("green");

private final Icon icon;

GlobalRole(String color) {
this.icon = Icon.texture(ResourceLocation.create(
"globaltags",
"textures/icons/roles/" + color + ".png"
));
}

public Icon getIcon() {
return icon;
}
}
36 changes: 31 additions & 5 deletions api/src/main/java/com/rappytv/globaltags/types/PlayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.labymod.api.client.gui.icon.Icon;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

Expand All @@ -17,16 +19,21 @@ public class PlayerInfo {
private final String plainTag;
private final String position;
private final String icon;
private final boolean admin;
private final List<GlobalRole> roles;
private final Suspension suspension;

public PlayerInfo(UUID uuid, String tag, String position, String icon, boolean admin, Ban ban) {
public PlayerInfo(UUID uuid, String tag, String position, String icon, String[] roles, Ban ban) {
this.uuid = uuid;
this.tag = Util.translateColorCodes(tag);
this.plainTag = tag != null ? tag : "";
this.position = position;
this.icon = icon;
this.admin = admin;
this.roles = new ArrayList<>();
for(String role : roles) {
try {
this.roles.add(GlobalRole.valueOf(role.toUpperCase()));
} catch (Exception ignored) {}
}
this.suspension = ban != null ? new Suspension(ban) : new Suspension();
}

Expand Down Expand Up @@ -81,7 +88,7 @@ public GlobalIcon getGlobalIcon() {
}

/**
* Returns the global icon of the player
* Returns the global icon of the player. See {@link GlobalIcon#getIcon()}
*/
public Icon getIcon() {
return getGlobalIcon().getIcon();
Expand All @@ -91,7 +98,26 @@ public Icon getIcon() {
* Returns if the player is a GlobalTag admin
*/
public boolean isAdmin() {
return admin;
return roles.contains(GlobalRole.ADMIN);
}

/**
* Returns all of the players roles
*/
@NotNull
public List<GlobalRole> getRoles() {
return roles;
}

/**
* Returns the players highest role
*/
@Nullable
public GlobalRole getHighestRole() {
for(GlobalRole role : GlobalRole.values()) {
if(roles.contains(role)) return role;
}
return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ labyMod {
author = "RappyTV"
description = "Get yourself a custom Globaltag that's publicly visible to anyone using this addon."
minecraftVersion = "*"
version = System.getenv().getOrDefault("VERSION", "1.2.0")
version = System.getenv().getOrDefault("VERSION", "1.2.1")
}

minecraft {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void preConfigurationLoad() {
Laby.references().revisionRegistry().register(new SimpleRevision("globaltags", new SemanticVersion("1.1.0"), "2023-11-24"));
Laby.references().revisionRegistry().register(new SimpleRevision("globaltags", new SemanticVersion("1.1.7"), "2024-02-27"));
Laby.references().revisionRegistry().register(new SimpleRevision("globaltags", new SemanticVersion("1.1.9"), "2024-06-01"));
Laby.references().revisionRegistry().register(new SimpleRevision("globaltags", new SemanticVersion("1.2.0"), "2024-07-06"));
Laby.references().revisionRegistry().register(new SimpleRevision("globaltags", new SemanticVersion("1.2.0"), "2024-07-14"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public GlobalTagConfig() {
@SpriteSlot(size = 32, y = 2, x = 2)
@SwitchSetting
private final ConfigProperty<Boolean> localizedResponses = new ConfigProperty<>(true);
@IntroducedIn(namespace = "globaltags", value = "1.2.0")
@MethodOrder(after = "localizedResponses")
@SpriteSlot(size = 32, y = 2, x = 3)
@ButtonSetting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
import net.labymod.api.Textures.SpriteCommon;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.client.gui.icon.Icon;
import net.labymod.api.client.gui.lss.property.annotation.AutoWidget;
import net.labymod.api.client.gui.screen.Parent;
import net.labymod.api.client.gui.screen.activity.Link;
import net.labymod.api.client.gui.screen.widget.widgets.ComponentWidget;
import net.labymod.api.client.gui.screen.widget.widgets.input.ButtonWidget;
import net.labymod.api.client.gui.screen.widget.widgets.layout.list.HorizontalListWidget;
import net.labymod.api.client.gui.screen.widget.widgets.renderer.IconWidget;
import net.labymod.api.client.resources.ResourceLocation;
import net.labymod.api.configuration.settings.Setting;
import net.labymod.api.configuration.settings.accessor.SettingAccessor;
import net.labymod.api.configuration.settings.annotation.SettingElement;
Expand All @@ -35,10 +33,6 @@
@SettingWidget
public class TagPreviewWidget extends HorizontalListWidget {

private final Icon adminIcon = Icon.texture(ResourceLocation.create(
"globaltags",
"textures/icons/staff.png"
));
private static boolean refetch = true;
private static boolean changed = false;
private final TagSubConfig config;
Expand Down Expand Up @@ -98,8 +92,9 @@ public void initialize(boolean refetched) {
if (config.icon().get() != GlobalIcon.NONE)
this.addEntryInitialized(new IconWidget(config.icon().get().getIcon()).addId("icon"));
this.addEntryInitialized(tag);
if (info.isAdmin())
this.addEntryInitialized(new IconWidget(adminIcon).addId("staff-icon"));
if (info.getHighestRole() != null)
this.addEntryInitialized(new IconWidget(info.getHighestRole().getIcon())
.addId("staff-icon"));
}
ButtonWidget refreshButton = ButtonWidget.icon(SpriteCommon.REFRESH, TagPreviewWidget::refetch)
.addId("refresh-button");
Expand Down
17 changes: 8 additions & 9 deletions core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@
import net.labymod.api.client.entity.player.tag.PositionType;
import net.labymod.api.client.entity.player.tag.tags.NameTag;
import net.labymod.api.client.entity.player.tag.tags.NameTagBackground;
import net.labymod.api.client.gui.icon.Icon;
import net.labymod.api.client.render.font.RenderableComponent;
import net.labymod.api.client.render.matrix.Stack;
import net.labymod.api.client.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.UUID;

@SuppressWarnings("deprecation")
public class CustomTag extends NameTag {

private final Icon admin;
private final int black = new Color(0, 0, 0, 70).getRGB();
private final GlobalTagConfig config;
private final PositionType position;
Expand All @@ -30,10 +26,6 @@ public class CustomTag extends NameTag {
public CustomTag(GlobalTagAddon addon, PositionType position) {
this.config = addon.configuration();
this.position = position;
admin = Icon.texture(ResourceLocation.create(
"globaltags",
"textures/icons/staff.png"
));
}

@Override
Expand Down Expand Up @@ -63,14 +55,21 @@ public float getScale() {
}

@Override
@SuppressWarnings("deprecation")
public void render(Stack stack, Entity entity) {
super.render(stack, entity);
if(this.getRenderableComponent() == null) return;
if(info == null) return;

Laby.labyAPI().renderPipeline().renderSeeThrough(entity, () -> {
if(info.getIcon() != null) info.getIcon().render(stack, -11, 0, 9, 9);
if(info.isAdmin()) admin.render(stack, getWidth() + 0.9F, -1.2F, 11, 11);
if(info.getHighestRole() != null) info.getHighestRole().getIcon().render(
stack,
getWidth() + 0.9F,
-1.2F,
11,
11
);
});
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.

0 comments on commit e684811

Please sign in to comment.