Skip to content

Commit

Permalink
Merge pull request #13 from RappyLabyAddons/feat/activities
Browse files Browse the repository at this point in the history
Add report activity
  • Loading branch information
RappyTV authored Nov 25, 2023
2 parents e1183d6 + 1643929 commit 6226a37
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 46 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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.0.7")
version = System.getenv().getOrDefault("VERSION", "1.0.8")
}

minecraft {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/rappytv/globaltags/GlobalTagAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.rappytv.globaltags.api.ApiHandler;
import com.rappytv.globaltags.command.GlobalTagCommand;
import com.rappytv.globaltags.config.GlobalTagConfig;
import com.rappytv.globaltags.context.ReportContext;
import com.rappytv.globaltags.interaction.ReportBulletPoint;
import com.rappytv.globaltags.listener.ServerNavigationListener;
import com.rappytv.globaltags.nametag.CustomTag;
import com.rappytv.globaltags.util.TagCache;
Expand Down Expand Up @@ -45,7 +45,7 @@ protected void enable() {
new CustomTag(this, positionType)
);
registerListener(new ServerNavigationListener());
labyAPI().interactionMenuRegistry().register(new ReportContext(this));
labyAPI().interactionMenuRegistry().register(new ReportBulletPoint(this));
registerCommand(new GlobalTagCommand());

// Clear cache every 5 minutes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.rappytv.globaltags.activities;

import com.rappytv.globaltags.GlobalTagAddon;
import net.labymod.api.Laby;
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.screen.Parent;
import net.labymod.api.client.gui.screen.ScreenInstance;
import net.labymod.api.client.gui.screen.activity.AutoActivity;
import net.labymod.api.client.gui.screen.activity.Link;
import net.labymod.api.client.gui.screen.activity.types.SimpleActivity;
import net.labymod.api.client.gui.screen.widget.Widget;
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.input.TextFieldWidget;
import net.labymod.api.client.gui.screen.widget.widgets.layout.FlexibleContentWidget;
import net.labymod.api.client.gui.screen.widget.widgets.layout.list.HorizontalListWidget;
import net.labymod.api.client.gui.screen.widget.widgets.layout.list.VerticalListWidget;
import net.labymod.api.client.gui.screen.widget.widgets.renderer.IconWidget;
import java.util.UUID;

@Link("report.lss")
@AutoActivity
public class ReportUUIDActivity extends SimpleActivity {

private final GlobalTagAddon addon;
private final UUID uuid;
private final String username;

public ReportUUIDActivity(GlobalTagAddon addon, UUID uuid, String username) {
this.addon = addon;
this.uuid = uuid;
this.username = username;
}

@Override
public void initialize(Parent parent) {
super.initialize(parent);
FlexibleContentWidget windowWidget = new FlexibleContentWidget().addId("window");
HorizontalListWidget profileWrapper = new HorizontalListWidget().addId("header");
IconWidget headWidget = new IconWidget(Icon.head(this.uuid)).addId("head");
ComponentWidget titleWidget = ComponentWidget.i18n("globaltags.report.title", this.username).addId("username");
VerticalListWidget<Widget> content = new VerticalListWidget<>().addId("content");
ComponentWidget reasonWidget = ComponentWidget.i18n("globaltags.report.reason").addId("reason");
TextFieldWidget textField = new TextFieldWidget()
.placeholder(Component.translatable("globaltags.report.placeholder", NamedTextColor.DARK_GRAY))
.addId("text-field");
ButtonWidget button = new ButtonWidget()
.updateComponent(Component.translatable("globaltags.report.send", NamedTextColor.RED))
.addId("report-button");
button.setEnabled(false);
button.setActionListener(() -> {
Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null);
addon.getApiHandler().reportPlayer(uuid, textField.getText());
});
textField.updateListener((text) -> button.setEnabled(!text.isBlank()));

profileWrapper.addEntry(headWidget);
profileWrapper.addEntry(titleWidget);

content.addChild(reasonWidget);
content.addChild(textField);
content.addChild(button);

windowWidget.addContent(profileWrapper);
windowWidget.addContent(content);
this.document.addChild(windowWidget);
}
}
5 changes: 3 additions & 2 deletions core/src/main/java/com/rappytv/globaltags/api/ApiHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rappytv.globaltags.api;

import com.rappytv.globaltags.api.RequestBody.StringType;
import com.rappytv.globaltags.api.requests.PositionSetRequest;
import com.rappytv.globaltags.api.requests.TagSetRequest;
import com.rappytv.globaltags.util.Util;
Expand Down Expand Up @@ -60,15 +61,15 @@ public RequestBody getBody() {
});
}

