This commit is contained in:
boy0001 2015-02-20 02:13:43 +11:00
parent 219d4ad469
commit c09179e9cd
5 changed files with 35 additions and 57 deletions

View File

@ -79,6 +79,22 @@ public class BukkitMain extends JavaPlugin implements Listener,IPlotMain {
return false; return false;
} }
// TODO restructure this
public static int hasPermissionRange(final Player player, final String stub, final int range) {
if ((player == null) || player.isOp() || player.hasPermission(PlotSquared.ADMIN_PERMISSION)) {
return Byte.MAX_VALUE;
}
if (player.hasPermission(stub + ".*")) {
return Byte.MAX_VALUE;
}
for (int i = range; i > 0; i--) {
if (player.hasPermission(stub + "." + i)) {
return i;
}
}
return 0;
}
// TODO restructure this // TODO restructure this
public static boolean teleportPlayer(final Player player, final Location from, final Plot plot) { public static boolean teleportPlayer(final Player player, final Location from, final Plot plot) {
Plot bot = PlayerFunctions.getBottomPlot(player.getWorld().getName(), plot); Plot bot = PlayerFunctions.getBottomPlot(player.getWorld().getName(), plot);

View File

@ -1157,30 +1157,6 @@ public class _PlotSquared {
return new HybridGen(world); return new HybridGen(world);
} }
/**
* Check a range of permissions e.g. 'plots.plot.<0-100>'<br> Returns highest integer in range.
*
* @param player to check
* @param stub to check
* @param range tp check
*
* @return permitted range
*/
public int hasPermissionRange(final Player player, final String stub, final int range) {
if ((player == null) || player.isOp() || player.hasPermission(PlotSquared.ADMIN_PERMISSION)) {
return Byte.MAX_VALUE;
}
if (player.hasPermission(stub + ".*")) {
return Byte.MAX_VALUE;
}
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 * Check a player for a permission<br> - Op has all permissions <br> - checks for '*' nodes
* *

View File

@ -13,6 +13,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.BukkitMain;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.Unlink; import com.intellectualcrafters.plot.commands.Unlink;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
@ -23,6 +24,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class ExpireManager { public class ExpireManager {
@ -64,7 +66,7 @@ public class ExpireManager {
} }
public static void runTask() { public static void runTask() {
ExpireManager.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotSquared.getMain(), new Runnable() { ExpireManager.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(BukkitMain.THIS, new Runnable() {
@Override @Override
public void run() { public void run() {
for (String world : PlotSquared.getPlotWorldsString()) { for (String world : PlotSquared.getPlotWorldsString()) {
@ -109,14 +111,13 @@ public class ExpireManager {
PlayerFunctions.sendMessage(player, C.PLOT_REMOVED_HELPER, plot.id.toString()); PlayerFunctions.sendMessage(player, C.PLOT_REMOVED_HELPER, plot.id.toString());
} }
} }
final World worldobj = Bukkit.getWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getPlotManager(world);
if (plot.settings.isMerged()) { if (plot.settings.isMerged()) {
Unlink.unlinkPlot(Bukkit.getWorld(world), plot); Unlink.unlinkPlot(Bukkit.getWorld(world), plot);
} }
PlotWorld plotworld = PlotSquared.getWorldSettings(world); PlotWorld plotworld = PlotSquared.getWorldSettings(world);
manager.clearPlot(worldobj, plotworld, plot, false, null); manager.clearPlot(plotworld, plot, false, null);
PlotHelper.removeSign(worldobj, plot); PlotHelper.removeSign(plot);
DBFunc.delete(world, plot); DBFunc.delete(world, plot);
PlotSquared.removePlot(world, plot.id, true); PlotSquared.removePlot(world, plot.id, true);
expiredPlots.get(world).remove(plot); expiredPlots.get(world).remove(plot);
@ -186,7 +187,7 @@ public class ExpireManager {
String worldname = Bukkit.getWorlds().get(0).getName(); String worldname = Bukkit.getWorlds().get(0).getName();
String foldername; String foldername;
String filename = null; String filename = null;
if (PlotSquared.checkVersion(1, 7, 5)) { if (BukkitMain.checkVersion(1, 7, 5)) {
foldername = "playerdata"; foldername = "playerdata";
try { try {
filename = op.getUniqueId() +".dat"; filename = op.getUniqueId() +".dat";

View File

@ -1,17 +0,0 @@
package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
public class MainUtil {
// TODO messages / permission stuff
/**
* Send a message to the console
*
* @param c message
*/
public static void log(final C c) {
PlotSquared.MAIN_IMP.log(c.s());
}
}

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.BukkitMain;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -29,6 +30,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
@ -127,7 +129,7 @@ import java.util.UUID;
* @return * @return
*/ */
public static PlotId getPlotAbs(final Location loc) { public static PlotId getPlotAbs(final Location loc) {
final String world = loc.getWorld().getName(); final String world = loc.getWorld();
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getPlotManager(world);
if (manager == null) { if (manager == null) {
return null; return null;
@ -145,7 +147,7 @@ import java.util.UUID;
* @return * @return
*/ */
public static PlotId getPlot(final Location loc) { public static PlotId getPlot(final Location loc) {
final String world = loc.getWorld().getName(); final String world = loc.getWorld();
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getPlotManager(world);
if (manager == null) { if (manager == null) {
return null; return null;
@ -169,18 +171,18 @@ import java.util.UUID;
* @return * @return
*/ */
public static Plot getCurrentPlot(final Player player) { public static Plot getCurrentPlot(final Player player) {
if (!PlotSquared.isPlotWorld(player.getWorld())) { if (!PlotSquared.isPlotWorld(player.getWorld().getName())) {
return null; return null;
} }
final PlotId id = getPlot(BukkitUtil.getLocation(entity)); final PlotId id = getPlot(BukkitUtil.getLocation(player));
final World world = player.getWorld(); final String world = player.getWorld().getName();
if (id == null) { if (id == null) {
return null; return null;
} }
if (PlotSquared.getPlots(world).containsKey(id)) { if (PlotSquared.getPlots(world).containsKey(id)) {
return PlotSquared.getPlots(world).get(id); return PlotSquared.getPlots(world).get(id);
} }
return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), world.getName()); return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
} }
@ -203,8 +205,8 @@ import java.util.UUID;
* *
* @return * @return
*/ */
public static Set<Plot> getPlayerPlots(final World world, final Player plr) { public static Set<Plot> getPlayerPlots(final String world, final Player plr) {
final Set<Plot> p = PlotSquared.getPlots(world, plr); final Set<Plot> p = PlotSquared.getPlots(world, plr.getName());
if (p == null) { if (p == null) {
return new HashSet<>(); return new HashSet<>();
} }
@ -218,7 +220,7 @@ import java.util.UUID;
* *
* @return * @return
*/ */
public static int getPlayerPlotCount(final World world, final Player plr) { public static int getPlayerPlotCount(final String world, final Player plr) {
final UUID uuid = UUIDHandler.getUUID(plr); final UUID uuid = UUIDHandler.getUUID(plr);
int count = 0; int count = 0;
for (final Plot plot : PlotSquared.getPlots(world).values()) { for (final Plot plot : PlotSquared.getPlots(world).values()) {
@ -237,7 +239,7 @@ import java.util.UUID;
* @return * @return
*/ */
public static int getAllowedPlots(final Player p) { public static int getAllowedPlots(final Player p) {
return PlotSquared.MAIN_IMP.(p, "plots.plot", Settings.MAX_PLOTS); return BukkitMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
} }
/** /**
@ -286,7 +288,7 @@ import java.util.UUID;
public static boolean sendMessage(final Player plr, final String msg, final boolean prefix) { public static boolean sendMessage(final Player plr, final String msg, final boolean prefix) {
if ((msg.length() > 0) && !msg.equals("")) { if ((msg.length() > 0) && !msg.equals("")) {
if (plr == null) { if (plr == null) {
PlotSquared.MAIN_IMP.log(C.PREFIX.s() + msg); PlotSquared.log(C.PREFIX.s() + msg);
} else { } else {
sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg)); sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg));
} }