Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Version 1.3 Update
Browse files Browse the repository at this point in the history
Fixed Bug where any Object of same ID will trigger

Added ability for wands to hold coordinates for dual use.

Selected Coordinates are now displayed on Wands Lore

Multiple Wands can be used at one time

Shortened Position Location Messages

Added Undo Command. Stores 5 commands at a time

Fixed up code and moved every function to api needed for organization
  • Loading branch information
serengon4k committed Nov 6, 2021
1 parent 5a3c439 commit 39b4786
Show file tree
Hide file tree
Showing 22 changed files with 160 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.azura4k</groupId>
<artifactId>PowerWorld</artifactId>
<version>1.2</version>
<version>1.3</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
26 changes: 11 additions & 15 deletions src/main/java/com/azura4k/PowerWorld/PowerWorld.java
Original file line number Diff line number Diff line change
@@ -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<Block> Blocks = new ArrayList<>();
public static ArrayList<ArrayList<Block>> UndoList = new ArrayList<>();
public static final int UndoStorageLimit = 5;

@Override
public void onLoad() {
Expand All @@ -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() {
Expand All @@ -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;
}
}
95 changes: 89 additions & 6 deletions src/main/java/com/azura4k/PowerWorld/PowerWorldCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
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<Block> Execution = new ArrayList<Block>();
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<ArrayList<Block>> 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;
}
}



Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/com/azura4k/PowerWorld/commands/SetBlocksCmd.java
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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());
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/azura4k/PowerWorld/commands/UndoCmd.java
Original file line number Diff line number Diff line change
@@ -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);
}


}
4 changes: 2 additions & 2 deletions src/main/java/com/azura4k/PowerWorld/commands/WandCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -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{

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,7 +18,10 @@
description: Replace Blocks With Specific ID with Another Block
usage: "//replace <NewBlockID:Meta> <BlockBeingReplaced:Meta>"
permission: powerworld.cmd.use

undo:
description: Reverse a Block Command to the most recent command, or more. Only 5 commands back
usage: "//undo <Sequence:Int>"
permission: powerworld.cmd.use
permissions:
powerworld.cmd.use:
description: "Allows the user to run any world edit commands"
Expand Down
Binary file added target/PowerWorld-1.3.jar
Binary file not shown.
Binary file modified target/classes/com/azura4k/PowerWorld/PowerWorld.class
Binary file not shown.
Binary file modified target/classes/com/azura4k/PowerWorld/PowerWorldCommon.class
Binary file not shown.
Binary file not shown.
Binary file modified target/classes/com/azura4k/PowerWorld/commands/SetBlocksCmd.class
Binary file not shown.
Binary file not shown.
Binary file modified target/classes/com/azura4k/PowerWorld/commands/WandCmd.class
Binary file not shown.
Binary file not shown.
Empty file added target/classes/data.yaml
Empty file.
7 changes: 5 additions & 2 deletions target/classes/plugin.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,7 +18,10 @@
description: Replace Blocks With Specific ID with Another Block
usage: "//replace <NewBlockID:Meta> <BlockBeingReplaced:Meta>"
permission: powerworld.cmd.use

undo:
description: Reverse a Block Command to the most recent command, or more. Only 5 commands back
usage: "//undo <Sequence:Int>"
permission: powerworld.cmd.use
permissions:
powerworld.cmd.use:
description: "Allows the user to run any world edit commands"
Expand Down
4 changes: 2 additions & 2 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 39b4786

Please sign in to comment.