Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI (1.21) #121

Open
wants to merge 5 commits into
base: 1.21.1
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = "${project.name}-mc${project.minecraft_version}"
version = project.mod_version
Expand Down Expand Up @@ -41,6 +41,7 @@ dependencies {

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "me.lucko:fabric-permissions-api:${project.lucko_permissions_version}"
modImplementation "eu.pb4:sgui:${project.sgui_version}"
BlueZeeKing marked this conversation as resolved.
Show resolved Hide resolved
modImplementation "eu.pb4:placeholder-api:${project.papi_version}"
compileOnly "us.dynmap:DynmapCoreAPI:${project.dynmap_api_version}"
compileOnly "de.bluecolored.bluemap:BlueMapAPI:${project.bluemap_api_version}"
Expand All @@ -58,7 +59,7 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 21
}

java {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ papi_version=2.4.0-pre.2+1.21
styled_chat_version=OQeEfRIi
bluemap_api_version=2.7.1
squaremap_api_version=1.2.3
sgui_version=1.6.1+1.21.1
2 changes: 1 addition & 1 deletion src/main/java/io/icker/factions/FactionsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class FactionsMod implements ModInitializer {

@Override
public void onInitialize() {
LOGGER.info("Initialized Factions Mod for Minecraft v1.20.1");
LOGGER.info("Initialized Factions Mod");

WorldUtils.register();

Expand Down
20 changes: 19 additions & 1 deletion src/main/java/io/icker/factions/command/AdminCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.icker.factions.api.persistents.Claim;
import io.icker.factions.api.persistents.Faction;
import io.icker.factions.api.persistents.User;
import io.icker.factions.ui.AdminGui;
import io.icker.factions.util.Command;
import io.icker.factions.util.Message;
import net.minecraft.server.command.CommandManager;
Expand All @@ -20,6 +21,15 @@
import net.minecraft.util.Formatting;

public class AdminCommand implements Command {
private int gui(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayerOrThrow();

// Show UI
new AdminGui(player);

return 1;
}

private int bypass(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer();

Expand Down Expand Up @@ -80,7 +90,12 @@ private int spoof(CommandContext<ServerCommandSource> context) throws CommandSyn
if ((profile = source.getServer().getUserCache().findByName(name)).isPresent()) {
target = User.get(profile.get().getId());
} else {
target = User.get(UUID.fromString(name));
try {
target = User.get(UUID.fromString(name));
} catch (Exception e) {
new Message("No such player %s", name).format(Formatting.RED).send(player, false);
return 0;
}
}

user.setSpoof(target);
Expand Down Expand Up @@ -123,6 +138,9 @@ private int audit(CommandContext<ServerCommandSource> context) {

public LiteralCommandNode<ServerCommandSource> getNode() {
return CommandManager.literal("admin")
.requires(Requires.hasPerms("factions.admin.gui",
FactionsMod.CONFIG.REQUIRED_BYPASS_LEVEL))
xllifi marked this conversation as resolved.
Show resolved Hide resolved
.executes(this::gui)
.then(CommandManager.literal("bypass")
.requires(Requires.hasPerms("factions.admin.bypass",
FactionsMod.CONFIG.REQUIRED_BYPASS_LEVEL))
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/io/icker/factions/command/HomeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ private int go(CommandContext<ServerCommandSource> context) throws CommandSyntax
return 0;

Faction faction = Command.getUser(player).getFaction();

if (faction == null)
return 0;

return execGo(player, faction);
}

public int execGo(ServerPlayerEntity player, Faction faction) {
Home home = faction.getHome();

if (home == null) {
Expand All @@ -51,15 +59,7 @@ private int go(CommandContext<ServerCommandSource> context) throws CommandSyntax

if (((DamageTrackerAccessor) player.getDamageTracker()).getAgeOnLastDamage() == 0
|| player.age - ((DamageTrackerAccessor) player.getDamageTracker())
.getAgeOnLastDamage() > FactionsMod.CONFIG.HOME.DAMAGE_COOLDOWN) { // damageRecord
// ==
// null
// ||
// player.age
// -
// damageRecord.getEntityAge()
// >
// FactionsMod.CONFIG.HOME.DAMAGE_COOLDOWN
.getAgeOnLastDamage() > FactionsMod.CONFIG.HOME.DAMAGE_COOLDOWN) {
player.teleport(world, home.x, home.y, home.z, home.yaw, home.pitch);
new Message("Warped to faction home").send(player, false);
} else {
Expand Down
67 changes: 4 additions & 63 deletions src/main/java/io/icker/factions/command/InfoCommand.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package io.icker.factions.command;

import java.util.List;
import java.util.stream.Collectors;
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.icker.factions.FactionsMod;
import io.icker.factions.api.persistents.Faction;
import io.icker.factions.api.persistents.User;
import io.icker.factions.ui.InfoGui;
import io.icker.factions.util.Command;
import io.icker.factions.util.Message;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Formatting;
import net.minecraft.util.UserCache;
import net.minecraft.util.Util;

public class InfoCommand implements Command {
private int self(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
Expand All @@ -30,7 +24,8 @@ private int self(CommandContext<ServerCommandSource> context) throws CommandSynt
return 0;
}

return info(player, user.getFaction());
new InfoGui(player, user.getFaction(), null);
return 1;
}

private int any(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
Expand All @@ -45,64 +40,10 @@ private int any(CommandContext<ServerCommandSource> context) throws CommandSynta
return 0;
}

return info(player, faction);
}

public static int info(ServerPlayerEntity player, Faction faction) {
List<User> users = faction.getUsers();

UserCache cache = player.getServer().getUserCache();
String owner = Formatting.WHITE + users.stream().filter(u -> u.rank == User.Rank.OWNER)
.map(user -> cache.getByUuid(user.getID())
.orElse(new GameProfile(Util.NIL_UUID, "{Uncached Player}")).getName())
.collect(Collectors.joining(", "));

String usersList = users.stream()
.map(user -> cache.getByUuid(user.getID())
.orElse(new GameProfile(Util.NIL_UUID, "{Uncached Player}")).getName())
.collect(Collectors.joining(", "));

String mutualAllies = faction.getMutualAllies().stream().map(rel -> Faction.get(rel.target))
.map(fac -> fac.getColor() + fac.getName())
.collect(Collectors.joining(Formatting.GRAY + ", "));

String enemiesWith = Formatting.GRAY + faction.getEnemiesWith().stream()
.map(rel -> Faction.get(rel.target)).map(fac -> fac.getColor() + fac.getName())
.collect(Collectors.joining(Formatting.GRAY + ", "));

int requiredPower = faction.getClaims().size() * FactionsMod.CONFIG.POWER.CLAIM_WEIGHT;
int maxPower =
users.size() * FactionsMod.CONFIG.POWER.MEMBER + FactionsMod.CONFIG.POWER.BASE;

// generate the ---
int numDashes = 32 - faction.getName().length();
String dashes =
new StringBuilder("--------------------------------").substring(0, numDashes / 2);

new Message(Formatting.BLACK + dashes + "[ " + faction.getColor() + faction.getName()
+ Formatting.BLACK + " ]" + dashes).send(player, false);
new Message(Formatting.GOLD + "Description: ")
.add(Formatting.WHITE + faction.getDescription()).send(player, false);
new Message(Formatting.GOLD + "Owner: ").add(Formatting.WHITE + owner).send(player, false);
new Message(Formatting.GOLD + "Members (" + Formatting.WHITE.toString() + users.size()
+ Formatting.GOLD.toString() + "): ").add(usersList).send(player, false);
new Message(Formatting.GOLD + "Power: ").add(Formatting.GREEN.toString()
+ faction.getPower() + slash() + requiredPower + slash() + maxPower)
.hover("Current / Required / Max").send(player, false);
new Message(Formatting.GREEN + "Allies (" + Formatting.WHITE
+ faction.getMutualAllies().size() + Formatting.GREEN + "): ").add(mutualAllies)
.send(player, false);
new Message(Formatting.RED + "Enemies (" + Formatting.WHITE
+ faction.getEnemiesWith().size() + Formatting.RED + "): ").add(enemiesWith)
.send(player, false);

new InfoGui(player, faction, null);
return 1;
}

private static String slash() {
return Formatting.GRAY + " / " + Formatting.GREEN;
}

public LiteralCommandNode<ServerCommandSource> getNode() {
return CommandManager.literal("info").requires(Requires.hasPerms("factions.info", 0))
.executes(this::self)
Expand Down
22 changes: 7 additions & 15 deletions src/main/java/io/icker/factions/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,32 @@
package io.icker.factions.command;

import java.util.Collection;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.icker.factions.api.persistents.Faction;
import io.icker.factions.api.persistents.User;
import io.icker.factions.ui.ListGui;
import io.icker.factions.util.Command;
import io.icker.factions.util.Message;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Formatting;

import java.util.Collection;

public class ListCommand implements Command {
private int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource source = context.getSource();
ServerPlayerEntity player = source.getPlayer();

User user = User.get(player.getUuid());

Collection<Faction> factions = Faction.all();
int size = factions.size();

new Message("There %s ", size == 1 ? "is" : "are")
.add(new Message(String.valueOf(size)).format(Formatting.YELLOW))
.add(" faction%s", size == 1 ? "" : "s").send(player, false);

if (size == 0)
return 1;

Message list = new Message("");
for (Faction faction : factions) {
String name = faction.getName();
list.add(new Message(name).click("/factions info " + name).format(faction.getColor()))
.add(", ");
}

list.send(player, false);
new ListGui(player, user, null);
return 1;
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/io/icker/factions/command/MemberCommand.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package io.icker.factions.command;

import java.util.List;
import java.util.stream.Collectors;
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.icker.factions.api.persistents.Faction;
import io.icker.factions.api.persistents.User;
import io.icker.factions.ui.MemberGui;
import io.icker.factions.util.Command;
import io.icker.factions.util.Message;
import net.minecraft.server.command.CommandManager;
Expand All @@ -18,6 +17,9 @@
import net.minecraft.util.UserCache;
import net.minecraft.util.Util;

import java.util.List;
import java.util.stream.Collectors;

public class MemberCommand implements Command {
private int self(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource source = context.getSource();
Expand All @@ -29,6 +31,7 @@ private int self(CommandContext<ServerCommandSource> context) throws CommandSynt
return 0;
}

new MemberGui(player, user.getFaction(), null);
return members(player, user.getFaction());
}

Expand All @@ -44,6 +47,7 @@ private int any(CommandContext<ServerCommandSource> context) throws CommandSynta
return 0;
}

new MemberGui(player, faction, null);
return members(player, faction);
}

Expand Down
17 changes: 15 additions & 2 deletions src/main/java/io/icker/factions/command/ModifyCommand.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.icker.factions.command;

import java.util.Locale;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.icker.factions.FactionsMod;
import io.icker.factions.api.persistents.Faction;
import io.icker.factions.ui.ModifyGui;
import io.icker.factions.util.Command;
import io.icker.factions.util.Message;
import net.minecraft.command.argument.ColorArgumentType;
Expand All @@ -16,7 +16,17 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Formatting;

import java.util.Locale;

public class ModifyCommand implements Command {
private int gui(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer();
Faction faction = Command.getUser(player).getFaction();

new ModifyGui(player, faction, null);
return 1;
}

private int name(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
String name = StringArgumentType.getString(context, "name");

Expand Down Expand Up @@ -92,7 +102,7 @@ private int color(CommandContext<ServerCommandSource> context) throws CommandSyn
faction.setColor(color);
new Message(
"Successfully updated faction color to " + Formatting.BOLD + color + color.name())
.prependFaction(faction).send(player, false);
.prependFaction(faction).send(player, false);

return 1;
}
Expand All @@ -116,6 +126,9 @@ private int open(CommandContext<ServerCommandSource> context) throws CommandSynt

public LiteralCommandNode<ServerCommandSource> getNode() {
return CommandManager.literal("modify").requires(Requires.isLeader())
.requires(Requires.multiple(Requires.hasPerms("factions.modify.gui", 0),
Requires.isOwner()))
.executes(this::gui)
.then(CommandManager.literal("name")
.requires(Requires.multiple(Requires.hasPerms("factions.modify.name", 0),
Requires.isOwner()))
Expand Down
Loading