Sign option permissions

Per-gate iconomy target
/sg reload command
Other misc fixes
This commit is contained in:
Drakia 2011-04-11 22:11:59 -07:00
parent 2d97b497d8
commit b9d9ee7c4f
6 changed files with 513 additions and 453 deletions

5
README
View File

@ -26,6 +26,10 @@ Hmm.. None?
- stargate.free.destroy - This player/group is not charged to destroy gates even if the gate has a cost.
- stargate.world.{worldname} - Allow this user/group access to gates on the world {worldname}
- stargate.network.{networkname} - Allow this user/group access to the network {networkname}
- stargate.option.hidden - Allow this user/group to create hidden gates.
- stargate.option.alwayson - Allow this user/group to create always-on gates.
- stargate.option.private - Allow this user/group to create private gates.
- stargate.option.free - Allow this user/group to create free gates.
=============
Instructions
@ -73,6 +77,7 @@ iConomy Support:
usecost=5
destroycost=5
createcost=5
toowner=true
==============
Custom Gate Layout

View File

@ -7,6 +7,7 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.logging.Level;
@ -25,6 +26,7 @@ public class Gate {
public static final int EXIT = -4;
private static HashMap<String, Gate> gates = new HashMap<String, Gate>();
private static HashMap<Integer, ArrayList<Gate>> controlBlocks = new HashMap<Integer, ArrayList<Gate>>();
private static HashSet<Integer> frameBlocks = new HashSet<Integer>();
private String filename;
private Integer[][] layout;
@ -41,6 +43,7 @@ public class Gate {
private int useCost = 0;
private int createCost = 0;
private int destroyCost = 0;
private boolean toOwner = false;
private Gate(String filename, Integer[][] layout, HashMap<Character, Integer> types) {
this.filename = filename;
@ -110,6 +113,7 @@ public class Gate {
writeConfig(bw, "createcost", createCost);
if (destroyCost != iConomyHandler.destroyCost)
writeConfig(bw, "destroycost", destroyCost);
writeConfig(bw, "toowner", toOwner);
for (Character type : types.keySet()) {
Integer value = types.get(type);
@ -161,6 +165,11 @@ public class Gate {
bw.newLine();
}
private void writeConfig(BufferedWriter bw, String key, boolean value) throws IOException {
bw.append(String.format("%s=%b", key, value));
bw.newLine();
}
public Integer[][] getLayout() {
return layout;
}
@ -212,6 +221,10 @@ public class Gate {
return destroyCost;
}
public Boolean getToOwner() {
return toOwner;
}
public boolean matches(Block topleft, int modX, int modZ) {
return matches(new Blox(topleft), modX, modZ);
}
@ -308,6 +321,7 @@ public class Gate {
Integer id = Integer.parseInt(value);
types.put(symbol, id);
frameBlocks.add(id);
} else {
config.put(key, value);
}
@ -345,6 +359,7 @@ public class Gate {
gate.useCost = readConfig(config, gate, file, "usecost", iConomyHandler.useCost);
gate.destroyCost = readConfig(config, gate, file, "destroycost", iConomyHandler.destroyCost);
gate.createCost = readConfig(config, gate, file, "createcost", iConomyHandler.createCost);
gate.toOwner = (config.containsKey("toowner") ? Boolean.valueOf(config.get("toowner")) : iConomyHandler.toOwner);
if (gate.getControls().length != 2) {
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points.");
@ -427,9 +442,19 @@ public class Gate {
return gates.size();
}
public static boolean isGateBlock(int type) {
return frameBlocks.contains(type);
}
static class StargateFilenameFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return name.endsWith(".gate");
}
}
public static void clearGates() {
gates.clear();
controlBlocks.clear();
frameBlocks.clear();
}
}

View File

@ -568,6 +568,12 @@ public class Portal {
boolean priv = (options.indexOf('p') != -1 || options.indexOf('P') != -1);
boolean free = (options.indexOf('f') != - 1|| options.indexOf('F') != -1);
// Check permissions for options.
if (!Stargate.hasPerm(player, "stargate.option.hidden", player.isOp())) hidden = false;
if (!Stargate.hasPerm(player, "stargate.option.alwayson", player.isOp())) alwaysOn = false;
if (!Stargate.hasPerm(player, "stargate.option.private", player.isOp())) priv = false;
if (!Stargate.hasPerm(player, "stargate.option.free", player.isOp())) free = false;
// Check if the user can only create personal gates, set network if so
if (Stargate.hasPerm(player, "stargate.create.personal", false) &&
!Stargate.hasPerm(player, "stargate.create", player.isOp()) ) {

View File

@ -10,17 +10,19 @@ import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
@ -85,7 +87,6 @@ public class Stargate extends JavaPlugin {
public static ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<Portal>();
public static ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<Portal>();
//private HashMap<Integer, Location> vehicles = new HashMap<Integer, Location>();
public void onDisable() {
Portal.closeAllGates();
@ -311,8 +312,9 @@ public class Stargate extends JavaPlugin {
if (dest == null) return;
boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp()));
String target = (portal.getGate().getToOwner() ? portal.getOwner() : null);
if (!iConCharge || iConomyHandler.chargePlayer(player.getName(), portal.getOwner(), portal.getGate().getUseCost())) {
if (!iConCharge || iConomyHandler.chargePlayer(player.getName(), target, portal.getGate().getUseCost())) {
if (iConCharge && portal.getGate().getUseCost() > 0) {
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(portal.getGate().getUseCost()));
@ -391,6 +393,7 @@ public class Stargate extends JavaPlugin {
Portal portal = Portal.getByBlock(block);
// Cycle through a stargates locations
if (portal != null) {
event.setUseItemInHand(Result.DENY);
if (!hasPerm(player, "stargate.use", true) ||
(networkFilter && !hasPerm(player, "stargate.network." + portal.getNetwork(), player.isOp()))) {
if (!denyMsg.isEmpty()) {
@ -432,16 +435,6 @@ public class Stargate extends JavaPlugin {
}
private class bListener extends BlockListener {
@Override
public void onBlockPlace(BlockPlaceEvent event) {
// Stop player from placing a block touching a portals controls
if (event.getBlockAgainst().getType() == Material.STONE_BUTTON ||
event.getBlockAgainst().getType() == Material.WALL_SIGN) {
Portal portal = Portal.getByBlock(event.getBlockAgainst());
if (portal != null) event.setCancelled(true);
}
}
@Override
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
@ -475,9 +468,10 @@ public class Stargate extends JavaPlugin {
@Override
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) return;
Block block = event.getBlock();
Player player = event.getPlayer();
if (block.getType() != Material.WALL_SIGN && block.getType() != Material.STONE_BUTTON && Gate.getGatesByControlBlock(block).length == 0) {
if (block.getType() != Material.WALL_SIGN && block.getType() != Material.STONE_BUTTON && !Gate.isGateBlock(block.getTypeId())) {
return;
}
@ -547,7 +541,7 @@ public class Stargate extends JavaPlugin {
public void onEntityExplode(EntityExplodeEvent event) {
if (event.isCancelled()) return;
for (Block b : event.blockList()) {
if (b.getTypeId() != Material.WALL_SIGN.getId() && b.getTypeId() != Material.STONE_BUTTON.getId()) continue;
if (b.getType() != Material.WALL_SIGN && b.getType() != Material.STONE_BUTTON && !Gate.isGateBlock(b.getTypeId())) continue;
Portal portal = Portal.getByBlock(b);
if (portal == null) continue;
if (destroyExplosion) {
@ -609,4 +603,30 @@ public class Stargate extends JavaPlugin {
}
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
sender.sendMessage("Permission Denied");
return true;
}
String cmd = command.getName();
if (cmd.equalsIgnoreCase("sg")) {
if (args.length != 1) return false;
if (args[0].equalsIgnoreCase("reload")) {
// Clear all lists
activeList.clear();
openList.clear();
Portal.clearGates();
Gate.clearGates();
// Reload data
reloadConfig();
reloadGates();
return true;
}
return false;
}
return false;
}
}

View File

@ -37,7 +37,7 @@ public class iConomyHandler {
if (balance < amount) return false;
acc.setBalance(balance - amount);
if (toOwner && target != null && !player.equals(target)) {
if (target != null && !player.equals(target)) {
Account tAcc = iConomy.getBank().getAccount(target);
if (tAcc != null) {
balance = tAcc.getBalance();

View File

@ -1,6 +1,10 @@
name: Stargate
main: net.TheDgtl.Stargate.Stargate
version: 0.4.0
version: 0.4.1
description: Stargate mod for Bukkit
author: Drakia
website: http://www.thedgtl.net
commands:
sg:
description: Used to reload the plugin. Console use only.
usage: /<command> reload - Used to reload the plugin. Console use only.