Fix schematics.

This commit is contained in:
bloodshot 2019-11-30 23:40:32 -05:00
parent 13361eeada
commit ef3659b33e
2 changed files with 19 additions and 18 deletions

View File

@ -37,6 +37,7 @@
import com.griefdefender.api.Tristate; import com.griefdefender.api.Tristate;
import com.griefdefender.api.claim.Claim; import com.griefdefender.api.claim.Claim;
import com.griefdefender.api.claim.ClaimBlockSystem; import com.griefdefender.api.claim.ClaimBlockSystem;
import com.griefdefender.api.claim.ClaimSchematic;
import com.griefdefender.api.claim.ClaimType; import com.griefdefender.api.claim.ClaimType;
import com.griefdefender.api.claim.TrustType; import com.griefdefender.api.claim.TrustType;
import com.griefdefender.api.economy.BankTransaction; import com.griefdefender.api.economy.BankTransaction;
@ -50,6 +51,7 @@
import com.griefdefender.claim.ClaimContextCalculator; import com.griefdefender.claim.ClaimContextCalculator;
import com.griefdefender.claim.GDClaim; import com.griefdefender.claim.GDClaim;
import com.griefdefender.claim.GDClaimManager; import com.griefdefender.claim.GDClaimManager;
import com.griefdefender.claim.GDClaimSchematic.ClaimSchematicBuilder;
import com.griefdefender.command.CommandAdjustBonusClaimBlocks; import com.griefdefender.command.CommandAdjustBonusClaimBlocks;
import com.griefdefender.command.CommandCallback; import com.griefdefender.command.CommandCallback;
import com.griefdefender.command.CommandClaimAbandon; import com.griefdefender.command.CommandClaimAbandon;
@ -463,7 +465,7 @@ public void onPreInit(GamePreInitializationEvent event, Logger logger, Path path
this.permissionProvider = new LuckPermsProvider(); this.permissionProvider = new LuckPermsProvider();
instance = this; instance = this;
this.getLogger().info("Grief Prevention boot start."); this.getLogger().info("GriefDefender boot start.");
this.getLogger().info("Finished loading configuration."); this.getLogger().info("Finished loading configuration.");
DEFAULT_HOLDER = new GDPermissionHolder("default"); DEFAULT_HOLDER = new GDPermissionHolder("default");
PUBLIC_USER = new GDPermissionUser(PUBLIC_UUID, PUBLIC_NAME); PUBLIC_USER = new GDPermissionUser(PUBLIC_UUID, PUBLIC_NAME);
@ -485,6 +487,7 @@ public void onPreInit(GamePreInitializationEvent event, Logger logger, Path path
WeatherTypeRegistryModule.getInstance().registerDefaults(); WeatherTypeRegistryModule.getInstance().registerDefaults();
OptionRegistryModule.getInstance().registerDefaults(); OptionRegistryModule.getInstance().registerDefaults();
GriefDefender.getRegistry().registerBuilderSupplier(Claim.Builder.class, GDClaim.ClaimBuilder::new); GriefDefender.getRegistry().registerBuilderSupplier(Claim.Builder.class, GDClaim.ClaimBuilder::new);
GriefDefender.getRegistry().registerBuilderSupplier(ClaimSchematic.Builder.class, ClaimSchematicBuilder::new);
GriefDefender.getRegistry().registerBuilderSupplier(BankTransaction.Builder.class, GDBankTransaction.BankTransactionBuilder::new); GriefDefender.getRegistry().registerBuilderSupplier(BankTransaction.Builder.class, GDBankTransaction.BankTransactionBuilder::new);
Sponge.getEventManager().registerListeners(GDBootstrap.getInstance(), GriefDefenderPlugin.getInstance()); Sponge.getEventManager().registerListeners(GDBootstrap.getInstance(), GriefDefenderPlugin.getInstance());
} }

View File

