Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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);
}

/**
Expand All @@ -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'!");
}
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright 2024 - present CommunityRadarGG <https://community-radar.de/>
*
* 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<RadarListEntry> 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<RadarListEntry> 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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 - present CommunityRadarGG <https://community-radar.de/>
*
* 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());
}
}
Loading