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>
|
<id>vault-repo</id>
|
||||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sk89q-repo</id>
|
||||||
|
<url>http://maven.sk89q.com/repo/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -65,6 +69,23 @@
|
|||||||
<version>1.6</version>
|
<version>1.6</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -22,8 +22,10 @@ import com.gmail.bleedobsidian.itemcase.Itemcase.ItemcaseListener;
|
|||||||
import com.gmail.bleedobsidian.itemcase.configurations.ConfigFile;
|
import com.gmail.bleedobsidian.itemcase.configurations.ConfigFile;
|
||||||
import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
|
import com.gmail.bleedobsidian.itemcase.managers.ItemcaseManager;
|
||||||
import com.gmail.bleedobsidian.itemcase.managers.OrderManager;
|
import com.gmail.bleedobsidian.itemcase.managers.OrderManager;
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -81,11 +83,21 @@ public final class ItemCaseCore extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
private boolean hasVault;
|
private boolean hasVault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the server has WorldGuard.
|
||||||
|
*/
|
||||||
|
private boolean hasWorldGuard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The economy provider if there is one.
|
* The economy provider if there is one.
|
||||||
*/
|
*/
|
||||||
private Economy economyProvider;
|
private Economy economyProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WorldGuard.
|
||||||
|
*/
|
||||||
|
private WorldGuardPlugin worldGuard;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
@ -144,6 +156,9 @@ public final class ItemCaseCore extends JavaPlugin {
|
|||||||
// Attempt to load Vault.
|
// Attempt to load Vault.
|
||||||
this.loadVault();
|
this.loadVault();
|
||||||
|
|
||||||
|
// Attempt to load WorldGuard.
|
||||||
|
this.loadWorldGuard();
|
||||||
|
|
||||||
// Set version placeholder and log.
|
// Set version placeholder and log.
|
||||||
this.translator.setPlaceholder("%VERSION%",
|
this.translator.setPlaceholder("%VERSION%",
|
||||||
this.getDescription().getVersion());
|
this.getDescription().getVersion());
|
||||||
@ -196,6 +211,28 @@ public final class ItemCaseCore extends JavaPlugin {
|
|||||||
this.hasVault = true;
|
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.
|
* @return Main ItemCase configuration file.
|
||||||
@ -253,10 +290,24 @@ public final class ItemCaseCore extends JavaPlugin {
|
|||||||
return this.hasVault;
|
return this.hasVault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return If WorldGuard is setup on this server.
|
||||||
|
*/
|
||||||
|
public boolean hasWorldGuard() {
|
||||||
|
return this.hasWorldGuard;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return EconomyProvider.
|
* @return EconomyProvider.
|
||||||
*/
|
*/
|
||||||
public Economy getEconomyProvider() {
|
public Economy getEconomyProvider() {
|
||||||
return this.economyProvider;
|
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.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -140,6 +141,12 @@ public final class Itemcase {
|
|||||||
public Itemcase(Type type, ItemStack itemStack, Location location,
|
public Itemcase(Type type, ItemStack itemStack, Location location,
|
||||||
OfflinePlayer owner) {
|
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.
|
// Set type.
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
@ -653,7 +660,7 @@ public final class Itemcase {
|
|||||||
* is particularly useful when servers use anti-lag plugins that forcibly
|
* is particularly useful when servers use anti-lag plugins that forcibly
|
||||||
* kill entities or a player has somehow caused an item to move.
|
* 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.
|
* 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.loggers.ChatLogger;
|
||||||
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
|
||||||
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -103,6 +104,23 @@ public final class CreateCommand implements Command {
|
|||||||
return;
|
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.
|
// Get item in players main hand to use as the Itemcase item.
|
||||||
itemStack = player.getInventory().getItemInMainHand();
|
itemStack = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
|
@ -69,6 +69,9 @@ command:
|
|||||||
# holding any item in their main hand.
|
# holding any item in their main hand.
|
||||||
main-hand: "You must be holding something in your 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.
|
# Shown to the player upon successful creation.
|
||||||
success: "ItemCase created."
|
success: "ItemCase created."
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user