added admin /re cancel command

This commit is contained in:
EtienneDx 2020-05-15 11:12:06 +02:00
parent 2fd872d707
commit b7eb449146
7 changed files with 99 additions and 24 deletions

View File

@ -304,6 +304,7 @@ public class RECommand extends BaseCommand
}
bt.exitOffer = null;
claim.dropPermission(bt.buyer.toString());
claim.managers.remove(bt.buyer.toString());
GriefPrevention.instance.dataStore.saveClaim(claim);
bt.buyer = null;
bt.update();// eventual cancel is contained in here
@ -399,6 +400,17 @@ public class RECommand extends BaseCommand
}
}
@Subcommand("cancel")
@Conditions("claimHasTransaction")
@CommandPermission("realestate.admin")
public static void cancelTransaction(Player player)
{
Location loc = player.getLocation();
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null);
Transaction t = RealEstate.transactionsStore.getTransaction(claim);
t.tryCancelTransaction(player, true);
}
@HelpCommand
public static void onHelp(CommandSender sender, CommandHelp help)
{

View File

@ -108,6 +108,22 @@ public class RealEstate extends JavaPlugin
}
throw new ConditionFailedException("You must stand inside of a claim to use this command!");
});
manager.getCommandConditions().addCondition("claimHasTransaction", (context) -> {
if(!context.getIssuer().isPlayer())
{
throw new ConditionFailedException("Only Players can perform this command!");
}
Claim c = GriefPrevention.instance.dataStore.getClaimAt(context.getIssuer().getPlayer().getLocation(), false, null);
if(c == null)
{
throw new ConditionFailedException("You must stand inside of a claim to use this command!");
}
Transaction tr = transactionsStore.getTransaction(c);
if(tr == null)
{
throw new ConditionFailedException("This claim has no ongoing transactions!");
}
});
manager.getCommandConditions().addCondition("inPendingTransactionClaim", (context) -> {
if(!context.getIssuer().isPlayer())
{

View File

@ -206,6 +206,23 @@ public class ClaimLease extends BoughtTransaction
}
else
{
this.exitLease();
}
// no need to re update, since there's no sign
RealEstate.transactionsStore.saveData();
}
private void exitLease()
{
if(buyer != null)
{
OfflinePlayer buyerPlayer = Bukkit.getOfflinePlayer(buyer);
OfflinePlayer seller = owner == null ? null : Bukkit.getOfflinePlayer(owner);
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
String claimType = claim.parent == null ? "claim" : "subclaim";
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
{
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
@ -238,23 +255,36 @@ public class ClaimLease extends BoughtTransaction
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
ChatColor.AQUA + ", the transaction has been cancelled");
}
RealEstate.transactionsStore.cancelTransaction(this);
claim.managers.remove(buyer.toString());
claim.dropPermission(buyer.toString());
}
// no need to re update, since there's no sign
RealEstate.transactionsStore.saveData();
else
{
getHolder().breakNaturally();// the sign should still be there since the lease has netver begun
}
RealEstate.transactionsStore.cancelTransaction(this);
}
@Override
public boolean tryCancelTransaction(Player p)
public boolean tryCancelTransaction(Player p, boolean force)
{
if(buyer != null)
{
if(p.hasPermission("realestate.admin") && force == true)
{
this.exitLease();
return true;
}
else
{
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
if(p != null)
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This " + (claim.parent == null ? "claim" : "subclaim") +
" is currently rented, you can't cancel the transaction!");
" is currently leased, you can't cancel the transaction!");
return false;
}
}
else
{
RealEstate.transactionsStore.cancelTransaction(this);

View File

@ -222,9 +222,17 @@ public class ClaimRent extends BoughtTransaction
}
@Override
public boolean tryCancelTransaction(Player p)
public boolean tryCancelTransaction(Player p, boolean force)
{
if(buyer != null)
{
if(p.hasPermission("realestate.admin") && force == true)
{
this.unRent(true);
RealEstate.transactionsStore.cancelTransaction(this);
return true;
}
else
{
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
if(p != null)
@ -232,6 +240,7 @@ public class ClaimRent extends BoughtTransaction
" is currently rented, you can't cancel the transaction!");
return false;
}
}
else
{
RealEstate.transactionsStore.cancelTransaction(this);

View File

@ -58,8 +58,9 @@ public class ClaimSell extends ClaimTransaction
}
@Override
public boolean tryCancelTransaction(Player p)
public boolean tryCancelTransaction(Player p, boolean force)
{
// nothing special here, this transaction can only be waiting for a buyer
RealEstate.transactionsStore.cancelTransaction(this);
return true;
}

View File

@ -68,4 +68,10 @@ public abstract class ClaimTransaction implements ConfigurationSerializable, Tra
{
return owner;
}
@Override
public boolean tryCancelTransaction(Player p)
{
return this.tryCancelTransaction(p, false);
}
}

View File

@ -15,5 +15,6 @@ public interface Transaction
public void preview(Player player);
public boolean update();
public boolean tryCancelTransaction(Player p);
public boolean tryCancelTransaction(Player p, boolean force);
public void msgInfo(CommandSender cs);
}