added /re seller command to change who is selling an admin claim

This commit is contained in:
EtienneDx 2019-07-31 17:26:15 +02:00
parent 96a50c1107
commit 2cff090309
6 changed files with 1292 additions and 1202 deletions

View File

@ -87,6 +87,55 @@ public class RECommand extends BaseCommand
}
}
@Subcommand("seller")
@Description("Displays or changes the seller of a claim (admin only)")
@Conditions("inPendingTransactionClaim")
public static void setSeller(Player player, @Optional String newSeller)
{
Location loc = player.getLocation();
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null);
Transaction tr = RealEstate.transactionsStore.getTransaction(claim);
if(!claim.isAdminClaim())
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This is not an admin claim");
}
else if(newSeller == null)
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "The seller of this claim is " +
ChatColor.GREEN + (tr.getOwner() == null ? "the server" : Bukkit.getPlayer(tr.getOwner()).getDisplayName()));
}
else if(!RealEstate.perms.has(player, "realestate.admin"))
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to change the seller");
}
else if(newSeller.equalsIgnoreCase("server"))
{
tr.setOwner(null);
tr.update();
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Changed the seller to the server");
}
else
{
Player newOwner = Bukkit.getPlayer(newSeller);
if(newOwner == null)
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Couldn't find this player (he may be offline)");
}
else if(!RealEstate.perms.has(newOwner, "realestate.admin"))
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"This player doesn't have the right to lease/rent/sell admin claims");
}
else
{
tr.setOwner(newOwner.getUniqueId());
tr.update();
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Changed the seller to " +
ChatColor.GREEN + newOwner.getDisplayName());
}
}
}
@Subcommand("exitoffer")
@Conditions("partOfBoughtTransaction")
public class ExitOfferCommand extends BaseCommand

View File

@ -181,7 +181,7 @@ public class REListener implements Listener
if(duration == 0)
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Couldn't read the date!\n" +
"Date must be formatted as follow" + ChatColor.GREEN + "10 weeks" + ChatColor.RED + " or " +
"Date must be formatted as follow : " + ChatColor.GREEN + "10 weeks" + ChatColor.RED + " or " +
ChatColor.GREEN + "3 days" + ChatColor.RED + " or " + ChatColor.GREEN + "1 week 3 days");
event.setCancelled(true);
event.getBlock().breakNaturally();
@ -370,7 +370,7 @@ public class REListener implements Listener
if(!RealEstate.transactionsStore.anyTransaction(claim))
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"This claim is no longer for rent or for sell, sorry...");
"This claim is no longer for rent, sell or lease, sorry...");
event.getClickedBlock().breakNaturally();
event.setCancelled(true);
return;
@ -396,11 +396,18 @@ public class REListener implements Listener
Transaction tr = RealEstate.transactionsStore.getTransaction(claim);
if(tr != null && event.getBlock().equals(tr.getHolder()))
{
if(event.getPlayer() != null && !tr.getOwner().equals(event.getPlayer().getUniqueId()) &&
if(event.getPlayer() != null && tr.getOwner() != null && !event.getPlayer().getUniqueId().equals(tr.getOwner()) &&
!RealEstate.perms.has(event.getPlayer(), "realestate.destroysigns"))
{
event.getPlayer().sendMessage(RealEstate.instance.config.chatPrefix +
ChatColor.RED + "Only the author of the sell/rent sign is allowed to destroy it");
ChatColor.RED + "Only the author of the sell/rent/lease sign is allowed to destroy it");
event.setCancelled(true);
return;
}
else if(event.getPlayer() != null && tr.getOwner() == null && !RealEstate.perms.has(event.getPlayer(), "realestate.admin"))
{
event.getPlayer().sendMessage(RealEstate.instance.config.chatPrefix +
ChatColor.RED + "Only an admin is allowed to destroy this sign");
event.setCancelled(true);
return;
}

View File

@ -108,6 +108,26 @@ public class RealEstate extends JavaPlugin
}
throw new ConditionFailedException("You must stand inside of a claim to use this command!");
});
manager.getCommandConditions().addCondition("inPendingTransactionClaim", (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 is neither to rent or to lease!");
}
else if(tr instanceof BoughtTransaction && ((BoughtTransaction)tr).getBuyer() != null)
{
throw new ConditionFailedException("This claim already has a buyer!");
}
});
manager.getCommandConditions().addCondition("inBoughtClaim", (context) -> {
if(!context.getIssuer().isPlayer())
{

View File

@ -60,4 +60,9 @@ public abstract class BoughtTransaction extends ClaimTransaction
{
return buyer;
}
public void setOwner(UUID newOwner)
{
this.owner = newOwner;
}
}

View File

@ -10,6 +10,8 @@ import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import net.md_5.bungee.api.ChatColor;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
@ -66,12 +68,12 @@ public class ClaimSell extends ClaimTransaction
}
String claimType = claim.parent == null ? "claim" : "subclaim";
if (owner.equals(player.getUniqueId()))
if (player.getUniqueId().equals(owner))
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
return;
}
if(claim.parent == null && !owner.equals(claim.ownerID))
if(claim.parent == null && owner != null && !owner.equals(claim.ownerID))
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
" does not have the right to sell this " + claimType + "!");
@ -176,4 +178,10 @@ public class ClaimSell extends ClaimTransaction
}
player.sendMessage(msg);
}
@Override
public void setOwner(UUID newOwner)
{
this.owner = newOwner;
}
}

View File

@ -9,6 +9,7 @@ public interface Transaction
{
public Block getHolder();
public UUID getOwner();
public void setOwner(UUID newOwner);
public void interact(Player player);
public void preview(Player player);
public void update();