mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-28 02:47:34 +01:00
Added WorldGuard container protection
This commit is contained in:
parent
e2305225d3
commit
b1b97bbaf9
@ -1,6 +1,7 @@
|
||||
package com.Acrobot.ChestShop.Listeners;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Economy.Economy;
|
||||
import com.Acrobot.ChestShop.Economy.NoProvider;
|
||||
import com.Acrobot.ChestShop.Economy.Register;
|
||||
import com.Acrobot.ChestShop.Economy.Vault;
|
||||
@ -17,7 +18,6 @@ import com.nijikokun.register.payment.forChestShop.Methods;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.webkonsept.bukkit.simplechestlock.SCL;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
@ -29,34 +29,36 @@ import org.yi.acru.bukkit.Lockette.Lockette;
|
||||
public class pluginEnable {
|
||||
|
||||
public static void initializePlugins() {
|
||||
Security.protections.add(new Default()); //Initialize basic protection
|
||||
Security.protections.add(Security.getDefaultProtection());
|
||||
|
||||
for (Object plugin : ChestShop.getDependencies()) {
|
||||
Plugin pl = ChestShop.pm.getPlugin((String) plugin);
|
||||
if (pl != null) initializePlugin((String) plugin, pl);
|
||||
if (pl != null) {
|
||||
initializePlugin((String) plugin, pl);
|
||||
}
|
||||
}
|
||||
loadRegister();
|
||||
}
|
||||
|
||||
private static void loadRegister() {
|
||||
if (com.Acrobot.ChestShop.Economy.Economy.economy == null) {
|
||||
Method m = Methods.load(ChestShop.pm);
|
||||
if (m == null) {
|
||||
com.Acrobot.ChestShop.Economy.Economy.economy = new NoProvider();
|
||||
return;
|
||||
}
|
||||
Register.eco = m;
|
||||
com.Acrobot.ChestShop.Economy.Economy.economy = new Register();
|
||||
System.out.println(ChestShop.chatPrefix + m.getName() + " version " + m.getVersion() + " loaded.");
|
||||
if (Economy.economy != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Method method = Methods.load(ChestShop.pm);
|
||||
if (method == null) {
|
||||
Economy.economy = new NoProvider();
|
||||
return;
|
||||
}
|
||||
Economy.economy = new Register(method);
|
||||
System.out.println(ChestShop.chatPrefix + method.getName() + " version " + method.getVersion() + " loaded.");
|
||||
}
|
||||
|
||||
private static void initializePlugin(String name, Plugin plugin) { //Really messy, right? But it's short and fast :)
|
||||
if (name.equals("LWC")) {
|
||||
LWCplugin.setLWC(((LWCPlugin) plugin).getLWC());
|
||||
Security.protections.add(new LWCplugin());
|
||||
Security.protections.add(new LWCplugin(((LWCPlugin) plugin).getLWC()));
|
||||
} else if (name.equals("Lockette")) {
|
||||
LockettePlugin.lockette = (Lockette) plugin;
|
||||
Security.protections.add(new LockettePlugin());
|
||||
Security.protections.add(new LockettePlugin((Lockette) plugin));
|
||||
} else if (name.equals("Deadbolt")) {
|
||||
Security.protections.add(new DeadboltPlugin());
|
||||
} else if (name.equals("OddItem")) {
|
||||
@ -64,22 +66,25 @@ public class pluginEnable {
|
||||
} else if (name.equals("Towny")) {
|
||||
uSign.towny = (Towny) plugin;
|
||||
} else if (name.equals("WorldGuard")) {
|
||||
Security.protections.add(new WorldGuardProtectionPlugin((WorldGuardPlugin) plugin));
|
||||
uWorldGuard.wg = (WorldGuardPlugin) plugin;
|
||||
uWorldGuard.injectHax(); //Inject hax into WorldGuard
|
||||
} else if (name.equals("Vault")) {
|
||||
if (com.Acrobot.ChestShop.Economy.Economy.economy != null) return;
|
||||
RegisteredServiceProvider<Economy> rsp = ChestShop.getBukkitServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (Economy.economy != null) return;
|
||||
|
||||
RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> rsp = ChestShop.getBukkitServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (rsp == null) return;
|
||||
|
||||
Vault.economy = rsp.getProvider();
|
||||
if (Vault.economy == null) return;
|
||||
com.Acrobot.ChestShop.Economy.Economy.economy = new Vault();
|
||||
|
||||
Economy.economy = new Vault();
|
||||
System.out.println(ChestShop.chatPrefix + "Vault loaded using economy plugin " + Vault.economy.getName());
|
||||
return;
|
||||
} else if (name.equals("Heroes")) {
|
||||
uHeroes.heroes = (Heroes) plugin;
|
||||
} else if (name.equals("SimpleChestLock")) {
|
||||
SCLplugin.scl = (SCL) plugin;
|
||||
Security.protections.add(new SCLplugin());
|
||||
Security.protections.add(new SCLplugin((SCL) plugin));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@ -89,6 +94,6 @@ public class pluginEnable {
|
||||
}
|
||||
|
||||
private static String generateOutdatedVersion(String pluginName, String curVersion, String neededVersion) {
|
||||
return (new StringBuilder(7).append(ChestShop.chatPrefix).append("Your ").append(pluginName).append(" is outdated! Need version AT LEAST ").append(neededVersion).append(" - Your version is ").append(curVersion).toString());
|
||||
return ChestShop.chatPrefix + "Your " + pluginName + " is outdated! Need version AT LEAST " + neededVersion + " - Your version is " + curVersion;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.Acrobot.ChestShop.Protection.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Protection.Protection;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class WorldGuardProtectionPlugin implements Protection {
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
public WorldGuardProtectionPlugin(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
public boolean isProtected(Block block) {
|
||||
Vector pt = BukkitUtil.toVector(block);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
return !set.allows(DefaultFlag.CHEST_ACCESS);
|
||||
}
|
||||
|
||||
public boolean canAccess(Player player, Block block) {
|
||||
Vector pt = BukkitUtil.toVector(block);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
LocalPlayer locPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
return plugin.getGlobalRegionManager().hasBypass(locPlayer, block.getWorld()) || set.canBuild(locPlayer) || set.allows(DefaultFlag.CHEST_ACCESS, locPlayer);
|
||||
}
|
||||
|
||||
public boolean protect(String name, Block block) {
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user