Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit dc56fb5

Browse files
authored
Merge pull request #847 from UnicacityAddon/develop
Release v2.4.0
2 parents fdd8544 + f1d3d7a commit dc56fb5

122 files changed

Lines changed: 2116 additions & 811 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/ISSUE_TEMPLATE/bug.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LabyMod version: `3` `4`
1515

1616
Minecraft version: `1.12.2`
1717

18-
Addon version: `2.3.0`
18+
Addon version: `2.4.0`
1919

2020
<hr>
2121

api/src/main/java/com/rettichlp/unicacityaddon/api/Broadcast.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = "com.rettichlp.unicacityaddon"
8-
version = "2.3.0"
8+
version = "2.4.0"
99

1010
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
1111

@@ -17,7 +17,7 @@ labyMod {
1717
author = "RettichLP & Dimiikou"
1818
description = "UnicacityAddon is a LabyMod addon written for the Minecraft server Unicacity and provides specialized, nice-to-have features and utilities for everyday gameplay."
1919
minecraftVersion = "1.12.2<*"
20-
version = System.getenv().getOrDefault("VERSION", "2.3.0")
20+
version = System.getenv().getOrDefault("VERSION", "2.4.0")
2121
}
2222

2323
minecraft {

core/src/main/java/com/rettichlp/unicacityaddon/UnicacityAddon.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import com.rettichlp.unicacityaddon.base.services.FileService;
1010
import com.rettichlp.unicacityaddon.base.services.NameTagService;
1111
import com.rettichlp.unicacityaddon.base.services.NavigationService;
12+
import com.rettichlp.unicacityaddon.base.services.NotificationService;
1213
import com.rettichlp.unicacityaddon.base.services.UtilService;
1314
import com.rettichlp.unicacityaddon.base.services.WebService;
1415
import com.rettichlp.unicacityaddon.base.teamspeak.TeamSpeakAPI;
1516
import com.rettichlp.unicacityaddon.controller.DeadBodyController;
1617
import com.rettichlp.unicacityaddon.controller.GuiController;
1718
import com.rettichlp.unicacityaddon.controller.PlayerListController;
19+
import com.rettichlp.unicacityaddon.controller.RenderController;
1820
import com.rettichlp.unicacityaddon.controller.ScreenshotController;
1921
import com.rettichlp.unicacityaddon.controller.SoundController;
2022
import com.rettichlp.unicacityaddon.controller.TransportController;
@@ -37,12 +39,12 @@
3739
* user-friendliness, an update should not always have to be created for changes to content-related data. I utilize an
3840
* API to provide data, leveraging a private server. Data is available for the following purposes:
3941
* <ul>
42+
* <li>activity check <a href="http://rettichlp.de:8888/unicacityaddon/v1/dhgpsklnag2354668ec1d905xcv34d9bdee4b877/activitycheck/LEMILIEU/add">API</a> (unauthorized)</li>
4043
* <li>auto nc <a href="http://rettichlp.de:8888/unicacityaddon/v1/dhgpsklnag2354668ec1d905xcv34d9bdee4b877/autonc">API</a> (unauthorized)</li>
4144
* <li>addon groups <a href="http://rettichlp.de:8888/unicacityaddon/v1/dhgpsklnag2354668ec1d905xcv34d9bdee4b877/player">API</a></li>
4245
* <li>banners <a href="http://rettichlp.de:8888/unicacityaddon/v1/dhgpsklnag2354668ec1d905xcv34d9bdee4b877/banner">API</a></li>
4346
* <li>blacklist reasons <a href="http://rettichlp.de:8888/unicacityaddon/v1/dhgpsklnag2354668ec1d905xcv34d9bdee4b877/blacklistreason/LEMILIEU">API</a> (unauthorized)</li>
4447
* <li>blackmarket locations <a href="http://rettichlp.de:8888/unicacityaddon/v1/dhgpsklnag2354668ec1d905xcv34d9bdee4b877/blackmarket">API</a></li>
45-
* <li>broadcasts <a href="http://rettichlp.de:8888/unicacityaddon/v1/dhgpsklnag2354668ec1d905xcv34d9bdee4b877/broadcast/queue">API</a></li>
4648
* <li>events <a href="http://rettichlp.de:8888/unicacityaddon/v1/dhgpsklnag2354668ec1d905xcv34d9bdee4b877/event">API</a></li>
4749
* <li>house bans <a href="http://rettichlp.de:8888/unicacityaddon/v1/dhgpsklnag2354668ec1d905xcv34d9bdee4b877/houseban?advanced=false">API</a> (unauthorized for <code>advanced=true</code>)</li>
4850
* <li>house ban reasons <a href="http://rettichlp.de:8888/unicacityaddon/v1/dhgpsklnag2354668ec1d905xcv34d9bdee4b877/housebanreason">API</a></li>
@@ -102,6 +104,7 @@ public class UnicacityAddon extends LabyAddon<DefaultUnicacityAddonConfiguration
102104
private FileService fileService;
103105
private NameTagService nameTagService;
104106
private NavigationService navigationService;
107+
private NotificationService notificationService;
105108
private UtilService utilService;
106109
private WebService webService;
107110

@@ -116,6 +119,7 @@ public void load() {
116119
this.fileService = new FileService(this);
117120
this.nameTagService = new NameTagService(this);
118121
this.navigationService = new NavigationService(this);
122+
this.notificationService = new NotificationService(this);
119123
this.utilService = new UtilService(this);
120124
this.webService = new WebService(this);
121125

@@ -130,6 +134,7 @@ protected void enable() {
130134
this.registry.registerHudWidgets();
131135
this.registry.registerListeners();
132136
this.registry.registerCommands();
137+
this.registry.registerGangzones();
133138

134139
new Thread(this.teamSpeakAPI::initialize).start();
135140

@@ -153,6 +158,10 @@ public PlayerListController playerListController() {
153158
return controller().getPlayerListController();
154159
}
155160

161+
public RenderController renderController() {
162+
return controller().getRenderController();
163+
}
164+
156165
public ScreenshotController screenshotController() {
157166
return controller().getScreenshotController();
158167
}

core/src/main/java/com/rettichlp/unicacityaddon/badge/NoPushBadge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public NoPushBadge(UnicacityAddon unicacityAddon) {
2626

2727
@Override
2828
public void render(Stack stack, float x, float y, NetworkPlayerInfo player) {
29-
Icon icon = Icon.sprite16(ResourceLocation.create("unicacityaddon", "themes/vanilla/textures/badges.png"), 0, 0);
29+
Icon icon = Icon.sprite16(ResourceLocation.create("unicacityaddon", "themes/vanilla/textures/sprite/badges.png"), 0, 0);
3030
icon.render(stack, x + 3, y + 1, 6);
3131
}
3232

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.rettichlp.unicacityaddon.badge;
2+
3+
import com.rettichlp.unicacityaddon.UnicacityAddon;
4+
import com.rettichlp.unicacityaddon.base.enums.api.AddonGroup;
5+
import com.rettichlp.unicacityaddon.base.registry.annotation.UCBadge;
6+
import net.labymod.api.client.entity.player.badge.renderer.BadgeRenderer;
7+
import net.labymod.api.client.gui.icon.Icon;
8+
import net.labymod.api.client.network.NetworkPlayerInfo;
9+
import net.labymod.api.client.render.matrix.Stack;
10+
import net.labymod.api.client.resources.ResourceLocation;
11+
12+
import java.util.Optional;
13+
14+
/**
15+
* @author RettichLP
16+
*/
17+
@UCBadge(name = "VipBadge")
18+
public class VipBadge extends BadgeRenderer {
19+
20+
private final UnicacityAddon unicacityAddon;
21+
22+
public VipBadge(UnicacityAddon unicacityAddon) {
23+
this.unicacityAddon = unicacityAddon;
24+
}
25+
26+
@Override
27+
public void render(Stack stack, float x, float y, NetworkPlayerInfo player) {
28+
Icon icon = Icon.sprite16(ResourceLocation.create("unicacityaddon", "themes/vanilla/textures/sprite/badges.png"), 1, 0);
29+
icon.render(stack, x + 3, y + 1, 6);
30+
}
31+
32+
@Override
33+
public boolean isVisible(NetworkPlayerInfo player) {
34+
return Optional.ofNullable(player.profile().getUsername())
35+
.map(s -> AddonGroup.VIP.getMemberList().contains(s))
36+
.orElse(false);
37+
}
38+
}

core/src/main/java/com/rettichlp/unicacityaddon/base/AddonPlayer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import net.labymod.api.client.scoreboard.Scoreboard;
99
import net.labymod.api.client.world.ClientWorld;
1010
import net.labymod.api.util.math.vector.FloatVector3;
11+
import org.jetbrains.annotations.Nullable;
1112

12-
import javax.annotation.Nullable;
1313
import java.util.UUID;
1414

1515
/**
@@ -36,8 +36,6 @@ public interface AddonPlayer {
3636

3737
void sendMessage(Component component);
3838

39-
void sendAPIMessage(String message, boolean success);
40-
4139
void sendEmptyMessage();
4240

4341
void sendErrorMessage(String message);

core/src/main/java/com/rettichlp/unicacityaddon/base/DefaultAddonPlayer.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,6 @@ public void sendMessage(Component component) {
8282
this.unicacityAddon.displayMessage(component);
8383
}
8484

85-
@Override
86-
public void sendAPIMessage(String message, boolean success) {
87-
sendMessage(Message.getBuilder()
88-
.prefix()
89-
.of("API Response:").color(ColorCode.GRAY).advance().space()
90-
.of(message).color(success ? ColorCode.GREEN : ColorCode.RED).advance()
91-
.createComponent());
92-
}
93-
9485
@Override
9586
public void sendEmptyMessage() {
9687
sendMessage("");
@@ -193,7 +184,7 @@ public boolean isSuperUser() {
193184

194185
@Override
195186
public boolean hasGangwar() {
196-
return getScoreboard().getScores(getScoreboard().getObjective(DisplaySlot.SIDEBAR)).stream()
187+
return this.unicacityAddon.configuration().gangwar().get() || getScoreboard().getScores(getScoreboard().getObjective(DisplaySlot.SIDEBAR)).stream()
197188
.map(ScoreboardScore::getName)
198189
.anyMatch(s -> s.contains("Angreifer") || s.contains("Verteidiger"));
199190
}

core/src/main/java/com/rettichlp/unicacityaddon/base/builder/ActivityCheckBuilder.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package com.rettichlp.unicacityaddon.base.builder;
22

33
import com.rettichlp.unicacityaddon.UnicacityAddon;
4-
import com.rettichlp.unicacityaddon.api.response.Success;
54
import com.rettichlp.unicacityaddon.base.enums.Activity;
65
import com.rettichlp.unicacityaddon.base.enums.faction.DrugPurity;
76
import com.rettichlp.unicacityaddon.base.enums.faction.DrugType;
7+
import com.rettichlp.unicacityaddon.base.enums.faction.Faction;
88
import lombok.NoArgsConstructor;
99

10+
import java.util.Collection;
11+
import java.util.List;
12+
1013
/**
1114
* @author RettichLP
1215
*/
1316
@NoArgsConstructor
1417
public class ActivityCheckBuilder {
1518

19+
private static final Collection<Faction> allowedFactions = List.of(Faction.LEMILIEU);
20+
1621
public static Builder getBuilder(UnicacityAddon unicacityAddon) {
1722
return new Builder(unicacityAddon);
1823
}
@@ -68,15 +73,17 @@ public Builder screenshot(String screenshot) {
6873
return this;
6974
}
7075

71-
public Success send() {
72-
return this.unicacityAddon.api().sendActivityCheckActivity(
73-
this.activity,
74-
this.type,
75-
this.value,
76-
this.drugType,
77-
this.drugPurity,
78-
this.date,
79-
this.screenshot);
76+
public void send() {
77+
if (allowedFactions.contains(this.unicacityAddon.player().getFaction())) {
78+
this.unicacityAddon.api().sendActivityCheckActivity(
79+
this.activity,
80+
this.type,
81+
this.value,
82+
this.drugType,
83+
this.drugPurity,
84+
this.date,
85+
this.screenshot);
86+
}
8087
}
8188
}
8289
}

core/src/main/java/com/rettichlp/unicacityaddon/base/builder/RequestBuilder.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import com.google.gson.JsonParser;
1111
import com.google.gson.JsonSyntaxException;
1212
import com.rettichlp.unicacityaddon.UnicacityAddon;
13+
import com.rettichlp.unicacityaddon.api.response.Success;
1314
import com.rettichlp.unicacityaddon.base.enums.api.ApplicationPath;
1415
import com.rettichlp.unicacityaddon.base.io.api.APIResponseException;
16+
import com.rettichlp.unicacityaddon.base.services.NotificationService;
1517

1618
import java.util.Collections;
1719
import java.util.HashSet;
@@ -77,8 +79,7 @@ public Builder parameter(Map<String, String> parameter) {
7779
public JsonElement send() throws APIResponseException {
7880
this.preConditionList.removeIf(preCondition -> preCondition);
7981
if (this.preConditionList.isEmpty()) {
80-
String urlString = this.unicacityAddon.webService().createUrl(this.nonProd, this.applicationPath, this.subPath, this.parameter);
81-
String response = this.unicacityAddon.webService().sendRequest(urlString);
82+
String response = this.unicacityAddon.webService().sendApiRequest(this.nonProd, this.applicationPath, this.subPath, this.parameter);
8283
return new JsonParser().parse(response);
8384
}
8485
return JsonNull.INSTANCE;
@@ -87,36 +88,38 @@ public JsonElement send() throws APIResponseException {
8788
public void sendAsync() {
8889
new Thread(() -> {
8990
try {
90-
send();
91+
JsonElement jsonElement = send();
92+
if (jsonElement.isJsonObject()) {
93+
Success success = parse(jsonElement.getAsJsonObject(), Success.class);
94+
this.unicacityAddon.notificationService().sendUnicacityAddonNotification(success.getInfo(), NotificationService.SendState.SUCCESS);
95+
}
9196
} catch (APIResponseException e) {
9297
e.sendNotification();
93-
this.unicacityAddon.logger().warn(e.getMessage());
98+
this.unicacityAddon.logger().error(e.getMessage());
9499
}
95100
}).start();
96101
}
97102

98-
@SuppressWarnings("unchecked")
99103
public <T> T getAsJsonObjectAndParse(Class<T> responseSchemaClass) {
100104
try {
101105
JsonElement jsonElement = send();
102106
return parse(jsonElement.getAsJsonObject(), responseSchemaClass);
103107
} catch (APIResponseException e) {
108+
this.unicacityAddon.logger().error(e.getMessage());
104109
e.sendNotification();
105-
this.unicacityAddon.logger().warn(e.getMessage());
106-
return (T) e.failureResponse();
107110
} catch (IllegalStateException e) {
108111
this.unicacityAddon.logger().info("Precondition(s) failed! Parsing of JSON response skipped for: {}", responseSchemaClass.getSimpleName());
109-
return null;
110112
}
113+
return null;
111114
}
112115

113116
public <T> List<T> getAsJsonArrayAndParse(Class<T> responseSchemaClass) {
114117
try {
115118
JsonElement jsonElement = send();
116119
return parse(jsonElement.getAsJsonArray(), responseSchemaClass);
117120
} catch (APIResponseException e) {
121+
this.unicacityAddon.logger().error(e.getMessage());
118122
e.sendNotification();
119-
this.unicacityAddon.logger().warn(e.getMessage());
120123
} catch (IllegalStateException e) {
121124
this.unicacityAddon.logger().info("Precondition(s) failed! Parsing of JSON response skipped for: {}", responseSchemaClass.getSimpleName());
122125
}
@@ -129,7 +132,7 @@ private <T> T parse(JsonObject jsonObject, Class<T> responseSchemaClass) throws
129132
return gson.fromJson(jsonObject, typeToken.getType());
130133
}
131134

132-
public <T> List<T> parse(JsonArray jsonArray, Class<T> responseSchemaClass) throws JsonSyntaxException {
135+
private <T> List<T> parse(JsonArray jsonArray, Class<T> responseSchemaClass) throws JsonSyntaxException {
133136
TypeToken<List<T>> typeToken = new TypeToken<List<T>>() {}.where(new TypeParameter<>() {}, responseSchemaClass);
134137
Gson gson = new Gson();
135138
return gson.fromJson(jsonArray, typeToken.getType());

0 commit comments

Comments
 (0)