added admin /re cancel command
This commit is contained in:
parent
2fd872d707
commit
b7eb449146
@ -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)
|
||||
{
|
||||
|
||||
@ -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())
|
||||
{
|
||||
|
||||
@ -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 +
|
||||
@ -214,13 +231,13 @@ public class ClaimLease extends BoughtTransaction
|
||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", the transaction has been cancelled.");
|
||||
}
|
||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||
{
|
||||
User u = RealEstate.ess.getUser(this.buyer);
|
||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||
{
|
||||
User u = RealEstate.ess.getUser(this.buyer);
|
||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||
"Couldn't pay the lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
|
||||
sign.getBlockX() + ", Y: " +
|
||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", the transaction has been cancelled.");
|
||||
}
|
||||
}
|
||||
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
||||
{
|
||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
||||
@ -230,30 +247,43 @@ public class ClaimLease extends BoughtTransaction
|
||||
ChatColor.AQUA + ", the transaction has been cancelled");
|
||||
}
|
||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||
{
|
||||
User u = RealEstate.ess.getUser(this.owner);
|
||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
||||
{
|
||||
User u = RealEstate.ess.getUser(this.owner);
|
||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
||||
ChatColor.AQUA + " couldn't pay lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
||||
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
||||
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)
|
||||
{
|
||||
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!");
|
||||
return false;
|
||||
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 leased, you can't cancel the transaction!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -222,15 +222,24 @@ public class ClaimRent extends BoughtTransaction
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryCancelTransaction(Player p)
|
||||
public boolean tryCancelTransaction(Player p, boolean force)
|
||||
{
|
||||
if(buyer != null)
|
||||
{
|
||||
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!");
|
||||
return false;
|
||||
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)
|
||||
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This " + (claim.parent == null ? "claim" : "subclaim") +
|
||||
" is currently rented, you can't cancel the transaction!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -68,4 +68,10 @@ public abstract class ClaimTransaction implements ConfigurationSerializable, Tra
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryCancelTransaction(Player p)
|
||||
{
|
||||
return this.tryCancelTransaction(p, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user