2019-07-24 05:31:17 +02:00
|
|
|
/*
|
|
|
|
* This file is part of GriefDefender, licensed under the MIT License (MIT).
|
|
|
|
*
|
|
|
|
* Copyright (c) bloodmc
|
|
|
|
* Copyright (c) contributors
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
package com.griefdefender.command;
|
|
|
|
|
|
|
|
import co.aikar.commands.BaseCommand;
|
|
|
|
import co.aikar.commands.InvalidCommandArgument;
|
|
|
|
import co.aikar.commands.annotation.CommandAlias;
|
|
|
|
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 com.google.common.collect.ImmutableMap;
|
|
|
|
import com.griefdefender.GDPlayerData;
|
|
|
|
import com.griefdefender.GriefDefenderPlugin;
|
|
|
|
import com.griefdefender.api.claim.Claim;
|
2019-07-30 22:53:58 +02:00
|
|
|
import com.griefdefender.cache.MessageCache;
|
2019-07-24 05:31:17 +02:00
|
|
|
import com.griefdefender.claim.GDClaim;
|
|
|
|
import com.griefdefender.configuration.MessageStorage;
|
|
|
|
import com.griefdefender.permission.GDPermissions;
|
|
|
|
import com.griefdefender.text.action.GDCallbackHolder;
|
|
|
|
import net.kyori.text.Component;
|
|
|
|
import net.kyori.text.TextComponent;
|
|
|
|
import net.kyori.text.event.ClickEvent;
|
|
|
|
import net.kyori.text.format.TextColor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
@CommandAlias("%griefdefender")
|
|
|
|
@CommandPermission(GDPermissions.COMMAND_CLAIM_SELL)
|
|
|
|
public class CommandClaimSell extends BaseCommand {
|
|
|
|
|
|
|
|
@CommandAlias("claimsell")
|
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("%sell-claim")
|
2019-07-24 05:31:17 +02:00
|
|
|
@Syntax("<amount> | cancel")
|
|
|
|
@Subcommand("sell claim")
|
|
|
|
public void execute(Player player, String arg) throws InvalidCommandArgument {
|
|
|
|
// if economy is disabled, don't do anything
|
|
|
|
if (GriefDefenderPlugin.getInstance().getVaultProvider() == null) {
|
2019-07-30 22:53:58 +02:00
|
|
|
GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().ECONOMY_NOT_INSTALLED);
|
2019-07-24 05:31:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
|
|
|
|
final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(player.getLocation());
|
|
|
|
|
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
|
|
|
if (claim.isWilderness()) {
|
2019-07-30 22:53:58 +02:00
|
|
|
GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().ECONOMY_CLAIM_NOT_FOR_SALE);
|
2019-07-24 05:31:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if ((claim.isAdminClaim() && !playerData.canManageAdminClaims) || !claim.isAdminClaim() && !playerData.canIgnoreClaim(claim) && !player.getUniqueId().equals(claim.getOwnerUniqueId())) {
|
2019-07-30 22:53:58 +02:00
|
|
|
GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().PERMISSION_CLAIM_SALE);
|
2019-07-24 05:31:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Double salePrice = null;
|
|
|
|
if (arg.equalsIgnoreCase("cancel")) {
|
|
|
|
claim.getEconomyData().setForSale(false);
|
|
|
|
claim.getEconomyData().setSalePrice(-1);
|
2019-07-30 22:53:58 +02:00
|
|
|
GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().ECONOMY_CLAIM_SALE_CANCELLED);
|
2019-07-24 05:31:17 +02:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
salePrice = Double.parseDouble(arg);
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
throw new InvalidCommandArgument();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (salePrice == null || salePrice < 0) {
|
2019-07-27 07:30:09 +02:00
|
|
|
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ECONOMY_CLAIM_SALE_INVALID_PRICE,
|
|
|
|
ImmutableMap.of(
|
|
|
|
"amount", salePrice));
|
2019-07-24 05:31:17 +02:00
|
|
|
GriefDefenderPlugin.sendMessage(player, message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-27 07:30:09 +02:00
|
|
|
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ECONOMY_CLAIM_SALE_CONFIRMATION,
|
|
|
|
ImmutableMap.of(
|
|
|
|
"amount", salePrice));
|
2019-07-24 05:31:17 +02:00
|
|
|
GriefDefenderPlugin.sendMessage(player, message);
|
|
|
|
|
|
|
|
final Component saleConfirmationText = TextComponent.builder("")
|
|
|
|
.append("\n[")
|
2020-06-06 01:26:14 +02:00
|
|
|
.append(MessageCache.getInstance().LABEL_CONFIRM.color(TextColor.GREEN))
|
2019-07-24 05:31:17 +02:00
|
|
|
.append("]\n")
|
2020-06-06 01:26:14 +02:00
|
|
|
.clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(player, createSaleConfirmationConsumer(player, claim, salePrice), true)))
|
2019-07-24 05:31:17 +02:00
|
|
|
.build();
|
|
|
|
GriefDefenderPlugin.sendMessage(player, saleConfirmationText);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Consumer<CommandSender> createSaleConfirmationConsumer(CommandSender src, Claim claim, double price) {
|
|
|
|
return confirm -> {
|
|
|
|
claim.getEconomyData().setSalePrice(price);
|
|
|
|
claim.getEconomyData().setForSale(true);
|
|
|
|
claim.getData().save();
|
2019-07-27 07:30:09 +02:00
|
|
|
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ECONOMY_CLAIM_SALE_CONFIRMED,
|
|
|
|
ImmutableMap.of("amount", price));
|
|
|
|
GriefDefenderPlugin.sendMessage(src, message);
|
2019-07-24 05:31:17 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|