added CoreProtect as a soft depend in preperation for next step of

self-cleaning rentals.

Set rental self-cleaning for admin-only claims to start with, must be
enabled for regular players.
This commit is contained in:
Famous_Longwing 2024-02-20 14:05:32 -05:00
parent ae476fdb28
commit 051eef009f
3 changed files with 74 additions and 63 deletions

View File

@ -3,7 +3,7 @@ main: me.EtienneDx.RealEstate.RealEstate
version: ${project.version} version: ${project.version}
authors: [EtienneDx, DmitryRendov, FamousLongwing] authors: [EtienneDx, DmitryRendov, FamousLongwing]
depend: [Vault, GriefPrevention] depend: [Vault, GriefPrevention]
softdepend: [WorldEdit] softdepend: [WorldEdit, CoreProtect]
api-version: "1.20" api-version: "1.20"
commands: commands:

View File

@ -103,6 +103,11 @@ public class Config extends AnnotationConfig
public String languageFile = "en.yml"; 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") @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() public Config()
{ {
this.pdf = RealEstate.instance.getDescription(); this.pdf = RealEstate.instance.getDescription();

View File

@ -77,40 +77,43 @@ public class ClaimRent extends BoughtTransaction
this.duration = duration; this.duration = duration;
this.maxPeriod = RealEstate.instance.config.cfgEnableRentPeriod ? rentPeriods : 1; this.maxPeriod = RealEstate.instance.config.cfgEnableRentPeriod ? rentPeriods : 1;
this.buildTrust = buildTrust; this.buildTrust = buildTrust;
//if worldedit saving is requested, here's where i think... to do it.. 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?
{ {
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?
{ {
if(RealEstate.instance.config.RestoreRentalState)//are we configured to use it?
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());
}
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());
}
}
} }
} }
} }
@ -233,42 +236,45 @@ public class ClaimRent extends BoughtTransaction
} }
buyer = null; buyer = null;
RealEstate.transactionsStore.saveData(); RealEstate.transactionsStore.saveData();
//if worldedit saving is requested, here's where i think... to do it.. //if worldedit saving is requested, here's where i load the saved area
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(RealEstate.instance.getServer().getPluginManager().getPlugin("WorldEdit")!=null) //is world edit installed?
{ {
//load schematic, paste where we got it. if(RealEstate.instance.config.RestoreRentalState)//are we configured to use 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()); //load schematic, paste where we got it.
update(); String schempath = RealEstate.pluginDirPath + "/schematics/"+claim.getID().toString()+".schem";
return; File file = new File(schempath);
} Clipboard clipboard =null;
Location lesser=claim.getLesserBoundaryCorner(); 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()); com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(lesser.getWorld());
try (EditSession editSession = WorldEdit.getInstance().newEditSession(world)) { try (EditSession editSession = WorldEdit.getInstance().newEditSession(world)) {
Operation operation = new ClipboardHolder(clipboard) Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession) .createPaste(editSession)
.to(BlockVector3.at(lesser.getX(), lesser.getWorld().getMinHeight(), lesser.getZ())) .to(BlockVector3.at(lesser.getX(), lesser.getWorld().getMinHeight(), lesser.getZ()))
// configure here // configure here
.build(); .build();
Operations.complete(operation); Operations.complete(operation);
} }
catch(Exception e) catch(Exception e)
{ {
RealEstate.instance.log.info("Failed to paste initial schematic: "+e.getMessage()); RealEstate.instance.log.info("Failed to paste initial schematic: "+e.getMessage());
update(); update();
return; return;
}
} }
} }
} }