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
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public static IdentityConfig getInstance() {

public abstract boolean enableSwaps();

/**
* Players listed here may swap identities even when {@link #enableSwaps()} is false.
* Names are compared case-insensitively.
*/
public abstract List<String> allowedSwappers();

public abstract int hostilityTime();

public abstract boolean wardenIsBlinded();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public void tick(MinecraftClient client) {
assert client.player != null;

if(IdentityClient.MENU_KEY.wasPressed()) {
if(IdentityConfig.getInstance().enableClientSwapMenu() || client.player.hasPermissionLevel(3)) {
if(IdentityConfig.getInstance().enableClientSwapMenu() ||
client.player.hasPermissionLevel(3) ||
IdentityConfig.getInstance().allowedSwappers().stream()
.anyMatch(p -> p.equalsIgnoreCase(client.player.getGameProfile().getName()))) {
MinecraftClient.getInstance().setScreen(new IdentityScreen());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public static void registerIdentityRequestPacketHandler() {

context.getPlayer().getServer().execute(() -> {
// Ensure player has permission to switch identities
if(IdentityConfig.getInstance().enableSwaps() || context.getPlayer().hasPermissionLevel(3)) {
if(IdentityConfig.getInstance().enableSwaps() ||
context.getPlayer().hasPermissionLevel(3) ||
IdentityConfig.getInstance().allowedSwappers().stream()
.anyMatch(p -> p.equalsIgnoreCase(context.getPlayer().getGameProfile().getName()))) {
// player type shouldn't be sent, but we still check regardless
if(entityType.equals(EntityType.PLAYER)) {
PlayerIdentity.updateIdentity((ServerPlayerEntity) context.getPlayer(), null, null);
Expand All @@ -43,7 +46,10 @@ public static void registerIdentityRequestPacketHandler() {
} else {
// Swap back to player if server allows it
context.getPlayer().getServer().execute(() -> {
if(IdentityConfig.getInstance().enableSwaps() || context.getPlayer().hasPermissionLevel(3)) {
if(IdentityConfig.getInstance().enableSwaps() ||
context.getPlayer().hasPermissionLevel(3) ||
IdentityConfig.getInstance().allowedSwappers().stream()
.anyMatch(p -> p.equalsIgnoreCase(context.getPlayer().getGameProfile().getName()))) {
PlayerIdentity.updateIdentity((ServerPlayerEntity) context.getPlayer(), null, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public class IdentityFabricConfig extends IdentityConfig implements Config {
@Comment(value = "If set to false, only operators can switch identities. Used on the server; guaranteed to be authoritative.")
public boolean enableSwaps = true;

@Comment(value = "List of player names allowed to swap identities when swaps are disabled.")
public List<String> allowedSwappers = new ArrayList<>();

@Comment(value = "In blocks, how far can the Enderman ability teleport?")
public int endermanAbilityTeleportDistance = 32;

Expand Down Expand Up @@ -338,6 +341,11 @@ public boolean enableSwaps() {
return enableSwaps;
}

@Override
public List<String> allowedSwappers() {
return allowedSwappers;
}

@Override
public int hostilityTime() {
return hostilityTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class IdentityForgeConfig extends IdentityConfig {
public int maxHealth = 20;
public boolean enableClientSwapMenu = true;
public boolean enableSwaps = true;
public List<String> allowedSwappers = new ArrayList<>();
public int endermanAbilityTeleportDistance = 32;
public boolean showPlayerNametag = false;
public boolean forceChangeNew = false;
Expand Down Expand Up @@ -279,6 +280,11 @@ public boolean enableSwaps() {
return enableSwaps;
}

@Override
public List<String> allowedSwappers() {
return allowedSwappers;
}

@Override
public int hostilityTime() {
return hostilityTime;
Expand Down
Loading