2019-08-23 22:49:00 +02:00
|
|
|
package com.griefdefender.command;
|
|
|
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
import com.griefdefender.GDPlayerData;
|
|
|
|
import com.griefdefender.GriefDefenderPlugin;
|
|
|
|
import com.griefdefender.cache.MessageCache;
|
2020-06-06 01:26:14 +02:00
|
|
|
import com.griefdefender.cache.PermissionHolderCache;
|
2019-08-23 22:49:00 +02:00
|
|
|
import com.griefdefender.configuration.MessageStorage;
|
2020-06-06 01:26:14 +02:00
|
|
|
import com.griefdefender.permission.GDPermissionUser;
|
2019-08-23 22:49:00 +02:00
|
|
|
import com.griefdefender.permission.GDPermissions;
|
|
|
|
import com.griefdefender.text.action.GDCallbackHolder;
|
|
|
|
|
|
|
|
import co.aikar.commands.BaseCommand;
|
|
|
|
import co.aikar.commands.annotation.CommandAlias;
|
|
|
|
import co.aikar.commands.annotation.CommandCompletion;
|
|
|
|
import co.aikar.commands.annotation.CommandPermission;
|
|
|
|
import co.aikar.commands.annotation.Description;
|
|
|
|
import co.aikar.commands.annotation.Subcommand;
|
|
|
|
import co.aikar.commands.annotation.Syntax;
|
|
|
|
import net.kyori.text.Component;
|
|
|
|
import net.kyori.text.TextComponent;
|
|
|
|
import net.kyori.text.adapter.bukkit.TextAdapter;
|
|
|
|
import net.kyori.text.event.ClickEvent;
|
|
|
|
import net.kyori.text.event.HoverEvent;
|
|
|
|
import net.kyori.text.format.TextColor;
|
|
|
|
|
|
|
|
@CommandAlias("%griefdefender")
|
|
|
|
@CommandPermission(GDPermissions.COMMAND_GIVE_BLOCKS)
|
|
|
|
public class CommandGiveBlocks extends BaseCommand {
|
|
|
|
|
|
|
|
@CommandCompletion("@gdplayers @gddummy")
|
|
|
|
@CommandAlias("giveblocks")
|
Update for 1.5.5 release.
* Add potion effects support.
* Add item enchantment support.
* Add pvp lookup methods for claim and playerdata.
* Add 'block-tileentity-id-list' used to override mod block id's that are used for many TE's.
- Ex. IC2 uses a base block id 'ic2:te' for all TE's. When the id is detected during block/item usage, it will be converted to the actual id.
* Add TileEntity registry to better support hybrid servers.
* Add '/claiminfo' UUID click support to copy text to chat.
* Add support for overriding option 'player-command-exit/enter' on player.
* Add command description translation support.
* Add zh_HK language support.
* Fix event cause not clearing on push.
* Fix abandon claim within town returning funds to owner in economy mode.
* Fix player afk detection during claim block task.
* Fix async chunk load during visual revert.
* Fix '/gd claim we' command.
* Fix advanced flag GUI toggle with definitions.
* Fix rent sign update not checking all children claims.
* Fix rent sign not being updated when cancelled via '/claimrent cancel'.
* Fix '/claimsell' on admin claim.
* Fix NPE when attempting to purchase an admin claim for sale.
* Fix command description translations.
* Fix isInvulnerable NPE on 1.8.8 servers.
* Fix '/abandonworld' exiting when no economy data found for player.
* Fix '/deletealladmin' only deleting admin claims in current world when passing no world argument.
* Fix '/claimcontract' and '/claimexpand' NPE in economy mode.
* Fix GD claim enter/exit prefix. The prefix will now use '[<playername>]'.
Note: This can be configured in lang file under 'claim-prefix-enter' and 'claim-prefix-exit'
* Clean up advanced flag GUI code.
* Disable /buyblocks command when economy-block-cost is <= 0
* Deny town claim abandon if basic claims exist owned by owner.
* Allow to input string as option value.
* Improve pvp source contexts.
* Clean up '/acb' command code.
* (Bukkit) Add potion splash protection support.
* (Bukkit) Fix tamed entities being hit by projectiles.
* (Bukkit) Fix enderman block place protection.
* (Hybrid) Fix wrong EnumCreatureType being registered for entities.
* (Hybrid) Add TileEntity registry.
* (Hybrid) Add mod command support for 'command-execute' flag.
* (Sponge) Add PlaceHolderAPI support.
* (Sponge) Add Nucleus v2 support.
* (Sponge) Add IgniteEntityEvent support.
* (Sponge) Fix '/cpp' and '/cpg' command.
* (Sponge) Fix player block placement deny not sending message.
Fixes #4
Fixes #200, Fixes #206, Fixes #222
Fixes #232, Fixes #237, Fixes #267
Fixes #269, Fixes #276, Fixes #296
Fixes #310, Fixes #311, Fixes #317
Fixes #324, Fixes #333, Fixes #334
Fixes #335, Fixes #336, Fixes #347
2020-12-28 23:28:12 +01:00
|
|
|
@Description("%player-give-blocks")
|
2019-08-23 22:49:00 +02:00
|
|
|
@Syntax("<player> <amount>")
|
|
|
|
@Subcommand("giveblocks")
|
|
|
|
public void execute(Player src, OfflinePlayer targetPlayer, int amount) {
|
2020-02-16 21:35:30 +01:00
|
|
|
if (amount <= 0) {
|
2020-06-06 01:26:14 +02:00
|
|
|
TextAdapter.sendComponent(src, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.COMMAND_INVALID_AMOUNT,
|
|
|
|
ImmutableMap.of("amount", TextComponent.of(amount, TextColor.GOLD))));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (targetPlayer.getUniqueId().equals(src.getUniqueId())) {
|
|
|
|
TextAdapter.sendComponent(src, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.COMMAND_INVALID_PLAYER,
|
|
|
|
ImmutableMap.of("player", TextComponent.of(src.getName(), TextColor.GOLD))));
|
2020-02-16 21:35:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-23 22:49:00 +02:00
|
|
|
final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(src.getWorld(), src.getUniqueId());
|
|
|
|
int availableBlocks = playerData.getAccruedClaimBlocks() + playerData.getBonusClaimBlocks();
|
|
|
|
if (amount > availableBlocks) {
|
|
|
|
TextAdapter.sendComponent(src, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.COMMAND_GIVEBLOCKS_NOT_ENOUGH,
|
|
|
|
ImmutableMap.of("amount", TextComponent.of(availableBlocks, TextColor.GOLD))));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-06 01:26:14 +02:00
|
|
|
final GDPermissionUser targetUser = PermissionHolderCache.getInstance().getOrCreateUser(targetPlayer);
|
|
|
|
if ((targetUser.getInternalPlayerData().getAccruedClaimBlocks() + amount) >= targetUser.getInternalPlayerData().getMaxAccruedClaimBlocks()) {
|
|
|
|
TextAdapter.sendComponent(src, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.PLAYER_ACCRUED_BLOCKS_EXCEEDED,
|
|
|
|
ImmutableMap.of(
|
|
|
|
"player", targetPlayer.getName(),
|
|
|
|
"total", targetUser.getInternalPlayerData().getAccruedClaimBlocks(),
|
|
|
|
"amount", amount)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-23 22:49:00 +02:00
|
|
|
final Component confirmationText = TextComponent.builder()
|
|
|
|
.append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.COMMAND_GIVEBLOCKS_CONFIRMATION,
|
|
|
|
ImmutableMap.of("player", TextComponent.of(targetPlayer.getName(), TextColor.AQUA),
|
|
|
|
"amount", TextComponent.of(amount, TextColor.GREEN))))
|
|
|
|
.append(TextComponent.builder()
|
|
|
|
.append("\n[")
|
2020-06-06 01:26:14 +02:00
|
|
|
.append(MessageCache.getInstance().LABEL_CONFIRM.color(TextColor.GREEN))
|
2019-08-23 22:49:00 +02:00
|
|
|
.append("]\n")
|
2020-06-06 01:26:14 +02:00
|
|
|
.clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(src, createConfirmationConsumer(src, targetUser, amount), true)))
|
2019-08-23 22:49:00 +02:00
|
|
|
.hoverEvent(HoverEvent.showText(MessageCache.getInstance().UI_CLICK_CONFIRM)).build())
|
|
|
|
.build();
|
|
|
|
TextAdapter.sendComponent(src, confirmationText);
|
|
|
|
}
|
|
|
|
|
2020-06-06 01:26:14 +02:00
|
|
|
private static Consumer<CommandSender> createConfirmationConsumer(Player src, GDPermissionUser targetUser, int amount) {
|
2019-08-23 22:49:00 +02:00
|
|
|
return confirm -> {
|
|
|
|
final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(src.getWorld(), src.getUniqueId());
|
|
|
|
final int accruedTotal = playerData.getAccruedClaimBlocks();
|
|
|
|
final int bonusTotal = playerData.getBonusClaimBlocks();
|
2020-06-06 01:26:14 +02:00
|
|
|
int availableBlocks = accruedTotal + bonusTotal;
|
|
|
|
if (amount > availableBlocks) {
|
|
|
|
TextAdapter.sendComponent(src, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.COMMAND_GIVEBLOCKS_NOT_ENOUGH,
|
|
|
|
ImmutableMap.of("amount", TextComponent.of(availableBlocks, TextColor.GOLD))));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((targetUser.getInternalPlayerData().getAccruedClaimBlocks() + amount) >= targetUser.getInternalPlayerData().getMaxAccruedClaimBlocks()) {
|
|
|
|
TextAdapter.sendComponent(src, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.PLAYER_ACCRUED_BLOCKS_EXCEEDED,
|
|
|
|
ImmutableMap.of(
|
|
|
|
"player", targetUser.getName(),
|
|
|
|
"total", targetUser.getInternalPlayerData().getAccruedClaimBlocks(),
|
|
|
|
"amount", amount)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-23 22:49:00 +02:00
|
|
|
if (bonusTotal >= amount) {
|
|
|
|
playerData.setBonusClaimBlocks(bonusTotal - amount);
|
|
|
|
} else if (accruedTotal >= amount) {
|
2020-06-06 01:26:14 +02:00
|
|
|
playerData.setAccruedClaimBlocks(accruedTotal - amount);
|
2019-08-23 22:49:00 +02:00
|
|
|
} else {
|
|
|
|
int remaining = amount - bonusTotal;
|
|
|
|
playerData.setBonusClaimBlocks(0);
|
|
|
|
int newAccrued = accruedTotal - remaining;
|
|
|
|
playerData.setAccruedClaimBlocks(newAccrued);
|
|
|
|
}
|
2020-06-06 01:26:14 +02:00
|
|
|
|
|
|
|
targetUser.getInternalPlayerData().setAccruedClaimBlocks(targetUser.getInternalPlayerData().getAccruedClaimBlocks() + amount);
|
2019-08-23 22:49:00 +02:00
|
|
|
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_GIVEBLOCKS_CONFIRMED);
|
|
|
|
TextAdapter.sendComponent(src, message);
|
|
|
|
|
2020-06-06 01:26:14 +02:00
|
|
|
if (targetUser.getOnlinePlayer() != null) {
|
2019-08-23 22:49:00 +02:00
|
|
|
final Component targetMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_GIVEBLOCKS_RECEIVED,
|
|
|
|
ImmutableMap.of("amount", TextComponent.of(amount, TextColor.GOLD),
|
2019-11-19 17:12:46 +01:00
|
|
|
"player", TextComponent.of(src.getName(), TextColor.AQUA)));
|
2020-06-06 01:26:14 +02:00
|
|
|
TextAdapter.sendComponent((Player) targetUser.getOnlinePlayer(), targetMessage);
|
2019-08-23 22:49:00 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|