@ -29,7 +29,6 @@
import com.griefdefender.api.claim.Claim; import com.griefdefender.api.claim.Claim;
import com.griefdefender.api.claim.ClaimSchematic; import com.griefdefender.api.claim.ClaimSchematic;
import com.griefdefender.internal.util.VecHelper; import com.griefdefender.internal.util.VecHelper;
import com.griefdefender.storage.FileStorage;
import org.spongepowered.api.data.DataContainer; import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.data.persistence.DataFormats; import org.spongepowered.api.data.persistence.DataFormats;
import org.spongepowered.api.data.persistence.DataTranslators; import org.spongepowered.api.data.persistence.DataTranslators;
@ -107,11 +106,11 @@ public Schematic getSchematic() {
* @return If schematic apply was successful, false if not * @return If schematic apply was successful, false if not
*/ */
public boolean apply() { public boolean apply() {
if (!this.schematic.containsBlock(this.claim.getLesserBoundaryCorner()) && !schematic.containsBlock(this.claim.getGreaterBoundaryCorner())) { if (!this.schematic.containsBlock(this.claim.getLesserBoundaryCorner()) && !this.schematic.containsBlock(this.claim.getGreaterBoundaryCorner())) {
return false; return false;
} }
this.schematic.apply(VecHelper.toLocation(((GDClaim)(this.claim)).getWorld(), this.claim.getLesserBoundaryCorner()), BlockChangeFlags.ALL); this.schematic.apply(VecHelper.toLocation(((GDClaim)(this.claim)).getWorld(), this.origin), BlockChangeFlags.ALL);
return true; return true;
} }
@ -124,16 +123,7 @@ public static class ClaimSchematicBuilder implements Builder {
@Override @Override
public Builder claim(Claim claim) { public Builder claim(Claim claim) {
final World world = ((GDClaim) claim).getWorld();
final ArchetypeVolume volume = world.createArchetypeVolume(this.claim.getLesserBoundaryCorner(), this.claim.getGreaterBoundaryCorner(), new Vector3i(0, 0, 0));
final Schematic schematic = Schematic.builder()
.metaValue(Schematic.METADATA_NAME, name)
.metaValue(Schematic.METADATA_DATE, Instant.now().toString())
.metaValue("UUID", this.claim.getUniqueId().toString())
.volume(volume)
.build();
this.claim = claim; this.claim = claim;
this.schematic = schematic;
return this; return this;
} }
@ -160,10 +150,18 @@ public Builder reset() {
@Override @Override
public Optional<ClaimSchematic> build() { public Optional<ClaimSchematic> build() {
if (this.origin == null) { if (this.origin == null) {
//this.origin = new Vector3i(0, 0, 0); this.origin = new Vector3i(0, 0, 0);
this.origin = this.claim.getLesserBoundaryCorner();
} }
final World world = ((GDClaim) this.claim).getWorld(); final World world = ((GDClaim) this.claim).getWorld();
final ArchetypeVolume volume = world.createArchetypeVolume(this.claim.getLesserBoundaryCorner(), this.claim.getGreaterBoundaryCorner(), this.origin);
final Schematic schematic = Schematic.builder()
.metaValue(Schematic.METADATA_NAME, this.name)
.metaValue(Schematic.METADATA_DATE, Instant.now().toString())
.metaValue("UUID", this.claim.getUniqueId().toString())
.volume(volume)
.build();
this.schematic = schematic;
DataContainer schematicData = DataTranslators.SCHEMATIC.translate(schematic); DataContainer schematicData = DataTranslators.SCHEMATIC.translate(schematic);
final Path schematicPath = GriefDefenderPlugin.getInstance().getWorldEditProvider().getSchematicWorldMap().get(world.getUniqueId()).resolve(this.claim.getUniqueId().toString()); final Path schematicPath = GriefDefenderPlugin.getInstance().getWorldEditProvider().getSchematicWorldMap().get(world.getUniqueId()).resolve(this.claim.getUniqueId().toString());
try { try {
@ -179,9 +177,9 @@ public Optional<ClaimSchematic> build() {
return Optional.empty(); return Optional.empty();
} }
final GDClaimSchematic schematic = new GDClaimSchematic(this.claim, this.schematic, this.name, this.origin); final GDClaimSchematic claimSchematic = new GDClaimSchematic(this.claim, this.schematic, this.name, this.origin);
((GDClaim) this.claim).schematics.put(this.name, schematic); ((GDClaim) this.claim).schematics.put(this.name, claimSchematic);
return Optional.of(schematic); return Optional.of(claimSchematic);
} }
} }
} }