Skip to content

Commit

Permalink
Fixed the setfloor command
Browse files Browse the repository at this point in the history
  • Loading branch information
Challenger2 committed Dec 10, 2022
1 parent 79e5110 commit 5cacd62
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 30 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ SpeedBuildArena

Build Instructions
------------------

1. Download BlocksHub and install that to the local Maven repository:
```
wget https://github.com/SBPrime/BlocksHub/releases/download/v3.1.0/BlocksHub-3.1.0.jar
mvn install:install-file -DgroupId=org.primesoft -DartifactId=blockshub -Dversion=3.1.0 \
-Dpackaging=jar -Dfile=./BlocksHub-3.1.0.jar
```
2. Finally, compile this plugin:

1. Compile:
```
git clone https://github.com/NerdNu/SpeedBuildArena
cd SpeedBuildArena
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>nu.nerd</groupId>
<artifactId>SpeedBuildArena</artifactId>
<version>0.6.0-SNAPSHOT</version>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>SpeedBuildArena</name>
<description>Speed Build Arena contest management commands.</description>
Expand Down Expand Up @@ -44,21 +44,21 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.8</version>
<version>7.2.12</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.6</version>
<version>7.0.7</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
Expand Down
107 changes: 91 additions & 16 deletions src/main/java/nu/nerd/SpeedBuildArena/SBAPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

// import com.sk89q.worldedit.MaxChangedBlocksException;
// import com.sk89q.worldedit.WorldEdit;
// import com.sk89q.worldedit.WorldEditException;
// import com.sk89q.worldedit.extension.factory.BlockFactory;
// import com.sk89q.worldedit.extension.input.ParserContext;
// import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;

import net.md_5.bungee.api.ChatColor;

Expand Down Expand Up @@ -198,16 +201,88 @@ private void cmdAbort(CommandSender sender, String[] args) {
* @param sender The player
* @param args The block type to set the floor too
*/
private void cmdSetFloor(CommandSender sender, String[] args) {
int num = (int)(Math.random()*4.0);
String msg;
switch (num) {
case 0: msg = "This command is down for repairs."; break;
case 1: msg = "Try again later."; break;
case 2: msg = "I can't do that Dave."; break;
default: msg = "This command is down. Please try again."; break;
private void cmdSetFloor(CommandSender sender, String[] args) throws WorldEditException, MaxChangedBlocksException{
if (!(sender instanceof Player)) {
sender.sendMessage("Silly Console. Trix are for kids");
return;
}

Player player = (Player)sender;

// Ensure that an event is in progress
if (_speedBuild == null) {
sender.sendMessage(ChatColor.RED + "A Speed Build event is not in progress. Sorry :(");
return;
}

if (args.length != 0) {
printSetFloorUsage(sender);
return;
}

World world = getServer().getWorld(_config.WORLD_NAME);
if (world == null) {
throw new IllegalStateException("Unknown world \"%s\"".format(_config.WORLD_NAME));
}

//// Find what plot the player is in.
int x, y, z;
x = (int)player.getLocation().getX();
y = (int)player.getLocation().getY();
z = (int)player.getLocation().getZ();
SBAPlot plot = null;
for(SBAPlot p : _speedBuild.getPlots()) {
if(p.getPlot().contains(x, y, z)) {
// Make sure the player is registered with this plot
if (p.getPlot().getOwners().contains(player.getUniqueId())
|| p.getPlot().getMembers().contains(player.getUniqueId())) {
plot = p;
break;
} else {
sender.sendMessage(ChatColor.RED + "Get off my lawn, you whippersnapper! Find your own plot!");
return;
}
}
}
if (plot == null) {
sender.sendMessage(ChatColor.RED + "You must be standing in your plot");
return;
}
sender.sendMessage(ChatColor.RED + msg);

//// Create WE region
CuboidRegion region = new CuboidRegion(
plot.getFloor().getMaximumPoint(),
plot.getFloor().getMinimumPoint());

//// Lookup the block.
BaseBlock block = null;
try {
block = BukkitAdapter.adapt(player).getBlockInHand(HandSide.MAIN_HAND);
} catch (NotABlockException e) {
sendInvalidBlockMsg(sender);
return;
}

//// Block blocks that are not solid, such as air and levers.
if (block == null || !block.getBlockType().getMaterial().isSolid()) {
// Don't allow org.bukkit.Materiall.AIR
sendInvalidBlockMsg(sender);
return;
}

//// Set the floor.
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world))) {
editSession.setBlocks(region, block);
}

}

/**
* Send the invalid block message to the player
*
*/
public void sendInvalidBlockMsg(CommandSender sender) {
sender.sendMessage(ChatColor.RED + "You must hold a " + ChatColor.BOLD + "block" + ChatColor.RESET + ChatColor.RED + " in your hand.");
}

/**
Expand Down Expand Up @@ -261,7 +336,7 @@ public void printReloadUsage(CommandSender sender) {
* @param sender
*/
public void printSetFloorUsage(CommandSender sender) {
sender.sendMessage(ChatColor.GREEN + "/SpeedBuildArena setfloor BLOCK");
sender.sendMessage(ChatColor.GREEN + "/SpeedBuildArena setfloor");
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ plots:
plot3:
region_plot: sbaplot03
region_floor: sbaplot03_floor
plot4:
region_plot: sbaplot04
region_floor: sbaplot04_floor

# Example arena command sequence.
# There are 4 commands you can use.
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ description: ${description}
website: ${url}
database: false
depend: [WorldGuard]
softdepend: [WGRegionEvents,BlocksHub,WorldEdit]
softdepend: [BlocksHub,WorldEdit]
author: [Challenger2]
main: nu.nerd.SpeedBuildArena.SBAPlugin
api-version: 1.13
api-version: 1.18

commands:
speedbuildarena:
Expand Down

0 comments on commit 5cacd62

Please sign in to comment.