SoftDependency added: WorldEdit

Rental properties can now become self-cleaning (Disabled by default)
WARNING: This is extremely distructive, if enabled the property will use
WorldEdit to create a schematic of the rental area (and save it), when
the rental period ends, the schematic is loaded and pasted.

Signs are no longer editable once they become RealEstate signs (in short
they become waxed).

Config changes:
Added configuration to enable or disable the self-cleaning rentals. As
this can cause a kind of infinite item exploit (place something down,
rent, remove, unrent).

Future plans:
Self cleaning rentals will factor changes made by rentor, for example if
the owner places a shulker with diamonds, those diamonds should still be
gone after the rental process completes. Similarly items, and blocks,
placed by rentors should be returned to them prior to finalizing the
close of the rent. For example rentor rents property, builds house, rent
expires, the materials that make up the house, and anything inside,
should return to the rentor.
This commit is contained in:
Famous_Longwing 2024-02-20 10:17:52 -05:00
parent 30e21a8c48
commit 9561dca8f2
8 changed files with 134 additions and 5 deletions

View File

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

22
pom.xml
View File

@ -29,8 +29,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
@ -96,6 +96,10 @@
</plugins>
</build>
<repositories>
<repository>
<id>enginehub-maven</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
@ -163,7 +167,19 @@
<groupId>com.github.EtienneDx</groupId>
<artifactId>AnnotationConfig</artifactId>
<version>e9eab24</version>
</dependency>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-core</artifactId>
<version>7.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -101,7 +101,8 @@ 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 Config()
{
this.pdf = RealEstate.instance.getDescription();

View File

@ -409,6 +409,7 @@ public class REListener implements Listener
if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getHand().equals(EquipmentSlot.HAND) &&
event.getClickedBlock().getState() instanceof Sign)
{
Sign sign = (Sign)event.getClickedBlock().getState();
RealEstate.instance.log.info(sign.getLine(0));
// it is a real estate sign
@ -427,6 +428,7 @@ public class REListener implements Listener
}
Transaction tr = RealEstate.transactionsStore.getTransaction(claim);
if(player.isSneaking())
tr.preview(player);
else

View File

@ -46,6 +46,7 @@ public class RealEstate extends JavaPlugin
public final static String pluginDirPath = "plugins" + File.separator + "RealEstate" + File.separator;
final static String languagesDirectory = RealEstate.pluginDirPath + "languages";
public static boolean vaultPresent = false;
public static boolean worldEditPresent = false;
public static Economy econ = null;
public static Permission perms = null;
public static Essentials ess = null;
@ -86,6 +87,13 @@ public class RealEstate extends JavaPlugin
return;
}
}
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("Essentials") != null)
{
org.bukkit.plugin.Plugin ess=getServer().getPluginManager().getPlugin("Essentials");
@ -267,6 +275,11 @@ public class RealEstate extends JavaPlugin
return vaultPresent;
}
private boolean checkWorldEdit()
{
worldEditPresent = getServer().getPluginManager().getPlugin("WorldEdit") !=null;
return worldEditPresent;
}
private boolean setupEconomy()
{
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);

View File

@ -66,6 +66,7 @@ public class ClaimLease extends BoughtTransaction
if(sign.getBlock().getState() instanceof Sign)
{
Sign s = (Sign)sign.getBlock().getState();
s.setWaxed(true);
s.setLine(0, Messages.getMessage(RealEstate.instance.config.cfgSignsHeader, false));
s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.config.cfgReplaceLease);
//s.setLine(2, owner != null ? Bukkit.getOfflinePlayer(owner).getName() : "SERVER");

View File

@ -1,5 +1,8 @@
package me.EtienneDx.RealEstate.Transactions;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
@ -8,7 +11,6 @@ import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
@ -17,6 +19,23 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.earth2me.essentials.User;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
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.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 me.EtienneDx.RealEstate.Messages;
import me.EtienneDx.RealEstate.RealEstate;
@ -58,6 +77,41 @@ public class ClaimRent extends BoughtTransaction
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(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());
}
}
}
}
@Override
@ -83,6 +137,7 @@ public class ClaimRent extends BoughtTransaction
if(sign.getBlock().getState() instanceof Sign)
{
Sign s = (Sign) sign.getBlock().getState();
s.setWaxed(true);
s.setLine(0, Messages.getMessage(RealEstate.instance.config.cfgSignsHeader, false));
s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.config.cfgReplaceRent);
//s.setLine(2, owner != null ? Bukkit.getOfflinePlayer(owner).getName() : "SERVER");
@ -178,6 +233,45 @@ public class ClaimRent extends BoughtTransaction
}
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(RealEstate.instance.config.RestoreRentalState)//are we configured to use it?
{
//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;
}
}
}
update();
}

View File

@ -38,6 +38,7 @@ public class ClaimSell extends ClaimTransaction
if(sign.getBlock().getState() instanceof Sign)
{
Sign s = (Sign) sign.getBlock().getState();
s.setWaxed(true);
s.setLine(0, Messages.getMessage(RealEstate.instance.config.cfgSignsHeader, false));
s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.config.cfgReplaceSell);
s.setLine(2, owner != null ? Utils.getSignString(Bukkit.getOfflinePlayer(owner).getName()) : "SERVER");