Skip to content

Commit

Permalink
pom - update StructureBlockLib
Browse files Browse the repository at this point in the history
- this also included a big re-write to the effects, since the lib changed how things work
  • Loading branch information
ShaneBeee committed Nov 6, 2020
1 parent 6287507 commit 63778ce
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 45 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<dependency>
<groupId>com.github.shynixn.structureblocklib</groupId>
<artifactId>structureblocklib-bukkit-core</artifactId>
<version>1.13.0</version>
<version>2.1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/tk/shanebee/bee/SkBee.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import com.github.shynixn.structureblocklib.bukkit.core.VersionSupport;
import com.github.shynixn.structureblocklib.bukkit.service.ProxyServiceImpl;
import com.shanebeestudios.vf.api.VirtualFurnaceAPI;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -212,7 +212,8 @@ private void loadStructureElements() {
return;
}
// Disable if StructureBlockLib is not currently updated for this server version
if (VersionSupport.getServerVersion() == null) {
ProxyServiceImpl impl = new ProxyServiceImpl(this);
if (impl.getServerVersion() == null) {
String ver = Skript.getMinecraftVersion().toString();
Util.log("&5Structure Elements &cDISABLED!");
Util.log(" - Your server version [&b" + ver + "&7] is not currently supported by the StructureBlock API");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import com.github.shynixn.structureblocklib.bukkit.api.StructureBlockApi;
import com.github.shynixn.structureblocklib.bukkit.api.business.enumeration.StructureMirror;
import com.github.shynixn.structureblocklib.bukkit.api.business.enumeration.StructureRotation;
import com.github.shynixn.structureblocklib.bukkit.api.business.service.PersistenceStructureService;
import com.github.shynixn.structureblocklib.bukkit.api.persistence.entity.StructureSaveConfiguration;
import com.github.shynixn.structureblocklib.api.bukkit.StructureBlockLibApi;
import com.github.shynixn.structureblocklib.api.enumeration.StructureMirror;
import com.github.shynixn.structureblocklib.api.enumeration.StructureRotation;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import tk.shanebee.bee.SkBee;

import java.io.File;

@Name("Structure Block - Load")
@Description("Load structure block structures that are saved on your server. " +
"Optional values for rotation, mirroring and the inclusion of entities. 1.9.4+ ONLY")
Expand All @@ -28,7 +29,16 @@
@Since("1.0.0")
public class EffLoadStructure extends Effect {

private static final String WORLD;
private static final StructureBlockLibApi STRUCTURE_API = StructureBlockLibApi.INSTANCE;

static {
String worldContainer = Bukkit.getWorldContainer().getPath();
if (worldContainer.equalsIgnoreCase(".")) {
WORLD = Bukkit.getServer().getWorlds().get(0).getName();
} else {
WORLD = worldContainer + File.separator + Bukkit.getServer().getWorlds().get(0).getName();
}
Skript.registerEffect(EffLoadStructure.class,
"(load|paste) [structure] %string% at %location% [with rotation (0¦0|1¦90|2¦180|3¦270)] [(|5¦[and] with entities)]",
"(load|paste) [structure] %string% at %location% [with rotation (0¦0|1¦90|2¦180|3¦270)] [and] [with] mirror front to back [(|5¦[and] with entities)]",
Expand All @@ -44,7 +54,7 @@ public class EffLoadStructure extends Effect {

@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(Expression<?>[] exprs, int i, Kleenean kleenean, ParseResult parseResult) {
public boolean init(Expression<?> @NotNull [] exprs, int i, @NotNull Kleenean kleenean, ParseResult parseResult) {
name = (Expression<String>) exprs[0];
loc = (Expression<Location>) exprs[1];
rotate = parseResult.mark;
Expand All @@ -54,54 +64,62 @@ public boolean init(Expression<?>[] exprs, int i, Kleenean kleenean, ParseResult
}

@Override
protected void execute(Event event) {
PersistenceStructureService service = StructureBlockApi.INSTANCE.getStructurePersistenceService();
String world = Bukkit.getServer().getWorlds().get(0).getName();
final StructureSaveConfiguration saveConfig = service.createSaveConfiguration("minecraft", name.getSingle(event), world);
switch (rotate) {
case 0:
case 5:
saveConfig.setRotation(StructureRotation.NONE);
break;
protected void execute(@NotNull Event event) {
StructureRotation rotation;
switch (this.rotate) {
case 1:
case 4:
saveConfig.setRotation(StructureRotation.ROTATION_90);
rotation = StructureRotation.ROTATION_90;
break;
case 2:
case 7:
saveConfig.setRotation(StructureRotation.ROTATION_180);
rotation = StructureRotation.ROTATION_180;
break;
case 3:
case 6:
saveConfig.setRotation(StructureRotation.ROTATION_270);
}
switch (mirror) {
case 0:
saveConfig.setMirror(StructureMirror.NONE);
rotation = StructureRotation.ROTATION_270;
break;
default:
rotation = StructureRotation.NONE;
}

StructureMirror mirror;
switch (this.mirror) {
case 1:
saveConfig.setMirror(StructureMirror.FRONT_BACK);
mirror = StructureMirror.FRONT_BACK;
break;
case 2:
saveConfig.setMirror(StructureMirror.LEFT_RIGHT);
mirror = StructureMirror.LEFT_RIGHT;
break;
default:
mirror = StructureMirror.NONE;
}
saveConfig.setIgnoreEntities(!withEntities);

boolean debug = SkBee.getPlugin().getPluginConfig().SETTINGS_DEBUG;
Location location = loc.getSingle(event);
if (location == null) {
if (SkBee.getPlugin().getPluginConfig().SETTINGS_DEBUG) {
if (debug) {
Skript.error("Could not load structure " + name.toString(event, true) +
" .. location does not exist: " + loc.toString(event, true));
}
return;
}
boolean structureExists = service.load(saveConfig, location);
if (!structureExists) {
Skript.error("Structure " + name.toString(event, true) + " does not exist!");
}
String name = this.name.getSingle(event);

STRUCTURE_API.loadStructure(SkBee.getPlugin())
.at(location).rotation(rotation).mirror(mirror)
.includeEntities(withEntities)
.loadFromWorld(WORLD, "minecraft", name)
.onException(e -> {
Skript.error("Structure " + this.name.toString(event, true) + " does not exist!");
if (debug) {
e.printStackTrace();
}
});
}

@Override
public String toString(Event e, boolean d) {
public @NotNull String toString(Event e, boolean d) {
return "load structure " + name.toString(e, d) + " at " + loc.toString(e, d);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,32 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import com.github.shynixn.structureblocklib.bukkit.api.StructureBlockApi;
import com.github.shynixn.structureblocklib.bukkit.api.business.service.PersistenceStructureService;
import com.github.shynixn.structureblocklib.bukkit.api.persistence.entity.StructureSaveConfiguration;
import com.github.shynixn.structureblocklib.api.bukkit.StructureBlockLibApi;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import tk.shanebee.bee.SkBee;

import java.io.File;

@Name("Structure Block - Save")
@Description("Save structure block structures. 1.9.4+ ONLY")
@Examples("save structure between {loc1} and {loc2} as \"house\"")
@Since("1.0.0")
public class EffSaveStructure extends Effect {

private static final String WORLD;
private static final StructureBlockLibApi STRUCTURE_API = StructureBlockLibApi.INSTANCE;

static {
String worldContainer = Bukkit.getWorldContainer().getPath();
if (worldContainer.equalsIgnoreCase(".")) {
WORLD = Bukkit.getServer().getWorlds().get(0).getName();
} else {
WORLD = worldContainer + File.separator + Bukkit.getServer().getWorlds().get(0).getName();
}
Skript.registerEffect(EffSaveStructure.class, "save [structure] between %location% and %location% as %string%");
}

Expand All @@ -33,24 +45,50 @@ public class EffSaveStructure extends Effect {

@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(Expression<?>[] exprs, int i, Kleenean kleenean, ParseResult parseResult) {
public boolean init(Expression<?> @NotNull [] exprs, int i, @NotNull Kleenean kleenean, @NotNull ParseResult parseResult) {
loc1 = (Expression<Location>) exprs[0];
loc2 = (Expression<Location>) exprs[1];
name = (Expression<String>) exprs[2];
return true;
}

@Override
protected void execute(Event event) {
PersistenceStructureService service = StructureBlockApi.INSTANCE.getStructurePersistenceService();
String world = Bukkit.getServer().getWorlds().get(0).getName();
final StructureSaveConfiguration saveConfig = service.createSaveConfiguration("minecraft", name.getSingle(event), world);
saveConfig.setIgnoreEntities(false);
service.save(saveConfig, loc1.getSingle(event), loc2.getSingle(event));
protected void execute(@NotNull Event event) {
Location loc1 = this.loc1.getSingle(event);
Location loc2 = this.loc2.getSingle(event);

if (loc1 == null || loc2 == null) return;

World world = loc1.getWorld();
int x = Math.min(loc1.getBlockX(), loc2.getBlockX());
int y = Math.min(loc1.getBlockY(), loc2.getBlockY());
int z = Math.min(loc1.getBlockZ(), loc2.getBlockZ());

Location low = new Location(world, x, y, z);

int x2 = Math.max(loc1.getBlockX(), loc2.getBlockX()) + 1;
int y2 = Math.max(loc1.getBlockY(), loc2.getBlockY()) + 1;
int z2 = Math.max(loc1.getBlockZ(), loc2.getBlockZ()) + 1;

int x3 = x2 - x;
int y3 = y2 - y;
int z3 = z2 - z;
String name = this.name.getSingle(event);

STRUCTURE_API.saveStructure(SkBee.getPlugin())
.at(low).sizeX(x3).sizeY(y3).sizeZ(z3)
.includeEntities(true)
.saveToWorld(WORLD, "minecraft", name)
.onException(e -> {
Skript.error("Could not save structure: " + name);
if (SkBee.getPlugin().getPluginConfig().SETTINGS_DEBUG) {
e.printStackTrace();
}
});
}

@Override
public String toString(Event e, boolean d) {
public @NotNull String toString(Event e, boolean d) {
return "save structure between " + loc1.toString(e, d) + " and " + loc2.toString(e, d) + " as " + name.toString(e, d);
}

Expand Down

0 comments on commit 63778ce

Please sign in to comment.