We should redo the permissions to support the '*' node.

This commit is contained in:
boy0001 2014-09-28 17:44:03 +10:00
parent 2eb82fe703
commit eba94c4738
7 changed files with 216 additions and 124 deletions

View File

@ -166,6 +166,10 @@ public enum C {
* Help
*/
HELP_CATEGORY("&6Current Category&c: &l%category%"), HELP_INFO("&6You need to specify a help category"), HELP_INFO_ITEM("&6/plots help %category% &c- &6%category_desc%"), HELP_PAGE("&c>> &6%usage% &c[&6%alias%&c] &c- &6%desc%"), HELP_HEADER("&6Help for Plots"),
/*
* Direction
*/
DIRECTION("&6Current direction: %dir%"),
/*
* Custom
*/

View File

@ -303,15 +303,7 @@ public class PlayerFunctions {
*/
@SuppressWarnings("SuspiciousNameCombination")
public static int getAllowedPlots(Player p) {
if (p.hasPermission("plots.admin")) {
return Integer.MAX_VALUE;
}
for (int x = 0; x <= 100; x++) {
if (p.hasPermission("plots.plot." + (100-x))) {
return 100-x;
}
}
return 0;
return PlotMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
}
/**

View File

@ -61,6 +61,121 @@ public class PlotHelper {
}
/**
* TODO auto plot merging
* Merges a set of plots with another set.<br>
* - Misuse of this method can result in unusable plots<br>
* - currentMegaPlots must be a single plot, or a set of already merged plots<br>
* - toMerge must be a list of unmerged plots<br>
* - the resultant mega plot must be rectangular<br>
* - the plot arrays must be sorted in ascending order<br>
* - Road will be removed where required<br>
* @param world
* @param player
* @param currentMegaPlots
* @param toMerge
* @param dir1
* @param dir2
* @return
*/
public static boolean mergePlot(World world, Player player, ArrayList<PlotId> currentMegaPlots, ArrayList<PlotId> toMerge, int dir1, int dir2) {
Location pos1 = PlotHelper.getPlotBottomLoc(world, currentMegaPlots.get(0)).add(1,0,1);
Location pos2 = PlotHelper.getPlotTopLoc(world, currentMegaPlots.get(currentMegaPlots.size()-1));
for (int i = 0;i < toMerge.size(); i++) {
PlotId plotid = toMerge.get(i);
Plot plot = PlotMain.getPlots(world).get(plotid);
if (i<toMerge.size()-1) {
PlotHelper.mergePlot(world, plot, PlotMain.getPlots(world).get(toMerge.get(i+1)));
}
}
Location pos3 = PlotHelper.getPlotBottomLoc(world, toMerge.get(0)).add(1,0,1);
Location pos4 = PlotHelper.getPlotTopLoc(world, toMerge.get(toMerge.size()-1));
for (PlotId plotid:currentMegaPlots) {
Plot plot = PlotMain.getPlots(world).get(plotid);
plot.settings.setMerged(dir1, true);
DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged());
}
for (int i = 0;i < toMerge.size(); i++) {
PlotId plotid = toMerge.get(i);
Plot plot = PlotMain.getPlots(world).get(plotid);
plot.settings.setMerged(dir2, true);
DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged());
}
try {
SetBlockFast.update(player);
}
catch (Exception e) {
}
PlotWorld plotworld = PlotMain.getWorldSettings(world);
int sx,sz,ex,ez;
if (dir1 == 0 || dir1 == 3) {
sx = Math.min(pos1.getBlockX(),pos2.getBlockX());
ex = Math.max(pos3.getBlockX(),pos4.getBlockX());
sz = Math.min(pos1.getBlockZ(),pos2.getBlockZ());
ez = Math.max(pos3.getBlockZ(),pos4.getBlockZ());
}
else {
sx = Math.max(pos1.getBlockX(),pos2.getBlockX());
ex = Math.min(pos3.getBlockX(),pos4.getBlockX());
sz = Math.max(pos1.getBlockZ(),pos2.getBlockZ());
ez = Math.min(pos3.getBlockZ(),pos4.getBlockZ());
}
int startx = Math.min(sx,ex);
int startz = Math.min(sz,ez);
int endx = Math.max(sx,ex)+1;
int endz = Math.max(sz,ez)+1;
final short[] plotfloors = new short[plotworld.TOP_BLOCK.length];
final short[] plotfloors_data = new short[plotworld.TOP_BLOCK.length];
final short[] filling = new short[plotworld.MAIN_BLOCK.length];
final short[] filling_data = new short[plotworld.MAIN_BLOCK.length];
for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) {
short[] result = PlotHelper.getBlock(plotworld.TOP_BLOCK[i]);
plotfloors[i] = result[0];
plotfloors_data[i] = result[1];
}
for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++) {
short[] result = PlotHelper.getBlock(plotworld.MAIN_BLOCK[i]);
filling[i] = result[0];
filling_data[i] = result[1];
}
PlotHelper.setSimpleCuboid(world, new Location(world, startx, 0, startz), new Location(world, endx, 1, endz), (short) 7);
PlotHelper.setSimpleCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT + 1, startz), new Location(world, endx, world.getMaxHeight(), endz), (short) 0);
PlotHelper.setCuboid(world, new Location(world, startx, 1, startz), new Location(world, endx, plotworld.PLOT_HEIGHT, endz), filling, filling_data);
PlotHelper.setCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT, startz), new Location(world, endx, plotworld.PLOT_HEIGHT + 1, endz), plotfloors, plotfloors_data);
pos1 = PlotHelper.getPlotBottomLoc(world, currentMegaPlots.get(0));
pos2 = PlotHelper.getPlotTopLoc(world, currentMegaPlots.get(0)).add(1,0,1);
short[] result_w = PlotHelper.getBlock(plotworld.WALL_BLOCK);
short w_id = result_w[0];
byte w_v = (byte) result_w[1];
for (int x = pos1.getBlockX(); x<=pos2.getBlockX(); x++) {
for (int z = pos1.getBlockZ(); z<=pos2.getBlockZ(); z++) {
if (z == pos1.getBlockZ() || z==pos2.getBlockZ() || x==pos1.getBlockX() || x==pos2.getBlockX()) {
world.getBlockAt(x, plotworld.WALL_HEIGHT+1, z).setTypeIdAndData(w_id, w_v, false);
}
}
}
return true;
}
/**
@ -70,7 +185,6 @@ public class PlotHelper {
* <br> - Assumes neither are a Mega-plot
* <br> - Assumes plots are directly next to each other
* <br> - Does not save to DB
* <br><b>This is the only public merge method as the other ones were deemed unsafe if used incorrectly</b>
* @param world
* @param lesserPlot
* @param greaterPlot
@ -111,24 +225,35 @@ public class PlotHelper {
filling_data[i] = result[1];
}
boolean noMerge = false;
if (lesserPlot.id.x == greaterPlot.id.x) {
noMerge = lesserPlot.settings.getMerged(2);
lesserPlot.settings.setMerged(2, true);
greaterPlot.settings.setMerged(0, true);
startx--;
endx++;
}
else {
noMerge = lesserPlot.settings.getMerged(1);
lesserPlot.settings.setMerged(1, true);
greaterPlot.settings.setMerged(3, true);
startz--;
endz++;
}
if (!noMerge) {
setSimpleCuboid(world, new Location(world, startx, 0, startz), new Location(world, endx, 1, endz), (short) 7);
setSimpleCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT + 1, startz), new Location(world, endx, world.getMaxHeight(), endz), (short) 0);
setCuboid(world, new Location(world, startx, 1, startz), new Location(world, endx, plotworld.PLOT_HEIGHT, endz), filling, filling_data);
setCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT, startz), new Location(world, endx, plotworld.PLOT_HEIGHT + 1, endz), plotfloors, plotfloors_data);
setSimpleCuboid(world, new Location(world, startx, 0, startz), new Location(world, endx, 1, endz), (short) 7);
setSimpleCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT + 1, startz), new Location(world, endx, world.getMaxHeight(), endz), (short) 0);
setCuboid(world, new Location(world, startx, 1, startz), new Location(world, endx, plotworld.PLOT_HEIGHT, endz), filling, filling_data);
setCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT, startz), new Location(world, endx, plotworld.PLOT_HEIGHT + 1, endz), plotfloors, plotfloors_data);
}
}
public static final long nextLong() {

View File

@ -33,6 +33,8 @@ import org.bukkit.*;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.*;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
@ -93,7 +95,6 @@ public class PlotMain extends JavaPlugin {
public static WorldGuardPlugin worldGuard;
/**
* !!WorldGeneration!!
*/
@ -117,6 +118,56 @@ public class PlotMain extends JavaPlugin {
}, 0l, 12 * 60 * 60 * 20l);
}
/**
* Check a range of permissions e.g. 'plots.plot.<0-100>'<br>
* Returns highest integer in range.
* @param player
* @param stub
* @param range
* @return
*/
public static int hasPermissionRange(Player player, String stub, int range) {
if (player.isOp()) {
return range;
}
if (player.hasPermission(stub+".*")) {
return range;
}
for (int i = range; i>0; i--) {
if (player.hasPermission(stub+"."+i)) {
return i;
}
}
return 0;
}
/**
* Check a player for a permission<br>
* - Op has all permissions <br>
* - checks for '*' nodes
* @param player
* @param perm
* @return
*/
public static boolean hasPermission(Player player, String perm) {
if (player.isOp()) {
return true;
}
if (player.hasPermission(perm)) {
return true;
}
String[] nodes = perm.split("\\.");
StringBuilder n = new StringBuilder();
for(int i = 0; i < nodes.length-1; i++) {
n.append(nodes[i]+".");
if (player.hasPermission(n+"*")) {
return true;
}
}
return false;
}
/**
* All loaded plots
*/
@ -812,7 +863,7 @@ public class PlotMain extends JavaPlugin {
}
/**
* SETUP: settings.properties
* SETUP: settings.yml
*/
private static void setupConfig() {
config.set("version", config_ver);
@ -827,6 +878,7 @@ public class PlotMain extends JavaPlugin {
options.put("debug", true);
options.put("clear.auto.enabled", false);
options.put("clear.auto.days", 365);
options.put("max_plots", Settings.MAX_PLOTS);
for (Entry<String, Object> node : options.entrySet()) {
if (!config.contains(node.getKey())) {
@ -843,6 +895,9 @@ public class PlotMain extends JavaPlugin {
Settings.WORLDGUARD = config.getBoolean("worldguard.enabled");
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding");
Settings.METRICS = config.getBoolean("metrics");
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
Settings.MAX_PLOTS = config.getInt("max_plots");
for (String node : config.getConfigurationSection("worlds").getKeys(false)) {
World world = Bukkit.getWorld(node);

View File

@ -17,6 +17,7 @@ package com.intellectualcrafters.plot;
* @author Empire92
*/
public class Settings {
public static int MAX_PLOTS = 20;
/**
* WorldGuard region on claimed plots
*/

View File

@ -43,6 +43,17 @@ public class Merge extends SubCommand {
super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS);
}
public static String direction(float yaw) {
yaw = yaw / 90;
yaw = (float)Math.round(yaw);
if (yaw == -4 || yaw == 0 || yaw == 4) {return "SOUTH";}
if (yaw == -1 || yaw == 3) {return "EAST";}
if (yaw == -2 || yaw == 2) {return "NORTH";}
if (yaw == -3 || yaw == 1) {return "WEST";}
return "";
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
@ -72,6 +83,7 @@ public class Merge extends SubCommand {
int direction2 = direction > 1 ? direction-2 : direction+2;
if (direction==-1) {
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values,C.BLOCK_LIST_SEPARATER.s()));
PlayerFunctions.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw())));
return false;
}
World world = plr.getWorld();
@ -115,106 +127,7 @@ public class Merge extends SubCommand {
return false;
}
PlayerFunctions.sendMessage(plr, "&cPlots have been merged");
return mergePlot(world, plr, PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,bot.y), new PlotId(top.x,top.y)), plots, direction, direction2);
return PlotHelper.mergePlot(world, plr, PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,bot.y), new PlotId(top.x,top.y)), plots, direction, direction2);
}
public static boolean mergePlot(World world, Player player, ArrayList<PlotId> currentMegaPlots, ArrayList<PlotId> toMerge, int dir1, int dir2) {
Location pos1 = PlotHelper.getPlotBottomLoc(world, currentMegaPlots.get(0)).add(1,0,1);
Location pos2 = PlotHelper.getPlotTopLoc(world, currentMegaPlots.get(currentMegaPlots.size()-1));
for (int i = 0;i < toMerge.size(); i++) {
PlotId plotid = toMerge.get(i);
Plot plot = PlotMain.getPlots(world).get(plotid);
if (i<toMerge.size()-1) {
PlotHelper.mergePlot(world, plot, PlotMain.getPlots(world).get(toMerge.get(i+1)));
}
}
System.out.print("OLD: "+currentMegaPlots.size());
System.out.print("NEW: "+toMerge.size());
Location pos3 = PlotHelper.getPlotBottomLoc(world, toMerge.get(0)).add(1,0,1);
Location pos4 = PlotHelper.getPlotTopLoc(world, toMerge.get(toMerge.size()-1));
for (PlotId plotid:currentMegaPlots) {
Plot plot = PlotMain.getPlots(world).get(plotid);
plot.settings.setMerged(dir1, true);
DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged());
}
for (int i = 0;i < toMerge.size(); i++) {
PlotId plotid = toMerge.get(i);
Plot plot = PlotMain.getPlots(world).get(plotid);
plot.settings.setMerged(dir2, true);
DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged());
}
try {
SetBlockFast.update(player);
}
catch (Exception e) {
}
PlotWorld plotworld = PlotMain.getWorldSettings(world);
int sx,sz,ex,ez;
if (dir1 == 0 || dir1 == 3) {
sx = Math.min(pos1.getBlockX(),pos2.getBlockX());
ex = Math.max(pos3.getBlockX(),pos4.getBlockX());
sz = Math.min(pos1.getBlockZ(),pos2.getBlockZ());
ez = Math.max(pos3.getBlockZ(),pos4.getBlockZ());
}
else {
sx = Math.max(pos1.getBlockX(),pos2.getBlockX());
ex = Math.min(pos3.getBlockX(),pos4.getBlockX());
sz = Math.max(pos1.getBlockZ(),pos2.getBlockZ());
ez = Math.min(pos3.getBlockZ(),pos4.getBlockZ());
}
int startx = Math.min(sx,ex);
int startz = Math.min(sz,ez);
int endx = Math.max(sx,ex)+1;
int endz = Math.max(sz,ez)+1;
final short[] plotfloors = new short[plotworld.TOP_BLOCK.length];
final short[] plotfloors_data = new short[plotworld.TOP_BLOCK.length];
final short[] filling = new short[plotworld.MAIN_BLOCK.length];
final short[] filling_data = new short[plotworld.MAIN_BLOCK.length];
for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) {
short[] result = PlotHelper.getBlock(plotworld.TOP_BLOCK[i]);
plotfloors[i] = result[0];
plotfloors_data[i] = result[1];
}
for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++) {
short[] result = PlotHelper.getBlock(plotworld.MAIN_BLOCK[i]);
filling[i] = result[0];
filling_data[i] = result[1];
}
PlotHelper.setSimpleCuboid(world, new Location(world, startx, 0, startz), new Location(world, endx, 1, endz), (short) 7);
PlotHelper.setSimpleCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT + 1, startz), new Location(world, endx, world.getMaxHeight(), endz), (short) 0);
PlotHelper.setCuboid(world, new Location(world, startx, 1, startz), new Location(world, endx, plotworld.PLOT_HEIGHT, endz), filling, filling_data);
PlotHelper.setCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT, startz), new Location(world, endx, plotworld.PLOT_HEIGHT + 1, endz), plotfloors, plotfloors_data);
pos1 = PlotHelper.getPlotBottomLoc(world, currentMegaPlots.get(0));
pos2 = PlotHelper.getPlotTopLoc(world, currentMegaPlots.get(0)).add(1,0,1);
short[] result_w = PlotHelper.getBlock(plotworld.WALL_BLOCK);
short w_id = result_w[0];
byte w_v = (byte) result_w[1];
for (int x = pos1.getBlockX(); x<=pos2.getBlockX(); x++) {
for (int z = pos1.getBlockZ(); z<=pos2.getBlockZ(); z++) {
if (z == pos1.getBlockZ() || z==pos2.getBlockZ() || x==pos1.getBlockX() || x==pos2.getBlockX()) {
world.getBlockAt(x, plotworld.WALL_HEIGHT+1, z).setTypeIdAndData(w_id, w_v, false);
}
}
}
return true;
}
}

View File

@ -36,9 +36,11 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent e) {
if (e.getPlayer().hasPermission("plots.worldedit.bypass")) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
System.out.print("PERM");
return;
}
System.out.print("NO PERM");
Location f = e.getFrom();
Location t = e.getTo();
boolean cm = false;
@ -67,7 +69,7 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent e) {
if (e.getPlayer().hasPermission("plots.worldedit.bypass")) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return;
}
Player p = e.getPlayer();
@ -80,7 +82,7 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTeleport(final PlayerTeleportEvent e) {
if (e.getPlayer().hasPermission("plots.worldedit.bypass")) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return;
}
Player p = e.getPlayer();
@ -99,7 +101,7 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPortal(PlayerPortalEvent e) {
if (e.getPlayer().hasPermission("plots.worldedit.bypass")) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return;
}
Player p = e.getPlayer();
@ -117,7 +119,7 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
if (e.getPlayer().hasPermission("plots.worldedit.bypass")) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
PWE.removeMask(e.getPlayer());
return;
}
@ -138,7 +140,7 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
if (p.hasPermission("plots.worldedit.bypass")) {
if (PlotMain.hasPermission(p, "plots.worldedit.bypass")) {
PWE.removeMask(p);
return;
}