Skip to content

Commit

Permalink
Updated for minecraft 1.18.2 - Removed WGRegionEvents dep
Browse files Browse the repository at this point in the history
  • Loading branch information
Challenger2 committed May 30, 2022
1 parent ed83184 commit 79e5110
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 164 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ SpeedBuildArena

Build Instructions
------------------
1. Build WorldGuard-Region-Events and install to the local Maven repository:
```
git clone https://github.com/NerdNu/WorldGuard-Region-Events
cd WorldGuard-Region-Events
mvn install
```
2. Download BlocksHub and install that to the local Maven repository:

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
```
3. Finally, compile this plugin:
2. Finally, compile this plugin:
```
git clone https://github.com/NerdNu/SpeedBuildArena
cd SpeedBuildArena
Expand Down
34 changes: 17 additions & 17 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.5.0-SNAPSHOT</version>
<version>0.6.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SpeedBuildArena</name>
<description>Speed Build Arena contest management commands.</description>
Expand All @@ -31,7 +31,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -41,26 +41,26 @@
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>
<version>7.0.0-SNAPSHOT</version>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.8</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.mewin</groupId>
<artifactId>WGRegionEvents</artifactId>
<version>1.3.0-nerdnu</version>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.6</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
</dependencies>

Expand All @@ -70,8 +70,8 @@
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>sk89q</id>
<url>http://maven.sk89q.com/repo</url>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
</repositories>
</project>
95 changes: 37 additions & 58 deletions src/main/java/nu/nerd/SpeedBuildArena/SBA.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
import java.util.ArrayList;
import java.util.List;

import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
//import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitTask;

import com.mewin.WGRegionEvents.events.RegionEnteredEvent;
import com.mewin.WGRegionEvents.events.RegionLeftEvent;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldedit.bukkit.BukkitAdapter;

import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.WorldGuard;

import nu.nerd.SpeedBuildArena.SBAScript.SBACommand;

