diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index f930df2..c7b0c40 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -1,37 +1,41 @@
name: Build
on:
- workflow_dispatch:
- push:
- branches: ["main"]
+ workflow_dispatch:
+ push:
+ branches:
+ - "**"
+ tags-ignore:
+ - "**"
jobs:
- build:
- if: github.repository_owner == 'CommunityRadarGG'
- runs-on: ubuntu-latest
- steps:
- - name: Checkout Repository
- uses: actions/checkout@v5
- - name: Validate Gradle Wrapper
- uses: gradle/actions/wrapper-validation@v5
- - name: Setup Java
- uses: actions/setup-java@v5
- with:
- distribution: 'zulu'
- java-version: 21
- - name: Setup Gradle
- uses: gradle/actions/setup-gradle@v5
- - name: Grant execute permission for gradlew
- run: chmod +x gradlew
- - name: Clean Build
- run: ./gradlew clean build
- - name: Extract Version from Gradle
- run: |
- version=$(./gradlew properties -q | grep "^version:" | awk '{print $2}')
- echo "VERSION=$version" >> $GITHUB_ENV
- echo $version
- - name: Upload Artifact
- uses: actions/upload-artifact@v4
- with:
- name: communityradar-${{ env.VERSION }}
- path: build/libs/*-${{ env.VERSION }}.jar
+ build:
+ if: github.repository_owner == 'CommunityRadarGG'
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout Repository
+ uses: actions/checkout@v5
+ - name: Setup Java
+ uses: actions/setup-java@v5
+ with:
+ distribution: 'zulu'
+ java-version: 21
+ - name: Validate Gradle Wrapper
+ uses: gradle/actions/wrapper-validation@v5
+ - name: Setup Gradle
+ uses: gradle/actions/setup-gradle@v5
+ - name: Grant execute permission for gradlew
+ run: chmod +x gradlew
+ - name: Build
+ run: ./gradlew build
+ - name: Extract Version from Gradle
+ run: |
+ version=$(./gradlew properties -q | grep "^version:" | awk '{print $2}')
+ echo "VERSION=$version" >> $GITHUB_ENV
+ echo $version
+ - name: Upload Artifact
+ if: startsWith(github.event.head_commit.message || '', 'Release')
+ uses: actions/upload-artifact@v4
+ with:
+ name: communityradar-${{ env.VERSION }}
+ path: build/libs/*-${{ env.VERSION }}.jar
diff --git a/src/main/java/io/github/communityradargg/forgemod/CommunityRadarMod.java b/src/main/java/io/github/communityradargg/forgemod/CommunityRadarMod.java
index 9f0d2fe..c879975 100644
--- a/src/main/java/io/github/communityradargg/forgemod/CommunityRadarMod.java
+++ b/src/main/java/io/github/communityradargg/forgemod/CommunityRadarMod.java
@@ -41,8 +41,8 @@
@Mod(modid = CommunityRadarMod.MOD_ID)
public class CommunityRadarMod {
public static final String MOD_ID = "communityradar";
- private static final Logger logger = LogManager.getLogger(CommunityRadarMod.class);
- private static RadarListManager listManager;
+ private static final Logger LOGGER = LogManager.getLogger(CommunityRadarMod.class);
+ private RadarListManager listManager;
private String version;
private boolean onGrieferGames = false;
@@ -52,9 +52,8 @@ public class CommunityRadarMod {
* @param event The event.
*/
@EventHandler
- @SuppressWarnings("unused") // called by the mod loader
public void init(final FMLInitializationEvent event) {
- logger.info("Loading the mod '" + MOD_ID + "'!");
+ LOGGER.info("Loading the mod '{}'", MOD_ID);
final ModContainer modContainer = Loader.instance().getIndexedModList().get(MOD_ID);
version = modContainer == null ? "UNKNOWN" : modContainer.getVersion();
@@ -63,16 +62,16 @@ public void init(final FMLInitializationEvent event) {
.getAbsolutePath(),"communityradar", "lists")
.toFile();
if (!directoryPath.exists() && !directoryPath.mkdirs()) {
- logger.error("Could not create directory: {}", directoryPath);
+ LOGGER.error("Could not create directory: {}", directoryPath);
}
- listManager = new RadarListManager(directoryPath.getAbsolutePath() + "/");
+ listManager = new RadarListManager(this, directoryPath.getAbsolutePath() + "/");
registerPublicLists();
// Needs to be after loading public lists
listManager.loadPrivateLists();
registerEvents();
registerCommands();
- logger.info("Successfully loaded the mod '" + MOD_ID + "'!");
+ LOGGER.info("Successfully loaded the mod '{}'", MOD_ID);
}
/**
@@ -97,11 +96,11 @@ private void registerCommands() {
*/
private void registerPublicLists() {
if (!listManager.registerPublicList("scammer", "&7[&cScammer&7]", "https://lists.community-radar.de/versions/v1/scammer.json")) {
- logger.error("Could not register public list 'scammers'!");
+ LOGGER.error("Could not register public list 'scammers'!");
}
if (!listManager.registerPublicList("trusted", "&7[&aTrusted&7]", "https://lists.community-radar.de/versions/v1/trusted.json")) {
- logger.error("Could not register public list 'verbvllert_trusted'!");
+ LOGGER.error("Could not register public list 'verbvllert_trusted'!");
}
}
@@ -110,7 +109,7 @@ private void registerPublicLists() {
*
* @return Returns the radar list manager instance.
*/
- public static @NotNull RadarListManager getListManager() {
+ public @NotNull RadarListManager getListManager() {
return listManager;
}
diff --git a/src/main/java/io/github/communityradargg/forgemod/command/CheckSubcommand.java b/src/main/java/io/github/communityradargg/forgemod/command/CheckSubcommand.java
new file mode 100644
index 0000000..16ad84a
--- /dev/null
+++ b/src/main/java/io/github/communityradargg/forgemod/command/CheckSubcommand.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2024 - present CommunityRadarGG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.github.communityradargg.forgemod.command;
+
+import io.github.communityradargg.forgemod.CommunityRadarMod;
+import io.github.communityradargg.forgemod.radarlistmanager.RadarListEntry;
+import io.github.communityradargg.forgemod.util.Messages;
+import io.github.communityradargg.forgemod.util.RadarMessage;
+import io.github.communityradargg.forgemod.util.Utils;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.network.NetworkPlayerInfo;
+import net.minecraft.entity.player.EntityPlayer;
+import org.jetbrains.annotations.NotNull;
+import java.util.Optional;
+
+/**
+ * Holds the logic of the check subcommand.
+ */
+public class CheckSubcommand implements Subcommand {
+ private final CommunityRadarMod communityRadarMod;
+ private final EntityPlayer player;
+ private final String[] args;
+
+ /**
+ * Constructs a {@link CheckSubcommand}.
+ *
+ * @param communityRadarMod The mod main class instance.
+ * @param player The player.
+ * @param args The args.
+ */
+ public CheckSubcommand(final @NotNull CommunityRadarMod communityRadarMod, final @NotNull EntityPlayer player, final @NotNull String[] args) {
+ this.communityRadarMod = communityRadarMod;
+ this.player = player;
+ this.args = args;
+ }
+
+ @Override
+ public void run() {
+ if (args.length != 2) {
+ // missing arguments
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
+ .build().toChatComponentText());
+ return;
+ }
+
+ if (args[1].equalsIgnoreCase("*")) {
+ // check all argument
+ handleCheckAllSubcommand(player);
+ return;
+ }
+ handleCheckPlayerSubcommand(player, args);
+ }
+
+ /**
+ * Handles the check - player subcommand.
+ *
+ * @param player The player, which executed the subcommand.
+ * @param args The arguments passed to the main command.
+ */
+ private void handleCheckPlayerSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.INPUT_PROCESSING)
+ .build().toChatComponentText());
+ Utils.getUUID(communityRadarMod, args[1]).thenAccept(checkPlayerOptional -> {
+ if (!checkPlayerOptional.isPresent()) {
+ // player uuid could not be fetched
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.FAILED)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final Optional entryOptional = communityRadarMod.getListManager().getRadarListEntry(checkPlayerOptional.get());
+ if (!entryOptional.isPresent()) {
+ // player uuid is on no list
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.FAILED)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final RadarListEntry entry = entryOptional.get();
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.FOUND + "\n" + Messages.Check.CHECK_ENTRY)
+ .replaceWithColorCodes("{prefix}", communityRadarMod.getListManager().getPrefix(entry.uuid()))
+ .replace("{name}", entry.name())
+ .replace("{cause}", entry.cause())
+ .replace("{entryCreationDate}", Utils.formatDateTime(entry.entryCreationDate()))
+ .replace("{entryUpdateDate}", Utils.formatDateTime(entry.entryUpdateDate()))
+ .build().toChatComponentText());
+ });
+ }
+
+ /**
+ * Handles the check - all subcommand.
+ *
+ * @param player The player, which executed the subcommand.
+ */
+ private void handleCheckAllSubcommand(final @NotNull EntityPlayer player) {
+ boolean anyPlayerFound = false;
+ for (final NetworkPlayerInfo networkPlayer : Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap()) {
+ if (networkPlayer.getGameProfile().getId() == null) {
+ continue;
+ }
+
+ final Optional listEntryOptional = communityRadarMod.getListManager()
+ .getRadarListEntry(networkPlayer.getGameProfile().getId());
+ if (!listEntryOptional.isPresent()) {
+ // player uuid is on no list
+ continue;
+ }
+
+ if (!anyPlayerFound) {
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.EVERYONE)
+ .build().toChatComponentText());
+ anyPlayerFound = true;
+ }
+
+ final RadarListEntry entry = listEntryOptional.get();
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.CHECK_ENTRY)
+ .replaceWithColorCodes("{prefix}", communityRadarMod.getListManager().getPrefix(entry.uuid()))
+ .replace("{name}", entry.name())
+ .replace("{cause}", entry.cause())
+ .replace("{entryCreationDate}", Utils.formatDateTime(entry.entryCreationDate()))
+ .replace("{entryUpdateDate}", Utils.formatDateTime(entry.entryUpdateDate()))
+ .build().toChatComponentText());
+ }
+
+ if (!anyPlayerFound) {
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.NOT_FOUND)
+ .build().toChatComponentText());
+ }
+ }
+}
diff --git a/src/main/java/io/github/communityradargg/forgemod/command/HelpSubcommand.java b/src/main/java/io/github/communityradargg/forgemod/command/HelpSubcommand.java
new file mode 100644
index 0000000..d697516
--- /dev/null
+++ b/src/main/java/io/github/communityradargg/forgemod/command/HelpSubcommand.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2024 - present CommunityRadarGG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.github.communityradargg.forgemod.command;
+
+import io.github.communityradargg.forgemod.CommunityRadarMod;
+import io.github.communityradargg.forgemod.util.Messages;
+import io.github.communityradargg.forgemod.util.RadarMessage;
+import net.minecraft.entity.player.EntityPlayer;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Holds the logic of the help subcommand.
+ */
+public class HelpSubcommand implements Subcommand {
+ private final CommunityRadarMod communityRadarMod;
+ private final EntityPlayer player;
+
+ /**
+ * Constructs a {@link HelpSubcommand}.
+ *
+ * @param communityRadarMod The mod main class instance.
+ * @param player The player.
+ */
+ public HelpSubcommand(final @NotNull CommunityRadarMod communityRadarMod, final @NotNull EntityPlayer player) {
+ this.communityRadarMod = communityRadarMod;
+ this.player = player;
+ }
+
+ @Override
+ public void run() {
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.HELP)
+ .replace("{code_version}", communityRadarMod.getVersion())
+ .excludePrefix()
+ .build().toChatComponentText());
+ }
+}
diff --git a/src/main/java/io/github/communityradargg/forgemod/command/ListSubcommand.java b/src/main/java/io/github/communityradargg/forgemod/command/ListSubcommand.java
new file mode 100644
index 0000000..da5cf47
--- /dev/null
+++ b/src/main/java/io/github/communityradargg/forgemod/command/ListSubcommand.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2024 - present CommunityRadarGG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.github.communityradargg.forgemod.command;
+
+import io.github.communityradargg.forgemod.CommunityRadarMod;
+import io.github.communityradargg.forgemod.radarlistmanager.RadarList;
+import io.github.communityradargg.forgemod.radarlistmanager.RadarListManager;
+import io.github.communityradargg.forgemod.util.Messages;
+import io.github.communityradargg.forgemod.util.RadarMessage;
+import io.github.communityradargg.forgemod.util.Utils;
+import net.minecraft.entity.player.EntityPlayer;
+import org.jetbrains.annotations.NotNull;
+import java.util.Collections;
+import java.util.Locale;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+
+/**
+ * Holds the logic of the list subcommand.
+ */
+public class ListSubcommand implements Subcommand {
+ private final CommunityRadarMod communityRadarMod;
+ private final EntityPlayer player;
+ private final String[] args;
+
+ /**
+ * Constructs a {@link ListSubcommand}.
+ *
+ * @param communityRadarMod The mod main class instance.
+ * @param player The player.
+ * @param args The args.
+ */
+ public ListSubcommand(final @NotNull CommunityRadarMod communityRadarMod, final @NotNull EntityPlayer player, final @NotNull String[] args) {
+ this.communityRadarMod = communityRadarMod;
+ this.player = player;
+ this.args = args;
+ }
+
+ @Override
+ public void run() {
+ if (args.length < 2) {
+ // missing arguments
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
+ .build().toChatComponentText());
+ return;
+ }
+
+ switch (args[1].toUpperCase(Locale.ENGLISH)) {
+ case "ADD":
+ handleListAddSubcommand(player, args);
+ break;
+ case "PREFIX":
+ handleListPrefixSubcommand(player, args);
+ break;
+ case "DELETE":
+ handleListDeleteSubcommand(player, args);
+ break;
+ case "SHOW":
+ handleListShowSubcommand(player, args);
+ break;
+ default:
+ new HelpSubcommand(communityRadarMod, player).run();
+ break;
+ }
+ }
+
+ /**
+ * Handles the list - add subcommand.
+ *
+ * @param player The player, which executed the subcommand.
+ * @param args The arguments passed to the main command.
+ */
+ private void handleListAddSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
+ if (args.length != 4) {
+ // missing arguments
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
+ .build().toChatComponentText());
+ return;
+ }
+
+ if (communityRadarMod.getListManager().getRadarList(args[2]).isPresent()) {
+ // list already existing
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.CREATE_FAILED)
+ .build().toChatComponentText());
+ return;
+ }
+
+ if (!communityRadarMod.getListManager().registerPrivateList(args[2], args[3])) {
+ // list could not be registered
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.CREATE_FAILED)
+ .build().toChatComponentText());
+ return;
+ }
+
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.CREATE_SUCCESS)
+ .build().toChatComponentText());
+ }
+
+ /**
+ * Handles the list - delete subcommand.
+ *
+ * @param player The player, which executed the subcommand.
+ * @param args The arguments passed to the main command.
+ */
+ private void handleListDeleteSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
+ if (args.length != 3) {
+ // missing arguments
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final RadarListManager listManager = communityRadarMod.getListManager();
+ final Set oldPrefixes = listManager.getExistingPrefixes();
+ final Set oldUuids = listManager.getRadarList(args[2])
+ .map(radarList -> radarList.getPlayerMap().keySet())
+ .orElse(Collections.emptySet());
+
+ if (!listManager.unregisterList(args[2])) {
+ // list is not existing, list is not private, file cannot be deleted
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.DELETE_FAILED)
+ .build().toChatComponentText());
+ return;
+ }
+
+ oldUuids.forEach(uuid -> Utils.updatePlayerByUuid(communityRadarMod, uuid, oldPrefixes));
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.DELETE_SUCCESS)
+ .build().toChatComponentText());
+ }
+
+ /**
+ * Handles the list - show subcommand.
+ *
+ * @param player The player, which executed the subcommand.
+ * @param args The arguments passed to the main command.
+ */
+ private void handleListShowSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
+ if (args.length != 3) {
+ // missing arguments
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final Optional listOptional = communityRadarMod.getListManager().getRadarList(args[2]);
+ if (!listOptional.isPresent()) {
+ // list is not existing
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.SHOW_FAILED)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final RadarList list = listOptional.get();
+ if (list.getPlayerMap().isEmpty()) {
+ // list is empty
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.SHOW_EMPTY)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final StringBuilder players = new StringBuilder();
+ list.getPlayerMap().values().forEach(value -> players.append(value.name()).append(", "));
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.SHOW_SUCCESS)
+ .replace("{list}", list.getNamespace())
+ .replaceWithColorCodes("{prefix}", listOptional.get().getPrefix())
+ .replace("{players}", players.substring(0, players.length() - 2))
+ .build().toChatComponentText());
+ }
+
+ /**
+ * Handles the list - prefix subcommand.
+ *
+ * @param player The player, which executed the subcommand.
+ * @param args The arguments passed to the main command.
+ */
+ private void handleListPrefixSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
+ if (args.length != 4) {
+ // missing arguments
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final RadarListManager listManager = communityRadarMod.getListManager();
+ final Optional listOptional = listManager.getRadarList(args[2]);
+ if (!listOptional.isPresent()) {
+ // list is not existing
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.PREFIX_FAILED)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final RadarList list = listOptional.get();
+ final Set oldPrefixes = listManager.getExistingPrefixes();
+ list.setPrefix(args[3]);
+ list.saveList();
+ list.getPlayerMap().keySet().forEach(uuid -> Utils.updatePlayerByUuid(communityRadarMod, uuid, oldPrefixes));
+
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.PREFIX_SUCCESS)
+ .replaceWithColorCodes("{prefix}", args[3])
+ .build().toChatComponentText());
+ }
+}
diff --git a/src/main/java/io/github/communityradargg/forgemod/command/ListsSubcommand.java b/src/main/java/io/github/communityradargg/forgemod/command/ListsSubcommand.java
new file mode 100644
index 0000000..6ecb7a7
--- /dev/null
+++ b/src/main/java/io/github/communityradargg/forgemod/command/ListsSubcommand.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2024 - present CommunityRadarGG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.github.communityradargg.forgemod.command;
+
+import io.github.communityradargg.forgemod.CommunityRadarMod;
+import io.github.communityradargg.forgemod.radarlistmanager.RadarListVisibility;
+import io.github.communityradargg.forgemod.util.Messages;
+import io.github.communityradargg.forgemod.util.RadarMessage;
+import net.minecraft.entity.player.EntityPlayer;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Holds the logic of the lists subcommand.
+ */
+public class ListsSubcommand implements Subcommand {
+ private final CommunityRadarMod communityRadarMod;
+ private final EntityPlayer player;
+
+ /**
+ * Constructs a {@link ListsSubcommand}.
+ *
+ * @param communityRadarMod The mod main class instance.
+ * @param player The player.
+ */
+ public ListsSubcommand(final @NotNull CommunityRadarMod communityRadarMod, final @NotNull EntityPlayer player) {
+ this.communityRadarMod = communityRadarMod;
+ this.player = player;
+ }
+
+ @Override
+ public void run() {
+ final StringBuilder listsText = new StringBuilder();
+ for (final String namespace : communityRadarMod.getListManager().getNamespaces()) {
+ communityRadarMod.getListManager().getRadarList(namespace)
+ .ifPresent(radarList -> listsText.append("§e").append(namespace).append(" §7(§c")
+ .append(radarList.getRadarListVisibility() == RadarListVisibility.PRIVATE ? Messages.Lists.PRIVATE : Messages.Lists.PUBLIC)
+ .append("§7)").append(", "));
+ }
+
+ if (listsText.length() > 0) {
+ // players on the list
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Lists.FOUND)
+ .replace("{lists}", listsText.substring(0, listsText.length() - 2))
+ .build().toChatComponentText());
+ } else {
+ // list is empty
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Lists.EMPTY)
+ .build().toChatComponentText());
+ }
+ }
+}
diff --git a/src/main/java/io/github/communityradargg/forgemod/command/PlayerSubcommand.java b/src/main/java/io/github/communityradargg/forgemod/command/PlayerSubcommand.java
new file mode 100644
index 0000000..e621150
--- /dev/null
+++ b/src/main/java/io/github/communityradargg/forgemod/command/PlayerSubcommand.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2024 - present CommunityRadarGG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.github.communityradargg.forgemod.command;
+
+import io.github.communityradargg.forgemod.CommunityRadarMod;
+import io.github.communityradargg.forgemod.radarlistmanager.RadarList;
+import io.github.communityradargg.forgemod.radarlistmanager.RadarListManager;
+import io.github.communityradargg.forgemod.util.Messages;
+import io.github.communityradargg.forgemod.util.RadarMessage;
+import io.github.communityradargg.forgemod.util.Utils;
+import net.minecraft.entity.player.EntityPlayer;
+import org.jetbrains.annotations.NotNull;
+import java.util.Locale;
+import java.util.Optional;
+import java.util.UUID;
+
+/**
+ * Holds the logic of the player subcommand.
+ */
+public class PlayerSubcommand implements Subcommand {
+ private final CommunityRadarMod communityRadarMod;
+ private final EntityPlayer player;
+ private final String[] args;
+
+ /**
+ * Constructs a {@link PlayerSubcommand}.
+ *
+ * @param communityRadarMod The mod main class instance.
+ * @param player The player.
+ * @param args The args.
+ */
+ public PlayerSubcommand(final @NotNull CommunityRadarMod communityRadarMod, final @NotNull EntityPlayer player, final @NotNull String[] args) {
+ this.communityRadarMod = communityRadarMod;
+ this.player = player;
+ this.args = args;
+ }
+
+ @Override
+ public void run() {
+ if (args.length < 2) {
+ // missing arguments
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
+ .build().toChatComponentText());
+ return;
+ }
+
+ switch (args[1].toUpperCase(Locale.ENGLISH)) {
+ case "ADD":
+ handlePlayerAddSubcommand(player, args);
+ break;
+ case "REMOVE":
+ handlePlayerRemoveSubcommand(player, args);
+ break;
+ default:
+ new HelpSubcommand(communityRadarMod, player).run();
+ break;
+ }
+ }
+
+ /**
+ * Handles the player - add subcommand.
+ *
+ * @param player The player, which executed the subcommand.
+ * @param args The arguments passed to the main command.
+ */
+ private void handlePlayerAddSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
+ if (args.length < 5) {
+ // missing arguments
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final RadarListManager listManager = communityRadarMod.getListManager();
+ final Optional listOptional = listManager.getRadarList(args[2]);
+ if (!listOptional.isPresent()) {
+ // list not existing
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_FAILED)
+ .build().toChatComponentText());
+ return;
+ }
+
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.INPUT_PROCESSING)
+ .build().toChatComponentText());
+ Utils.getUUID(communityRadarMod, args[3]).thenAccept(uuidOptional -> {
+ if (!uuidOptional.isPresent()) {
+ // player uuid could not be fetched
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(args[3].startsWith("!") ? Messages.Player.NAME_INVALID_BEDROCK : Messages.Player.NAME_INVALID)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final UUID uuid = uuidOptional.get();
+ if (listOptional.get().isInList(uuid)) {
+ // player already on list
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_IN_LIST)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final StringBuilder notes = new StringBuilder();
+ for (int i = 4; i < args.length; i++) {
+ notes.append(args[i]).append(" ");
+ }
+
+ if (!communityRadarMod.getListManager().addRadarListEntry(args[2], uuid, args[3], notes.substring(0, notes.length() - 1))) {
+ // list is not private
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_FAILED)
+ .build().toChatComponentText());
+ return;
+ }
+
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_SUCCESS)
+ .build().toChatComponentText());
+ Utils.updatePlayerByUuid(communityRadarMod, uuid, listManager.getExistingPrefixes());
+ });
+ }
+
+ /**
+ * Handles the player - remove subcommand.
+ *
+ * @param player The player, which executed the subcommand.
+ * @param args The arguments passed to the main command.
+ */
+ private void handlePlayerRemoveSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
+ if (args.length != 4) {
+ // missing arguments
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final RadarListManager listManager = communityRadarMod.getListManager();
+ final Optional listOptional = listManager.getRadarList(args[2]);
+ if (!listOptional.isPresent()) {
+ // list is not existing
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.REMOVE_FAILED)
+ .build().toChatComponentText());
+ return;
+ }
+
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.INPUT_PROCESSING)
+ .build().toChatComponentText());
+ final RadarList list = listOptional.get();
+ Utils.getUUID(communityRadarMod, args[3]).thenAccept(uuidOptional -> {
+ if (!uuidOptional.isPresent()) {
+ // player uuid could not be fetched
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(args[3].startsWith("!") ? Messages.Player.NAME_INVALID_BEDROCK : Messages.Player.NAME_INVALID)
+ .build().toChatComponentText());
+ return;
+ }
+
+ final UUID uuid = uuidOptional.get();
+ if (!list.isInList(uuid)) {
+ // player uuid not on list
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.REMOVE_NOT_IN_LIST)
+ .build().toChatComponentText());
+ return;
+ }
+
+ list.getPlayerMap().remove(uuid);
+ Utils.updatePlayerByUuid(communityRadarMod, uuid, listManager.getExistingPrefixes());
+ player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.REMOVE_SUCCESS)
+ .build().toChatComponentText());
+ });
+ }
+}
diff --git a/src/main/java/io/github/communityradargg/forgemod/command/RadarCommand.java b/src/main/java/io/github/communityradargg/forgemod/command/RadarCommand.java
index f03fbaa..698ff72 100644
--- a/src/main/java/io/github/communityradargg/forgemod/command/RadarCommand.java
+++ b/src/main/java/io/github/communityradargg/forgemod/command/RadarCommand.java
@@ -16,74 +16,57 @@
package io.github.communityradargg.forgemod.command;
import io.github.communityradargg.forgemod.CommunityRadarMod;
-import io.github.communityradargg.forgemod.radarlistmanager.RadarList;
-import io.github.communityradargg.forgemod.radarlistmanager.RadarListManager;
-import io.github.communityradargg.forgemod.radarlistmanager.RadarListVisibility;
-import io.github.communityradargg.forgemod.radarlistmanager.RadarListEntry;
import io.github.communityradargg.forgemod.util.Messages;
import io.github.communityradargg.forgemod.util.RadarMessage;
-import io.github.communityradargg.forgemod.util.Utils;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import java.util.Locale;
-import java.util.Optional;
-import java.util.Set;
-import java.util.UUID;
/**
- * The class containing all logic for the radar command.
+ * The class containing all logic for the main radar command.
*/
public class RadarCommand extends CommandBase {
- private final CommunityRadarMod mod;
+ private final CommunityRadarMod communityRadarMod;
/**
* Constructs a {@link RadarCommand}.
*
- * @param mod The mod main class instance.
+ * @param communityRadarMod The mod main class instance.
*/
- public RadarCommand(final CommunityRadarMod mod) {
- this.mod = mod;
+ public RadarCommand(final CommunityRadarMod communityRadarMod) {
+ this.communityRadarMod = communityRadarMod;
}
- /** {@inheritDoc} */
@Override
public @NotNull String getCommandName() {
return "radar";
}
- /** {@inheritDoc} */
@Override
public String getCommandUsage(final @NotNull ICommandSender sender) {
return "/radar";
}
- /** {@inheritDoc} */
@Override
public List getCommandAliases() {
return Arrays.asList("communityradar", "scammer", "trustedmm", "mm");
}
- /** {@inheritDoc} */
@Override
public int getRequiredPermissionLevel() {
return 0;
}
- /** {@inheritDoc} */
@Override
public boolean canCommandSenderUseCommand(final ICommandSender sender) {
return sender instanceof EntityPlayer;
}
- /** {@inheritDoc} */
@Override
public void processCommand(final ICommandSender sender, final String[] args) {
if (!(sender instanceof EntityPlayer)) {
@@ -93,469 +76,31 @@ public void processCommand(final ICommandSender sender, final String[] args) {
}
final EntityPlayer player = (EntityPlayer) sender;
+ Subcommand subcommand = null;
if (args.length == 0) {
- handleHelpSubcommand(player);
- return;
- }
-
- switch (args[0].toUpperCase(Locale.ENGLISH)) {
- case "CHECK":
- handleCheckSubcommand(player, args);
- break;
- case "LIST":
- handleListSubcommand(player, args);
- break;
- case "PLAYER":
- handlePlayerSubcommand(player, args);
- break;
- case "LISTS":
- handleListsSubcommand(player);
- break;
- default:
- handleHelpSubcommand(player);
- break;
- }
- }
-
- /**
- * Handles the player subcommand.
- *
- * @param player The player, which executed the subcommand.
- * @param args The arguments passed to the main command.
- */
- private void handlePlayerSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
- if (args.length < 2) {
- // missing arguments
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
- .build().toChatComponentText());
- return;
- }
-
- switch (args[1].toUpperCase(Locale.ENGLISH)) {
- case "ADD":
- handlePlayerAddSubcommand(player, args);
- break;
- case "REMOVE":
- handlePlayerRemoveSubcommand(player, args);
- break;
- default:
- handleHelpSubcommand(player);
- break;
- }
- }
-
- /**
- * Handles the player - add subcommand.
- *
- * @param player The player, which executed the subcommand.
- * @param args The arguments passed to the main command.
- */
- private void handlePlayerAddSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
- if (args.length < 5) {
- // missing arguments
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
- .build().toChatComponentText());
- return;
- }
-
- final RadarListManager listManager = CommunityRadarMod.getListManager();
- final Optional listOptional = listManager.getRadarList(args[2]);
- if (!listOptional.isPresent()) {
- // list not existing
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_FAILED)
- .build().toChatComponentText());
- return;
- }
-
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.INPUT_PROCESSING)
- .build().toChatComponentText());
- Utils.getUUID(mod, args[3]).thenAccept(uuidOptional -> {
- if (!uuidOptional.isPresent()) {
- // player uuid could not be fetched
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(args[3].startsWith("!") ? Messages.Player.NAME_INVALID_BEDROCK : Messages.Player.NAME_INVALID)
- .build().toChatComponentText());
- return;
- }
-
- final UUID uuid = uuidOptional.get();
- if (listOptional.get().isInList(uuid)) {
- // player already on list
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_IN_LIST)
- .build().toChatComponentText());
- return;
- }
-
- final StringBuilder notes = new StringBuilder();
- for (int i = 4; i < args.length; i++) {
- notes.append(args[i]).append(" ");
- }
-
- if (!CommunityRadarMod.getListManager().addRadarListEntry(args[2], uuid, args[3], notes.substring(0, notes.length() - 1))) {
- // list is not private
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_FAILED)
- .build().toChatComponentText());
- return;
- }
-
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_SUCCESS)
- .build().toChatComponentText());
- Utils.updatePlayerByUuid(uuid, listManager.getExistingPrefixes());
- });
- }
-
- /**
- * Handles the player - remove subcommand.
- *
- * @param player The player, which executed the subcommand.
- * @param args The arguments passed to the main command.
- */
- private void handlePlayerRemoveSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
- if (args.length != 4) {
- // missing arguments
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
- .build().toChatComponentText());
- return;
- }
-
- final RadarListManager listManager = CommunityRadarMod.getListManager();
- final Optional listOptional = listManager.getRadarList(args[2]);
- if (!listOptional.isPresent()) {
- // list is not existing
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.REMOVE_FAILED)
- .build().toChatComponentText());
- return;
- }
-
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.INPUT_PROCESSING)
- .build().toChatComponentText());
- final RadarList list = listOptional.get();
- Utils.getUUID(mod, args[3]).thenAccept(uuidOptional -> {
- if (!uuidOptional.isPresent()) {
- // player uuid could not be fetched
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(args[3].startsWith("!") ? Messages.Player.NAME_INVALID_BEDROCK : Messages.Player.NAME_INVALID)
- .build().toChatComponentText());
- return;
+ subcommand = new HelpSubcommand(communityRadarMod, player);
+ }
+
+ if (subcommand == null) {
+ switch (args[0].toUpperCase(Locale.ENGLISH)) {
+ case "CHECK":
+ subcommand = new CheckSubcommand(communityRadarMod, player, args);
+ break;
+ case "LIST":
+ subcommand = new ListSubcommand(communityRadarMod, player, args);
+ break;
+ case "PLAYER":
+ subcommand = new PlayerSubcommand(communityRadarMod, player, args);
+ break;
+ case "LISTS":
+ subcommand = new ListsSubcommand(communityRadarMod, player);
+ break;
+ default:
+ subcommand = new HelpSubcommand(communityRadarMod, player);
+ break;
}
-
- final UUID uuid = uuidOptional.get();
- if (!list.isInList(uuid)) {
- // player uuid not on list
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.REMOVE_NOT_IN_LIST)
- .build().toChatComponentText());
- return;
- }
-
- list.getPlayerMap().remove(uuid);
- Utils.updatePlayerByUuid(uuid, listManager.getExistingPrefixes());
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Player.REMOVE_SUCCESS)
- .build().toChatComponentText());
- });
- }
-
- /**
- * Handles the list subcommand.
- *
- * @param player The player, which executed the subcommand.
- * @param args The arguments passed to the main command.
- */
- private void handleListSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
- if (args.length < 2) {
- // missing arguments
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
- .build().toChatComponentText());
- return;
- }
-
- switch (args[1].toUpperCase(Locale.ENGLISH)) {
- case "ADD":
- handleListAddSubcommand(player, args);
- break;
- case "PREFIX":
- handleListPrefixSubcommand(player, args);
- break;
- case "DELETE":
- handleListDeleteSubcommand(player, args);
- break;
- case "SHOW":
- handleListShowSubcommand(player, args);
- break;
- default:
- handleHelpSubcommand(player);
- break;
- }
- }
-
- /**
- * Handles the list - add subcommand.
- *
- * @param player The player, which executed the subcommand.
- * @param args The arguments passed to the main command.
- */
- private void handleListAddSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
- if (args.length != 4) {
- // missing arguments
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
- .build().toChatComponentText());
- return;
- }
-
- if (CommunityRadarMod.getListManager().getRadarList(args[2]).isPresent()) {
- // list already existing
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.CREATE_FAILED)
- .build().toChatComponentText());
- return;
- }
-
- if (!CommunityRadarMod.getListManager().registerPrivateList(args[2], args[3])) {
- // list could not be registered
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.CREATE_FAILED)
- .build().toChatComponentText());
- return;
}
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.CREATE_SUCCESS)
- .build().toChatComponentText());
- }
-
- /**
- * Handles the list - delete subcommand.
- *
- * @param player The player, which executed the subcommand.
- * @param args The arguments passed to the main command.
- */
- private void handleListDeleteSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
- if (args.length != 3) {
- // missing arguments
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
- .build().toChatComponentText());
- return;
- }
-
- final RadarListManager listManager = CommunityRadarMod.getListManager();
- final Set oldPrefixes = listManager.getExistingPrefixes();
- final Set oldUuids = listManager.getRadarList(args[2])
- .map(radarList -> radarList.getPlayerMap().keySet())
- .orElse(Collections.emptySet());
-
- if (!listManager.unregisterList(args[2])) {
- // list is not existing, list is not private, file cannot be deleted
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.DELETE_FAILED)
- .build().toChatComponentText());
- return;
- }
-
- oldUuids.forEach(uuid -> Utils.updatePlayerByUuid(uuid, oldPrefixes));
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.DELETE_SUCCESS)
- .build().toChatComponentText());
- }
-
- /**
- * Handles the list - show subcommand.
- *
- * @param player The player, which executed the subcommand.
- * @param args The arguments passed to the main command.
- */
- private void handleListShowSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
- if (args.length != 3) {
- // missing arguments
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
- .build().toChatComponentText());
- return;
- }
-
- final Optional listOptional = CommunityRadarMod.getListManager().getRadarList(args[2]);
- if (!listOptional.isPresent()) {
- // list is not existing
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.SHOW_FAILED)
- .build().toChatComponentText());
- return;
- }
-
- final RadarList list = listOptional.get();
- if (list.getPlayerMap().isEmpty()) {
- // list is empty
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.SHOW_EMPTY)
- .build().toChatComponentText());
- return;
- }
-
- final StringBuilder players = new StringBuilder();
- list.getPlayerMap().values().forEach(value -> players.append(value.name()).append(", "));
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.SHOW_SUCCESS)
- .replace("{list}", list.getNamespace())
- .replaceWithColorCodes("{prefix}", listOptional.get().getPrefix())
- .replace("{players}", players.substring(0, players.length() - 2))
- .build().toChatComponentText());
- }
-
- /**
- * Handles the list - prefix subcommand.
- *
- * @param player The player, which executed the subcommand.
- * @param args The arguments passed to the main command.
- */
- private void handleListPrefixSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
- if (args.length != 4) {
- // missing arguments
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
- .build().toChatComponentText());
- return;
- }
-
- final RadarListManager listManager = CommunityRadarMod.getListManager();
- final Optional listOptional = listManager.getRadarList(args[2]);
- if (!listOptional.isPresent()) {
- // list is not existing
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.PREFIX_FAILED)
- .build().toChatComponentText());
- return;
- }
-
- final RadarList list = listOptional.get();
- final Set oldPrefixes = listManager.getExistingPrefixes();
- list.setPrefix(args[3]);
- list.saveList();
- list.getPlayerMap().keySet().forEach(uuid -> Utils.updatePlayerByUuid(uuid, oldPrefixes));
-
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.List.PREFIX_SUCCESS)
- .replaceWithColorCodes("{prefix}", args[3])
- .build().toChatComponentText());
- }
-
- /**
- * Handles the check subcommand.
- *
- * @param player The player, which executed the subcommand.
- * @param args The arguments passed to the main command.
- */
- private void handleCheckSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
- if (args.length != 2) {
- // missing arguments
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.MISSING_ARGS)
- .build().toChatComponentText());
- return;
- }
-
- if (args[1].equalsIgnoreCase("*")) {
- // check all argument
- handleCheckAllSubcommand(player);
- return;
- }
- handleCheckPlayerSubcommand(player, args);
- }
-
- /**
- * Handles the check - player subcommand.
- *
- * @param player The player, which executed the subcommand.
- * @param args The arguments passed to the main command.
- */
- private void handleCheckPlayerSubcommand(final @NotNull EntityPlayer player, final @NotNull String[] args) {
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.INPUT_PROCESSING)
- .build().toChatComponentText());
- Utils.getUUID(mod, args[1]).thenAccept(checkPlayerOptional -> {
- if (!checkPlayerOptional.isPresent()) {
- // player uuid could not be fetched
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.FAILED)
- .build().toChatComponentText());
- return;
- }
-
- final Optional entryOptional = CommunityRadarMod.getListManager().getRadarListEntry(checkPlayerOptional.get());
- if (!entryOptional.isPresent()) {
- // player uuid is on no list
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.FAILED)
- .build().toChatComponentText());
- return;
- }
-
- final RadarListEntry entry = entryOptional.get();
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.FOUND + "\n" + Messages.Check.CHECK_ENTRY)
- .replaceWithColorCodes("{prefix}", CommunityRadarMod.getListManager().getPrefix(entry.uuid()))
- .replace("{name}", entry.name())
- .replace("{cause}", entry.cause())
- .replace("{entryCreationDate}", Utils.formatDateTime(entry.entryCreationDate()))
- .replace("{entryUpdateDate}", Utils.formatDateTime(entry.entryUpdateDate()))
- .build().toChatComponentText());
- });
- }
-
- /**
- * Handles the check - all subcommand.
- *
- * @param player The player, which executed the subcommand.
- */
- private void handleCheckAllSubcommand(final @NotNull EntityPlayer player) {
- boolean anyPlayerFound = false;
- for (final NetworkPlayerInfo networkPlayer : Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap()) {
- if (networkPlayer.getGameProfile().getId() == null) {
- continue;
- }
-
- final Optional listEntryOptional = CommunityRadarMod.getListManager()
- .getRadarListEntry(networkPlayer.getGameProfile().getId());
- if (!listEntryOptional.isPresent()) {
- // player uuid is on no list
- continue;
- }
-
- if (!anyPlayerFound) {
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.EVERYONE)
- .build().toChatComponentText());
- anyPlayerFound = true;
- }
-
- final RadarListEntry entry = listEntryOptional.get();
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.CHECK_ENTRY)
- .replaceWithColorCodes("{prefix}", CommunityRadarMod.getListManager().getPrefix(entry.uuid()))
- .replace("{name}", entry.name())
- .replace("{cause}", entry.cause())
- .replace("{entryCreationDate}", Utils.formatDateTime(entry.entryCreationDate()))
- .replace("{entryUpdateDate}", Utils.formatDateTime(entry.entryUpdateDate()))
- .build().toChatComponentText());
- }
-
- if (!anyPlayerFound) {
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Check.NOT_FOUND)
- .build().toChatComponentText());
- }
- }
-
- /**
- * Handles the help subcommand.
- *
- * @param player The player, which executed the subcommand.
- */
- private void handleHelpSubcommand(final @NotNull EntityPlayer player) {
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.HELP)
- .replace("{code_version}", mod.getVersion())
- .excludePrefix()
- .build().toChatComponentText());
- }
-
- /**
- * Handles the lists subcommand.
- *
- * @param player The player, which executed the subcommand.
- */
- private void handleListsSubcommand(final @NotNull EntityPlayer player) {
- final StringBuilder listsText = new StringBuilder();
- for (final String namespace : CommunityRadarMod.getListManager().getNamespaces()) {
- CommunityRadarMod.getListManager().getRadarList(namespace)
- .ifPresent(radarList -> listsText.append("§e").append(namespace).append(" §7(§c")
- .append(radarList.getRadarListVisibility() == RadarListVisibility.PRIVATE ? Messages.Lists.PRIVATE : Messages.Lists.PUBLIC)
- .append("§7)").append(", "));
- }
-
- if (listsText.length() > 0) {
- // players on the list
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Lists.FOUND)
- .replace("{lists}", listsText.substring(0, listsText.length() - 2))
- .build().toChatComponentText());
- } else {
- // list is empty
- player.addChatComponentMessage(new RadarMessage.RadarMessageBuilder(Messages.Lists.EMPTY)
- .build().toChatComponentText());
- }
+ subcommand.run();
}
}
diff --git a/src/main/java/io/github/communityradargg/forgemod/command/Subcommand.java b/src/main/java/io/github/communityradargg/forgemod/command/Subcommand.java
new file mode 100644
index 0000000..87f46b6
--- /dev/null
+++ b/src/main/java/io/github/communityradargg/forgemod/command/Subcommand.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2024 - present CommunityRadarGG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.github.communityradargg.forgemod.command;
+
+/**
+ * Represents a subcommand of a command.
+ */
+public interface Subcommand {
+ /**
+ * Runs the logic defined in the subcommand.
+ */
+ void run();
+}
diff --git a/src/main/java/io/github/communityradargg/forgemod/event/ClientChatReceivedListener.java b/src/main/java/io/github/communityradargg/forgemod/event/ClientChatReceivedListener.java
index cbdb202..bc48f59 100644
--- a/src/main/java/io/github/communityradargg/forgemod/event/ClientChatReceivedListener.java
+++ b/src/main/java/io/github/communityradargg/forgemod/event/ClientChatReceivedListener.java
@@ -32,16 +32,16 @@ public class ClientChatReceivedListener {
/**
* A pattern matching private messages (in and out) and payments (in and out) as well as global and plot chat messages with the player name (nicked, bedrock and java) as only group.
*/
- private static final Pattern pattern = Pattern.compile("[A-Za-z\\-+]+\\s\\u2503\\s(~?!?\\w{1,16})");
- private final CommunityRadarMod mod;
+ private static final Pattern PATTERN = Pattern.compile("[A-Za-z\\-+]+\\s\\u2503\\s(~?!?\\w{1,16})");
+ private final CommunityRadarMod communityRadarMod;
/**
* Constructs the class {@link ClientChatReceivedListener}.
*
- * @param mod The mod main class instance.
+ * @param communityRadarMod The mod main class instance.
*/
- public ClientChatReceivedListener(final @NotNull CommunityRadarMod mod) {
- this.mod = mod;
+ public ClientChatReceivedListener(final @NotNull CommunityRadarMod communityRadarMod) {
+ this.communityRadarMod = communityRadarMod;
}
/**
@@ -50,13 +50,12 @@ public ClientChatReceivedListener(final @NotNull CommunityRadarMod mod) {
* @param event The event.
*/
@SubscribeEvent
- @SuppressWarnings("unused") // event listener
public void onClientChatReceived(final ClientChatReceivedEvent event) {
- if (!mod.isOnGrieferGames()) {
+ if (!communityRadarMod.isOnGrieferGames()) {
return;
}
- final Matcher matcher = pattern.matcher(event.message.getUnformattedText());
+ final Matcher matcher = PATTERN.matcher(event.message.getUnformattedText());
if (!matcher.find()) {
return;
}
@@ -67,9 +66,9 @@ public void onClientChatReceived(final ClientChatReceivedEvent event) {
return;
}
- Utils.getUUID(mod, playerName).thenAccept(uuid -> {
- if (uuid.isPresent() && CommunityRadarMod.getListManager().isInList(uuid.get())) {
- event.message = new ChatComponentText(CommunityRadarMod.getListManager().getPrefix(uuid.get()).replace("&", "§"))
+ Utils.getUUID(communityRadarMod, playerName).thenAccept(uuid -> {
+ if (uuid.isPresent() && communityRadarMod.getListManager().isInList(uuid.get())) {
+ event.message = new ChatComponentText(communityRadarMod.getListManager().getPrefix(uuid.get()).replace("&", "§"))
.appendText(" §r")
.appendText(event.message.getFormattedText());
}
diff --git a/src/main/java/io/github/communityradargg/forgemod/event/ClientConnectionDisconnectListener.java b/src/main/java/io/github/communityradargg/forgemod/event/ClientConnectionDisconnectListener.java
index 353e701..b89d2a3 100644
--- a/src/main/java/io/github/communityradargg/forgemod/event/ClientConnectionDisconnectListener.java
+++ b/src/main/java/io/github/communityradargg/forgemod/event/ClientConnectionDisconnectListener.java
@@ -45,7 +45,6 @@ public ClientConnectionDisconnectListener(final @NotNull CommunityRadarMod commu
* @param event The event.
*/
@SubscribeEvent
- @SuppressWarnings("unused") // called by forge
public void onFMLNetworkClientConnectedToServer(final FMLNetworkEvent.ClientConnectedToServerEvent event) {
if (event.isLocal) {
return;
@@ -70,7 +69,6 @@ public void onFMLNetworkClientConnectedToServer(final FMLNetworkEvent.ClientConn
* @param event The event.
*/
@SubscribeEvent
- @SuppressWarnings("unused") // called by forge
public void onFMLNetworkClientDisconnectionFromServer(final FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
communityRadarMod.setOnGrieferGames(false);
}
diff --git a/src/main/java/io/github/communityradargg/forgemod/event/KeyInputListener.java b/src/main/java/io/github/communityradargg/forgemod/event/KeyInputListener.java
index b3b3a24..bd3253c 100644
--- a/src/main/java/io/github/communityradargg/forgemod/event/KeyInputListener.java
+++ b/src/main/java/io/github/communityradargg/forgemod/event/KeyInputListener.java
@@ -43,7 +43,6 @@ public KeyInputListener(final @NotNull CommunityRadarMod communityRadarMod) {
* @param event The event.
*/
@SubscribeEvent
- @SuppressWarnings("unused") // called by mod loader on event
public void onKeyInput(final InputEvent.KeyInputEvent event) {
if (!communityRadarMod.isOnGrieferGames()) {
return;
@@ -54,6 +53,6 @@ public void onKeyInput(final InputEvent.KeyInputEvent event) {
return;
}
- Utils.updatePrefixes(CommunityRadarMod.getListManager().getExistingPrefixes());
+ Utils.updatePrefixes(communityRadarMod, communityRadarMod.getListManager().getExistingPrefixes());
}
}
diff --git a/src/main/java/io/github/communityradargg/forgemod/event/PlayerNameFormatListener.java b/src/main/java/io/github/communityradargg/forgemod/event/PlayerNameFormatListener.java
index 1e30044..1aab8c2 100644
--- a/src/main/java/io/github/communityradargg/forgemod/event/PlayerNameFormatListener.java
+++ b/src/main/java/io/github/communityradargg/forgemod/event/PlayerNameFormatListener.java
@@ -42,11 +42,10 @@ public PlayerNameFormatListener(final @NotNull CommunityRadarMod communityRadarM
* @param event The event.
*/
@SubscribeEvent
- @SuppressWarnings("unused") // called by forge event system
public void onPlayerNameFormat(final PlayerEvent.NameFormat event) {
if (!communityRadarMod.isOnGrieferGames()) {
return;
}
- Utils.updatePlayerNameTag(event.entityPlayer, CommunityRadarMod.getListManager().getExistingPrefixes());
+ Utils.updatePlayerNameTag(communityRadarMod, event.entityPlayer, communityRadarMod.getListManager().getExistingPrefixes());
}
}
diff --git a/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/RadarList.java b/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/RadarList.java
index 5607509..6685429 100644
--- a/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/RadarList.java
+++ b/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/RadarList.java
@@ -38,7 +38,8 @@
* A class representing a radar list.
*/
public class RadarList {
- private static final Logger logger = LogManager.getLogger(RadarList.class);
+ private static final Logger LOGGER = LogManager.getLogger(RadarList.class);
+ private transient final CommunityRadarMod communityRadarMod;
@SerializedName("VERSION")
@SuppressWarnings("unused") // needed in future
private final int version = 1;
@@ -55,12 +56,14 @@ public class RadarList {
/**
* Constructs a {@link RadarList}.
*
+ * @param communityRadarMod The mod main class instance.
* @param namespace The namespace for the list.
* @param prefix The prefix for the list.
* @param url The url for the list.
* @param visibility The visibility of the list.
*/
- public RadarList(final @NotNull String namespace, final @NotNull String prefix, final @NotNull String url, final @NotNull RadarListVisibility visibility) {
+ public RadarList(final @NotNull CommunityRadarMod communityRadarMod, final @NotNull String namespace, final @NotNull String prefix, final @NotNull String url, final @NotNull RadarListVisibility visibility) {
+ this.communityRadarMod = communityRadarMod;
this.namespace = namespace;
this.prefix = prefix;
this.visibility = visibility;
@@ -178,7 +181,7 @@ private void loadRadarListEntry(final @NotNull RadarListEntry radarListEntry) {
*/
public void saveList() {
if (visibility == RadarListVisibility.PRIVATE) {
- CommunityRadarMod.getListManager().saveRadarList(this);
+ communityRadarMod.getListManager().saveRadarList(this);
}
}
@@ -191,7 +194,7 @@ private void loadPublicList() {
.fromJson(reader, new TypeToken>() {}.getType());
players.forEach(this::loadRadarListEntry);
} catch (final IOException | JsonIOException | JsonSyntaxException e) {
- logger.error("Could not load public list", e);
+ LOGGER.error("Could not load public list", e);
}
}
diff --git a/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/RadarListManager.java b/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/RadarListManager.java
index d532f9d..233b216 100644
--- a/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/RadarListManager.java
+++ b/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/RadarListManager.java
@@ -20,6 +20,7 @@
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
+import io.github.communityradargg.forgemod.CommunityRadarMod;
import io.github.communityradargg.forgemod.radarlistmanager.adapters.GsonLocalDateTimeAdapter;
import io.github.communityradargg.forgemod.radarlistmanager.adapters.GsonRadarListPlayerMapAdapter;
import org.apache.logging.log4j.LogManager;
@@ -49,22 +50,25 @@
* A class containing the methods to manage lists.
*/
public class RadarListManager {
- private static final Logger logger = LogManager.getLogger(RadarListManager.class);
- private static final Gson gson = new GsonBuilder()
+ private static final Logger LOGGER = LogManager.getLogger(RadarListManager.class);
+ private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.registerTypeAdapter(LocalDateTime.class, new GsonLocalDateTimeAdapter())
.registerTypeAdapter(Map.class, new GsonRadarListPlayerMapAdapter())
.create();
+ private final CommunityRadarMod communityRadarMod;
private final List lists;
private final String directoryPath;
/**
* Constructs a {@link RadarListManager}
*
+ * @param communityRadarMod The mod main class instance.
* @param directoryPath The directory path of the list the manager manages.
*/
- public RadarListManager(final @NotNull String directoryPath) {
+ public RadarListManager(final @NotNull CommunityRadarMod communityRadarMod, final @NotNull String directoryPath) {
this.lists = new ArrayList<>();
+ this.communityRadarMod = communityRadarMod;
this.directoryPath = directoryPath;
}
@@ -169,9 +173,9 @@ public void saveRadarList(final @NotNull RadarList list) {
}
try (final FileWriter writer = new FileWriter(directoryPath + list.getNamespace() + ".json")) {
- writer.write(gson.toJson(list));
+ writer.write(GSON.toJson(list));
} catch (final IOException e) {
- logger.error("Could not save list", e);
+ LOGGER.error("Could not save list", e);
}
}
@@ -189,7 +193,7 @@ public boolean registerPrivateList(final @NotNull String namespace, final @NotNu
return false;
}
- lists.add(new RadarList(namespace, prefix, directoryPath + namespace + ".json", RadarListVisibility.PRIVATE));
+ lists.add(new RadarList(communityRadarMod, namespace, prefix, directoryPath + namespace + ".json", RadarListVisibility.PRIVATE));
final Optional listOptional = getRadarList(namespace);
if (!listOptional.isPresent()) {
@@ -215,7 +219,7 @@ public boolean registerPublicList(final @NotNull String namespace, final @NotNul
return false;
}
- lists.add(new RadarList(namespace, prefix, url, RadarListVisibility.PUBLIC));
+ lists.add(new RadarList(communityRadarMod, namespace, prefix, url, RadarListVisibility.PUBLIC));
return true;
}
@@ -273,13 +277,13 @@ public void loadPrivateLists() {
*/
private @NotNull Optional loadRadarListFromFile(final @NotNull String filePath) {
try (final FileReader reader = new FileReader(filePath)) {
- final RadarList list = gson.fromJson(reader, new TypeToken() {}.getType());
+ final RadarList list = GSON.fromJson(reader, new TypeToken() {}.getType());
list.setUrl(filePath);
if (list.validateList()) {
return Optional.of(list);
}
} catch (final IOException | IllegalStateException | JsonIOException | JsonSyntaxException e) {
- logger.error("Could not load list from file", e);
+ LOGGER.error("Could not load list from file", e);
}
return Optional.empty();
}
@@ -298,7 +302,7 @@ public void loadPrivateLists() {
.filter(string -> string.endsWith(".json"))
.collect(Collectors.toSet());
} catch (final IOException e) {
- logger.error("Could not get json urls", e);
+ LOGGER.error("Could not get json urls", e);
}
return new HashSet<>();
}
@@ -309,7 +313,7 @@ public void loadPrivateLists() {
* @return Returns the pre-configured {@link Gson} instance.
*/
public static @NotNull Gson getGson() {
- return gson;
+ return GSON;
}
/**
diff --git a/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/adapters/GsonLocalDateTimeAdapter.java b/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/adapters/GsonLocalDateTimeAdapter.java
index 9b11ea6..3e671ad 100644
--- a/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/adapters/GsonLocalDateTimeAdapter.java
+++ b/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/adapters/GsonLocalDateTimeAdapter.java
@@ -31,13 +31,11 @@
* A class with an adapter for serialization and deserialization of the class {@link LocalDateTime} for the GSON library.
*/
public class GsonLocalDateTimeAdapter implements JsonSerializer, JsonDeserializer {
- /** {@inheritDoc} */
@Override
public LocalDateTime deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
return LocalDateTime.parse(json.getAsString(), DateTimeFormatter.ISO_DATE_TIME);
}
- /** {@inheritDoc} */
@Override
public JsonElement serialize(final LocalDateTime localDateTime, final Type typeOfSrc, final JsonSerializationContext context) {
return new JsonPrimitive(localDateTime.format(DateTimeFormatter.ISO_DATE_TIME));
diff --git a/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/adapters/GsonRadarListPlayerMapAdapter.java b/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/adapters/GsonRadarListPlayerMapAdapter.java
index 98d91dc..877d1f4 100644
--- a/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/adapters/GsonRadarListPlayerMapAdapter.java
+++ b/src/main/java/io/github/communityradargg/forgemod/radarlistmanager/adapters/GsonRadarListPlayerMapAdapter.java
@@ -33,7 +33,6 @@
* A class with an adapter for serialization and deserialization of following structure {@code Map} for the GSON library.
*/
public class GsonRadarListPlayerMapAdapter implements JsonSerializer