mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-11-26 23:03:09 +00:00
Teams GUI (#384)
This commit is contained in:
1 parent
ea76587d9f
commit
1a4615bc19
33 files changed
+2500
-21
No files matched your search
@@ -3,6 +3,10 @@ package com.gtnewhorizon.gtnhlib;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.CustomGuiTextures;
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.CustomWidgetTheme;
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.TeamGuiFactory;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
@@ -27,6 +31,7 @@ public class GTNHLib {
|
||||
|
||||
public static boolean isMFRLoaded;
|
||||
public static boolean isCoFHCoreLoaded;
|
||||
public static boolean isMui2Loaded;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void construct(FMLConstructionEvent event) {
|
||||
@@ -37,6 +42,14 @@ public class GTNHLib {
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
isMFRLoaded = Loader.isModLoaded("MineFactoryReloaded");
|
||||
isCoFHCoreLoaded = Loader.isModLoaded("CoFHCore");
|
||||
isMui2Loaded = Loader.isModLoaded("modularui2");
|
||||
|
||||
LOG.info("GTNHLib MUI2 integration enabled (for teams UI): {}", isMui2Loaded);
|
||||
if (isMui2Loaded) {
|
||||
CustomGuiTextures.init();
|
||||
CustomWidgetTheme.init();
|
||||
TeamGuiFactory.init();
|
||||
}
|
||||
|
||||
proxy.preInit(event);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
|
||||
import com.cleanroommc.modularui.widgets.textfield.BaseTextFieldWidget;
|
||||
|
||||
public class ClientTextField extends BaseTextFieldWidget<ClientTextField> {
|
||||
|
||||
public ClientTextField() {
|
||||
super();
|
||||
|
||||
widgetTheme(CustomWidgetTheme.BACKGROUND_TEXT_FIELD);
|
||||
setText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFocus(ModularGuiContext context) {
|
||||
super.onFocus(context);
|
||||
Point main = this.handler.getMainCursor();
|
||||
if (main.x == 0) {
|
||||
this.handler.setCursor(main.y, getText().length(), true, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHover() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getText() {
|
||||
if (this.handler.getText().isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
if (this.handler.getText().size() > 1) {
|
||||
throw new IllegalStateException("This widget only supports one line!");
|
||||
}
|
||||
return this.handler.getText().get(0);
|
||||
}
|
||||
|
||||
public void setText(@NotNull String text) {
|
||||
if (this.handler.getText().isEmpty()) {
|
||||
this.handler.getText().add(text);
|
||||
} else {
|
||||
this.handler.getText().set(0, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import com.cleanroommc.modularui.api.drawable.IKey;
|
||||
import com.cleanroommc.modularui.widgets.ButtonWidget;
|
||||
import com.cleanroommc.modularui.widgets.Dialog;
|
||||
import com.cleanroommc.modularui.widgets.TextWidget;
|
||||
import com.cleanroommc.modularui.widgets.layout.Flow;
|
||||
|
||||
public class ConfirmationDialog extends Dialog<Boolean> {
|
||||
|
||||
private String message = "";
|
||||
private Runnable runnable = () -> {};
|
||||
|
||||
public ConfirmationDialog(String name) {
|
||||
super(name, _unused -> {});
|
||||
this.size(140, 70).child(
|
||||
Flow.column()
|
||||
.child(
|
||||
new TextWidget<>(IKey.dynamic(() -> this.message)).top(10).sizeRel(0.9f, 0.5f)
|
||||
.horizontalCenter())
|
||||
.child(
|
||||
Flow.row().bottom(5).size(110, 16).horizontalCenter()
|
||||
.child(
|
||||
new ButtonWidget<>().size(45, 16).left(5)
|
||||
.overlay(IKey.lang("gtnhlib.gui.teams.confirm"))
|
||||
.onMouseTapped(mouse -> {
|
||||
this.closeWith(true);
|
||||
return true;
|
||||
}))
|
||||
.child(
|
||||
new ButtonWidget<>().size(45, 16).right(5)
|
||||
.overlay(IKey.lang("gtnhlib.gui.teams.cancel"))
|
||||
.onMouseTapped(mouse -> {
|
||||
this.closeWith(false);
|
||||
return true;
|
||||
}))));
|
||||
|
||||
this.setDisablePanelsBelow(true).setDraggable(false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeWith(Boolean result) {
|
||||
if (result) {
|
||||
this.runnable.run();
|
||||
}
|
||||
closeIfOpen();
|
||||
}
|
||||
|
||||
public void setParams(String message, Runnable runnable) {
|
||||
this.message = message;
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import com.cleanroommc.modularui.ModularUI;
|
||||
import com.cleanroommc.modularui.drawable.UITexture;
|
||||
import com.gtnewhorizon.gtnhlib.GTNHLib;
|
||||
|
||||
public class CustomGuiTextures {
|
||||
|
||||
public static void init() {}
|
||||
|
||||
public static final UITexture TEXT_FIELD_BACKGROUND = UITexture.builder()
|
||||
.location(GTNHLib.MODID, "gui/background/text_field_background").imageSize(61, 12).adaptable(1)
|
||||
.canApplyTheme().name("text_field_background").build();
|
||||
|
||||
public static final UITexture LIST_BACKGROUND = UITexture.builder()
|
||||
.location(ModularUI.ID, "gui/background/list_background").canApplyTheme().imageSize(153, 15).adaptable(4)
|
||||
.name("list_background").build();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import com.cleanroommc.modularui.api.IThemeApi;
|
||||
import com.cleanroommc.modularui.theme.TextFieldTheme;
|
||||
import com.cleanroommc.modularui.theme.WidgetThemeKey;
|
||||
import com.cleanroommc.modularui.utils.Color;
|
||||
|
||||
public class CustomWidgetTheme {
|
||||
|
||||
public static void init() {}
|
||||
|
||||
private static final IThemeApi themeApi = IThemeApi.get();
|
||||
|
||||
public static final WidgetThemeKey<TextFieldTheme> BACKGROUND_TEXT_FIELD = themeApi
|
||||
.widgetThemeKeyBuilder("text_field_theme", TextFieldTheme.class)
|
||||
.defaultTheme(
|
||||
new TextFieldTheme(
|
||||
0,
|
||||
0,
|
||||
CustomGuiTextures.TEXT_FIELD_BACKGROUND,
|
||||
Color.WHITE.main,
|
||||
0xFF404040,
|
||||
false,
|
||||
0,
|
||||
0,
|
||||
0xFF404040))
|
||||
.defaultHoverTheme(null).register();
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizon.gtnhlib.teams.TeamRole;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
|
||||
@Desugar
|
||||
/**
|
||||
* spotless:off
|
||||
* Represents a display item on the ListDisplay flag: Representation changes depending on the ScreenType this
|
||||
* displayItem was sent, as follows:
|
||||
* VIEW_CONSUMPTION_REQUESTS: ignored.
|
||||
* PLAYER_LIST: Set to true if player cannot be demoted or kicked (last owner of team).
|
||||
* TEAM_LIST: Set to true if team can be disbanded (size > 1).
|
||||
* TEAMS_INVITING_PLAYERS: Set to true if the player is unable to accept the invite (eg. last
|
||||
* owner of their team with more than one member.
|
||||
* INVITE_PLAYERS, REQUEST_MERGE: Set to true if an invite or merge requests to this player/team already exists.
|
||||
*
|
||||
* uuid: represents team or player id depending on what screen this displayitem was sent.
|
||||
* spotless:on
|
||||
*/
|
||||
public record DisplayItem(@Nonnull DisplayItemType type, String text, @Nullable TeamRole role, @Nonnull UUID uuid,
|
||||
boolean flag) {
|
||||
|
||||
/**
|
||||
* Represents team or player id depending on what screen this displayitem was sent.
|
||||
*/
|
||||
@Override
|
||||
public UUID uuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a display item on the ListDisplay flag: Representation changes depending on the ScreenType this
|
||||
* displayItem was sent, as follows:
|
||||
* <ul>
|
||||
* <li><b>VIEW_CONSUMPTION_REQUESTS</b>: ignored.</li>
|
||||
* <li><b>PLAYER_LIST</b>: Set to true if player cannot be demoted or kicked (last owner of team).</li>
|
||||
* <li><b>TEAM_LIST</b>: Set to true if team can be disbanded (size > 1).</li>
|
||||
* <li><b>TEAMS_INVITING_PLAYERS</b>: Set to true if the player is unable to accept the invite (eg. last owner of
|
||||
* their team with more than one member.</li>
|
||||
* <li><b>INVITE_PLAYERS, REQUEST_MERGE</b>: Set to true if an invite or merge requests to this player/team already
|
||||
* exists.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Override
|
||||
public boolean flag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public static DisplayItem copyOf(DisplayItem other) {
|
||||
return new DisplayItem(other.type, other.text, other.role, other.uuid, other.flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof DisplayItem that)) return false;
|
||||
return flag == that.flag && Objects.equals(uuid, that.uuid)
|
||||
&& Objects.equals(text, that.text)
|
||||
&& role == that.role
|
||||
&& type == that.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(type, text, role, uuid, flag);
|
||||
}
|
||||
|
||||
public void serializeInto(PacketBuffer buffer) {
|
||||
buffer.writeShort(type.ordinal());
|
||||
ByteBufUtils.writeUTF8String(buffer, text);
|
||||
buffer.writeBoolean(role == null);
|
||||
if (role != null) buffer.writeShort(role.ordinal());
|
||||
buffer.writeLong(uuid.getMostSignificantBits());
|
||||
buffer.writeLong(uuid.getLeastSignificantBits());
|
||||
buffer.writeBoolean(flag);
|
||||
}
|
||||
|
||||
public static DisplayItem deserializeFrom(PacketBuffer buffer) {
|
||||
return new DisplayItem(
|
||||
DisplayItemType.values()[buffer.readShort()],
|
||||
ByteBufUtils.readUTF8String(buffer),
|
||||
buffer.readBoolean() ? null : TeamRole.values()[buffer.readShort()],
|
||||
new UUID(buffer.readLong(), buffer.readLong()),
|
||||
buffer.readBoolean());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
public enum DisplayItemType {
|
||||
PLAYER,
|
||||
TEAM
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import com.cleanroommc.modularui.screen.ModularPanel;
|
||||
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
|
||||
|
||||
public class FreezablePanel extends ModularPanel {
|
||||
|
||||
// stop updates when shiftHeld
|
||||
public boolean shiftHeld = false;
|
||||
|
||||
private final TeamGui gui;
|
||||
private final TeamGuiData data;
|
||||
private final PanelSyncManager syncManager;
|
||||
private int ticksSinceRefresh = 0;
|
||||
|
||||
public FreezablePanel(@NotNull String name, TeamGui gui, TeamGuiData data, PanelSyncManager syncManager) {
|
||||
super(name);
|
||||
this.size(176, 166);
|
||||
|
||||
this.gui = gui;
|
||||
this.data = data;
|
||||
this.syncManager = syncManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyPressed(char typedChar, int keyCode) {
|
||||
if (keyCode == Keyboard.KEY_LSHIFT || keyCode == Keyboard.KEY_RSHIFT) {
|
||||
shiftHeld = true;
|
||||
}
|
||||
|
||||
if (keyCode == Keyboard.KEY_BACK) {
|
||||
gui.restoreView(this.data, this.syncManager);
|
||||
}
|
||||
|
||||
return super.onKeyPressed(typedChar, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyRelease(char typedChar, int keyCode) {
|
||||
if (keyCode == Keyboard.KEY_LSHIFT || keyCode == Keyboard.KEY_RSHIFT) {
|
||||
shiftHeld = false;
|
||||
}
|
||||
|
||||
TeamGui.forceRefresh = true;
|
||||
return super.onKeyRelease(typedChar, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
super.onUpdate();
|
||||
|
||||
if (TeamGui.forceRefresh || ticksSinceRefresh > 20) {
|
||||
TeamGui.updateDisplayList(TeamGui.forceRefresh || !shiftHeld);
|
||||
TeamGui.forceRefresh = false;
|
||||
ticksSinceRefresh = 0;
|
||||
return;
|
||||
}
|
||||
ticksSinceRefresh++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class GuiUtils {
|
||||
|
||||
public static String clampString(String str, int length) {
|
||||
return str.length() <= length ? str : (str.substring(0, length) + "...");
|
||||
}
|
||||
|
||||
public static boolean isOpServerSideOnly(EntityPlayer player) {
|
||||
return player.canCommandSenderUseCommand(2, "gtnhteam_admin");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
|
||||
@Desugar
|
||||
public record GuiView(ScreenType type, UUID currentTeam) {
|
||||
|
||||
public GuiView(ScreenType type, @Nonnull UUID currentTeam) {
|
||||
this.type = type;
|
||||
this.currentTeam = currentTeam;
|
||||
}
|
||||
|
||||
public static GuiView getDefaultView(@Nonnull UUID team) {
|
||||
return new GuiView(ScreenType.PLAYER_LIST, team);
|
||||
}
|
||||
|
||||
public void writeToBuf(PacketBuffer buffer) {
|
||||
buffer.writeInt(type.ordinal());
|
||||
buffer.writeLong(currentTeam.getMostSignificantBits());
|
||||
buffer.writeLong(currentTeam.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
public static GuiView readFromBuf(PacketBuffer buffer) {
|
||||
return new GuiView(ScreenType.values()[buffer.readInt()], new UUID(buffer.readLong(), buffer.readLong()));
|
||||
}
|
||||
|
||||
public static GuiView deepCopyOf(GuiView value) {
|
||||
return new GuiView(value.type, value.currentTeam);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof GuiView guiView)) return false;
|
||||
return type == guiView.type && Objects.equals(currentTeam, guiView.currentTeam);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
public enum ScreenType {
|
||||
|
||||
// I thought really hard about this naming scheme guys
|
||||
INVALID("gtnhlib.gui.teams.select_screen.invalid"),
|
||||
TEAM_LIST("gtnhlib.gui.teams.select_screen.team_list"),
|
||||
PLAYER_LIST("gtnhlib.gui.teams.select_screen.player_list"),
|
||||
INVITE_PLAYERS("gtnhlib.gui.teams.select_screen.invite"),
|
||||
TEAMS_INVITING_PLAYER("gtnhlib.gui.teams.select_screen.get_invites"),
|
||||
REQUEST_CONSUME("gtnhlib.gui.teams.select_screen.team_merge"),
|
||||
VIEW_CONSUMPTION_REQUESTS("gtnhlib.gui.teams.select_screen.get_team_merge");
|
||||
|
||||
public final String langKey;
|
||||
|
||||
public static final ScreenType[] types = values();
|
||||
|
||||
ScreenType(String langKey) {
|
||||
this.langKey = langKey;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.cleanroommc.modularui.widgets.ToggleButton;
|
||||
|
||||
public class SelectButton extends ToggleButton {
|
||||
|
||||
private static final int UNSELECTED_STATE = 0;
|
||||
|
||||
@Override
|
||||
public @NotNull Result onMousePressed(int mouseButton) {
|
||||
if (getState() == UNSELECTED_STATE) {
|
||||
return super.onMousePressed(mouseButton);
|
||||
}
|
||||
return Result.IGNORE;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,19 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.cleanroommc.modularui.factory.GuiData;
|
||||
|
||||
public class TeamGuiData extends GuiData {
|
||||
|
||||
public GuiView currentView;
|
||||
public boolean forceRefreshWithNextUpdate;
|
||||
|
||||
public TeamGuiData(@NotNull EntityPlayer player, GuiView currentView) {
|
||||
super(player);
|
||||
this.currentView = currentView;
|
||||
this.forceRefreshWithNextUpdate = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.cleanroommc.modularui.api.IGuiHolder;
|
||||
import com.cleanroommc.modularui.factory.AbstractUIFactory;
|
||||
import com.cleanroommc.modularui.factory.GuiManager;
|
||||
|
||||
public class TeamGuiFactory extends AbstractUIFactory<TeamGuiData> {
|
||||
|
||||
public static final TeamGuiFactory INSTANCE = new TeamGuiFactory("gtnhlib:team_panel_gui", TeamGui::new);
|
||||
|
||||
private final Supplier<IGuiHolder<TeamGuiData>> guiHolderSupplier;
|
||||
private IGuiHolder<TeamGuiData> guiHolder;
|
||||
|
||||
@Override
|
||||
public @NotNull IGuiHolder<TeamGuiData> getGuiHolder(TeamGuiData data) {
|
||||
if (this.guiHolder == null) {
|
||||
this.guiHolder = this.guiHolderSupplier.get();
|
||||
Objects.requireNonNull(this.guiHolder, "IGuiHolder must not be null");
|
||||
}
|
||||
return this.guiHolder;
|
||||
}
|
||||
|
||||
public TeamGuiFactory(String name, IGuiHolder<TeamGuiData> guiHolder) {
|
||||
this(name, () -> guiHolder);
|
||||
}
|
||||
|
||||
public TeamGuiFactory(String name, Supplier<IGuiHolder<TeamGuiData>> guiHolderSupplier) {
|
||||
super(name);
|
||||
this.guiHolderSupplier = guiHolderSupplier;
|
||||
GuiManager.registerFactory(this);
|
||||
}
|
||||
|
||||
public static void init() {}
|
||||
|
||||
public void open(EntityPlayerMP player, @Nonnull UUID playerTeam) {
|
||||
GuiManager.open(this, new TeamGuiData(player, GuiView.getDefaultView(playerTeam)), player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(TeamGuiData guiData, PacketBuffer buffer) {
|
||||
guiData.currentView.writeToBuf(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TeamGuiData readGuiData(EntityPlayer player, PacketBuffer buffer) {
|
||||
return new TeamGuiData(player, GuiView.readFromBuf(buffer));
|
||||
}
|
||||
|
||||
public IGuiHolder<TeamGuiData> getGuiHolder() {
|
||||
if (this.guiHolder == null) {
|
||||
this.guiHolder = this.guiHolderSupplier.get();
|
||||
Objects.requireNonNull(this.guiHolder, "IGuiHolder must not be null");
|
||||
}
|
||||
return guiHolder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.cleanroommc.modularui.api.drawable.IKey;
|
||||
import com.cleanroommc.modularui.widgets.ButtonWidget;
|
||||
import com.cleanroommc.modularui.widgets.Dialog;
|
||||
import com.cleanroommc.modularui.widgets.TextWidget;
|
||||
import com.cleanroommc.modularui.widgets.layout.Flow;
|
||||
import com.gtnewhorizon.gtnhlib.teams.Team;
|
||||
|
||||
public class TextDialog extends Dialog<String> {
|
||||
|
||||
private String message = "";
|
||||
private String initialValue = "";
|
||||
private Consumer<String> stringConsumer = string -> {};
|
||||
private final ClientTextField field = new ClientTextField();
|
||||
|
||||
public TextDialog(String name) {
|
||||
super(name, _unused -> {});
|
||||
|
||||
this.size(140, 90).child(
|
||||
Flow.column().child(
|
||||
new TextWidget<>(IKey.dynamic(() -> this.message)).size(120, 40).top(10).horizontalCenter())
|
||||
.child(this.field.width(120).height(14).horizontalCenter().bottom(25)).child(
|
||||
Flow.row().bottom(5).size(110, 16).horizontalCenter()
|
||||
.child(
|
||||
new ButtonWidget<>().size(45, 16).left(5)
|
||||
.overlay(IKey.lang("gtnhlib.gui.teams.confirm"))
|
||||
.onMouseTapped(mouse -> {
|
||||
this.closeWith(this.field.getText());
|
||||
return true;
|
||||
}))
|
||||
.child(
|
||||
new ButtonWidget<>().size(45, 16).right(5)
|
||||
.overlay(IKey.lang("gtnhlib.gui.teams.cancel"))
|
||||
.onMouseTapped(mouse -> {
|
||||
this.closeWith(null);
|
||||
return true;
|
||||
}))));
|
||||
|
||||
this.setDisablePanelsBelow(true).setDraggable(false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeWith(String result) {
|
||||
if (result != null && !result.isEmpty()
|
||||
&& result.length() < Team.MAX_TEAM_NAME_LENGTH
|
||||
&& !result.equals(this.initialValue)) {
|
||||
this.stringConsumer.accept(result.replace("\n", ""));
|
||||
}
|
||||
closeIfOpen();
|
||||
}
|
||||
|
||||
public void setParams(String message, String initialValue, Consumer<String> stringConsumer) {
|
||||
this.message = message;
|
||||
this.initialValue = initialValue;
|
||||
this.stringConsumer = stringConsumer;
|
||||
this.field.setText(initialValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2.sync;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.DisplayItem;
|
||||
|
||||
public class DisplayListSync {
|
||||
|
||||
public final boolean forceRefresh;
|
||||
public final List<DisplayItem> data;
|
||||
|
||||
protected DisplayListSync(boolean forceRefresh, @Nonnull List<DisplayItem> data) {
|
||||
this.forceRefresh = forceRefresh;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static DisplayListSync copyOf(DisplayListSync other) {
|
||||
List<DisplayItem> copy = other.data.stream().map(DisplayItem::copyOf).collect(Collectors.toList());
|
||||
return new DisplayListSync(other.forceRefresh, copy);
|
||||
}
|
||||
|
||||
public boolean equalsIgnoreUnsetForceRefresh(Object o) {
|
||||
if (!(o instanceof DisplayListSync that)) return false;
|
||||
return data.equals(that.data) && !that.forceRefresh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(forceRefresh, data);
|
||||
}
|
||||
|
||||
protected void serializeInto(PacketBuffer buffer) {
|
||||
buffer.writeBoolean(forceRefresh);
|
||||
buffer.writeInt(data.size());
|
||||
data.forEach(displayItem -> displayItem.serializeInto(buffer));
|
||||
}
|
||||
|
||||
protected static DisplayListSync deserializeFrom(PacketBuffer buffer) {
|
||||
boolean forceRefresh = buffer.readBoolean();
|
||||
int size = buffer.readInt();
|
||||
List<DisplayItem> data = new ArrayList<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
data.add(DisplayItem.deserializeFrom(buffer));
|
||||
}
|
||||
return new DisplayListSync(forceRefresh, data);
|
||||
}
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2.sync;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import com.cleanroommc.modularui.value.sync.AbstractGenericSyncValue;
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.DisplayItem;
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.DisplayItemType;
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.GuiUtils;
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.GuiView;
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.TeamGui;
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.TeamGuiData;
|
||||
import com.gtnewhorizon.gtnhlib.teams.Team;
|
||||
import com.gtnewhorizon.gtnhlib.teams.TeamManager;
|
||||
import com.gtnewhorizon.gtnhlib.util.ServerPlayerUtils;
|
||||
|
||||
public class DisplayListSyncValue extends AbstractGenericSyncValue<DisplayListSync, DisplayListSyncValue> {
|
||||
|
||||
public DisplayListSyncValue(TeamGuiData data, Consumer<DisplayListSync> clientSetter) {
|
||||
super(
|
||||
DisplayListSync.class,
|
||||
() -> null,
|
||||
clientSetter,
|
||||
() -> new DisplayListSync(data.forceRefreshWithNextUpdate, getDisplayListAndResetRefresh(data)),
|
||||
newValue -> {});
|
||||
}
|
||||
|
||||
private static List<DisplayItem> getDisplayListAndResetRefresh(TeamGuiData data) {
|
||||
List<DisplayItem> displayItems = new ArrayList<>();
|
||||
Team viewTeamTmp = TeamManager.getTeamById(data.currentView.currentTeam());
|
||||
// Team ID can be invalid if a solo player joins a team or their team gets merged while they're in a view,
|
||||
// and then the player returns to a view for their non-existent team.
|
||||
// In such a case, we default to showing the player the view for their current team.
|
||||
final Team viewTeam;
|
||||
if (viewTeamTmp == null) {
|
||||
viewTeam = TeamManager.getTeamByPlayer(data.getPlayer().getUniqueID());
|
||||
assert viewTeam != null;
|
||||
data.currentView = new GuiView(data.currentView.type(), viewTeam.getTeamId());
|
||||
} else {
|
||||
viewTeam = viewTeamTmp;
|
||||
}
|
||||
|
||||
UUID currentPlayer = data.getPlayer().getUniqueID();
|
||||
Team currentPlayerTeam = TeamManager.getTeamByPlayer(currentPlayer);
|
||||
switch (data.currentView.type()) {
|
||||
case PLAYER_LIST:
|
||||
viewTeam.getMembers().stream()
|
||||
.sorted(
|
||||
Comparator.<UUID>comparingInt(id -> viewTeam.getRole(id).ordinal()).reversed()
|
||||
.thenComparing(ServerPlayerUtils::getPlayerName))
|
||||
.forEach(
|
||||
playerId -> displayItems.add(
|
||||
new DisplayItem(
|
||||
DisplayItemType.PLAYER,
|
||||
ServerPlayerUtils.getPlayerName(playerId),
|
||||
viewTeam.getRole(playerId),
|
||||
playerId,
|
||||
viewTeam.isOwner(playerId) && viewTeam.getOwners().size() == 1)));
|
||||
break;
|
||||
case TEAM_LIST:
|
||||
TeamManager.getTeamMap().forEach(
|
||||
(teamId, teamObj) -> displayItems.add(
|
||||
new DisplayItem(
|
||||
DisplayItemType.TEAM,
|
||||
GuiUtils.clampString(teamObj.getTeamName(), TeamGui.MAX_DISPLAY_STRING_LENGTH),
|
||||
null,
|
||||
teamId,
|
||||
teamObj.canBeDisbanded())));
|
||||
displayItems.sort(Comparator.comparing(DisplayItem::text));
|
||||
break;
|
||||
case INVITE_PLAYERS:
|
||||
Set<UUID> teamPlayerList = viewTeam.getMembers();
|
||||
ServerPlayerUtils.forAllOnlinePlayers(player -> {
|
||||
UUID playerId = player.getUniqueID();
|
||||
if (!teamPlayerList.contains(playerId)) {
|
||||
displayItems.add(
|
||||
new DisplayItem(
|
||||
DisplayItemType.PLAYER,
|
||||
GuiUtils.clampString(
|
||||
ServerPlayerUtils.getPlayerName(playerId),
|
||||
TeamGui.MAX_DISPLAY_STRING_LENGTH),
|
||||
null,
|
||||
playerId,
|
||||
TeamManager.getPendingInvites(playerId).contains(viewTeam)));
|
||||
}
|
||||
});
|
||||
displayItems.sort(Comparator.comparing(DisplayItem::flag).thenComparing(DisplayItem::text));
|
||||
break;
|
||||
case TEAMS_INVITING_PLAYER:
|
||||
boolean playerCannotAcceptInvites = currentPlayerTeam == null
|
||||
|| currentPlayerTeam.playerCannotAcceptInvites(currentPlayer);
|
||||
TeamManager.getPendingInvites(currentPlayer).stream().sorted(Comparator.comparing(Team::getTeamName))
|
||||
.forEach(
|
||||
t -> displayItems.add(
|
||||
new DisplayItem(
|
||||
DisplayItemType.TEAM,
|
||||
GuiUtils.clampString(
|
||||
t.getTeamName(),
|
||||
TeamGui.MAX_DISPLAY_STRING_LENGTH),
|
||||
null,
|
||||
t.getTeamId(),
|
||||
playerCannotAcceptInvites)));
|
||||
break;
|
||||
case REQUEST_CONSUME:
|
||||
TeamManager.getTeamMap().forEach((teamId, teamObj) -> {
|
||||
if (teamObj.equals(currentPlayerTeam)) return;
|
||||
displayItems.add(
|
||||
new DisplayItem(
|
||||
DisplayItemType.TEAM,
|
||||
GuiUtils.clampString(teamObj.getTeamName(), TeamGui.MAX_DISPLAY_STRING_LENGTH),
|
||||
null,
|
||||
teamId,
|
||||
TeamManager.getPendingMergeRequests(teamObj).contains(currentPlayerTeam)));
|
||||
});
|
||||
displayItems.sort(Comparator.comparing(DisplayItem::flag).reversed().thenComparing(DisplayItem::text));
|
||||
break;
|
||||
case VIEW_CONSUMPTION_REQUESTS:
|
||||
TeamManager.getPendingMergeRequests(currentPlayerTeam).stream()
|
||||
.sorted(Comparator.comparing(Team::getTeamName)).forEach(
|
||||
t -> displayItems.add(
|
||||
new DisplayItem(
|
||||
DisplayItemType.TEAM,
|
||||
GuiUtils.clampString(
|
||||
t.getTeamName(),
|
||||
TeamGui.MAX_DISPLAY_STRING_LENGTH),
|
||||
null,
|
||||
t.getTeamId(),
|
||||
false)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
data.forceRefreshWithNextUpdate = false;
|
||||
return displayItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayListSync createDeepCopyOf(DisplayListSync value) {
|
||||
return DisplayListSync.copyOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean areEqual(DisplayListSync cachedValue, DisplayListSync newValue) {
|
||||
if (cachedValue == null || newValue == null) return cachedValue == newValue;
|
||||
return cachedValue.equalsIgnoreUnsetForceRefresh(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serialize(PacketBuffer buffer, DisplayListSync value) throws IOException {
|
||||
value.serializeInto(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayListSync deserialize(PacketBuffer buffer) throws IOException {
|
||||
return DisplayListSync.deserializeFrom(buffer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2.sync;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import com.cleanroommc.modularui.value.sync.AbstractGenericSyncValue;
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.GuiView;
|
||||
|
||||
public class GuiViewSyncValue extends AbstractGenericSyncValue<GuiView, GuiViewSyncValue> {
|
||||
|
||||
public GuiViewSyncValue(Supplier<GuiView> getter, Consumer<GuiView> setter) {
|
||||
super(GuiView.class, getter, setter);
|
||||
this.allowC2S();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiView createDeepCopyOf(GuiView value) {
|
||||
return GuiView.deepCopyOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean areEqual(GuiView a, GuiView b) {
|
||||
if (a == null || b == null) return a == b;
|
||||
return a.equals(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serialize(PacketBuffer buffer, GuiView value) throws IOException {
|
||||
value.writeToBuf(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiView deserialize(PacketBuffer buffer) throws IOException {
|
||||
return GuiView.readFromBuf(buffer);
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2.sync;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.cleanroommc.modularui.value.sync.AbstractGenericSyncValue;
|
||||
|
||||
public class TwoUuidActionSyncValue extends AbstractGenericSyncValue<Pair<UUID, UUID>, TwoUuidActionSyncValue> {
|
||||
|
||||
public TwoUuidActionSyncValue(@Nullable Consumer<Pair<UUID, UUID>> serverSetter) {
|
||||
super(
|
||||
(Class<Pair<UUID, UUID>>) (Class<?>) Pair.class,
|
||||
() -> null,
|
||||
clientSetValue -> {},
|
||||
() -> null,
|
||||
serverSetter);
|
||||
this.allowC2S();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<UUID, UUID> createDeepCopyOf(Pair<UUID, UUID> value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return new ImmutablePair<>(value.getLeft(), value.getRight());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean areEqual(Pair<UUID, UUID> a, Pair<UUID, UUID> b) {
|
||||
if (a == null || b == null) {
|
||||
return a == b;
|
||||
}
|
||||
return a.getLeft().equals(b.getLeft()) && a.getRight().equals(b.getRight());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serialize(PacketBuffer buffer, Pair<UUID, UUID> value) throws IOException {
|
||||
// SyncValueIsNull, LeftUUIDIsNull, LeftUUID, RightUUIDIsNull, RightUUID
|
||||
if (value == null) {
|
||||
buffer.writeBoolean(true);
|
||||
return;
|
||||
}
|
||||
buffer.writeBoolean(false);
|
||||
buffer.writeBoolean(value.getLeft() == null);
|
||||
if (value.getLeft() != null) {
|
||||
buffer.writeLong(value.getLeft().getMostSignificantBits());
|
||||
buffer.writeLong(value.getLeft().getLeastSignificantBits());
|
||||
}
|
||||
buffer.writeBoolean(value.getRight() == null);
|
||||
if (value.getRight() != null) {
|
||||
buffer.writeLong(value.getRight().getMostSignificantBits());
|
||||
buffer.writeLong(value.getRight().getLeastSignificantBits());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<UUID, UUID> deserialize(PacketBuffer buffer) throws IOException {
|
||||
if (buffer.readBoolean()) {
|
||||
return null;
|
||||
}
|
||||
UUID firstValue = null;
|
||||
if (!buffer.readBoolean()) {
|
||||
firstValue = new UUID(buffer.readLong(), buffer.readLong());
|
||||
}
|
||||
UUID secondValue = null;
|
||||
if (!buffer.readBoolean()) {
|
||||
secondValue = new UUID(buffer.readLong(), buffer.readLong());
|
||||
}
|
||||
return new ImmutablePair<>(firstValue, secondValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2.sync;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import com.cleanroommc.modularui.value.sync.AbstractGenericSyncValue;
|
||||
|
||||
public class UuidActionSyncValue extends AbstractGenericSyncValue<UUID, UuidActionSyncValue> {
|
||||
|
||||
public UuidActionSyncValue(@Nullable Consumer<UUID> serverSetter) {
|
||||
super(UUID.class, () -> null, clientSetValue -> {}, () -> null, serverSetter);
|
||||
this.allowC2S();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID createDeepCopyOf(UUID value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean areEqual(UUID a, UUID b) {
|
||||
if (a == null || b == null) return a == b;
|
||||
return a.equals(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serialize(PacketBuffer buffer, UUID value) throws IOException {
|
||||
buffer.writeBoolean(value == null);
|
||||
if (value != null) {
|
||||
buffer.writeLong(value.getMostSignificantBits());
|
||||
buffer.writeLong(value.getLeastSignificantBits());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID deserialize(PacketBuffer buffer) throws IOException {
|
||||
if (buffer.readBoolean()) return null;
|
||||
return new UUID(buffer.readLong(), buffer.readLong());
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package com.gtnewhorizon.gtnhlib.integration.mui2.sync;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.cleanroommc.modularui.value.sync.AbstractGenericSyncValue;
|
||||
import com.gtnewhorizon.gtnhlib.teams.Team;
|
||||
|
||||
public class UuidStringActionSyncValue extends AbstractGenericSyncValue<Pair<UUID, String>, UuidStringActionSyncValue> {
|
||||
|
||||
public UuidStringActionSyncValue(@Nullable Consumer<Pair<UUID, String>> serverSetter) {
|
||||
super(
|
||||
(Class<Pair<UUID, String>>) (Class<?>) Pair.class,
|
||||
() -> null,
|
||||
clientSetValue -> {},
|
||||
() -> null,
|
||||
serverSetter);
|
||||
this.allowC2S();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<UUID, String> createDeepCopyOf(Pair<UUID, String> value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return new ImmutablePair<>(value.getLeft(), value.getRight());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean areEqual(Pair<UUID, String> a, Pair<UUID, String> b) {
|
||||
if (a == null || b == null) {
|
||||
return a == b;
|
||||
}
|
||||
return a.getLeft().equals(b.getLeft()) && a.getRight().equals(b.getRight());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serialize(PacketBuffer buffer, Pair<UUID, String> value) throws IOException {
|
||||
// SyncValueIsNull, uuidIsNull, UUID, stringIsNull, String
|
||||
if (value == null) {
|
||||
buffer.writeBoolean(true);
|
||||
return;
|
||||
}
|
||||
buffer.writeBoolean(false);
|
||||
buffer.writeBoolean(value.getLeft() == null);
|
||||
if (value.getLeft() != null) {
|
||||
buffer.writeLong(value.getLeft().getMostSignificantBits());
|
||||
buffer.writeLong(value.getLeft().getLeastSignificantBits());
|
||||
}
|
||||
buffer.writeBoolean(value.getRight() == null);
|
||||
if (value.getRight() != null) {
|
||||
buffer.writeStringToBuffer(value.getRight());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<UUID, String> deserialize(PacketBuffer buffer) throws IOException {
|
||||
if (buffer.readBoolean()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
UUID firstValue = null;
|
||||
if (!buffer.readBoolean()) {
|
||||
firstValue = new UUID(buffer.readLong(), buffer.readLong());
|
||||
}
|
||||
|
||||
String secondValue = null;
|
||||
if (!buffer.readBoolean()) {
|
||||
secondValue = buffer.readStringFromBuffer(Team.MAX_TEAM_NAME_LENGTH);
|
||||
}
|
||||
return new ImmutablePair<>(firstValue, secondValue);
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class Team {
|
||||
this(teamName, teamId, false);
|
||||
}
|
||||
|
||||
Team(String teamName, UUID teamId, boolean clientSide) {
|
||||
public Team(String teamName, UUID teamId, boolean clientSide) {
|
||||
this.teamName = teamName;
|
||||
this.teamId = teamId;
|
||||
this.clientSide = clientSide;
|
||||
@@ -173,4 +173,12 @@ public class Team {
|
||||
public Set<Map.Entry<String, ITeamData>> getAllDataEntries() {
|
||||
return teamData.entrySet();
|
||||
}
|
||||
|
||||
public boolean canBeDisbanded() {
|
||||
return members.size() > 1;
|
||||
}
|
||||
|
||||
public boolean playerCannotAcceptInvites(UUID player) {
|
||||
return owners.contains(player) && owners.size() == 1 && members.size() > 1;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ public class TeamActions {
|
||||
|
||||
public static void onRename(Team team, String oldName, String newName, boolean adminAction,
|
||||
@Nullable ICommandSender admin) {
|
||||
team.markDirty();
|
||||
TeamManager.forEachOnlineTeamMember(team, member -> {
|
||||
NetworkHandler.instance.sendTo(TeamNetwork.createTeamInfoSyncPacket(member.getUniqueID()), member);
|
||||
success(
|
||||
@@ -64,6 +65,10 @@ public class TeamActions {
|
||||
colorChatComponent(EnumChatFormatting.GOLD, ServerPlayerUtils.getPlayerName(target)));
|
||||
}
|
||||
|
||||
public static void onCancelInvite(Team team, UUID target) {
|
||||
TeamManager.removePendingInvite(target, team);
|
||||
}
|
||||
|
||||
public static void onAccept(Team invitingTeam, EntityPlayer player) {
|
||||
// Leave current team first. If the team would be disbanded, merge it into the new team automatically.
|
||||
UUID playerId = player.getUniqueID();
|
||||
@@ -74,6 +79,7 @@ public class TeamActions {
|
||||
} else {
|
||||
TeamManager.transferTeamData(oldTeam, invitingTeam, playerId, TeamDataTransferReason.JoinedExistingTeam);
|
||||
oldTeam.removeMember(playerId);
|
||||
oldTeam.markDirty();
|
||||
TeamDataSync oldTeamData = TeamNetwork.createCompleteTeamDataSyncPacket(oldTeam);
|
||||
TeamManager.forEachOnlineTeamMember(oldTeam, member -> {
|
||||
if (member.getUniqueID().equals(playerId)) return;
|
||||
@@ -83,7 +89,6 @@ public class TeamActions {
|
||||
"gtnhlib.chat.teams.message.other_left_team",
|
||||
colorChatComponent(EnumChatFormatting.GOLD, ServerPlayerUtils.getPlayerName(player)));
|
||||
});
|
||||
oldTeam.markDirty();
|
||||
invitingTeam.addMember(playerId);
|
||||
}
|
||||
TeamManager.removeAllPendingInvites(playerId);
|
||||
@@ -117,6 +122,43 @@ public class TeamActions {
|
||||
colorChatComponent(EnumChatFormatting.GOLD, team.getTeamName()));
|
||||
}
|
||||
|
||||
public static void onKick(Team team, UUID kicked, boolean adminAction, @Nullable ICommandSender admin) {
|
||||
team.removeMember(kicked);
|
||||
|
||||
Team newTeam = TeamManager.createTeam(ServerPlayerUtils.getPlayerName(kicked), kicked);
|
||||
TeamManager.transferTeamData(team, newTeam, kicked, TeamDataTransferReason.JoinedNewTeam);
|
||||
team.markDirty();
|
||||
newTeam.markDirty();
|
||||
TeamDataSync teamData = TeamNetwork.createCompleteTeamDataSyncPacket(team);
|
||||
TeamManager.forEachOnlineTeamMember(team, member -> {
|
||||
NetworkHandler.instance.sendTo(teamData, member);
|
||||
success(
|
||||
member,
|
||||
adminAction ? "gtnhlib.chat.teams.message.admin_other_kicked_from_team"
|
||||
: "gtnhlib.chat.teams.message.other_kicked_from_team",
|
||||
colorChatComponent(EnumChatFormatting.GOLD, ServerPlayerUtils.getPlayerName(kicked)));
|
||||
});
|
||||
|
||||
TeamManager.forEachOnlineTeamMember(newTeam, member -> {
|
||||
if (member.getUniqueID().equals(kicked)) {
|
||||
TeamNetwork.sendPlayerAllTeamData(member, newTeam);
|
||||
success(
|
||||
member,
|
||||
adminAction ? "gtnhlib.chat.teams.message.admin_kicked_from_team"
|
||||
: "gtnhlib.chat.teams.message.kicked_from_team",
|
||||
colorChatComponent(EnumChatFormatting.GOLD, team.getTeamName()));
|
||||
}
|
||||
});
|
||||
|
||||
if (adminAction && admin != null) {
|
||||
success(
|
||||
admin,
|
||||
"gtnhlib.chat.admin.message.kicked",
|
||||
colorChatComponent(EnumChatFormatting.GOLD, ServerPlayerUtils.getPlayerName(kicked)),
|
||||
colorChatComponent(EnumChatFormatting.GOLD, team.getTeamName()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void onLeave(EntityPlayer player) {
|
||||
UUID playerId = player.getUniqueID();
|
||||
Team oldTeam = TeamManager.getTeamByPlayer(playerId);
|
||||
@@ -140,8 +182,10 @@ public class TeamActions {
|
||||
}
|
||||
|
||||
// Create a new solo team for the player
|
||||
Team newTeam = TeamManager.getOrCreateTeam(player.getCommandSenderName(), player.getUniqueID());
|
||||
Team newTeam = TeamManager.createTeam(player.getCommandSenderName(), player.getUniqueID());
|
||||
TeamManager.transferTeamData(oldTeam, newTeam, playerId, TeamDataTransferReason.JoinedNewTeam);
|
||||
if (!oldTeam.getMembers().isEmpty()) oldTeam.markDirty();
|
||||
newTeam.markDirty();
|
||||
TeamNetwork.sendPlayerAllTeamData((EntityPlayerMP) player, newTeam);
|
||||
|
||||
success(player, "gtnhlib.chat.teams.message.left_team", colorChatComponent(EnumChatFormatting.GOLD, teamName));
|
||||
@@ -248,6 +292,13 @@ public class TeamActions {
|
||||
});
|
||||
}
|
||||
|
||||
public static void onMergeCancel(EntityPlayer player, Team source, Team target) {
|
||||
TeamManager.removePendingMergeRequest(source, target);
|
||||
|
||||
ChatComponentText targetComponent = colorChatComponent(EnumChatFormatting.GOLD, target.getTeamName());
|
||||
success(player, "gtnhlib.chat.teams.message.merge_request_cancelled", targetComponent);
|
||||
}
|
||||
|
||||
public static void onMergeAccept(Team source, Team target, boolean adminAction, @Nullable ICommandSender admin) {
|
||||
ChatComponentText sourceComponent = colorChatComponent(EnumChatFormatting.GOLD, source.getTeamName());
|
||||
ChatComponentText targetComponent = colorChatComponent(EnumChatFormatting.GOLD, target.getTeamName());
|
||||
@@ -290,6 +341,7 @@ public class TeamActions {
|
||||
public static void onDisband(Team team, boolean adminAction, @Nullable ICommandSender admin) {
|
||||
List<UUID> members = new ArrayList<>(team.getMembers());
|
||||
String teamName = team.getTeamName();
|
||||
members.forEach(team::removeMember);
|
||||
|
||||
TeamManager.TEAMS.remove(team);
|
||||
TeamManager.TEAM_MAP.remove(team.getTeamId());
|
||||
@@ -308,8 +360,9 @@ public class TeamActions {
|
||||
|
||||
for (UUID uuid : members) {
|
||||
String name = ServerPlayerUtils.getPlayerName(uuid);
|
||||
Team newTeam = TeamManager.getOrCreateTeam(name, uuid);
|
||||
Team newTeam = TeamManager.createTeam(name, uuid);
|
||||
TeamManager.transferTeamData(team, newTeam, uuid, TeamDataTransferReason.JoinedNewTeam);
|
||||
newTeam.markDirty();
|
||||
TeamManager.forEachOnlineTeamMember(newTeam, member -> {
|
||||
NetworkHandler.instance.sendTo(TeamNetwork.createTeamInfoSyncPacket(member.getUniqueID()), member);
|
||||
TeamNetwork.sendPlayerAllTeamData(member, newTeam);
|
||||
|
||||
@@ -52,6 +52,14 @@ public class TeamAdminCommand {
|
||||
ctx.getSource(),
|
||||
StringArgumentType.getString(ctx, ARG_TEAM_NAME),
|
||||
StringArgumentType.getString(ctx, ARG_PLAYER))))))
|
||||
.then(
|
||||
literal("kick").then(
|
||||
argument(ARG_TEAM_NAME, StringArgumentType.string()).then(
|
||||
argument(ARG_PLAYER, StringArgumentType.string()).executes(
|
||||
ctx -> executeAdminKick(
|
||||
ctx.getSource(),
|
||||
StringArgumentType.getString(ctx, ARG_TEAM_NAME),
|
||||
StringArgumentType.getString(ctx, ARG_PLAYER))))))
|
||||
.then(
|
||||
literal("merge").then(
|
||||
argument(ARG_TEAM_NAME, StringArgumentType.string()).then(
|
||||
@@ -120,6 +128,21 @@ public class TeamAdminCommand {
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int executeAdminKick(ICommandSender sender, String teamName, String playerName) {
|
||||
Team team = TeamManager.getTeamByName(teamName);
|
||||
if (team == null) return error(sender, "gtnhlib.chat.teams.admin.error.team_not_found", teamName);
|
||||
|
||||
UUID uuid = resolveTeamMemberUuid(team, playerName);
|
||||
if (uuid == null || !team.isMember(uuid))
|
||||
return error(sender, "gtnhlib.chat.teams.admin.error.player_not_in_team", playerName, teamName);
|
||||
if (team.isOwner(uuid) && team.getOwners().size() == 1)
|
||||
return error(sender, "gtnhlib.chat.teams.admin.error.kick_last_owner", playerName, teamName);
|
||||
|
||||
TeamActions.onKick(team, uuid, true, sender);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int executeAdminMerge(ICommandSender sender, String sourceName, String targetName) {
|
||||
Team sourceTeam = TeamManager.getTeamByName(sourceName);
|
||||
if (sourceTeam == null) return error(sender, "gtnhlib.chat.teams.admin.error.team_not_found", sourceName);
|
||||
@@ -138,6 +161,7 @@ public class TeamAdminCommand {
|
||||
private static int executeAdminDisband(ICommandSender sender, String teamName) {
|
||||
Team team = TeamManager.getTeamByName(teamName);
|
||||
if (team == null) return error(sender, "gtnhlib.chat.teams.admin.error.team_not_found", teamName);
|
||||
if (!team.canBeDisbanded()) return error(sender, "gtnhlib.chat.teams.admin.error.cannot_disband_solo_team");
|
||||
|
||||
TeamActions.onDisband(team, true, sender);
|
||||
|
||||
@@ -163,6 +187,7 @@ public class TeamAdminCommand {
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.admin.help.5", root));
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.admin.help.6", root));
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.admin.help.7", root));
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.admin.help.8", root));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,14 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.GTNHLib;
|
||||
import com.gtnewhorizon.gtnhlib.GTNHLibConfig;
|
||||
import com.gtnewhorizon.gtnhlib.brigadier.BrigadierApi;
|
||||
import com.gtnewhorizon.gtnhlib.integration.mui2.TeamGuiFactory;
|
||||
import com.gtnewhorizon.gtnhlib.util.ServerPlayerUtils;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
@@ -31,12 +34,14 @@ public class TeamCommand {
|
||||
BrigadierApi.getCommandDispatcher().register(literal(GTNHLibConfig.teamCommandRoot).executes(ctx -> {
|
||||
sendUsage(ctx.getSource());
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}).then(
|
||||
literal("rename").then(
|
||||
argument(ARG_NEW_NAME, StringArgumentType.string()).executes(
|
||||
ctx -> executeRename(
|
||||
ctx.getSource(),
|
||||
StringArgumentType.getString(ctx, ARG_NEW_NAME)))))
|
||||
}).then(literal("gui").executes(ctx -> executeGui(ctx.getSource())))
|
||||
|
||||
.then(
|
||||
literal("rename").then(
|
||||
argument(ARG_NEW_NAME, StringArgumentType.string()).executes(
|
||||
ctx -> executeRename(
|
||||
ctx.getSource(),
|
||||
StringArgumentType.getString(ctx, ARG_NEW_NAME)))))
|
||||
|
||||
.then(
|
||||
literal("invite")
|
||||
@@ -87,6 +92,14 @@ public class TeamCommand {
|
||||
ctx -> executeDemote(
|
||||
ctx.getSource(),
|
||||
StringArgumentType.getString(ctx, ARG_PLAYER)))))
|
||||
.then(
|
||||
literal("kick").then(
|
||||
argument(ARG_PLAYER, StringArgumentType.word())
|
||||
.suggests((ctx, builder) -> suggestTeamMembers(ctx.getSource(), builder))
|
||||
.executes(
|
||||
ctx -> executeKick(
|
||||
ctx.getSource(),
|
||||
StringArgumentType.getString(ctx, ARG_PLAYER)))))
|
||||
|
||||
.then(literal("info").executes(ctx -> executeInfo(ctx.getSource())))
|
||||
|
||||
@@ -101,6 +114,15 @@ public class TeamCommand {
|
||||
ctx.getSource(),
|
||||
StringArgumentType
|
||||
.getString(ctx, ARG_TEAM_NAME)))))
|
||||
.then(
|
||||
literal("cancel").then(
|
||||
argument(ARG_TEAM_NAME, StringArgumentType.string()).suggests(
|
||||
(ctx, builder) -> suggestOtherTeams(ctx.getSource(), builder))
|
||||
.executes(
|
||||
ctx -> executeMergeCancel(
|
||||
ctx.getSource(),
|
||||
StringArgumentType
|
||||
.getString(ctx, ARG_TEAM_NAME)))))
|
||||
.then(
|
||||
literal("accept").executes(ctx -> executeMergeAccept(ctx.getSource(), ""))
|
||||
.then(
|
||||
@@ -134,6 +156,22 @@ public class TeamCommand {
|
||||
.then(literal("help").executes(ctx -> executeHelp(ctx.getSource()))));
|
||||
}
|
||||
|
||||
private static int executeGui(ICommandSender sender) {
|
||||
if (!GTNHLib.isMui2Loaded) {
|
||||
return error(sender, "gtnhlib.chat.teams.error.mui2_not_loaded");
|
||||
}
|
||||
|
||||
EntityPlayerMP player = TeamCommandsUtils.asPlayerMP(sender);
|
||||
if (player == null) return Command.SINGLE_SUCCESS;
|
||||
|
||||
Team team = TeamManager.getTeamByPlayer(player.getUniqueID());
|
||||
if (team == null) return error(sender, "gtnhlib.chat.teams.error.not_in_team");
|
||||
|
||||
TeamGuiFactory.INSTANCE.open(player, team.getTeamId());
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int executeRename(ICommandSender sender, String newName) {
|
||||
if (newName.length() > Team.MAX_TEAM_NAME_LENGTH) {
|
||||
return error(sender, "gtnhlib.chat.teams.message.team_name_too_long");
|
||||
@@ -286,6 +324,21 @@ public class TeamCommand {
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int executeKick(ICommandSender sender, String targetName) {
|
||||
EntityPlayer player = TeamCommandsUtils.asPlayer(sender);
|
||||
if (player == null) return Command.SINGLE_SUCCESS;
|
||||
Team team = TeamManager.getTeamByPlayer(player.getUniqueID());
|
||||
if (team == null) return error(sender, "gtnhlib.chat.teams.error.not_in_team");
|
||||
|
||||
UUID targetUuid = resolveTeamMemberUuid(team, targetName);
|
||||
if (targetUuid == null) return error(sender, "gtnhlib.chat.teams.error.other_not_in_team", targetName);
|
||||
if (targetUuid.equals(player.getUniqueID())) return error(sender, "gtnhlib.chat.teams.error.cannot_kick_self");
|
||||
if (!TeamCommandsUtils.canKick(team.getRole(player.getUniqueID()), team.getRole(targetUuid)))
|
||||
return error(sender, "gtnhlib.chat.teams.error.kick_not_allowed");
|
||||
TeamActions.onKick(team, targetUuid, false, null);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int executeInfo(ICommandSender sender) {
|
||||
EntityPlayer player = TeamCommandsUtils.asPlayer(sender);
|
||||
if (player == null) return Command.SINGLE_SUCCESS;
|
||||
@@ -319,6 +372,24 @@ public class TeamCommand {
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int executeMergeCancel(ICommandSender sender, String targetTeamName) {
|
||||
EntityPlayer player = TeamCommandsUtils.asPlayer(sender);
|
||||
if (player == null) return Command.SINGLE_SUCCESS;
|
||||
|
||||
Team source = TeamManager.getTeamByPlayer(player.getUniqueID());
|
||||
if (source == null) return error(sender, "gtnhlib.chat.teams.error.not_in_team");
|
||||
if (!source.isOwner(player.getUniqueID()))
|
||||
return error(sender, "gtnhlib.chat.teams.error.not_owner_merge_request");
|
||||
Team target = TeamManager.getTeamByName(targetTeamName);
|
||||
if (target == null) return error(sender, "gtnhlib.chat.teams.error.team_not_found", targetTeamName);
|
||||
if (!TeamManager.hasPendingMergeRequest(source, target))
|
||||
return error(sender, "gtnhlib.chat.teams.error.no_such_merge_request", targetTeamName);
|
||||
|
||||
TeamActions.onMergeCancel(player, source, target);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int executeMergeAccept(ICommandSender sender, String sourceTeamName) {
|
||||
EntityPlayer player = TeamCommandsUtils.asPlayer(sender);
|
||||
if (player == null) return Command.SINGLE_SUCCESS;
|
||||
@@ -386,7 +457,7 @@ public class TeamCommand {
|
||||
if (!team.isOwner(playerId)) {
|
||||
return error(sender, "gtnhlib.chat.teams.error.not_owner_disband");
|
||||
}
|
||||
if (team.getMembers().size() == 1) {
|
||||
if (!team.canBeDisbanded()) {
|
||||
return error(sender, "gtnhlib.chat.teams.error.last_owner_disband");
|
||||
}
|
||||
|
||||
@@ -395,6 +466,9 @@ public class TeamCommand {
|
||||
}
|
||||
|
||||
private static int executeHelp(ICommandSender sender) {
|
||||
if (GTNHLib.isMui2Loaded) {
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.help.gui"));
|
||||
}
|
||||
String root = TeamCommandsUtils.getCommandRoot();
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.help.1", GTNHLibConfig.teamSystemName));
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.help.2", root));
|
||||
@@ -409,6 +483,7 @@ public class TeamCommand {
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.help.11", root));
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.help.12", root));
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.help.13", root));
|
||||
sender.addChatMessage(new ChatComponentTranslation("gtnhlib.chat.teams.help.14", root));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.UUID;
|
||||
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
@@ -92,6 +93,29 @@ public abstract class TeamCommandsUtils {
|
||||
return player;
|
||||
}
|
||||
|
||||
static EntityPlayerMP asPlayerMP(ICommandSender sender) {
|
||||
// MUI2 specifically wants the EntityPlayerMP object, so here we are lol
|
||||
if (!(sender instanceof EntityPlayerMP player)) {
|
||||
ChatComponentTranslation msg = new ChatComponentTranslation("gtnhlib.chat.teams.error.not_player");
|
||||
msg.getChatStyle().setColor(EnumChatFormatting.RED);
|
||||
sender.addChatMessage(msg);
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
public static boolean canPromote(TeamRole promoter, TeamRole promoted) {
|
||||
return promoter == TeamRole.OWNER;
|
||||
}
|
||||
|
||||
public static boolean canDemote(TeamRole demoter, TeamRole demoted) {
|
||||
return demoter == TeamRole.OWNER;
|
||||
}
|
||||
|
||||
public static boolean canKick(TeamRole kicker, TeamRole toKick) {
|
||||
return kicker == TeamRole.OWNER || kicker.ordinal() > toKick.ordinal();
|
||||
}
|
||||
|
||||
static String getCommandRoot() {
|
||||
return "/" + GTNHLibConfig.teamCommandRoot;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import com.gtnewhorizon.gtnhlib.GTNHLib;
|
||||
import com.gtnewhorizon.gtnhlib.teams.TeamEvents.TeamCreateEvent;
|
||||
import com.gtnewhorizon.gtnhlib.teams.TeamEvents.TeamMergeEvent;
|
||||
import com.gtnewhorizon.gtnhlib.util.ServerPlayerUtils;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
|
||||
@@ -59,7 +60,10 @@ public class TeamManager {
|
||||
}
|
||||
}
|
||||
PLAYER_TEAM_CACHE.remove(playerUuid);
|
||||
GTNHLib.LOG.error("Unable to find team for player {}", playerUuid);
|
||||
GTNHLib.LOG.error(
|
||||
"Unable to find team for player {} ({})",
|
||||
playerUuid,
|
||||
ServerPlayerUtils.getPlayerName(playerUuid));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -83,9 +87,14 @@ public class TeamManager {
|
||||
Team existing = getTeamByPlayer(playerUuid);
|
||||
if (existing != null) return existing;
|
||||
|
||||
return createTeam(playerName, playerUuid);
|
||||
}
|
||||
|
||||
public static Team createTeam(String playerName, UUID playerUuid) {
|
||||
Team team = new Team(playerName + "'s Team", UUID.randomUUID());
|
||||
team.initializeData(TeamDataRegistry.getRegisteredKeys().toArray(new String[0]));
|
||||
team.addOwner(playerUuid);
|
||||
PLAYER_TEAM_CACHE.put(playerUuid, team);
|
||||
MinecraftForge.EVENT_BUS.post(new TeamCreateEvent(team, playerUuid));
|
||||
TEAMS.add(team);
|
||||
TEAM_MAP.put(team.getTeamId(), team);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.gtnewhorizon.gtnhlib.teams;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -52,6 +54,10 @@ public class TeamManagerClient {
|
||||
return TEAM;
|
||||
}
|
||||
|
||||
public static UUID GetTeamId() {
|
||||
return TEAM == null ? null : TEAM.getTeamId();
|
||||
}
|
||||
|
||||
public static TeamRole getRole() {
|
||||
return currentRole;
|
||||
}
|
||||
@@ -60,4 +66,16 @@ public class TeamManagerClient {
|
||||
return currentRole.ordinal() >= role.ordinal();
|
||||
}
|
||||
|
||||
public static boolean canPlayerPromote(TeamRole role) {
|
||||
return TeamCommandsUtils.canPromote(currentRole, role);
|
||||
}
|
||||
|
||||
public static boolean canPlayerDemote(TeamRole role) {
|
||||
return TeamCommandsUtils.canDemote(currentRole, role);
|
||||
}
|
||||
|
||||
public static boolean canPlayerKick(TeamRole role) {
|
||||
return TeamCommandsUtils.canKick(currentRole, role);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user