diff --git a/pom.xml b/pom.xml index 19aa75b..1f0cfdc 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.azura4k PowerWorld - 1.2 + 1.3 1.8 diff --git a/src/main/java/com/azura4k/PowerWorld/PowerWorld.java b/src/main/java/com/azura4k/PowerWorld/PowerWorld.java index 8252b57..567cc04 100644 --- a/src/main/java/com/azura4k/PowerWorld/PowerWorld.java +++ b/src/main/java/com/azura4k/PowerWorld/PowerWorld.java @@ -1,21 +1,26 @@ package com.azura4k.PowerWorld; +import cn.nukkit.Player; import cn.nukkit.block.Block; import cn.nukkit.command.SimpleCommandMap; +import cn.nukkit.item.Item; +import cn.nukkit.item.enchantment.Enchantment; +import cn.nukkit.level.Level; import cn.nukkit.math.Vector3; +import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.plugin.PluginBase; import com.azura4k.PowerWorld.commands.ReplaceBlocksCmd; import com.azura4k.PowerWorld.commands.SetBlocksCmd; +import com.azura4k.PowerWorld.commands.UndoCmd; import com.azura4k.PowerWorld.commands.WandCmd; import com.azura4k.PowerWorld.listeners.WandListener; import java.util.ArrayList; -import java.util.List; + public class PowerWorld extends PluginBase { - public static Vector3 Vector1; - public static Vector3 Vector2; - public static List Blocks = new ArrayList<>(); + public static ArrayList> UndoList = new ArrayList<>(); + public static final int UndoStorageLimit = 5; @Override public void onLoad() { @@ -25,6 +30,8 @@ public void onLoad() { CM.register("/wand", new WandCmd()); CM.register("/set", new SetBlocksCmd()); CM.register("/replace", new ReplaceBlocksCmd()); + CM.register("/undo", new UndoCmd()); + //Config Stuff } public void onEnable() { @@ -41,15 +48,4 @@ public void onDisable() { } - //Needed for Wand Selector - public void StorePosLocation(Vector3 Vector1, Vector3 Vector2){ - this.Vector1 = Vector1; - this.Vector2 = Vector2; - } - public final Vector3 GetPos1() { - return this.Vector1; - } - public final Vector3 GetPos2() { - return this.Vector2; - } } diff --git a/src/main/java/com/azura4k/PowerWorld/PowerWorldCommon.java b/src/main/java/com/azura4k/PowerWorld/PowerWorldCommon.java index b5644ff..d70f00f 100644 --- a/src/main/java/com/azura4k/PowerWorld/PowerWorldCommon.java +++ b/src/main/java/com/azura4k/PowerWorld/PowerWorldCommon.java @@ -2,24 +2,107 @@ import cn.nukkit.Player; import cn.nukkit.block.Block; +import cn.nukkit.item.Item; +import cn.nukkit.item.enchantment.Enchantment; import cn.nukkit.level.Level; import cn.nukkit.math.Vector3; +import cn.nukkit.nbt.tag.CompoundTag; import java.util.ArrayList; import java.util.List; -import java.util.Vector; public class PowerWorldCommon extends PowerWorld { - public int WandID; public PowerWorldCommon() { //Setup All Config stuff here - this.WandID = 288; + this.WandID = 271; } - public boolean WandisSelected(Player player) { //Returns false if both are not true. - return player.getInventory().getItemInHand().getId() == this.WandID || player.getInventory().getItemInHand().getCustomName().equals("Magic Wand"); + return player.getInventory().getItemInHand().getId() == this.WandID & player.getInventory().getItemInHand().getCustomName().equals("Magic Wand") & player.getInventory().getItemInHand().hasEnchantment(15); + } + + + //Needed for Wand Selector + public void StorePosLocation(Vector3 Vector1, Vector3 Vector2, Player player) { + Item wand = player.getInventory().getItemInHand(); + int[] Positions = new int[6]; + Positions[0] = Vector1.getFloorX(); + Positions[1] = Vector1.getFloorY(); + Positions[2] = Vector1.getFloorZ(); + Positions[3] = Vector2.getFloorX(); + Positions[4] = Vector2.getFloorY(); + Positions[5] = Vector2.getFloorZ(); + wand.setNamedTag(new CompoundTag().putIntArray("Coords", Positions)); + wand.setLore( + "X:" + Positions[0] + " Y:" + Positions[1] + " Z:" + Positions[2] + + "\n X1:" + Positions[3] + " Y1:" + Positions[4] + " Z1:" + Positions[5] + ); + wand.setCustomName("Magic Wand"); + wand.addEnchantment(Enchantment.getEnchantment(15)); + player.getInventory().setItemInHand(wand); + } + public final Vector3 GetPos1(Player player) { + Vector3 temp = new Vector3(); + int[] pos1 = player.getInventory().getItemInHand().getNamedTag().getIntArray("Coords"); + temp.x = pos1[0]; + temp.y = pos1[1]; + temp.z = pos1[2]; + return temp; } -} \ No newline at end of file + public final Vector3 GetPos2(Player player) { + Vector3 temp = new Vector3(); + int[] pos2 = player.getInventory().getItemInHand().getNamedTag().getIntArray("Coords"); + temp.x = pos2[3]; + temp.y = pos2[4]; + temp.z = pos2[5]; + return temp; + } + + + public void InsertFunctionHistory(Vector3 Pos1, Vector3 Pos2, Level world, Player player) { + ArrayList Execution = new ArrayList(); + int minX = Math.min(Pos1.getFloorX(), Pos2.getFloorX()); + int minY = Math.min(Pos1.getFloorY(), Pos2.getFloorY()); + int minZ = Math.min(Pos1.getFloorZ(), Pos2.getFloorZ()); + int maxX = Math.max(Pos1.getFloorX(), Pos2.getFloorX()); + int maxY = Math.max(Pos1.getFloorY(), Pos2.getFloorY()); + int maxZ = Math.max(Pos1.getFloorZ(), Pos2.getFloorZ()); + for (int x = minX; x <= maxX; x++) { + for (int y = minY; y <= maxY; y++) { + for (int z = minZ; z <= maxZ; z++) { + Block block = world.getBlock(x, y, z); + Execution.add(block); + } + } + } + this.UndoList.add(Execution); + //Down Shifts list as we go + if (this.UndoList.size() > this.UndoStorageLimit) { + ArrayList> Temp = new ArrayList<>(); + for (int i = 1; i < this.UndoList.size(); i++) { + Temp.add(this.UndoList.get(i)); + } + this.UndoList = Temp; + } + } + + public boolean RestoreUndoCmd(Player player, int Sequence) { + //Sets Sequence = to the latest, minus one for + //Index protection and minus sequence for step count + Sequence = this.UndoList.size() - 1 - Sequence; + if (Sequence > this.UndoList.size() || Sequence > this.UndoStorageLimit || Sequence < 0) { + player.sendMessage("The sequence you entered overflows \nthe range of stored commands executed."); + return false; + } + for (int i = 0; i < this.UndoList.get(Sequence).size(); i++){ + Block block = this.UndoList.get(Sequence).get(i); + player.level.setBlock(block.getFloorX(), block.getFloorY(), block.getFloorZ(), block, true, true); + } + return true; + } +} + + + diff --git a/src/main/java/com/azura4k/PowerWorld/commands/ReplaceBlocksCmd.java b/src/main/java/com/azura4k/PowerWorld/commands/ReplaceBlocksCmd.java index 1565306..74e4a08 100644 --- a/src/main/java/com/azura4k/PowerWorld/commands/ReplaceBlocksCmd.java +++ b/src/main/java/com/azura4k/PowerWorld/commands/ReplaceBlocksCmd.java @@ -1,8 +1,8 @@ package com.azura4k.PowerWorld.commands; +import cn.nukkit.Player; import cn.nukkit.block.Block; import cn.nukkit.command.Command; -import cn.nukkit.command.CommandExecutor; import cn.nukkit.command.CommandSender; import cn.nukkit.level.Level; import cn.nukkit.math.Vector3; @@ -55,10 +55,12 @@ public boolean execute(CommandSender commandSender, String s, String[] args) { } //PART TWO - GET PLAYER INFO - Level world = commandSender.getServer().getPlayer(commandSender.getName()).level; - Vector3 Pos1 = PC.GetPos1(); - Vector3 Pos2 = PC.GetPos2(); - + Player player = commandSender.getServer().getPlayer(commandSender.getName()); + Level world = player.level; + Vector3 Pos1 = PC.GetPos1(player); + Vector3 Pos2 = PC.GetPos2(player); + //Part TWO1/2 Save Blocks in Position + PC.InsertFunctionHistory(Pos1, Pos2, world, player); //PART THREE - PLACE BLOCKS IN WORLD //Curtsy of DaPorkChop - Thank You SOOOOO Much int minX = Math.min(Pos1.getFloorX(), Pos2.getFloorX()); diff --git a/src/main/java/com/azura4k/PowerWorld/commands/SetBlocksCmd.java b/src/main/java/com/azura4k/PowerWorld/commands/SetBlocksCmd.java index 2806b76..5769a7e 100644 --- a/src/main/java/com/azura4k/PowerWorld/commands/SetBlocksCmd.java +++ b/src/main/java/com/azura4k/PowerWorld/commands/SetBlocksCmd.java @@ -1,18 +1,13 @@ package com.azura4k.PowerWorld.commands; +import cn.nukkit.Player; import cn.nukkit.block.Block; -import cn.nukkit.blockstate.BlockState; import cn.nukkit.command.Command; -import cn.nukkit.command.CommandExecutor; import cn.nukkit.command.CommandSender; import cn.nukkit.level.Level; import cn.nukkit.math.Vector3; import com.azura4k.PowerWorld.PowerWorldCommon; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - public class SetBlocksCmd extends Command { PowerWorldCommon PC = new PowerWorldCommon(); @@ -49,11 +44,13 @@ public boolean execute(CommandSender commandSender, String s, String[] args) { } //PART TWO - GATHER PLAYER INFO - Level world = commandSender.getServer().getPlayer(commandSender.getName()).level; - Vector3 Pos1 = PC.GetPos1(); - Vector3 Pos2 = PC.GetPos2(); - + Player player = commandSender.getServer().getPlayer(commandSender.getName()); + Level world = player.level; + Vector3 Pos1 = PC.GetPos1(player); + Vector3 Pos2 = PC.GetPos2(player); + //Part Two-1/2 Save State of Positions + PC.InsertFunctionHistory(Pos1, Pos2, world, player); //PART THREE - PLACE BLOCKS IN WORLD //Curtsy of DaPorkChop - Thank You SOOOOO Much int minX = Math.min(Pos1.getFloorX(), Pos2.getFloorX()); diff --git a/src/main/java/com/azura4k/PowerWorld/commands/UndoCmd.java b/src/main/java/com/azura4k/PowerWorld/commands/UndoCmd.java new file mode 100644 index 0000000..c88a00a --- /dev/null +++ b/src/main/java/com/azura4k/PowerWorld/commands/UndoCmd.java @@ -0,0 +1,25 @@ +package com.azura4k.PowerWorld.commands; + +import cn.nukkit.Player; +import cn.nukkit.command.Command; +import cn.nukkit.command.CommandSender; +import com.azura4k.PowerWorld.PowerWorldCommon; + +public class UndoCmd extends Command { + PowerWorldCommon PC = new PowerWorldCommon(); + public UndoCmd(){ + super("/undo"); + } + @Override + public boolean execute(CommandSender commandSender, String s, String[] args) { + Player player = commandSender.getServer().getPlayerExact(commandSender.getName()); + if (args.length == 0 || args[0] == null || args[0] == ""){ + //Assume latest Undo + return PC.RestoreUndoCmd(player, 0); + } + int Sequence = Integer.parseInt(args[0]); + return PC.RestoreUndoCmd(player, Sequence); + } + + + } diff --git a/src/main/java/com/azura4k/PowerWorld/commands/WandCmd.java b/src/main/java/com/azura4k/PowerWorld/commands/WandCmd.java index 021689b..10e7c29 100644 --- a/src/main/java/com/azura4k/PowerWorld/commands/WandCmd.java +++ b/src/main/java/com/azura4k/PowerWorld/commands/WandCmd.java @@ -3,11 +3,10 @@ import cn.nukkit.Player; import cn.nukkit.command.Command; -import cn.nukkit.command.CommandExecutor; import cn.nukkit.command.CommandSender; import cn.nukkit.item.Item; +import cn.nukkit.item.enchantment.Enchantment; import com.azura4k.PowerWorld.PowerWorldCommon; -import cn.nukkit.permission.Permission; public class WandCmd extends Command{ @@ -24,6 +23,7 @@ public boolean execute(CommandSender commandSender, String s, String[] strings) Player player = commandSender.getServer().getPlayerExact(commandSender.getName()); Item wand = new Item(PC.WandID); wand.setCustomName("Magic Wand"); + wand.addEnchantment(Enchantment.getEnchantment(15)); player.giveItem(wand); return true; } diff --git a/src/main/java/com/azura4k/PowerWorld/listeners/WandListener.java b/src/main/java/com/azura4k/PowerWorld/listeners/WandListener.java index 58b5af7..bee272a 100644 --- a/src/main/java/com/azura4k/PowerWorld/listeners/WandListener.java +++ b/src/main/java/com/azura4k/PowerWorld/listeners/WandListener.java @@ -19,15 +19,15 @@ public void onWandClick(PlayerInteractEvent event){ PrimaryPoint.x = event.getBlock().getFloorX(); PrimaryPoint.y = event.getBlock().getFloorY(); PrimaryPoint.z = event.getBlock().getFloorZ(); - event.getPlayer().sendMessage("Primary Location Selected: X" + PrimaryPoint.x + " Y" + PrimaryPoint.y + " Z" + PrimaryPoint.z); - PC.StorePosLocation(this.PrimaryPoint, this.SecondaryPoint); + event.getPlayer().sendMessage("Pos1: X" + PrimaryPoint.x + " Y" + PrimaryPoint.y + " Z" + PrimaryPoint.z); + PC.StorePosLocation(this.PrimaryPoint, this.SecondaryPoint, event.getPlayer()); } else if(event.getAction() == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK){ SecondaryPoint.x = event.getBlock().getFloorX(); SecondaryPoint.y = event.getBlock().getFloorY(); SecondaryPoint.z = event.getBlock().getFloorZ(); - event.getPlayer().sendMessage("Secondary Location Selected: X" + SecondaryPoint.x + " Y" + SecondaryPoint.y + " Z" + SecondaryPoint.z); - PC.StorePosLocation(this.PrimaryPoint, this.SecondaryPoint); + event.getPlayer().sendMessage("Pos2: X" + SecondaryPoint.x + " Y" + SecondaryPoint.y + " Z" + SecondaryPoint.z); + PC.StorePosLocation(this.PrimaryPoint, this.SecondaryPoint, event.getPlayer()); } } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index aa89052..1f57531 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: PowerWorld main: com.azura4k.PowerWorld.PowerWorld - version: 1.2 + version: 1.3 api: ["1.0.13"] author: Azura4k description: World Edit Designed for PowerNukkit Use. @@ -18,7 +18,10 @@ description: Replace Blocks With Specific ID with Another Block usage: "//replace " permission: powerworld.cmd.use - + undo: + description: Reverse a Block Command to the most recent command, or more. Only 5 commands back + usage: "//undo " + permission: powerworld.cmd.use permissions: powerworld.cmd.use: description: "Allows the user to run any world edit commands" diff --git a/target/PowerWorld-1.3.jar b/target/PowerWorld-1.3.jar new file mode 100644 index 0000000..9c08666 Binary files /dev/null and b/target/PowerWorld-1.3.jar differ diff --git a/target/classes/com/azura4k/PowerWorld/PowerWorld.class b/target/classes/com/azura4k/PowerWorld/PowerWorld.class index a5a6e20..90690e8 100644 Binary files a/target/classes/com/azura4k/PowerWorld/PowerWorld.class and b/target/classes/com/azura4k/PowerWorld/PowerWorld.class differ diff --git a/target/classes/com/azura4k/PowerWorld/PowerWorldCommon.class b/target/classes/com/azura4k/PowerWorld/PowerWorldCommon.class index 38b9d94..04c2e14 100644 Binary files a/target/classes/com/azura4k/PowerWorld/PowerWorldCommon.class and b/target/classes/com/azura4k/PowerWorld/PowerWorldCommon.class differ diff --git a/target/classes/com/azura4k/PowerWorld/commands/ReplaceBlocksCmd.class b/target/classes/com/azura4k/PowerWorld/commands/ReplaceBlocksCmd.class index f2ef872..ea36cb9 100644 Binary files a/target/classes/com/azura4k/PowerWorld/commands/ReplaceBlocksCmd.class and b/target/classes/com/azura4k/PowerWorld/commands/ReplaceBlocksCmd.class differ diff --git a/target/classes/com/azura4k/PowerWorld/commands/SetBlocksCmd.class b/target/classes/com/azura4k/PowerWorld/commands/SetBlocksCmd.class index 3d1c082..cbf744c 100644 Binary files a/target/classes/com/azura4k/PowerWorld/commands/SetBlocksCmd.class and b/target/classes/com/azura4k/PowerWorld/commands/SetBlocksCmd.class differ diff --git a/target/classes/com/azura4k/PowerWorld/commands/UndoCmd.class b/target/classes/com/azura4k/PowerWorld/commands/UndoCmd.class new file mode 100644 index 0000000..7796bca Binary files /dev/null and b/target/classes/com/azura4k/PowerWorld/commands/UndoCmd.class differ diff --git a/target/classes/com/azura4k/PowerWorld/commands/WandCmd.class b/target/classes/com/azura4k/PowerWorld/commands/WandCmd.class index 1468387..29d3007 100644 Binary files a/target/classes/com/azura4k/PowerWorld/commands/WandCmd.class and b/target/classes/com/azura4k/PowerWorld/commands/WandCmd.class differ diff --git a/target/classes/com/azura4k/PowerWorld/listeners/WandListener.class b/target/classes/com/azura4k/PowerWorld/listeners/WandListener.class index 3008ddf..583e5cd 100644 Binary files a/target/classes/com/azura4k/PowerWorld/listeners/WandListener.class and b/target/classes/com/azura4k/PowerWorld/listeners/WandListener.class differ diff --git a/target/classes/data.yaml b/target/classes/data.yaml new file mode 100644 index 0000000..e69de29 diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml index aa89052..1f57531 100644 --- a/target/classes/plugin.yml +++ b/target/classes/plugin.yml @@ -1,6 +1,6 @@ name: PowerWorld main: com.azura4k.PowerWorld.PowerWorld - version: 1.2 + version: 1.3 api: ["1.0.13"] author: Azura4k description: World Edit Designed for PowerNukkit Use. @@ -18,7 +18,10 @@ description: Replace Blocks With Specific ID with Another Block usage: "//replace " permission: powerworld.cmd.use - + undo: + description: Reverse a Block Command to the most recent command, or more. Only 5 commands back + usage: "//undo " + permission: powerworld.cmd.use permissions: powerworld.cmd.use: description: "Allows the user to run any world edit commands" diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index b7e3ecf..bd7d70e 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven -#Wed Nov 03 22:46:35 EDT 2021 +#Fri Nov 05 20:24:33 EDT 2021 groupId=com.azura4k artifactId=PowerWorld -version=1.2 +version=1.3 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 27dbec3..a649aac 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -4,3 +4,4 @@ com/azura4k/PowerWorld/listeners/WandListener.class com/azura4k/PowerWorld/commands/ReplaceBlocksCmd.class com/azura4k/PowerWorld/PowerWorldCommon.class com/azura4k/PowerWorld/commands/SetBlocksCmd.class +com/azura4k/PowerWorld/commands/UndoCmd.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 98abaeb..7f90647 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1,4 +1,5 @@ /Users/azura4k/Documents/Personal/Projects/Nukkit Plugins/PowerWorld/src/main/java/com/azura4k/PowerWorld/commands/WandCmd.java +/Users/azura4k/Documents/Personal/Projects/Nukkit Plugins/PowerWorld/src/main/java/com/azura4k/PowerWorld/commands/UndoCmd.java /Users/azura4k/Documents/Personal/Projects/Nukkit Plugins/PowerWorld/src/main/java/com/azura4k/PowerWorld/commands/SetBlocksCmd.java /Users/azura4k/Documents/Personal/Projects/Nukkit Plugins/PowerWorld/src/main/java/com/azura4k/PowerWorld/PowerWorld.java /Users/azura4k/Documents/Personal/Projects/Nukkit Plugins/PowerWorld/src/main/java/com/azura4k/PowerWorld/commands/ReplaceBlocksCmd.java