mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 12:35:15 +01:00
Started changing to PlotPlayer
This commit is contained in:
parent
e6c3c143b6
commit
89fcb6b600
@ -1,7 +1,24 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import com.intellectualcrafters.plot.commands.Buy;
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -18,46 +35,17 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import com.intellectualcrafters.plot.commands.Buy;
|
||||
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.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;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
public static BukkitMain THIS = null;
|
||||
public static PlotSquared MAIN = null;
|
||||
|
||||
// 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)) {
|
||||
return true;
|
||||
}
|
||||
@ -74,9 +62,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 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)) {
|
||||
return Byte.MAX_VALUE;
|
||||
}
|
||||
@ -136,6 +124,24 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
public static void worldLoad(final WorldLoadEvent event) {
|
||||
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
|
||||
public void PlayerCommand(final PlayerCommandPreprocessEvent event) {
|
||||
@ -270,24 +276,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
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
|
||||
public void registerPlayerEvents() {
|
||||
getServer().getPluginManager().registerEvents(new PlayerEvents(), this);
|
||||
|
@ -1,11 +1,11 @@
|
||||
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 com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import java.io.File;
|
||||
|
||||
public interface IPlotMain {
|
||||
public void log(String message);
|
||||
@ -41,4 +41,8 @@ public interface IPlotMain {
|
||||
public void getGenerator(String world, String name);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -20,9 +20,8 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.BukkitMain;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-08-03.
|
||||
@ -47,7 +46,7 @@ public class CommandPermission {
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
@ -20,29 +20,27 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
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.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
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
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
public class MainCommand {
|
||||
/**
|
||||
* Main Permission Node
|
||||
*/
|
||||
@ -52,13 +50,13 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
addAll(Arrays.asList(_subCommands));
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
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<>();
|
||||
for (final SubCommand c : subCommands) {
|
||||
if (!c.isPlayer || (player != null)) {
|
||||
@ -69,8 +67,8 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
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;
|
||||
if (category != null) {
|
||||
commands = getCommands(category, player);
|
||||
@ -109,10 +107,8 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
private static String t(final String s) {
|
||||
return ChatColor.translateAlternateColorCodes('&', s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) {
|
||||
final Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||
|
||||
public boolean onCommand(final PlotPlayer player, final String cmd, final String... args) {
|
||||
if (!BukkitMain.hasPermission(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)) {
|
||||
help.append(string).append("\n");
|
||||
}
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', help.toString()));
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', help.toString()));
|
||||
// return PlayerFunctions.sendMessage(player, help.toString());
|
||||
} else {
|
||||
for (final SubCommand command : subCommands) {
|
||||
|
@ -20,14 +20,13 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
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.Arrays;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.util.bukkit.PlayerFunctions;
|
||||
|
||||
/**
|
||||
* SubCommand class
|
||||
*
|
||||
@ -127,7 +126,7 @@ public abstract class SubCommand {
|
||||
*
|
||||
* @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
|
||||
@ -148,7 +147,7 @@ public abstract class SubCommand {
|
||||
* @see com.intellectualcrafters.plot.util.bukkit.PlayerFunctions#sendMessage(org.bukkit.entity.Player,
|
||||
* 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);
|
||||
return true;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -20,26 +20,25 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
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.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
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.
|
||||
@ -193,7 +192,7 @@ public class PlayerFunctions {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getAllowedPlots(final Player p) {
|
||||
public static int getAllowedPlots(final PlotPlayer p) {
|
||||
return BukkitMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
|
||||
}
|
||||
|
||||
@ -203,7 +202,7 @@ public class PlayerFunctions {
|
||||
* @param plr
|
||||
* @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) {
|
||||
final String[] ss = ChatPaginator.wordWrap(msg, ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH);
|
||||
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(...))
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
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 (plr == null) {
|
||||
PlotSquared.log(C.PREFIX.s() + msg);
|
||||
@ -249,7 +248,7 @@ public class PlayerFunctions {
|
||||
*
|
||||
* @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) {
|
||||
String msg = c.s();
|
||||
if ((args != null) && (args.length > 0)) {
|
||||
|
Loading…
Reference in New Issue
Block a user