change gui data to generics so its safer
This commit is contained in:
parent
5c4af308bb
commit
2d3108f4c5
@ -0,0 +1,10 @@
|
||||
package io.github.flemmli97.flan.gui;
|
||||
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
|
||||
interface ClaimGroup {
|
||||
|
||||
Claim getClaim();
|
||||
|
||||
String getGroup();
|
||||
}
|
@ -20,7 +20,7 @@ import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
|
||||
private final Claim claim;
|
||||
|
||||
@ -45,8 +45,7 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
|
||||
Claim claim = (Claim) additionalData[0];
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Claim claim) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
|
@ -16,12 +16,12 @@ import net.minecraft.util.Formatting;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ConfirmScreenHandler extends ServerOnlyScreenHandler {
|
||||
public class ConfirmScreenHandler extends ServerOnlyScreenHandler<Object> {
|
||||
|
||||
private final Consumer<Boolean> cons;
|
||||
|
||||
private ConfirmScreenHandler(int syncId, PlayerInventory playerInventory, Consumer<Boolean> cons) {
|
||||
super(syncId, playerInventory, 1);
|
||||
super(syncId, playerInventory, 1, null);
|
||||
this.cons = cons;
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ public class ConfirmScreenHandler extends ServerOnlyScreenHandler {
|
||||
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object additionalData) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
switch (i) {
|
||||
case 3:
|
||||
|
@ -22,14 +22,25 @@ import net.minecraft.util.Formatting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler {
|
||||
public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler<ClaimGroup> {
|
||||
|
||||
private final Claim claim;
|
||||
private final String group;
|
||||
private boolean removeMode;
|
||||
|
||||
private GroupPlayerScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim, String group) {
|
||||
super(syncId, playerInventory, 6, claim, group);
|
||||
super(syncId, playerInventory, 6, new ClaimGroup() {
|
||||
|
||||
@Override
|
||||
public Claim getClaim() {
|
||||
return claim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
});
|
||||
this.claim = claim;
|
||||
this.group = group;
|
||||
}
|
||||
@ -50,11 +61,9 @@ public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
|
||||
if (additionalData == null || additionalData.length < 2)
|
||||
return;
|
||||
Claim claim = (Claim) additionalData[0];
|
||||
List<String> players = claim.playersFromGroup(player.getServer(), (String) additionalData[1]);
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, ClaimGroup additionalData) {
|
||||
Claim claim = additionalData.getClaim();
|
||||
List<String> players = claim.playersFromGroup(player.getServer(), additionalData.getGroup());
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
|
@ -18,7 +18,7 @@ import net.minecraft.util.Formatting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupScreenHandler extends ServerOnlyScreenHandler {
|
||||
public class GroupScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
|
||||
private final Claim claim;
|
||||
|
||||
@ -45,10 +45,7 @@ public class GroupScreenHandler extends ServerOnlyScreenHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
|
||||
if (additionalData == null)
|
||||
return;
|
||||
Claim claim = (Claim) additionalData[0];
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Claim claim) {
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
|
@ -21,14 +21,24 @@ import net.minecraft.util.Formatting;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup> {
|
||||
|
||||
private final Claim claim;
|
||||
private final String group;
|
||||
private int page;
|
||||
|
||||
private PermissionScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim, String group, int page) {
|
||||
super(syncId, playerInventory, 6, claim, group, page);
|
||||
private PermissionScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim, String group) {
|
||||
super(syncId, playerInventory, 6, new ClaimGroup() {
|
||||
@Override
|
||||
public Claim getClaim() {
|
||||
return claim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
});
|
||||
this.claim = claim;
|
||||
this.group = group;
|
||||
this.page = page;
|
||||
@ -38,7 +48,7 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
return new PermissionScreenHandler(syncId, inv, claim, group, 0);
|
||||
return new PermissionScreenHandler(syncId, inv, claim, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,28 +59,13 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
player.openHandledScreen(fac);
|
||||
}
|
||||
|
||||
private static void openClaimMenu(PlayerEntity player, Claim claim, String group, int page) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
return new PermissionScreenHandler(syncId, inv, claim, group, page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
return PermHelper.simpleColoredText(group == null ? ConfigHandler.lang.screenGlobalPerms : String.format(ConfigHandler.lang.screenGroupPerms, group));
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, ClaimGroup additionalData) {
|
||||
List<ClaimPermission> perms = new ArrayList<>(PermissionRegistry.getPerms());
|
||||
if (this.group != null)
|
||||
perms.removeAll(PermissionRegistry.globalPerms());
|
||||
for (int i = 0; i < 54; i++) {
|
||||
int page = (int) additionalData[2];
|
||||
int page = 0;
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
@ -89,7 +84,7 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1 + page * 28;
|
||||
if (id < perms.size())
|
||||
inv.setStack(i, ServerScreenHelper.fromPermission((Claim) additionalData[0], perms.get(id), additionalData[1] == null ? null : additionalData[1].toString()));
|
||||
inv.setStack(i, ServerScreenHelper.fromPermission(additionalData.getClaim(), perms.get(id), additionalData.getGroup() == null ? null : additionalData.getGroup()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ import net.minecraft.util.Formatting;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PersonalGroupScreenHandler extends ServerOnlyScreenHandler {
|
||||
public class PersonalGroupScreenHandler extends ServerOnlyScreenHandler<Object> {
|
||||
|
||||
private boolean removeMode;
|
||||
|
||||
private PersonalGroupScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||
super(syncId, playerInventory, 6);
|
||||
super(syncId, playerInventory, 6, null);
|
||||
}
|
||||
|
||||
public static void openGroupMenu(PlayerEntity player) {
|
||||
@ -44,7 +44,7 @@ public class PersonalGroupScreenHandler extends ServerOnlyScreenHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object additionalData) {
|
||||
if (!(player instanceof ServerPlayerEntity))
|
||||
return;
|
||||
for (int i = 0; i < 54; i++) {
|
||||
|
@ -23,14 +23,14 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<String> {
|
||||
|
||||
private final String group;
|
||||
private int page;
|
||||
private final PlayerEntity player;
|
||||
|
||||
private PersonalPermissionScreenHandler(int syncId, PlayerInventory playerInventory, String group, int page) {
|
||||
super(syncId, playerInventory, 6, group, page);
|
||||
private PersonalPermissionScreenHandler(int syncId, PlayerInventory playerInventory, String group) {
|
||||
super(syncId, playerInventory, 6, group);
|
||||
this.group = group;
|
||||
this.page = page;
|
||||
this.player = playerInventory.player;
|
||||
@ -40,7 +40,7 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
return new PersonalPermissionScreenHandler(syncId, inv, group, 0);
|
||||
return new PersonalPermissionScreenHandler(syncId, inv, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,14 +52,14 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, String group) {
|
||||
if (!(player instanceof ServerPlayerEntity))
|
||||
return;
|
||||
List<ClaimPermission> perms = new ArrayList<>(PermissionRegistry.getPerms());
|
||||
if (this.group != null)
|
||||
perms.removeAll(PermissionRegistry.globalPerms());
|
||||
for (int i = 0; i < 54; i++) {
|
||||
int page = (int) additionalData[1];
|
||||
int page = 0;
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
@ -78,7 +78,7 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1 + page * 28;
|
||||
if (id < perms.size())
|
||||
inv.setStack(i, ServerScreenHelper.getFromPersonal((ServerPlayerEntity) player, perms.get(id), additionalData[0] == null ? null : additionalData[0].toString()));
|
||||
inv.setStack(i, ServerScreenHelper.getFromPersonal((ServerPlayerEntity) player, perms.get(id), group == null ? null : group));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PotionEditScreenHandler extends ServerOnlyScreenHandler {
|
||||
public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
|
||||
private final Claim claim;
|
||||
|
||||
@ -54,10 +54,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
|
||||
if (additionalData == null)
|
||||
return;
|
||||
Claim claim = (Claim) additionalData[0];
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Claim claim) {
|
||||
Map<StatusEffect, Integer> potions = claim.getPotions();
|
||||
List<StatusEffect> key = Lists.newArrayList(potions.keySet());
|
||||
key.sort(Comparator.comparing(CrossPlatformStuff::stringFromEffect));
|
||||
|
@ -16,12 +16,12 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ServerOnlyScreenHandler extends ScreenHandler {
|
||||
public abstract class ServerOnlyScreenHandler<T> extends ScreenHandler {
|
||||
|
||||
private final Inventory inventory;
|
||||
private final List<ScreenHandlerListener> listeners = new ArrayList<>();
|
||||
|
||||
protected ServerOnlyScreenHandler(int syncId, PlayerInventory playerInventory, int rows, Object... additionalData) {
|
||||
protected ServerOnlyScreenHandler(int syncId, PlayerInventory playerInventory, int rows, T additionalData) {
|
||||
super(fromRows(rows), syncId);
|
||||
int i = (rows - 4) * 18;
|
||||
this.inventory = new SimpleInventory(rows * 9);
|
||||
@ -61,7 +61,7 @@ public abstract class ServerOnlyScreenHandler extends ScreenHandler {
|
||||
return ScreenHandlerType.GENERIC_9X1;
|
||||
}
|
||||
|
||||
protected abstract void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData);
|
||||
protected abstract void fillInventoryWith(PlayerEntity player, Inventory inv, T additionalData);
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user