Skip to content

Commit

Permalink
Messages had a small error where someone accepting the offer to exit a
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Famous_Longwing authored and Famous_Longwing committed Feb 21, 2024
1 parent 051eef0 commit a18a886
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 33 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
</plugins>
</build>
<repositories>

<repository>
<id>enginehub-maven</id>
<url>https://maven.enginehub.org/repo/</url>
Expand Down Expand Up @@ -180,6 +181,7 @@
<version>7.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
Expand Down
2 changes: 1 addition & 1 deletion src/me/EtienneDx/RealEstate/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down
1 change: 1 addition & 0 deletions src/me/EtienneDx/RealEstate/RECommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 11 additions & 5 deletions src/me/EtienneDx/RealEstate/RealEstate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
77 changes: 51 additions & 26 deletions src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -92,14 +101,17 @@ 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) {

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))) {
Expand Down Expand Up @@ -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?
Expand All @@ -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();
}

Expand Down

0 comments on commit a18a886

Please sign in to comment.