mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-30 22:44:07 +01:00
Added sign alternative for /buyregion
Added flag for lever and button usability
This commit is contained in:
parent
676e744c02
commit
82dc78523f
@ -83,6 +83,7 @@ regions:
|
|||||||
creeper: on
|
creeper: on
|
||||||
mobdamage: on
|
mobdamage: on
|
||||||
waterflow: on
|
waterflow: on
|
||||||
|
leverandbutton: on
|
||||||
|
|
||||||
iconomy:
|
iconomy:
|
||||||
enable: on
|
enable: on
|
||||||
|
@ -18,23 +18,31 @@
|
|||||||
*/
|
*/
|
||||||
package com.sk89q.worldguard.bukkit;
|
package com.sk89q.worldguard.bukkit;
|
||||||
|
|
||||||
|
import com.nijiko.coelho.iConomy.iConomy;
|
||||||
|
import com.nijiko.coelho.iConomy.system.Account;
|
||||||
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.block.*;
|
import org.bukkit.event.block.*;
|
||||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.blacklist.events.*;
|
import com.sk89q.worldguard.blacklist.events.*;
|
||||||
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||||
|
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
|
||||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||||
|
|
||||||
public class WorldGuardBlockListener extends BlockListener {
|
public class WorldGuardBlockListener extends BlockListener {
|
||||||
@ -399,6 +407,7 @@ public void onBlockInteract(BlockInteractEvent event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
|
Material type = block.getType();
|
||||||
LivingEntity entity = event.getEntity();
|
LivingEntity entity = event.getEntity();
|
||||||
|
|
||||||
WorldGuardConfiguration cfg = plugin.getWgConfiguration();
|
WorldGuardConfiguration cfg = plugin.getWgConfiguration();
|
||||||
@ -427,6 +436,19 @@ public void onBlockInteract(BlockInteractEvent event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wcfg.useRegions && (type == Material.LEVER || type == Material.STONE_BUTTON) && entity instanceof Player) {
|
||||||
|
Vector pt = toVector(block);
|
||||||
|
RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().getRegionManager(((Player)entity).getWorld().getName());
|
||||||
|
ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt);
|
||||||
|
LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(cfg, (Player)entity);
|
||||||
|
|
||||||
|
if (!applicableRegions.isFlagAllowed(AreaFlags.FLAG_LEVER_AND_BUTTON, true, localPlayer)) {
|
||||||
|
((Player)entity).sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (wcfg.getBlacklist() != null && entity instanceof Player) {
|
if (wcfg.getBlacklist() != null && entity instanceof Player) {
|
||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
|
|
||||||
@ -547,6 +569,49 @@ public void onBlockRightClick(BlockRightClickEvent event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wcfg.useRegions && wcfg.useiConomy && cfg.getiConomy() != null && (type == Material.SIGN || type == Material.WALL_SIGN)) {
|
||||||
|
if (((Sign)blockClicked).getLine(0) == "[WorldGuard]" && ((Sign)blockClicked).getLine(1) == "For sale") {
|
||||||
|
String regionId = ((Sign)blockClicked).getLine(2);
|
||||||
|
String regionComment = ((Sign)blockClicked).getLine(3);
|
||||||
|
|
||||||
|
if (regionId != null && regionId != "") {
|
||||||
|
RegionManager mgr = cfg.getWorldGuardPlugin().getGlobalRegionManager().getRegionManager(player.getWorld().getName());
|
||||||
|
ProtectedRegion region = mgr.getRegion(regionId);
|
||||||
|
|
||||||
|
if (region != null) {
|
||||||
|
AreaFlags flags = region.getFlags();
|
||||||
|
|
||||||
|
if (flags.getBooleanFlag("iconomy", "buyable", false)) {
|
||||||
|
if (iConomy.getBank().hasAccount(player.getName())) {
|
||||||
|
Account account = iConomy.getBank().getAccount(player.getName());
|
||||||
|
double balance = account.getBalance();
|
||||||
|
int regionPrice = flags.getIntFlag("iconomy", "price");
|
||||||
|
|
||||||
|
if (balance >= regionPrice) {
|
||||||
|
account.subtract(regionPrice);
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "You have bought the region " + regionId + " for " +
|
||||||
|
iConomy.getBank().format(regionPrice));
|
||||||
|
DefaultDomain owners = region.getOwners();
|
||||||
|
owners.addPlayer(player.getName());
|
||||||
|
region.setOwners(owners);
|
||||||
|
flags.setFlag("iconomy", "buyable", false);
|
||||||
|
account.save();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.RED + "Region: " + regionId + " is not buyable");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.DARK_RED + "The region " + regionId + " does not exist.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.DARK_RED + "No region specified.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,6 +64,7 @@ public static enum FlagValueType { STRING, BOOLEAN, INT, FLOAT, DOUBLE, STATE, L
|
|||||||
flagList.add(new FlagInfo("teleport", "set", FlagValueType.LOCATION, "teleport", ""));
|
flagList.add(new FlagInfo("teleport", "set", FlagValueType.LOCATION, "teleport", ""));
|
||||||
flagList.add(new FlagInfo("teleport", "delete", FlagValueType.LOCATION, "teleport", ""));
|
flagList.add(new FlagInfo("teleport", "delete", FlagValueType.LOCATION, "teleport", ""));
|
||||||
flagList.add(new FlagInfo("teleport", "allow", FlagValueType.STRING, "teleport", "allow"));
|
flagList.add(new FlagInfo("teleport", "allow", FlagValueType.STRING, "teleport", "allow"));
|
||||||
|
flagList.add(new FlagInfo("leverandbutton", null, FlagValueType.STATE, "states", "leverandbutton"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FlagInfo getFlagInfo(String name, String subName) {
|
public static FlagInfo getFlagInfo(String name, String subName) {
|
||||||
|
@ -108,12 +108,14 @@ public boolean allowsFlag(String flag) {
|
|||||||
def = global.allowMobDamage;
|
def = global.allowMobDamage;
|
||||||
} else if (flag.equals(AreaFlags.FLAG_WATER_FLOW)) {
|
} else if (flag.equals(AreaFlags.FLAG_WATER_FLOW)) {
|
||||||
def = global.allowWaterflow;
|
def = global.allowWaterflow;
|
||||||
|
} else if (flag.equals(AreaFlags.FLAG_LEVER_AND_BUTTON)) {
|
||||||
|
def = global.canLeverandbutton;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isFlagAllowed(flag, def, null);
|
return isFlagAllowed(flag, def, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
|
public boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
|
||||||
|
|
||||||
State defState = def ? State.ALLOW : State.DENY;
|
State defState = def ? State.ALLOW : State.DENY;
|
||||||
return getStateAreaFlag("states", flag, defState, true, player) == State.ALLOW;
|
return getStateAreaFlag("states", flag, defState, true, player) == State.ALLOW;
|
||||||
|
@ -30,6 +30,7 @@ public class GlobalFlags {
|
|||||||
public boolean canPvP = true;
|
public boolean canPvP = true;
|
||||||
public boolean canLighter = true;
|
public boolean canLighter = true;
|
||||||
public boolean canTnt = true;
|
public boolean canTnt = true;
|
||||||
|
public boolean canLeverandbutton = true;
|
||||||
public boolean allowCreeper = true;
|
public boolean allowCreeper = true;
|
||||||
public boolean allowMobDamage = true;
|
public boolean allowMobDamage = true;
|
||||||
public boolean allowWaterflow = true;
|
public boolean allowWaterflow = true;
|
||||||
|
@ -49,6 +49,7 @@ public enum State {
|
|||||||
public static final String FLAG_LAVA_FIRE = "lavafirespread";
|
public static final String FLAG_LAVA_FIRE = "lavafirespread";
|
||||||
public static final String FLAG_CHEST_ACCESS = "chest";
|
public static final String FLAG_CHEST_ACCESS = "chest";
|
||||||
public static final String FLAG_WATER_FLOW = "waterflow";
|
public static final String FLAG_WATER_FLOW = "waterflow";
|
||||||
|
public static final String FLAG_LEVER_AND_BUTTON = "leverandbutton";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user