clean ups
This commit is contained in:
parent
ab567278ee
commit
5855f02480
@ -105,7 +105,7 @@ public class PermissionRegistry {
|
|||||||
|
|
||||||
public static ClaimPermission get(String id) {
|
public static ClaimPermission get(String id) {
|
||||||
if (!permissions.containsKey(id))
|
if (!permissions.containsKey(id))
|
||||||
throw new NullPointerException("No such permission registered");
|
throw new NullPointerException("No such permission " + id + " registered");
|
||||||
return permissions.get(id);
|
return permissions.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class Claim implements IPermissionContainer {
|
|||||||
|
|
||||||
private final ServerWorld world;
|
private final ServerWorld world;
|
||||||
|
|
||||||
private Map<StatusEffect, Integer> potions = new HashMap<>();
|
private final Map<StatusEffect, Integer> potions = new HashMap<>();
|
||||||
|
|
||||||
private Claim(ServerWorld world) {
|
private Claim(ServerWorld world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
@ -488,9 +488,7 @@ public class Claim implements IPermissionContainer {
|
|||||||
|
|
||||||
public void applyEffects(ServerPlayerEntity player) {
|
public void applyEffects(ServerPlayerEntity player) {
|
||||||
if (player.world.getTime() % 80 == 0)
|
if (player.world.getTime() % 80 == 0)
|
||||||
this.potions.forEach((effect, amp) -> {
|
this.potions.forEach((effect, amp) -> player.applyStatusEffect(new StatusEffectInstance(effect, 200, amp - 1, true, false)));
|
||||||
player.applyStatusEffect(new StatusEffectInstance(effect, 200, amp - 1, true, false));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockPos getHomePos() {
|
public BlockPos getHomePos() {
|
||||||
|
@ -179,26 +179,22 @@ public class CommandClaim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int openMenu(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
private static int openMenu(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||||
try {
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
PlayerClaimData data = PlayerClaimData.get(player);
|
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
||||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
if (claim == null) {
|
||||||
if (claim == null) {
|
PermHelper.noClaimMessage(player);
|
||||||
PermHelper.noClaimMessage(player);
|
return 0;
|
||||||
return 0;
|
}
|
||||||
}
|
if (data.getEditMode() == EnumEditMode.DEFAULT) {
|
||||||
if (data.getEditMode() == EnumEditMode.DEFAULT) {
|
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
||||||
|
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||||
|
} else {
|
||||||
|
Claim sub = claim.getSubClaim(player.getBlockPos());
|
||||||
|
if (sub != null)
|
||||||
|
ClaimMenuScreenHandler.openClaimMenu(player, sub);
|
||||||
|
else
|
||||||
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
||||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
|
||||||
} else {
|
|
||||||
Claim sub = claim.getSubClaim(player.getBlockPos());
|
|
||||||
if (sub != null)
|
|
||||||
ClaimMenuScreenHandler.openClaimMenu(player, sub);
|
|
||||||
else
|
|
||||||
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -476,7 +472,7 @@ public class CommandClaim {
|
|||||||
}
|
}
|
||||||
players.add(prof.getName());
|
players.add(prof.getName());
|
||||||
}
|
}
|
||||||
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.adminDeleteAll, players.toString()), Formatting.GOLD), true);
|
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.adminDeleteAll, players), Formatting.GOLD), true);
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,7 +521,7 @@ public class CommandClaim {
|
|||||||
PlayerClaimData.editForOfflinePlayer(src.getMinecraftServer(), prof.getId(), amount);
|
PlayerClaimData.editForOfflinePlayer(src.getMinecraftServer(), prof.getId(), amount);
|
||||||
players.add(prof.getName());
|
players.add(prof.getName());
|
||||||
}
|
}
|
||||||
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.giveClaimBlocks, players.toString(), amount), Formatting.GOLD), true);
|
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.giveClaimBlocks, players, amount), Formatting.GOLD), true);
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ import net.minecraft.text.MutableText;
|
|||||||
import net.minecraft.text.Style;
|
import net.minecraft.text.Style;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -27,7 +26,6 @@ public class CommandHelp {
|
|||||||
|
|
||||||
public static int helpMessage(CommandContext<ServerCommandSource> context, int page, Collection<CommandNode<ServerCommandSource>> nodes) {
|
public static int helpMessage(CommandContext<ServerCommandSource> context, int page, Collection<CommandNode<ServerCommandSource>> nodes) {
|
||||||
List<String> subCommands = registeredCommands(context, nodes);
|
List<String> subCommands = registeredCommands(context, nodes);
|
||||||
subCommands.forEach(s -> System.out.println(Arrays.toString(ConfigHandler.lang.cmdLang.getCommandHelp(s))));
|
|
||||||
int max = subCommands.size() / 8;
|
int max = subCommands.size() / 8;
|
||||||
if (page > max)
|
if (page > max)
|
||||||
page = max;
|
page = max;
|
||||||
|
@ -237,7 +237,7 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean globallyDefined(ServerWorld world, ClaimPermission perm) {
|
public boolean globallyDefined(ServerWorld world, ClaimPermission perm) {
|
||||||
return !getGlobal(world, perm).canModify();
|
return !this.getGlobal(world, perm).canModify();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GlobalType getGlobal(ServerWorld world, ClaimPermission perm) {
|
public GlobalType getGlobal(ServerWorld world, ClaimPermission perm) {
|
||||||
|
@ -7,7 +7,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class LangCommands {
|
public class LangCommands {
|
||||||
|
|
||||||
private Map<String, String[]> commands = Config.createHashMap(map -> {
|
private final Map<String, String[]> commands = Config.createHashMap(map -> {
|
||||||
map.put("help", new String[]{"help <page> | (cmd <command>)", "Shows all available commands or info for the given command."});
|
map.put("help", new String[]{"help <page> | (cmd <command>)", "Shows all available commands or info for the given command."});
|
||||||
map.put("menu", new String[]{"menu", "When standing in a claim you have permissions for opens the claim menu."});
|
map.put("menu", new String[]{"menu", "When standing in a claim you have permissions for opens the claim menu."});
|
||||||
map.put("claimInfo", new String[]{"claimInfo", "Prints infos about the claim you're standing in."});
|
map.put("claimInfo", new String[]{"claimInfo", "Prints infos about the claim you're standing in."});
|
||||||
|
@ -66,9 +66,9 @@ public class ItemInteractEvents {
|
|||||||
|
|
||||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||||
BlockPos pos = player.getBlockPos();
|
BlockPos pos = player.getBlockPos();
|
||||||
HitResult hitResult = IItemAccessor.getRaycast(world, player, RaycastContext.FluidHandling.SOURCE_ONLY);
|
BlockHitResult hitResult = IItemAccessor.getRaycast(world, player, RaycastContext.FluidHandling.SOURCE_ONLY);
|
||||||
if (hitResult.getType() == HitResult.Type.BLOCK) {
|
if (hitResult.getType() == HitResult.Type.BLOCK) {
|
||||||
pos = new ItemPlacementContext(player, hand, stack, (BlockHitResult) hitResult).getBlockPos();
|
pos = new ItemPlacementContext(player, hand, stack, hitResult).getBlockPos();
|
||||||
}
|
}
|
||||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||||
if (claim == null)
|
if (claim == null)
|
||||||
|
@ -41,7 +41,6 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup>
|
|||||||
});
|
});
|
||||||
this.claim = claim;
|
this.claim = claim;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.page = page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openClaimMenu(PlayerEntity player, Claim claim, String group) {
|
public static void openClaimMenu(PlayerEntity player, Claim claim, String group) {
|
||||||
|
@ -32,7 +32,6 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
|||||||
private PersonalPermissionScreenHandler(int syncId, PlayerInventory playerInventory, String group) {
|
private PersonalPermissionScreenHandler(int syncId, PlayerInventory playerInventory, String group) {
|
||||||
super(syncId, playerInventory, 6, group);
|
super(syncId, playerInventory, 6, group);
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.page = page;
|
|
||||||
this.player = playerInventory.player;
|
this.player = playerInventory.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +77,7 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
|||||||
int row = i / 9 - 1;
|
int row = i / 9 - 1;
|
||||||
int id = (i % 9) + row * 7 - 1 + page * 28;
|
int id = (i % 9) + row * 7 - 1 + page * 28;
|
||||||
if (id < perms.size())
|
if (id < perms.size())
|
||||||
inv.setStack(i, ServerScreenHelper.getFromPersonal((ServerPlayerEntity) player, perms.get(id), group == null ? null : group));
|
inv.setStack(i, ServerScreenHelper.getFromPersonal((ServerPlayerEntity) player, perms.get(id), group));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +149,7 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerClaimData data = PlayerClaimData.get(player);
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
Map<ClaimPermission, Boolean> perms = data.playerDefaultGroups().getOrDefault(group, new HashMap<>());
|
Map<ClaimPermission, Boolean> perms = data.playerDefaultGroups().getOrDefault(this.group, new HashMap<>());
|
||||||
boolean success = data.editDefaultPerms(this.group, perm, (perms.containsKey(perm) ? perms.get(perm) ? 1 : 0 : -1) + 1);
|
boolean success = data.editDefaultPerms(this.group, perm, (perms.containsKey(perm) ? perms.get(perm) ? 1 : 0 : -1) + 1);
|
||||||
slot.setStack(ServerScreenHelper.getFromPersonal(player, perm, this.group));
|
slot.setStack(ServerScreenHelper.getFromPersonal(player, perm, this.group));
|
||||||
if (success)
|
if (success)
|
||||||
|
@ -156,7 +156,7 @@ public class ClaimDisplay {
|
|||||||
state = world.getBlockState(pos);
|
state = world.getBlockState(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int[] yRet = new int[]{pos.getY(), pos.getY()};
|
int[] yRet = {pos.getY(), pos.getY()};
|
||||||
if (state.getMaterial().isLiquid()) {
|
if (state.getMaterial().isLiquid()) {
|
||||||
pos = pos.up();
|
pos = pos.up();
|
||||||
state = world.getBlockState(pos);
|
state = world.getBlockState(pos);
|
||||||
|
@ -30,7 +30,6 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -62,8 +61,6 @@ public class PlayerClaimData implements IPlayerData {
|
|||||||
|
|
||||||
private final Map<String, Map<ClaimPermission, Boolean>> defaultGroups = new HashMap<>();
|
private final Map<String, Map<ClaimPermission, Boolean>> defaultGroups = new HashMap<>();
|
||||||
|
|
||||||
private Date lastOnline;
|
|
||||||
|
|
||||||
public PlayerClaimData(ServerPlayerEntity player) {
|
public PlayerClaimData(ServerPlayerEntity player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.claimBlocks = ConfigHandler.config.startingBlocks;
|
this.claimBlocks = ConfigHandler.config.startingBlocks;
|
||||||
|
@ -19,7 +19,6 @@ public class PermissionCheckEvent extends Event {
|
|||||||
* @param player The corresponding player. Can be null if the check is e.g. caused by tnt explosions
|
* @param player The corresponding player. Can be null if the check is e.g. caused by tnt explosions
|
||||||
* @param permission The permission to check
|
* @param permission The permission to check
|
||||||
* @param pos The block pos where the action is occuring
|
* @param pos The block pos where the action is occuring
|
||||||
* @return ActionResult#PASS to do nothing. ActionResult#FAIL to prevent the action. Else to allow the action
|
|
||||||
*/
|
*/
|
||||||
public PermissionCheckEvent(ServerPlayerEntity player, ClaimPermission permission, BlockPos pos) {
|
public PermissionCheckEvent(ServerPlayerEntity player, ClaimPermission permission, BlockPos pos) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -27,6 +26,9 @@ public class PermissionCheckEvent extends Event {
|
|||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ActionResult#PASS to do nothing. ActionResult#FAIL to prevent the action. Else to allow the action
|
||||||
|
*/
|
||||||
public ActionResult getActionResult() {
|
public ActionResult getActionResult() {
|
||||||
return this.result;
|
return this.result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user