From a18a88616ce4ac730e6bffb4aaa33bfd65e1f52b Mon Sep 17 00:00:00 2001 From: Famous_Longwing Date: Wed, 21 Feb 2024 13:49:06 -0500 Subject: [PATCH] Messages had a small error where someone accepting the offer to exit a contract early would *say* the land lord paid, when the tennant was paying Removed CoreProtect as a soft-depend as it does not appear to actually do what I need. Updated the "Self cleaning" rentals so that broken blocks do not restore themselves upon breaking the rental agreement. The plugin will restore *only* air, so new structures will be destroyed, unless they occupy a block that was already present (replacing a dirt block with a chest will result in the chest remaining when the agreement breaks). --- plugin.yml | 2 +- pom.xml | 2 + src/me/EtienneDx/RealEstate/Messages.java | 2 +- src/me/EtienneDx/RealEstate/RECommand.java | 1 + src/me/EtienneDx/RealEstate/RealEstate.java | 16 ++-- .../RealEstate/Transactions/ClaimRent.java | 77 ++++++++++++------- 6 files changed, 67 insertions(+), 33 deletions(-) diff --git a/plugin.yml b/plugin.yml index 558552d..a45972d 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,7 @@ main: me.EtienneDx.RealEstate.RealEstate version: ${project.version} authors: [EtienneDx, DmitryRendov, FamousLongwing] depend: [Vault, GriefPrevention] -softdepend: [WorldEdit, CoreProtect] +softdepend: [WorldEdit] api-version: "1.20" commands: diff --git a/pom.xml b/pom.xml index 2949768..c6a28a8 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,7 @@ + enginehub-maven https://maven.enginehub.org/repo/ @@ -180,6 +181,7 @@ 7.2.0-SNAPSHOT provided + diff --git a/src/me/EtienneDx/RealEstate/Messages.java b/src/me/EtienneDx/RealEstate/Messages.java index 8132e30..95c7667 100644 --- a/src/me/EtienneDx/RealEstate/Messages.java +++ b/src/me/EtienneDx/RealEstate/Messages.java @@ -283,7 +283,7 @@ public class Messages extends AnnotationConfig public String msgInfoExitOfferCreatedByOther = "$a{0} $bhas created an offer to exit the transaction for the {1} at $a{3} $bfor $a{2}"; @ConfigField(name="RealEstate.Info.ExitOffer.AcceptedBySelf", comment = "0: claim type, 1:formatted price") - public String msgInfoExitOfferAcceptedBySelf = "$bThe {0} is no longer rented or leased, you have been charged $a{1}"; + public String msgInfoExitOfferAcceptedBySelf = "$bThe {0} is no longer rented or leased, you have been paid $a{1}"; @ConfigField(name="RealEstate.Info.ExitOffer.AcceptedByOther", comment = "0: player name, 1: claim type, 2: formatted price, 3: claim location") public String msgInfoExitOfferAcceptedByOther = "$a{0} $bhas accepted the offer to exit the transaction for the {1} at $a{3} $bfor $a{2}. It is no longer leased or rented."; diff --git a/src/me/EtienneDx/RealEstate/RECommand.java b/src/me/EtienneDx/RealEstate/RECommand.java index 9263537..e9cc9e8 100644 --- a/src/me/EtienneDx/RealEstate/RECommand.java +++ b/src/me/EtienneDx/RealEstate/RECommand.java @@ -309,6 +309,7 @@ else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null) claim.dropPermission(bt.buyer.toString()); claim.managers.remove(bt.buyer.toString()); GriefPrevention.instance.dataStore.saveClaim(claim); + ClaimRent.restore_rental(claim); bt.buyer = null; bt.update();// eventual cancel is contained in here } diff --git a/src/me/EtienneDx/RealEstate/RealEstate.java b/src/me/EtienneDx/RealEstate/RealEstate.java index 4463f6b..d7ba6aa 100644 --- a/src/me/EtienneDx/RealEstate/RealEstate.java +++ b/src/me/EtienneDx/RealEstate/RealEstate.java @@ -88,13 +88,19 @@ public void onEnable() return; } } - if (checkWorldEdit()) - { - org.bukkit.plugin.Plugin WorldEditPlugin=getServer().getPluginManager().getPlugin("WorldEdit"); - this.log.info("Found WorldEdit, using version "+WorldEditPlugin.getDescription().getVersion()); + if (checkWorldEdit()) + { + org.bukkit.plugin.Plugin WorldEditPlugin=getServer().getPluginManager().getPlugin("WorldEdit"); + this.log.info("Found WorldEdit, using version "+WorldEditPlugin.getDescription().getVersion()); - } + } + if(getServer().getPluginManager().getPlugin("CoreProtect")!=null) + { + org.bukkit.plugin.Plugin cp=getServer().getPluginManager().getPlugin("CoreProtect"); + this.log.info("Found CoreProtect, using version"+cp.getDescription().getVersion()); + + } if(getServer().getPluginManager().getPlugin("Essentials") != null) { org.bukkit.plugin.Plugin ess=getServer().getPluginManager().getPlugin("Essentials"); diff --git a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java index 9656567..7fa7114 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java +++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java @@ -9,10 +9,13 @@ import java.time.LocalTime; import java.time.Period; import java.time.format.DateTimeFormatter; +import java.util.Collection; +import java.util.HashSet; import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.block.Sign; import org.bukkit.command.CommandSender; @@ -30,12 +33,18 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; +import com.sk89q.worldedit.function.mask.BlockTypeMask; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; +import com.sk89q.worldedit.world.block.BlockCategory; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; import me.EtienneDx.RealEstate.Messages; import me.EtienneDx.RealEstate.RealEstate; @@ -92,6 +101,10 @@ public ClaimRent(Claim claim, Player player, double price, Location sign, int du com.sk89q.worldedit.world.World adaptedworld= BukkitAdapter.adapt(lesser.getWorld()); EditSession editSession=WorldEdit.getInstance().newEditSession(adaptedworld); ForwardExtentCopy CopyArea=new ForwardExtentCopy(editSession,region,clipboard,region.getMinimumPoint()); + CopyArea.setCopyingEntities(false); + + + try { Operations.complete(CopyArea); } catch (WorldEditException e) { @@ -99,7 +112,6 @@ public ClaimRent(Claim claim, Player player, double price, Location sign, int du RealEstate.instance.log.info("Failed to copy rental area, WorldEdit gives error: "+e.getMessage()); } - String schempath = RealEstate.pluginDirPath + "/schematics/"+claim.getID().toString()+".schem"; File file = new File(schempath); try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) { @@ -215,28 +227,10 @@ else if(sign.getBlock().getState() instanceof Sign) } - private void unRent(boolean msgBuyer) + public static void restore_rental(Claim claim) { - Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null); - claim.dropPermission(buyer.toString()); - claim.managers.remove(buyer.toString()); - claim.setSubclaimRestrictions(false); - GriefPrevention.instance.dataStore.saveClaim(claim); - if(msgBuyer && Bukkit.getOfflinePlayer(buyer).isOnline() && RealEstate.instance.config.cfgMessageBuyer) - { - String location = "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + - sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]"; - String claimType = claim.parent == null ? - RealEstate.instance.messages.keywordClaim : - RealEstate.instance.messages.keywordSubclaim; - - Messages.sendMessage(Bukkit.getPlayer(buyer), RealEstate.instance.messages.msgInfoClaimInfoRentCancelled, - claimType, - location); - } - buyer = null; - RealEstate.transactionsStore.saveData(); - //if worldedit saving is requested, here's where i load the saved area + + //if worldedit saving is requested, here's where I load the saved area if((claim.isAdminClaim()&&RealEstate.instance.config.RestoreAdminOnly)|| !RealEstate.instance.config.RestoreAdminOnly) //if we are in an admin claim *and* admin only is selected, or if admin only is false { if(RealEstate.instance.getServer().getPluginManager().getPlugin("WorldEdit")!=null) //is world edit installed? @@ -254,30 +248,61 @@ private void unRent(boolean msgBuyer) catch (Exception e) { RealEstate.instance.log.info("Failed to import previously saved schematic: "+e.getMessage()); - update(); + return; } Location lesser=claim.getLesserBoundaryCorner(); - + + com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(lesser.getWorld()); + try (EditSession editSession = WorldEdit.getInstance().newEditSession(world)) { + + + + BlockType air=new BlockType("minecraft:air");//we want to capture all the air from the saved schematic, to empty out the space that used to be empty + BlockTypeMask mask= new BlockTypeMask(clipboard,air);//create a mask, specifying we want to keep just the air from the schematic Operation operation = new ClipboardHolder(clipboard) .createPaste(editSession) .to(BlockVector3.at(lesser.getX(), lesser.getWorld().getMinHeight(), lesser.getZ())) - // configure here + .maskSource(mask)//ignore non-air blocks from the schematic. + .ignoreAirBlocks(false) //well that would be silly, we want the air .build(); Operations.complete(operation); } catch(Exception e) { RealEstate.instance.log.info("Failed to paste initial schematic: "+e.getMessage()); - update(); return; } } + } } + } + private void unRent(boolean msgBuyer) + { + Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null); + claim.dropPermission(buyer.toString()); + claim.managers.remove(buyer.toString()); + claim.setSubclaimRestrictions(false); + GriefPrevention.instance.dataStore.saveClaim(claim); + if(msgBuyer && Bukkit.getOfflinePlayer(buyer).isOnline() && RealEstate.instance.config.cfgMessageBuyer) + { + String location = "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]"; + String claimType = claim.parent == null ? + RealEstate.instance.messages.keywordClaim : + RealEstate.instance.messages.keywordSubclaim; + + Messages.sendMessage(Bukkit.getPlayer(buyer), RealEstate.instance.messages.msgInfoClaimInfoRentCancelled, + claimType, + location); + } + buyer = null; + RealEstate.transactionsStore.saveData(); + ClaimRent.restore_rental(claim); update(); }