Add WorldGuard support.
This commit is contained in:
parent
2cf6eda7a6
commit
232d8150e6
21
pom.xml
21
pom.xml
@ -28,6 +28,10 @@
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>http://maven.sk89q.com/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -65,6 +69,23 @@
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -22,8 +22,10 @@ import com.gmail.bleedobsidian.itemcase.Itemcase.ItemcaseListener;
|
||||
import com.gmail.bleedobsidian.itemcase.configurations.ConfigFile;
|
||||
import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
|
||||
import com.gmail.bleedobsidian.itemcase.managers.OrderManager;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import java.io.IOException;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -81,10 +83,20 @@ public final class ItemCaseCore extends JavaPlugin {
|
||||
*/
|
||||
private boolean hasVault;
|
||||
|
||||
/**
|
||||
* If the server has WorldGuard.
|
||||
*/
|
||||
private boolean hasWorldGuard;
|
||||
|
||||
/**
|
||||
* The economy provider if there is one.
|
||||
*/
|
||||
private Economy economyProvider;
|
||||
|
||||
/**
|
||||
* WorldGuard.
|
||||
*/
|
||||
private WorldGuardPlugin worldGuard;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@ -144,6 +156,9 @@ public final class ItemCaseCore extends JavaPlugin {
|
||||
// Attempt to load Vault.
|
||||
this.loadVault();
|
||||
|
||||
// Attempt to load WorldGuard.
|
||||
this.loadWorldGuard();
|
||||
|
||||
// Set version placeholder and log.
|
||||
this.translator.setPlaceholder("%VERSION%",
|
||||
this.getDescription().getVersion());
|
||||
@ -196,6 +211,28 @@ public final class ItemCaseCore extends JavaPlugin {
|
||||
this.hasVault = true;
|
||||
}
|
||||
|
||||
private void loadWorldGuard() {
|
||||
|
||||
// Get plugin.
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
|
||||
// Check if the server has WorldGuard installed.
|
||||
if(plugin == null) {
|
||||
|
||||
// Set false.
|
||||
this.hasWorldGuard = false;
|
||||
|
||||
// Exit.
|
||||
return;
|
||||
}
|
||||
|
||||
// Set true.
|
||||
this.hasWorldGuard = true;
|
||||
|
||||
// Set worldguard.
|
||||
this.worldGuard = (WorldGuardPlugin) plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* @return Main ItemCase configuration file.
|
||||
@ -253,10 +290,24 @@ public final class ItemCaseCore extends JavaPlugin {
|
||||
return this.hasVault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If WorldGuard is setup on this server.
|
||||
*/
|
||||
public boolean hasWorldGuard() {
|
||||
return this.hasWorldGuard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EconomyProvider.
|
||||
*/
|
||||
public Economy getEconomyProvider() {
|
||||
return this.economyProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WorldGuard.
|
||||
*/
|
||||
public WorldGuardPlugin getWorldGuard() {
|
||||
return this.worldGuard;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
@ -140,6 +141,12 @@ public final class Itemcase {
|
||||
public Itemcase(Type type, ItemStack itemStack, Location location,
|
||||
OfflinePlayer owner) {
|
||||
|
||||
// Check params are not null.
|
||||
Validate.notNull(type, "Itemcase type can not be null.");
|
||||
Validate.notNull(itemStack, "Itemstack can not be null.");
|
||||
Validate.notNull(location, "Location can not be null.");
|
||||
Validate.notNull(owner, "Owner can not be null.");
|
||||
|
||||
// Set type.
|
||||
this.type = type;
|
||||
|
||||
@ -349,7 +356,7 @@ public final class Itemcase {
|
||||
// Location of this itemcase.
|
||||
return this.location;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The owner of this itemcase.
|
||||
*/
|
||||
@ -653,7 +660,7 @@ public final class Itemcase {
|
||||
* is particularly useful when servers use anti-lag plugins that forcibly
|
||||
* kill entities or a player has somehow caused an item to move.
|
||||
*/
|
||||
private final class ItemcaseTask extends BukkitRunnable {
|
||||
public final class ItemcaseTask extends BukkitRunnable {
|
||||
|
||||
/**
|
||||
* The itemcase that this task is for.
|
||||
|
@ -18,6 +18,7 @@ import com.gmail.bleedobsidian.itemcase.Command;
|
||||
import com.gmail.bleedobsidian.itemcase.loggers.ChatLogger;
|
||||
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
||||
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -102,6 +103,23 @@ public final class CreateCommand implements Command {
|
||||
// Exit.
|
||||
return;
|
||||
}
|
||||
|
||||
// If this server has WorldGuard.
|
||||
if(ItemCaseCore.instance.hasWorldGuard()) {
|
||||
|
||||
// Get world guard.
|
||||
WorldGuardPlugin worldGuard = ItemCaseCore.instance.getWorldGuard();
|
||||
|
||||
// If player cannot build here.
|
||||
if(!worldGuard.canBuild(player, target)) {
|
||||
|
||||
// Show message.
|
||||
chatLogger.message(player, "command.create.no-build");
|
||||
|
||||
// Exit.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Get item in players main hand to use as the Itemcase item.
|
||||
itemStack = player.getInventory().getItemInMainHand();
|
||||
|
@ -69,6 +69,9 @@ command:
|
||||
# holding any item in their main hand.
|
||||
main-hand: "You must be holding something in your main hand."
|
||||
|
||||
# Shown when a player tries to make an itemcase in a WorldGuard restricted location.
|
||||
no-build: "You do not have building permission here."
|
||||
|
||||
# Shown to the player upon successful creation.
|
||||
success: "ItemCase created."
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user