Started changing to PlotPlayer

This commit is contained in:
Sauilitired 2015-02-20 11:53:18 +01:00
parent e6c3c143b6
commit 89fcb6b600
8 changed files with 158 additions and 111 deletions

View File

@ -1,7 +1,24 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.io.File; import com.intellectualcrafters.plot.commands.Buy;
import java.util.Arrays; import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.commands.WE_Anywhere;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.PlotMeConverter;
import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.listeners.*;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.PlotHelper;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.*;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -18,46 +35,17 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.plot.commands.Buy;
import com.intellectualcrafters.plot.commands.MainCommand; import java.io.File;
import com.intellectualcrafters.plot.commands.WE_Anywhere; import java.util.Arrays;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.PlotMeConverter;
import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.listeners.ForceFieldListener;
import com.intellectualcrafters.plot.listeners.InventoryListener;
import com.intellectualcrafters.plot.listeners.PlayerEvents;
import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8;
import com.intellectualcrafters.plot.listeners.PlotListener;
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
import com.intellectualcrafters.plot.listeners.WorldEditListener;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.PlotHelper;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.Metrics;
import com.intellectualcrafters.plot.util.bukkit.PlayerFunctions;
import com.intellectualcrafters.plot.util.bukkit.SendChunk;
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast;
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast_1_8;
import com.intellectualcrafters.plot.util.bukkit.SetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.SetBlockSlow;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public static BukkitMain THIS = null; public static BukkitMain THIS = null;
public static PlotSquared MAIN = null; public static PlotSquared MAIN = null;
// TODO restructure this // TODO restructure this
public static boolean hasPermission(final Player player, final String perm) { public static boolean hasPermission(final PlotPlayer p, final String perm) {
final Player player = Bukkit.getPlayer(p + "");
if ((player == null) || player.isOp() || player.hasPermission(PlotSquared.ADMIN_PERMISSION)) { if ((player == null) || player.isOp() || player.hasPermission(PlotSquared.ADMIN_PERMISSION)) {
return true; return true;
} }
@ -76,7 +64,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
// TODO restructure this // TODO restructure this
public static int hasPermissionRange(final Player player, final String stub, final int range) { public static int hasPermissionRange(final PlotPlayer player, final String stub, final int range) {
if ((player == null) || player.isOp() || player.hasPermission(PlotSquared.ADMIN_PERMISSION)) { if ((player == null) || player.isOp() || player.hasPermission(PlotSquared.ADMIN_PERMISSION)) {
return Byte.MAX_VALUE; return Byte.MAX_VALUE;
} }
@ -137,6 +125,24 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
UUIDHandler.cacheAll(); UUIDHandler.cacheAll();
} }
public static boolean checkVersion(final int major, final int minor, final int minor2) {
try {
final String[] version = Bukkit.getBukkitVersion().split("-")[0].split("\\.");
final int a = Integer.parseInt(version[0]);
final int b = Integer.parseInt(version[1]);
int c = 0;
if (version.length == 3) {
c = Integer.parseInt(version[2]);
}
if ((a > major) || ((a == major) && (b > minor)) || ((a == major) && (b == minor) && (c >= minor2))) {
return true;
}
return false;
} catch (final Exception e) {
return false;
}
}
@EventHandler @EventHandler
public void PlayerCommand(final PlayerCommandPreprocessEvent event) { public void PlayerCommand(final PlayerCommandPreprocessEvent event) {
final String message = event.getMessage(); final String message = event.getMessage();
@ -270,24 +276,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
return new HybridGen(world); return new HybridGen(world);
} }
public static boolean checkVersion(final int major, final int minor, final int minor2) {
try {
final String[] version = Bukkit.getBukkitVersion().split("-")[0].split("\\.");
final int a = Integer.parseInt(version[0]);
final int b = Integer.parseInt(version[1]);
int c = 0;
if (version.length == 3) {
c = Integer.parseInt(version[2]);
}
if ((a > major) || ((a == major) && (b > minor)) || ((a == major) && (b == minor) && (c >= minor2))) {
return true;
}
return false;
} catch (final Exception e) {
return false;
}
}
@Override @Override
public void registerPlayerEvents() { public void registerPlayerEvents() {
getServer().getPluginManager().registerEvents(new PlayerEvents(), this); getServer().getPluginManager().registerEvents(new PlayerEvents(), this);

View File

@ -1,11 +1,11 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.io.File; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.TaskManager;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import com.intellectualcrafters.plot.object.PlotId; import java.io.File;
import com.intellectualcrafters.plot.util.TaskManager;
public interface IPlotMain { public interface IPlotMain {
public void log(String message); public void log(String message);
@ -41,4 +41,8 @@ public interface IPlotMain {
public void getGenerator(String world, String name); public void getGenerator(String world, String name);
public boolean callRemovePlot(String world, PlotId id); public boolean callRemovePlot(String world, PlotId id);
public boolean hasPermission(final PlotPlayer player, final String permission);
public void sendMessage(final PlotPlayer player, final String message);
} }

View File

@ -0,0 +1,19 @@
package com.intellectualcrafters.plot.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
/**
* Created 2015-02-20 for PlotSquared
*
* @author Citymonstret
*/
public class BukkitCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
MainCommand
return false;
}
}

View File

@ -20,9 +20,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.BukkitMain; import com.intellectualcrafters.plot.BukkitMain;
import com.intellectualcrafters.plot.object.PlotPlayer;
/** /**
* Created by Citymonstret on 2014-08-03. * Created by Citymonstret on 2014-08-03.
@ -47,7 +46,7 @@ public class CommandPermission {
* *
* @return true of player has the required permission node * @return true of player has the required permission node
*/ */
public boolean hasPermission(final Player player) { public boolean hasPermission(final PlotPlayer player) {
return BukkitMain.hasPermission(player, this.permission); return BukkitMain.hasPermission(player, this.permission);
} }
} }

View File

@ -20,29 +20,27 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.BukkitMain; 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.object.PlotPlayer;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.bukkit.PlayerFunctions; import com.intellectualcrafters.plot.util.bukkit.PlayerFunctions;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/** /**
* PlotSquared command class * PlotSquared command class
* *
* @author Citymonstret * @author Citymonstret
*/ */
public class MainCommand implements CommandExecutor, TabCompleter { public class MainCommand {
/** /**
* Main Permission Node * Main Permission Node
*/ */
@ -53,12 +51,12 @@ public class MainCommand implements CommandExecutor, TabCompleter {
} }
}; };
public static boolean no_permission(final Player player, final String permission) { public static boolean no_permission(final PlotPlayer player, final String permission) {
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, permission); PlayerFunctions.sendMessage(player, C.NO_PERMISSION, permission);
return false; return false;
} }
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final Player player) { public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final PlotPlayer player) {
final List<SubCommand> cmds = new ArrayList<>(); final List<SubCommand> cmds = new ArrayList<>();
for (final SubCommand c : subCommands) { for (final SubCommand c : subCommands) {
if (!c.isPlayer || (player != null)) { if (!c.isPlayer || (player != null)) {
@ -70,7 +68,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
return cmds; return cmds;
} }
public static List<String> helpMenu(final Player player, final SubCommand.CommandCategory category, int page) { public static List<String> helpMenu(final PlotPlayer player, final SubCommand.CommandCategory category, int page) {
List<SubCommand> commands; List<SubCommand> commands;
if (category != null) { if (category != null) {
commands = getCommands(category, player); commands = getCommands(category, player);
@ -110,9 +108,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
return ChatColor.translateAlternateColorCodes('&', s); return ChatColor.translateAlternateColorCodes('&', s);
} }
@Override public boolean onCommand(final PlotPlayer player, final String cmd, final String... args) {
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) {
final Player player = (sender instanceof Player) ? (Player) sender : null;
if (!BukkitMain.hasPermission(player, PlotSquared.MAIN_PERMISSION)) { if (!BukkitMain.hasPermission(player, PlotSquared.MAIN_PERMISSION)) {
return no_permission(player, PlotSquared.MAIN_PERMISSION); return no_permission(player, PlotSquared.MAIN_PERMISSION);
} }
@ -166,7 +162,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
for (final String string : helpMenu(player, cato, page)) { for (final String string : helpMenu(player, cato, page)) {
help.append(string).append("\n"); help.append(string).append("\n");
} }
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', help.toString())); player.sendMessage(ChatColor.translateAlternateColorCodes('&', help.toString()));
// return PlayerFunctions.sendMessage(player, help.toString()); // return PlayerFunctions.sendMessage(player, help.toString());
} else { } else {
for (final SubCommand command : subCommands) { for (final SubCommand command : subCommands) {

View File

@ -20,14 +20,13 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.bukkit.PlayerFunctions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.util.bukkit.PlayerFunctions;
/** /**
* SubCommand class * SubCommand class
* *
@ -127,7 +126,7 @@ public abstract class SubCommand {
* *
* @return true on success, false on failure * @return true on success, false on failure
*/ */
public abstract boolean execute(final Player plr, final String... args); public abstract boolean execute(final PlotPlayer plr, final String... args);
/** /**
* Execute the command as console * Execute the command as console
@ -148,7 +147,7 @@ public abstract class SubCommand {
* @see com.intellectualcrafters.plot.util.bukkit.PlayerFunctions#sendMessage(org.bukkit.entity.Player, * @see com.intellectualcrafters.plot.util.bukkit.PlayerFunctions#sendMessage(org.bukkit.entity.Player,
* com.intellectualcrafters.plot.config.C, String...) * com.intellectualcrafters.plot.config.C, String...)
*/ */
public boolean sendMessage(final Player plr, final C c, final String... args) { public boolean sendMessage(final PlotPlayer plr, final C c, final String... args) {
PlayerFunctions.sendMessage(plr, c, args); PlayerFunctions.sendMessage(plr, c, args);
return true; return true;
} }

View File

@ -0,0 +1,43 @@
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.BukkitMain;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.util.UUID;
/**
* Created 2015-02-20 for PlotSquared
*
* @author Citymonstret
*/
public class PlotPlayer {
private final String name;
private final Location location;
public PlotPlayer(final String name, final Location location) {
this.name = name;
this.location = location;
}
@Override
public String toString() {
return this.name;
}
public Location getLocation() {
return this.location;
}
public UUID getUUID() {
return UUIDHandler.getUUID(name);
}
public boolean hasPermission(final String perm) {
return BukkitMain.hasPermission(this, perm);
}
public void sendMessage(final String message) {
return BukkitMain.sendMessage( final PlotPlayer player);
}
}

View File

@ -20,26 +20,25 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.util.ChatPaginator;
import org.bukkit.ChatColor;
import net.milkbowl.vault.economy.Economy;
import com.intellectualcrafters.plot.BukkitMain; 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;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.PlotHelper;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.util.ChatPaginator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/** /**
* Functions involving players, plots and locations. * Functions involving players, plots and locations.
@ -193,7 +192,7 @@ public class PlayerFunctions {
* *
* @return * @return
*/ */
public static int getAllowedPlots(final Player p) { public static int getAllowedPlots(final PlotPlayer p) {
return BukkitMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS); return BukkitMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
} }
@ -203,7 +202,7 @@ public class PlayerFunctions {
* @param plr * @param plr
* @param msg Was used to wrap the chat client length (Packets out--) * @param msg Was used to wrap the chat client length (Packets out--)
*/ */
public static void sendMessageWrapped(final Player plr, String msg) { public static void sendMessageWrapped(final PlotPlayer plr, String msg) {
if (msg.length() > ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH) { if (msg.length() > ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH) {
final String[] ss = ChatPaginator.wordWrap(msg, ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH); final String[] ss = ChatPaginator.wordWrap(msg, ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH);
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -226,11 +225,11 @@ public class PlayerFunctions {
* *
* @return true Can be used in things such as commands (return PlayerFunctions.sendMessage(...)) * @return true Can be used in things such as commands (return PlayerFunctions.sendMessage(...))
*/ */
public static boolean sendMessage(final Player plr, final String msg) { public static boolean sendMessage(final PlotPlayer plr, final String msg) {
return sendMessage(plr, msg, true); return sendMessage(plr, msg, true);
} }
public static boolean sendMessage(final Player plr, final String msg, final boolean prefix) { public static boolean sendMessage(final PlotPlayer 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.log(C.PREFIX.s() + msg); PlotSquared.log(C.PREFIX.s() + msg);
@ -249,7 +248,7 @@ public class PlayerFunctions {
* *
* @return * @return
*/ */
public static boolean sendMessage(final Player plr, final C c, final String... args) { public static boolean sendMessage(final PlotPlayer plr, final C c, final String... args) {
if (c.s().length() > 1) { if (c.s().length() > 1) {
String msg = c.s(); String msg = c.s();
if ((args != null) && (args.length > 0)) { if ((args != null) && (args.length > 0)) {