public void reportPlayer(UUID uuid) {
public void reportPlayer(UUID uuid, String reason) {
ApiRequest request = new ApiRequest(
"POST",
"/players/" + uuid + "/report",
Util.getSessionToken()
) {
@Override
public RequestBody getBody() {
return null;
return new RequestBody(reason, StringType.REPORT_REASON);
}
};
request.sendAsyncRequest().thenRun(() -> {
Expand Down
13 changes: 11 additions & 2 deletions core/src/main/java/com/rappytv/globaltags/api/RequestBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ public class RequestBody {

public String tag;
public String position;
public String reason;

public RequestBody(String tag) {
this.tag = tag;
public RequestBody(String argument, StringType type) {
switch (type) {
case TAG -> this.tag = argument;
case REPORT_REASON -> this.reason = argument;
}
}
public RequestBody(PositionType type) {
position = switch (type) {
Expand All @@ -18,4 +22,9 @@ public RequestBody(PositionType type) {
case LEFT_TO_NAME -> "LEFT";
};
}

public enum StringType {
TAG,
REPORT_REASON
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.rappytv.globaltags.api.ApiRequest;
import com.rappytv.globaltags.api.RequestBody;
import com.rappytv.globaltags.api.RequestBody.StringType;
import net.labymod.api.Laby;

public class TagSetRequest extends ApiRequest {
Expand All @@ -15,6 +16,6 @@ public TagSetRequest(String token, String key) {

@Override
public RequestBody getBody() {
return new RequestBody(key);
return new RequestBody(key, StringType.TAG);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.rappytv.globaltags.interaction;

import com.rappytv.globaltags.GlobalTagAddon;
import com.rappytv.globaltags.activities.ReportUUIDActivity;
import com.rappytv.globaltags.util.PlayerInfo;
import com.rappytv.globaltags.util.TagCache;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.entity.player.Player;
import net.labymod.api.client.entity.player.interaction.BulletPoint;
import net.labymod.api.client.gui.icon.Icon;

public class ReportBulletPoint implements BulletPoint {

private final GlobalTagAddon addon;

public ReportBulletPoint(GlobalTagAddon addon) {
this.addon = addon;
}

@Override
public Component getTitle() {
return Component.translatable("globaltags.context.report");
}

@Override
public Icon getIcon() {
return null;
}

@Override
public void execute(Player player) {
Laby.labyAPI().minecraft().executeNextTick(() ->
Laby.labyAPI().minecraft().minecraftWindow().displayScreen(new ReportUUIDActivity(addon, player.getUniqueId(), player.getName()))
);
}

@Override
public boolean isVisible(Player player) {
PlayerInfo playerInfo = TagCache.get(player.getUniqueId());
return playerInfo != null && playerInfo.getTag() != null;
}
}
6 changes: 6 additions & 0 deletions core/src/main/resources/assets/globaltags/i18n/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
},
"context": {
"report": "Report Globaltag"
},
"report": {
"title": "Report %s",
"send": "Send report",
"reason": "Reason",
"placeholder": "Please enter a reason..."
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.window {
left: 50%;
top: 50%;
width: 300;
height: 180;
alignment-x: center;
alignment-y: center;
# background-color: rgba(20, 20, 20, 0.9);
# border: 1 dark_gray;

.header {
left: 50%;
width: 100%;
height: 20;
padding: 0 2 0 2;
space-between-entries: 2;
# background-color: rgba(10, 10, 10, 0.4);

.head {
width: 16;
height: width;
alignment: center;
}

.username {
alignment: center;
}
}

.content {
width: 100%;
height: 100%;
alignment-x: center;
alignment-y: center;
overwrite-width: false;

.reason {
margin-top: 40;
alignment-x: center;
alignment-y: center;
}

.text-field {
margin-top: 6;
width: 200;
alignment-x: center;
alignment-y: center;
}

.report-button {
margin-top: 5;
width: 50;
height: 20;
alignment-x: center;
alignment-y: center;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.window {
left: 50%;
top: 50%;
width: 300;
height: 180;
alignment-x: center;
alignment-y: center;
# background-color: rgba(20, 20, 20, 0.9);
# border: 1 dark_gray;

.header {
left: 50%;
width: 100%;
height: 20;
padding: 0 2 0 2;
space-between-entries: 2;
# background-color: rgba(10, 10, 10, 0.4);

.head {
width: 16;
height: width;
alignment: center;
}

.username {
alignment: center;
}
}

.content {
width: 100%;
height: 100%;
alignment-x: center;
alignment-y: center;
overwrite-width: false;

.reason {
margin-top: 40;
alignment-x: center;
alignment-y: center;
}

.text-field {
margin-top: 6;
width: 200;
alignment-x: center;
alignment-y: center;
}

.report-button {
margin-top: 5;
width: 70;
height: 20;
alignment-x: center;
alignment-y: center;
}
}
}

0 comments on commit 6226a37

Please sign in to comment.