Skip to content

Commit

Permalink
added CoreProtect as a soft depend in preperation for next step of
Browse files Browse the repository at this point in the history
self-cleaning rentals.

Set rental self-cleaning for admin-only claims to start with, must be
enabled for regular players.
  • Loading branch information
Famous_Longwing authored and Famous_Longwing committed Feb 20, 2024
1 parent ae476fd commit 051eef0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 63 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]
softdepend: [WorldEdit, CoreProtect]
api-version: "1.20"

commands:
Expand Down
7 changes: 6 additions & 1 deletion src/me/EtienneDx/RealEstate/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ public class Config extends AnnotationConfig
@ConfigField(name="RealEstate.Settings.MessagesFiles", comment="Language file to be used. You can see all languages files in the languages directory. If the language file does not exist, it will be created and you'll be able to modify it later on.")
public String languageFile = "en.yml";
@ConfigField(name="RealEstate.Settings.UseWorldEdit", comment="This setting specifies whether we should restore rental areas to the state it was in before the are was rented")
public boolean RestoreRentalState=false; //this will destroy whatever was added during rental period to start with, will default to true once I save the items as rental period ends.
public boolean RestoreRentalState=false; //this will destroy whatever was added during rental period to start with, will default to true once I save the items as rental period ends.

@ConfigField(name="RealEstate.Settings.RestoreAdminClaimsOnly",comment="This setting will let us know if the rental areas should only be restored via WorldEdit if it is an admin claim, if true we will restore only admin claims, false will restore all claims (provided it is enabled by the previous setting)")
public boolean RestoreAdminOnly=true;


public Config()
{
this.pdf = RealEstate.instance.getDescription();
Expand Down
128 changes: 67 additions & 61 deletions src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,41 +77,44 @@ public ClaimRent(Claim claim, Player player, double price, Location sign, int du
this.duration = duration;
this.maxPeriod = RealEstate.instance.config.cfgEnableRentPeriod ? rentPeriods : 1;
this.buildTrust = buildTrust;
//if worldedit saving is requested, here's where i think... to do it..
if(RealEstate.instance.getServer().getPluginManager().getPlugin("WorldEdit")!=null) //is world edit installed?
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.config.RestoreRentalState)//are we configured to use it?
//if worldedit saving is requested, here's where i think... to do it..
if(RealEstate.instance.getServer().getPluginManager().getPlugin("WorldEdit")!=null) //is world edit installed?
{

Location lesser=claim.getLesserBoundaryCorner();
Location greater=claim.getGreaterBoundaryCorner();
CuboidRegion region = new CuboidRegion(BlockVector3.at(lesser.getX(), lesser.getWorld().getMinHeight(), lesser.getZ()),BlockVector3.at(greater.getX(),greater.getWorld().getMaxHeight(),greater.getZ()));
BlockArrayClipboard clipboard = new BlockArrayClipboard (region);
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());
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))) {
writer.write(clipboard);
}
catch (Exception e)
if(RealEstate.instance.config.RestoreRentalState)//are we configured to use it?
{
RealEstate.instance.log.info("Failed to copy rental area, Writing out schematic failed: "+e.getMessage());

Location lesser=claim.getLesserBoundaryCorner();
Location greater=claim.getGreaterBoundaryCorner();
CuboidRegion region = new CuboidRegion(BlockVector3.at(lesser.getX(), lesser.getWorld().getMinHeight(), lesser.getZ()),BlockVector3.at(greater.getX(),greater.getWorld().getMaxHeight(),greater.getZ()));
BlockArrayClipboard clipboard = new BlockArrayClipboard (region);
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());
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))) {
writer.write(clipboard);
}
catch (Exception e)
{
RealEstate.instance.log.info("Failed to copy rental area, Writing out schematic failed: "+e.getMessage());
}


}


}

}
}
}

@Override
Expand Down Expand Up @@ -233,42 +236,45 @@ private void unRent(boolean msgBuyer)
}
buyer = null;
RealEstate.transactionsStore.saveData();
//if worldedit saving is requested, here's where i think... to do it..
if(RealEstate.instance.getServer().getPluginManager().getPlugin("WorldEdit")!=null) //is world edit installed?
//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.config.RestoreRentalState)//are we configured to use it?
if(RealEstate.instance.getServer().getPluginManager().getPlugin("WorldEdit")!=null) //is world edit installed?
{
//load schematic, paste where we got it.
String schempath = RealEstate.pluginDirPath + "/schematics/"+claim.getID().toString()+".schem";
File file = new File(schempath);
Clipboard clipboard =null;
ClipboardFormat format= ClipboardFormats.findByFile(file);
try (ClipboardReader reader = format.getReader(new FileInputStream(file))) {
clipboard = reader.read();
}
catch (Exception e)
if(RealEstate.instance.config.RestoreRentalState)//are we configured to use it?
{
RealEstate.instance.log.info("Failed to import previously saved schematic: "+e.getMessage());
update();
return;
}
Location lesser=claim.getLesserBoundaryCorner();
//load schematic, paste where we got it.
String schempath = RealEstate.pluginDirPath + "/schematics/"+claim.getID().toString()+".schem";
File file = new File(schempath);
Clipboard clipboard =null;
ClipboardFormat format= ClipboardFormats.findByFile(file);
try (ClipboardReader reader = format.getReader(new FileInputStream(file))) {
clipboard = reader.read();
}
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)) {
Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(BlockVector3.at(lesser.getX(), lesser.getWorld().getMinHeight(), lesser.getZ()))
// configure here
.build();
Operations.complete(operation);
}
catch(Exception e)
{
RealEstate.instance.log.info("Failed to paste initial schematic: "+e.getMessage());
update();
return;

com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(lesser.getWorld());
try (EditSession editSession = WorldEdit.getInstance().newEditSession(world)) {
Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(BlockVector3.at(lesser.getX(), lesser.getWorld().getMinHeight(), lesser.getZ()))
// configure here
.build();
Operations.complete(operation);
}
catch(Exception e)
{
RealEstate.instance.log.info("Failed to paste initial schematic: "+e.getMessage());
update();
return;

}
}
}
}
Expand Down

0 comments on commit 051eef0

Please sign in to comment.