Expand All @@ -34,7 +33,7 @@
* permissions at the end of the round
*
*/
public class SBA implements AutoCloseable, Runnable, Listener {
public class SBA implements AutoCloseable, Runnable {
private SBAPlugin _sba;
private SBAConfig _config;
private RegionManager _wgrm;
Expand Down Expand Up @@ -75,7 +74,7 @@ public SBA(SBAPlugin sba) throws Exception {
}

// Get the region manager for the world
_wgrm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(new BukkitWorld(world));
_wgrm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
if (_wgrm == null) {
logNthrow("Failed to get World guard RegionManager for world: \"%s\".", world);
}
Expand Down Expand Up @@ -115,13 +114,8 @@ private void logNthrow(String format, Object... args) throws Exception {
* Remove all owners and members from all sba plots
*/
public void wipePlots() {
// String worldName = _config.WORLD_NAME;
try {
for (SBAPlot plot : _plots) {
// dispatchCommand(String.format("rg removeowner %s -a -w %s",
// plot.getPlot().getId(), worldName));
// dispatchCommand(String.format("rg removemember %s -a -w %s",
// plot.getPlot().getId(), worldName));
plot.getPlot().getOwners().clear();
plot.getPlot().getMembers().clear();
}
Expand Down Expand Up @@ -164,9 +158,8 @@ public void run() {
stopBossBar();
} else if (now > _bossBarNextUpdateTime) {
_bossBarNextUpdateTime += 1000;
_bossBar.setProgress(1.0 - ((double) now - (double) _bossBarStartTime)
/ ((double) _bossBarStopTime
- (double) _bossBarStartTime));
_bossBar.setProgress(((double) now - (double) _bossBarStopTime)
/ ((double) _bossBarStartTime - (double) _bossBarStopTime));
updateBossTitle(_bossBarStopTime - now);
}
}
Expand All @@ -185,30 +178,6 @@ public void run() {
}
}

/**
* Add players to the boss bar if they enter the Speed Build Arena
*
* @param event The Event
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerEnteredRegion(RegionEnteredEvent event) {
if (event.getRegion() == _arena && _bossBar != null) {
_bossBar.addPlayer(event.getPlayer());
}
}

/**
* Remove players from the boss bar if they leave the Speed Build Arena
*
* @param event The Event
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLeftRegion(RegionLeftEvent event) {
if (event.getRegion() == _arena && _bossBar != null) {
_bossBar.removePlayer(event.getPlayer());
}
}

/**
* Get the SpeedBuildPlugin
*
Expand Down Expand Up @@ -292,31 +261,17 @@ public void startBossTimer(long duration) {
if (_bossBar == null) {
_bossBar = _sba.getServer().createBossBar("", BarColor.BLUE, BarStyle.SOLID);
_bossBar.setProgress(1.0);
_bossBar.setVisible(false);
_bossBar.setVisible(true);
updateBossTitle(duration);

// Register for events
if (_config.HAVE_WGREGION_EVENTS) {
_sba.getServer().getPluginManager().registerEvents(this, _sba);
}
}

// Show the boss bar to all players in Speed Build Arena
for (Player player : getServer().getOnlinePlayers()) {
int x, y, z;
x = (int) player.getLocation().getX();
y = (int) player.getLocation().getY();
z = (int) player.getLocation().getZ();
if (_arena.contains(x, y, z)) {
_bossBar.addPlayer(player);
}
}
_bossBar.setVisible(true);

// Setup all the timers
_bossBarStartTime = System.currentTimeMillis();
_bossBarStopTime = _bossBarStartTime + duration;
_bossBarNextUpdateTime = _bossBarStartTime + 1000;

// Add palyers
freshenBossPlayers();
}

/**
Expand All @@ -328,7 +283,6 @@ public void stopBossBar() {
_bossBar.setVisible(false);
_bossBar = null;
}
HandlerList.unregisterAll(this);
}

/**
Expand All @@ -347,6 +301,31 @@ private void updateBossTitle(long timeRemaining) {
long minutes = acc / 60;

_bossBar.setTitle(String.format("Speed Build %02d:%02d", minutes, seconds));
freshenBossPlayers();
}
}

/**
* Make sure only players in the _arena see the boss bar.
*/
private void freshenBossPlayers() {
if (_bossBar == null) {
return;
}

for (Player player: getServer().getOnlinePlayers()) {
Location location = player.getLocation();
int x = (int)location.getX();
int y = (int)location.getY();
int z = (int)location.getZ();

// It is apparently OK to add or remove a player multiple times
// from the boss bar.
if (_arena.contains(x, y, z)) {
_bossBar.addPlayer(player);
} else {
_bossBar.removePlayer(player);
}
}
}

Expand Down
49 changes: 6 additions & 43 deletions src/main/java/nu/nerd/SpeedBuildArena/SBAPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
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.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.factory.BlockFactory;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
// 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 net.md_5.bungee.api.ChatColor;

Expand All @@ -39,9 +36,6 @@
*/
public class SBAPlugin extends JavaPlugin {

private WorldGuardPlugin _wg = null;
private WorldEdit _we = null;
private WorldEditPlugin _wep = null;
private SBAConfig _config;
private SBA _speedBuild = null;

Expand All @@ -52,25 +46,6 @@ public class SBAPlugin extends JavaPlugin {
public void onEnable() {
getLogger().info("Loading SpeedBuildArena");

// Load plugins
Plugin p;

p = getServer().getPluginManager().getPlugin("WorldGuard");
if (p == null || !(p instanceof WorldGuardPlugin)) {
getLogger().severe("Failed to load WorldGuard plugin");
getServer().getPluginManager().disablePlugin(this);
return;
}
_wg = (WorldGuardPlugin) p;
getLogger().info("Loaded WorldGuard plugin");

p = getServer().getPluginManager().getPlugin("WorldEdit");
if (p != null && (p instanceof WorldEditPlugin)) {
_wep = (WorldEditPlugin) p;
_we = _wep.getWorldEdit();
getLogger().info("Loaded WorldEdit plugin");
}

saveDefaultConfig();

_config = new SBAConfig();
Expand All @@ -93,9 +68,6 @@ public void onDisable() {
_speedBuild = null;
}
_config = null;
_wg = null;
_we = null;
_wep = null;
}

/**
Expand Down Expand Up @@ -292,15 +264,6 @@ public void printSetFloorUsage(CommandSender sender) {
sender.sendMessage(ChatColor.GREEN + "/SpeedBuildArena setfloor BLOCK");
}

/**
* Return the world guard plugin.
*
* @return World Guard
*/
public WorldGuardPlugin getWorldGuard() {
return _wg;
}

/**
* Return configuration object
*
Expand Down
38 changes: 0 additions & 38 deletions src/test/java/nu/nerd/SpeedBuild/AppTest.java

This file was deleted.

0 comments on commit 79e5110

Please sign in to comment.