Added /v10lift build worldedit command, closes #80
This commit is contained in:
parent
92a60be306
commit
ee9aecce8e
4 changed files with 118 additions and 1 deletions
14
pom.xml
14
pom.xml
|
@ -5,7 +5,7 @@
|
|||
|
||||
<groupId>tech.sbdevelopment</groupId>
|
||||
<artifactId>V10Lift</artifactId>
|
||||
<version>0.8</version>
|
||||
<version>0.9</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>V10Lift</name>
|
||||
|
@ -146,6 +146,10 @@
|
|||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>enginehub-maven</id>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
@ -196,5 +200,13 @@
|
|||
<version>5.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- WorldEdit, optional for creating lifts -->
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.2.9</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,6 +1,14 @@
|
|||
package tech.sbdevelopment.v10lift.commands;
|
||||
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
@ -131,6 +139,17 @@ public class V10LiftCommand implements CommandExecutor {
|
|||
} else {
|
||||
ConfigUtil.sendMessage(sender, "General.NoPermission");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("build") && args.length == 2 && args[1].equalsIgnoreCase("worldedit")) {
|
||||
//v10lift build worldedit
|
||||
if (!(sender instanceof Player)) {
|
||||
ConfigUtil.sendMessage(sender, "General.PlayerOnly");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||
return buildWorldEditCommand(sender);
|
||||
} else {
|
||||
ConfigUtil.sendMessage(sender, "General.NoPermission");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("rope") && args.length == 2) {
|
||||
//v10lift rope add || v10lift rope del
|
||||
if (!(sender instanceof Player)) {
|
||||
|
@ -784,6 +803,86 @@ public class V10LiftCommand implements CommandExecutor {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean buildWorldEditCommand(CommandSender sender) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
ConfigUtil.sendMessage(sender, "General.SwitchOnEdit");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
||||
DataManager.addBuilderPlayer(p.getUniqueId());
|
||||
}
|
||||
|
||||
LocalSession ls = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(p));
|
||||
Region region;
|
||||
try {
|
||||
region = ls.getSelection(BukkitAdapter.adapt(p.getWorld()));
|
||||
} catch (IncompleteRegionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (region == null) {
|
||||
ConfigUtil.sendMessage(sender, "Build.NoSelection");
|
||||
return true;
|
||||
}
|
||||
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
boolean success = true;
|
||||
int failed = 0;
|
||||
if (region instanceof Polygonal2DRegion) {
|
||||
//Get all blocks in region
|
||||
Polygonal2DRegion poly = (Polygonal2DRegion) region;
|
||||
for (BlockVector2 bv : poly.getPoints()) {
|
||||
for (int y = poly.getMinimumPoint().getBlockY(); y <= poly.getMaximumPoint().getBlockY(); y++) {
|
||||
Block b = p.getWorld().getBlockAt(bv.getBlockX(), y, bv.getBlockZ());
|
||||
if (b.getType() == Material.AIR) continue;
|
||||
|
||||
if (V10LiftAPI.getInstance().switchBlockAtLift(DataManager.getEditPlayer(p.getUniqueId()), b) == 0) {
|
||||
blocks.add(b);
|
||||
continue;
|
||||
}
|
||||
success = false;
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
} else if (region instanceof CuboidRegion) {
|
||||
//Get all blocks in region
|
||||
CuboidRegion cuboid = (CuboidRegion) region;
|
||||
for (int x = cuboid.getMinimumPoint().getBlockX(); x <= cuboid.getMaximumPoint().getBlockX(); x++) {
|
||||
for (int y = cuboid.getMinimumPoint().getBlockY(); y <= cuboid.getMaximumPoint().getBlockY(); y++) {
|
||||
for (int z = cuboid.getMinimumPoint().getBlockZ(); z <= cuboid.getMaximumPoint().getBlockZ(); z++) {
|
||||
Block b = p.getWorld().getBlockAt(x, y, z);
|
||||
if (b.getType() == Material.AIR) continue;
|
||||
|
||||
if (V10LiftAPI.getInstance().switchBlockAtLift(DataManager.getEditPlayer(p.getUniqueId()), b) == 0) {
|
||||
blocks.add(b);
|
||||
continue;
|
||||
}
|
||||
success = false;
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ConfigUtil.sendMessage(sender, "Build.UnsupportedSelection");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
ConfigUtil.sendMessage(sender, "Build.BlocksAdded");
|
||||
} else {
|
||||
ConfigUtil.sendMessage(sender, "Build.BlocksFailed", Collections.singletonMap("%Failed%", String.valueOf(failed)));
|
||||
}
|
||||
|
||||
if (DataManager.containsBuilderPlayer(p.getUniqueId())) {
|
||||
DataManager.removeBuilderPlayer(p.getUniqueId());
|
||||
V10LiftAPI.getInstance().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
ConfigUtil.sendMessage(sender, "Build.Disabled");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean buildCommand(CommandSender sender) {
|
||||
Player p = (Player) sender;
|
||||
if (!DataManager.containsEditPlayer(p.getUniqueId())) {
|
||||
|
|
|
@ -76,6 +76,8 @@ public class V10LiftTabCompleter implements TabCompleter {
|
|||
return StringUtil.copyPartialMatches(args[2], playerOrGroupNames, new ArrayList<>());
|
||||
} else if (args[0].equalsIgnoreCase("setoffline")) {
|
||||
return StringUtil.copyPartialMatches(args[2], BOOL, new ArrayList<>());
|
||||
} else if (args[0].equalsIgnoreCase("build")) {
|
||||
return StringUtil.copyPartialMatches(args[2], List.of("worldedit"), new ArrayList<>());
|
||||
}
|
||||
} else if (args.length == 4) {
|
||||
//Command based arguments
|
||||
|
|
|
@ -72,6 +72,10 @@ Build:
|
|||
BlockAdded: '&aBlock added to the elevator.'
|
||||
BlockRemoved: '&6Block removed from the elevator.'
|
||||
BlacklistedMaterial: '&cThe material %Name% cannot be used!'
|
||||
NoSelection: '&cYou must select a region with the WorldEdit wand first!'
|
||||
UnsupportedSelection: '&cThe selection must be cuboid or polygonal!'
|
||||
BlocksAdded: '&aBlocks added to the elevator.'
|
||||
BlocksFailed: '&cNot all blocks could be added to the elevator. Failure amount: %Failed%'
|
||||
|
||||
Rope:
|
||||
StillAdjusting: '&cYou are still adjusting a rope.'
|
||||
|
|
Loading…
Reference in a new issue