@Listener(order = Order.LATE) public void onMessageChannelEventChat(MessageChannelEvent.Chat event, @First Player player) { Builder playerTag = Text.builder().onHover(TextActions.showText(Text.of(player.getName()))); Optional<PlayerTag> optionalPlayerTag = PlayerTag.get(player); if (!optionalPlayerTag.isPresent()) { playerTag.append(PlayerTag.getDefault(player)); } else { playerTag.append(optionalPlayerTag.get().getTag()); } Text worldTag = Text.EMPTY; Optional<WorldTag> optionalWorldTag = WorldTag.get(player.getWorld().getProperties()); if (optionalWorldTag.isPresent()) { worldTag = optionalWorldTag.get().getTag(); } Builder groupTagBuilder = Text.builder(); for (Entry<Set<Context>, List<Subject>> parent : player.getSubjectData().getAllParents().entrySet()) { for (Subject subject : parent.getValue()) { String group = subject.getIdentifier(); if (group.equalsIgnoreCase("op_0") || group.equalsIgnoreCase("op_1") || group.equalsIgnoreCase("op_2") || group.equalsIgnoreCase("op_3") || group.equalsIgnoreCase("op_4")) { group = "op"; } Optional<GroupTag> optionalGroupTag = GroupTag.get(group); if (optionalGroupTag.isPresent()) { groupTagBuilder.append(optionalGroupTag.get().getTag()); } } } MessageFormatter formatter = event.getFormatter(); String oldStr = TextSerializers.FORMATTING_CODE.serialize(formatter.getHeader().toText()); String name = oldStr.substring(oldStr.indexOf("<"), oldStr.lastIndexOf(">") + 1); Text old = TextSerializers.FORMATTING_CODE.deserialize(oldStr.replace(name, "")); formatter.setHeader( TextTemplate.of( worldTag, groupTagBuilder.build(), playerTag.build(), old, TextColors.RESET)); }
@Override public CommandResult execute(CommandSource src, CommandContext ctx) { Player player; try { player = GriefPrevention.checkPlayer(src); } catch (CommandException e) { src.sendMessage(e.getText()); return CommandResult.success(); } // which claim is being abandoned? PlayerData playerData = GriefPrevention.instance.dataStore.getOrCreatePlayerData( player.getWorld(), player.getUniqueId()); Claim claim = GriefPrevention.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation(), true); UUID ownerId = claim.ownerID; if (claim.parent != null) { ownerId = claim.parent.ownerID; } if (claim.isWildernessClaim()) { GriefPrevention.sendMessage(player, TextMode.Instr, Messages.AbandonClaimMissing); return CommandResult.success(); } else if (claim.allowEdit(player) != null || (!claim.isAdminClaim() && !player.getUniqueId().equals(ownerId))) { // verify ownership GriefPrevention.sendMessage(player, TextMode.Err, Messages.NotYourClaim); return CommandResult.success(); } // warn if has children and we're not explicitly deleting a top level claim else if (claim.children.size() > 0 && !deleteTopLevelClaim) { GriefPrevention.sendMessage(player, TextMode.Instr, Messages.DeleteTopLevelClaim); return CommandResult.empty(); } else { // delete it claim.removeSurfaceFluids(null); // remove all context permissions player.getSubjectData().clearPermissions(ImmutableSet.of(claim.getContext())); GriefPrevention.GLOBAL_SUBJECT .getSubjectData() .clearPermissions(ImmutableSet.of(claim.getContext())); GriefPrevention.instance.dataStore.deleteClaim(claim, true); // if in a creative mode world, restore the claim area if (GriefPrevention.instance.claimModeIsActive( claim.getLesserBoundaryCorner().getExtent().getProperties(), ClaimsMode.Creative)) { GriefPrevention.addLogEntry( player.getName() + " abandoned a claim @ " + GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner())); GriefPrevention.sendMessage(player, TextMode.Warn, Messages.UnclaimCleanupWarning); GriefPrevention.instance.restoreClaim(claim, 20L * 60 * 2); } // this prevents blocks being gained without spending adjust claim blocks when abandoning a // top level claim if (!claim.isSubdivision() && !claim.isAdminClaim()) { int newAccruedClaimCount = playerData.getAccruedClaimBlocks() - ((int) Math.ceil(claim.getArea() * (1 - playerData.optionAbandonReturnRatio))); playerData.setAccruedClaimBlocks(newAccruedClaimCount); } // tell the player how many claim blocks he has left int remainingBlocks = playerData.getRemainingClaimBlocks(); GriefPrevention.sendMessage( player, TextMode.Success, Messages.AbandonSuccess, String.valueOf(remainingBlocks)); // revert any current visualization playerData.revertActiveVisual(player); playerData.warnedAboutMajorDeletion = false; } return CommandResult.success(); }