diff --git a/plugin.yml b/plugin.yml index a45972d..558552d 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] +softdepend: [WorldEdit, CoreProtect] api-version: "1.20" commands: diff --git a/src/me/EtienneDx/RealEstate/Config.java b/src/me/EtienneDx/RealEstate/Config.java index 60650d0..e8ac804 100644 --- a/src/me/EtienneDx/RealEstate/Config.java +++ b/src/me/EtienneDx/RealEstate/Config.java @@ -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(); diff --git a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java index 33aa88c..9656567 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java +++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java @@ -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 @@ -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; + + } } } }