Added a configuration file. Made various classes read from the configuration.
This commit is contained in:
parent
78283a4f34
commit
9e36cf189b
7
resources/config.yml
Normal file
7
resources/config.yml
Normal file
@ -0,0 +1,7 @@
|
||||
maxGateBlocks: 50
|
||||
playerGateBlockUpdateRadius: 64
|
||||
checkForBrokenGateFrames: true
|
||||
gateTeleportMessage: "Thank you for traveling with Craft Inc. Gates."
|
||||
showTeleportMessage: true
|
||||
gateTeleportNoPermissionMessage: "You are not allowed to use this gate!"
|
||||
showTeleportNoPermissionMessage: true
|
@ -35,17 +35,17 @@ import de.craftinc.gates.util.SimpleLocation;
|
||||
|
||||
public class GatesManager
|
||||
{
|
||||
private File gatesConfigFile;
|
||||
private FileConfiguration gatesConfig;
|
||||
private static final String gatesPath = "gates"; // path to gates inside the yaml file
|
||||
private static final String storageVersionPath = "version";
|
||||
private static final int storageVersion = 1;
|
||||
protected File gatesConfigFile;
|
||||
protected FileConfiguration gatesConfig;
|
||||
protected static final String gatesPath = "gates"; // path to gates inside the yaml file
|
||||
protected static final String storageVersionPath = "version";
|
||||
protected static final int storageVersion = 1;
|
||||
|
||||
private static final int chunkRadius = 4; // TODO: move search radius into a config file / get value from config class
|
||||
protected int chunkRadius;
|
||||
|
||||
private Map<String, Gate> gatesById;
|
||||
private Map<SimpleChunk, Set<Gate>> gatesByChunk;
|
||||
private Map<SimpleLocation, Gate> gatesByLocation;
|
||||
protected Map<String, Gate> gatesById;
|
||||
protected Map<SimpleChunk, Set<Gate>> gatesByChunk;
|
||||
protected Map<SimpleLocation, Gate> gatesByLocation;
|
||||
|
||||
private List<Gate> gates;
|
||||
|
||||
@ -136,7 +136,18 @@ public class GatesManager
|
||||
}
|
||||
|
||||
|
||||
private void fillGatesById()
|
||||
protected int getChunkRadius()
|
||||
{
|
||||
if (this.chunkRadius == 0) {
|
||||
this.chunkRadius = Plugin.getPlugin().getConfig().getInt(Plugin.confPlayerGateBlockUpdateRadiusKey);
|
||||
this.chunkRadius = this.chunkRadius >> 4;
|
||||
}
|
||||
|
||||
return this.chunkRadius;
|
||||
}
|
||||
|
||||
|
||||
protected void fillGatesById()
|
||||
{
|
||||
gatesById = new HashMap<String, Gate>((int)(gates.size() * 1.25));
|
||||
|
||||
@ -146,7 +157,7 @@ public class GatesManager
|
||||
}
|
||||
|
||||
|
||||
private void fillGatesByChunk()
|
||||
protected void fillGatesByChunk()
|
||||
{
|
||||
HashSet<SimpleChunk> chunksUsedByGates = new HashSet<SimpleChunk>();
|
||||
|
||||
@ -159,9 +170,9 @@ public class GatesManager
|
||||
int x = c.getX();
|
||||
int z = c.getZ();
|
||||
|
||||
for (int i = x-chunkRadius; i < x+chunkRadius; i++) {
|
||||
for (int i = x-getChunkRadius(); i < x+getChunkRadius(); i++) {
|
||||
|
||||
for (int j = z-chunkRadius; j < z+chunkRadius; j++) {
|
||||
for (int j = z-getChunkRadius(); j < z+getChunkRadius(); j++) {
|
||||
|
||||
chunksUsedByGates.add(new SimpleChunk(i, j, c.getWorld()));
|
||||
}
|
||||
@ -177,7 +188,7 @@ public class GatesManager
|
||||
}
|
||||
|
||||
|
||||
private void fillGatesByLocation()
|
||||
protected void fillGatesByLocation()
|
||||
{
|
||||
int numGateBlocks = 0;
|
||||
|
||||
@ -193,19 +204,19 @@ public class GatesManager
|
||||
}
|
||||
|
||||
|
||||
private void removeGateById(String id)
|
||||
protected void removeGateById(String id)
|
||||
{
|
||||
gatesById.remove(id);
|
||||
}
|
||||
|
||||
|
||||
private void addGateWithId(Gate g)
|
||||
protected void addGateWithId(Gate g)
|
||||
{
|
||||
gatesById.put(g.getId(), g);
|
||||
}
|
||||
|
||||
|
||||
private void removeGateFromLocations(Set<Location> gateBlocks)
|
||||
protected void removeGateFromLocations(Set<Location> gateBlocks)
|
||||
{
|
||||
for (Location l : gateBlocks) {
|
||||
SimpleLocation sl = new SimpleLocation(l);
|
||||
@ -214,7 +225,7 @@ public class GatesManager
|
||||
}
|
||||
|
||||
|
||||
private void addGateByLocations(Gate g)
|
||||
protected void addGateByLocations(Gate g)
|
||||
{
|
||||
for (Location l : g.getGateBlockLocations()) {
|
||||
SimpleLocation sl = new SimpleLocation(l);
|
||||
@ -223,7 +234,7 @@ public class GatesManager
|
||||
}
|
||||
|
||||
|
||||
private void removeGateFromChunk(Gate g, Location l)
|
||||
protected void removeGateFromChunk(Gate g, Location l)
|
||||
{
|
||||
if (l != null) {
|
||||
|
||||
@ -231,9 +242,9 @@ public class GatesManager
|
||||
int x = c.getX();
|
||||
int z = c.getZ();
|
||||
|
||||
for (int i = x-chunkRadius; i < x+chunkRadius; i++) {
|
||||
for (int i = x-getChunkRadius(); i < x+getChunkRadius(); i++) {
|
||||
|
||||
for (int j = z-chunkRadius; j < z+chunkRadius; j++) {
|
||||
for (int j = z-getChunkRadius(); j < z+getChunkRadius(); j++) {
|
||||
|
||||
SimpleChunk sc = new SimpleChunk(i, j, c.getWorld());
|
||||
Set<Gate> gatesInChunk = gatesByChunk.get(sc);
|
||||
@ -248,7 +259,7 @@ public class GatesManager
|
||||
}
|
||||
|
||||
|
||||
private void addGateByChunk(Gate g)
|
||||
protected void addGateByChunk(Gate g)
|
||||
{
|
||||
Location gateLocation = g.getLocation();
|
||||
|
||||
@ -258,9 +269,9 @@ public class GatesManager
|
||||
int x = c.getX();
|
||||
int z = c.getZ();
|
||||
|
||||
for (int i = x-chunkRadius; i < x+chunkRadius; i++) {
|
||||
for (int i = x-getChunkRadius(); i < x+getChunkRadius(); i++) {
|
||||
|
||||
for (int j = z-chunkRadius; j < z+chunkRadius; j++) {
|
||||
for (int j = z-getChunkRadius(); j < z+getChunkRadius(); j++) {
|
||||
|
||||
SimpleChunk sc = new SimpleChunk(i, j, c.getWorld());
|
||||
|
||||
|
@ -24,6 +24,7 @@ import java.util.logging.Logger;
|
||||
import de.craftinc.gates.listeners.*;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
@ -40,6 +41,14 @@ public class Plugin extends JavaPlugin
|
||||
public static final String permissionManage = "craftincgates.manage";
|
||||
public static final String permissionUse = "craftincgates.use";
|
||||
|
||||
public static final String confMaxGateBlocksKey = "maxGateBlocks";
|
||||
public static final String confPlayerGateBlockUpdateRadiusKey = "playerGateBlockUpdateRadius";
|
||||
public static final String confCheckForBrokenGateFramesKey = "checkForBrokenGateFrames";
|
||||
public static final String confGateTeleportMessageKey = "gateTeleportMessage";
|
||||
public static final String confShowTeleportMessageKey = "showTeleportMessage";
|
||||
public static final String confGateTeleportNoPermissionMessageKey = "gateTeleportNoPermissionMessage";
|
||||
public static final String confShowTeleportNoPermissionMessageKey = "showTeleportNoPermissionMessage";
|
||||
|
||||
private static Plugin instance;
|
||||
private static Permission permission;
|
||||
|
||||
@ -112,6 +121,9 @@ public class Plugin extends JavaPlugin
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
// Setup configuration
|
||||
this.saveDefaultConfig();
|
||||
|
||||
// Setup permissions
|
||||
setupPermissions();
|
||||
|
||||
@ -149,6 +161,8 @@ public class Plugin extends JavaPlugin
|
||||
pm.registerEvents(this.respawnListener, this);
|
||||
pm.registerEvents(this.worldChangeListener, this);
|
||||
pm.registerEvents(this.joinListener, this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -199,7 +213,8 @@ public class Plugin extends JavaPlugin
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage("Unknown gate-command \"" + commandName + "\". Try " + "/" + getBaseCommand() + " help");
|
||||
sender.sendMessage(ChatColor.RED + "Unknown gate-command \"" + commandName + "\"." +
|
||||
ChatColor.GREEN + " Try " + "/" + getBaseCommand() + " help");
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,7 +62,8 @@ public class PlayerMoveListener implements Listener
|
||||
|
||||
|
||||
// Check for permission
|
||||
if (!hasPermission(event.getPlayer(), gateAtLocation)) {
|
||||
if (!hasPermission(event.getPlayer(), gateAtLocation)
|
||||
&& Plugin.getPlugin().getConfig().getBoolean(Plugin.confShowTeleportNoPermissionMessageKey)) {
|
||||
|
||||
String playerName = event.getPlayer().getName();
|
||||
|
||||
@ -75,7 +76,9 @@ public class PlayerMoveListener implements Listener
|
||||
|
||||
// do not display messages more often than once per second
|
||||
if (!this.lastNoPermissionMessages.containsKey(playerName) || this.lastNoPermissionMessages.get(playerName) < now - 10000L) {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are not allowed to use this gate!");
|
||||
|
||||
String noPermissionString = Plugin.getPlugin().getConfig().getString(Plugin.confGateTeleportNoPermissionMessageKey);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + noPermissionString);
|
||||
this.lastNoPermissionMessages.put(playerName, now);
|
||||
}
|
||||
}
|
||||
@ -103,7 +106,11 @@ public class PlayerMoveListener implements Listener
|
||||
);
|
||||
|
||||
p.teleport(destLocation);
|
||||
p.sendMessage(ChatColor.DARK_AQUA + "Thank you for traveling with Craft Inc. Gates.");
|
||||
|
||||
if (Plugin.getPlugin().getConfig().getBoolean(Plugin.confShowTeleportMessageKey)) {
|
||||
String teleporMessage = Plugin.getPlugin().getConfig().getString(Plugin.confGateTeleportMessageKey);
|
||||
p.sendMessage(ChatColor.DARK_AQUA + teleporMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,10 +29,8 @@ import de.craftinc.gates.Plugin;
|
||||
|
||||
public class FloodUtil
|
||||
{
|
||||
private final static int frameBlockSearchLimit = 100; // TODO: move search radius into a config file / get value from config class
|
||||
|
||||
private static final Set<BlockFace> exp1 = new HashSet<BlockFace>();
|
||||
private static final Set<BlockFace> exp2 = new HashSet<BlockFace>();
|
||||
protected static final Set<BlockFace> exp1 = new HashSet<BlockFace>();
|
||||
protected static final Set<BlockFace> exp2 = new HashSet<BlockFace>();
|
||||
|
||||
static
|
||||
{
|
||||
@ -51,6 +49,8 @@ public class FloodUtil
|
||||
// For the same frame and location this set of blocks is deterministic
|
||||
public static Set<Block> getGateFrameBlocks(Block block)
|
||||
{
|
||||
int frameBlockSearchLimit = Plugin.getPlugin().getConfig().getInt(Plugin.confMaxGateBlocksKey);
|
||||
|
||||
Set<Block> blocks1 = getAirFloodBlocks(block, new HashSet<Block>(), exp1, frameBlockSearchLimit);
|
||||
Set<Block> blocks2 = getAirFloodBlocks(block, new HashSet<Block>(), exp2, frameBlockSearchLimit);
|
||||
|
||||
@ -74,7 +74,7 @@ public class FloodUtil
|
||||
}
|
||||
|
||||
|
||||
private static Set<Block> getAirFloodBlocks(Block startBlock, Set<Block> foundBlocks, Set<BlockFace> expandFaces, int limit)
|
||||
protected static Set<Block> getAirFloodBlocks(Block startBlock, Set<Block> foundBlocks, Set<BlockFace> expandFaces, int limit)
|
||||
{
|
||||
if (foundBlocks == null) {
|
||||
return null;
|
||||
|
@ -29,9 +29,6 @@ import java.util.Set;
|
||||
|
||||
public class GateBlockChangeSender
|
||||
{
|
||||
protected static final int searchRadius = 64; // TODO: move search radius into a config file / get value from config class
|
||||
|
||||
|
||||
public static void updateGateBlocks(final Player player)
|
||||
{
|
||||
if (player == null) {
|
||||
@ -84,6 +81,8 @@ public class GateBlockChangeSender
|
||||
Location gateLocation = gate.getLocation();
|
||||
ArrayList<Player> playersNearby = new ArrayList<Player>();
|
||||
|
||||
int searchRadius = Plugin.getPlugin().getConfig().getInt(Plugin.confPlayerGateBlockUpdateRadiusKey);
|
||||
|
||||
for (Player p : Plugin.getPlugin().getServer().getOnlinePlayers()) {
|
||||
|
||||
if (p.getLocation().distance(gateLocation) < searchRadius) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user