mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Added trusted users
This commit is contained in:
parent
3a653c2dea
commit
56537dcafc
@ -124,7 +124,7 @@ public enum C {
|
|||||||
/*
|
/*
|
||||||
* Info
|
* Info
|
||||||
*/
|
*/
|
||||||
PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), PLOT_INFO("plot ID: &6%id%&c, plot Alias: &6%alias%&c, plot Owner: &6%owner%&c, plot Biome: &6%biome%&c, plot Time: &6%time%&c, plot Weather: &6%weather%&c, plot Helpers:&6%helpers%&c, plot Denied:&6%denied%&c, plot flags: &6%flags%"), PLOT_USER_LIST(" &6%user%&c,"),
|
PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), PLOT_INFO("plot ID: &6%id%&c, plot Alias: &6%alias%&c, plot Owner: &6%owner%&c, plot Biome: &6%biome%&c, plot Time: &6%time%&c, plot Weather: &6%weather%&c, plot Helpers:&6%helpers%&c, plot Trusted:&6%trusted%&c, plot Denied:&6%denied%&c, plot flags: &6%flags%"), PLOT_USER_LIST(" &6%user%&c,"),
|
||||||
/*
|
/*
|
||||||
* Generating
|
* Generating
|
||||||
*/
|
*/
|
||||||
@ -169,6 +169,10 @@ public enum C {
|
|||||||
* Helper
|
* Helper
|
||||||
*/
|
*/
|
||||||
HELPER_ADDED("&6You successfully added a helper to the plot"), HELPER_REMOVED("&6You successfully removed a helper from the plot"), HELPER_NEED_ARGUMENT("&cArguments are missing. &6/plot helpers add {name} &cor &6/plot helpers remove {name}"), WAS_NOT_ADDED("&cThat player was not added as a helper on this plot"),
|
HELPER_ADDED("&6You successfully added a helper to the plot"), HELPER_REMOVED("&6You successfully removed a helper from the plot"), HELPER_NEED_ARGUMENT("&cArguments are missing. &6/plot helpers add {name} &cor &6/plot helpers remove {name}"), WAS_NOT_ADDED("&cThat player was not added as a helper on this plot"),
|
||||||
|
/*
|
||||||
|
* Trusted
|
||||||
|
*/
|
||||||
|
TRUSTED_ADDED("&6You successfully added a trusted user to the plot"), TRUSTED_REMOVED("&6You successfully removed a trusted user from the plot"), TRUSTED_NEED_ARGUMENT("&cArguments are missing. &6/plot trusted add {name} &cor &6/plot trusted remove {name}"), T_WAS_NOT_ADDED("&cThat player was not added as a trusted user on this plot"),
|
||||||
/*
|
/*
|
||||||
* Set Owner
|
* Set Owner
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.intellectualcrafters.plot;
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -30,7 +32,7 @@ public class PWE {
|
|||||||
boolean r;
|
boolean r;
|
||||||
r = plot.getOwner() != null && plot.getOwner().equals(p.getUniqueId());
|
r = plot.getOwner() != null && plot.getOwner().equals(p.getUniqueId());
|
||||||
if (!r) {
|
if (!r) {
|
||||||
if (p.hasPermission("plots.we.member") && plot.hasRights(p)) {
|
if (p.hasPermission("plots.we.member") && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) {
|
||||||
r = true;
|
r = true;
|
||||||
} else if (p.hasPermission("plots.we.bypass")) {
|
} else if (p.hasPermission("plots.we.bypass")) {
|
||||||
s.setMask(null);
|
s.setMask(null);
|
||||||
|
@ -48,6 +48,10 @@ public class Plot implements Cloneable {
|
|||||||
* List of helpers (with plot permissions)
|
* List of helpers (with plot permissions)
|
||||||
*/
|
*/
|
||||||
public ArrayList<UUID> helpers;
|
public ArrayList<UUID> helpers;
|
||||||
|
/**
|
||||||
|
* List of trusted users (with plot permissions)
|
||||||
|
*/
|
||||||
|
public ArrayList<UUID> trusted;
|
||||||
/**
|
/**
|
||||||
* List of denied players
|
* List of denied players
|
||||||
*/
|
*/
|
||||||
@ -104,12 +108,13 @@ public class Plot implements Cloneable {
|
|||||||
* @param time
|
* @param time
|
||||||
* @param merged
|
* @param merged
|
||||||
*/
|
*/
|
||||||
public Plot(PlotId id, UUID owner, Biome plotBiome, ArrayList<UUID> helpers, ArrayList<UUID> denied, boolean changeTime, long time, boolean rain, String alias, PlotHomePosition position, Flag[] flags, String world, boolean[] merged) {
|
public Plot(PlotId id, UUID owner, Biome plotBiome, ArrayList<UUID> helpers, ArrayList<UUID> trusted, ArrayList<UUID> denied, boolean changeTime, long time, boolean rain, String alias, PlotHomePosition position, Flag[] flags, String world, boolean[] merged) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.settings = new PlotSettings(this);
|
this.settings = new PlotSettings(this);
|
||||||
this.settings.setBiome(plotBiome);
|
this.settings.setBiome(plotBiome);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.deny_entry = this.owner != null;
|
this.deny_entry = this.owner != null;
|
||||||
|
this.trusted = trusted;
|
||||||
this.helpers = helpers;
|
this.helpers = helpers;
|
||||||
this.denied = denied;
|
this.denied = denied;
|
||||||
this.settings.setTime(time);
|
this.settings.setTime(time);
|
||||||
@ -152,7 +157,7 @@ public class Plot implements Cloneable {
|
|||||||
* @return true if the player is added as a helper or is the owner
|
* @return true if the player is added as a helper or is the owner
|
||||||
*/
|
*/
|
||||||
public boolean hasRights(Player player) {
|
public boolean hasRights(Player player) {
|
||||||
return player.hasPermission("plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(player.getUniqueId())) || ((this.owner != null) && this.owner.equals(player.getUniqueId()));
|
return player.hasPermission("plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(player.getUniqueId())) || ((this.owner != null) && this.owner.equals(player.getUniqueId())) || (this.owner != null && this.trusted != null && Bukkit.getPlayer(this.owner) != null && (this.trusted.contains(player.getUniqueId()) || this.trusted.contains(DBFunc.everyone)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -220,6 +225,16 @@ public class Plot implements Cloneable {
|
|||||||
public void addHelper(UUID uuid) {
|
public void addHelper(UUID uuid) {
|
||||||
this.helpers.add(uuid);
|
this.helpers.add(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add someone as a trusted user (use DBFunc as well)
|
||||||
|
*
|
||||||
|
* @param uuid
|
||||||
|
*/
|
||||||
|
public void addTrusted(UUID uuid) {
|
||||||
|
this.trusted.add(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get plot display name
|
* Get plot display name
|
||||||
@ -250,6 +265,15 @@ public class Plot implements Cloneable {
|
|||||||
public void removeHelper(UUID uuid) {
|
public void removeHelper(UUID uuid) {
|
||||||
this.helpers.remove(uuid);
|
this.helpers.remove(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a trusted user (use DBFunc as well)
|
||||||
|
*
|
||||||
|
* @param uuid
|
||||||
|
*/
|
||||||
|
public void removeTrusted(UUID uuid) {
|
||||||
|
this.trusted.remove(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear a plot
|
* Clear a plot
|
||||||
@ -261,14 +285,4 @@ public class Plot implements Cloneable {
|
|||||||
PlotHelper.clear(plr, this);
|
PlotHelper.clear(plr, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a plot
|
|
||||||
*
|
|
||||||
* @param plr
|
|
||||||
* initiator
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public void delete(Player plr) {
|
|
||||||
this.clear(plr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,14 @@ public enum Command {
|
|||||||
// (Rating system) (ratings can be stored as the average, and number of ratings)
|
// (Rating system) (ratings can be stored as the average, and number of ratings)
|
||||||
// - /plot rate <number out of 10>
|
// - /plot rate <number out of 10>
|
||||||
// - /plot list <some parameter to list the most popular, and highest rated plots>
|
// - /plot list <some parameter to list the most popular, and highest rated plots>
|
||||||
|
TRUSTED("trusted","trust"),
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
COPY("copy"),
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
KICK("kick","k"),
|
KICK("kick","k"),
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) IntellectualCrafters - 2014.
|
||||||
|
* You are not allowed to distribute and/or monetize any of our intellectual property.
|
||||||
|
* IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB.
|
||||||
|
*
|
||||||
|
* >> File = Clear.java
|
||||||
|
* >> Generated by: Citymonstret at 2014-08-09 01:41
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.C;
|
||||||
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
||||||
|
import com.intellectualcrafters.plot.Plot;
|
||||||
|
import com.intellectualcrafters.plot.PlotHelper;
|
||||||
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Citymonstret on 2014-08-01.
|
||||||
|
*/
|
||||||
|
public class Copy extends SubCommand {
|
||||||
|
|
||||||
|
public Copy() {
|
||||||
|
super(Command.COPY, "Copy a plot", "clear", CommandCategory.ACTIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(Player plr, String... args) {
|
||||||
|
if (!PlayerFunctions.isInPlot(plr)) {
|
||||||
|
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
||||||
|
if ((plot==null || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) {
|
||||||
|
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
plot.clear(plr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -37,9 +37,6 @@ public class Home extends SubCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(Player plr, String... args) {
|
public boolean execute(Player plr, String... args) {
|
||||||
|
|
||||||
// TODO plot names / alias
|
|
||||||
|
|
||||||
Plot[] plots = PlotMain.getPlots(plr).toArray(new Plot[0]);
|
Plot[] plots = PlotMain.getPlots(plr).toArray(new Plot[0]);
|
||||||
if (plots.length == 1) {
|
if (plots.length == 1) {
|
||||||
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[0]);
|
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[0]);
|
||||||
|
@ -49,6 +49,7 @@ public class Info extends SubCommand {
|
|||||||
|
|
||||||
boolean hasOwner = plot.hasOwner();
|
boolean hasOwner = plot.hasOwner();
|
||||||
boolean containsEveryone;
|
boolean containsEveryone;
|
||||||
|
boolean trustedEveryone;
|
||||||
|
|
||||||
// Wildcard player {added}
|
// Wildcard player {added}
|
||||||
{
|
{
|
||||||
@ -57,10 +58,15 @@ public class Info extends SubCommand {
|
|||||||
} else {
|
} else {
|
||||||
containsEveryone = plot.helpers.contains(DBFunc.everyone);
|
containsEveryone = plot.helpers.contains(DBFunc.everyone);
|
||||||
}
|
}
|
||||||
|
if (plot.trusted == null) {
|
||||||
|
trustedEveryone = false;
|
||||||
|
} else {
|
||||||
|
trustedEveryone = plot.trusted.contains(DBFunc.everyone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unclaimed?
|
// Unclaimed?
|
||||||
if (!hasOwner && !containsEveryone) {
|
if (!hasOwner && !containsEveryone && !trustedEveryone) {
|
||||||
PlayerFunctions.sendMessage(player, C.PLOT_INFO_UNCLAIMED, plot.id.x + ";" + plot.id.y);
|
PlayerFunctions.sendMessage(player, C.PLOT_INFO_UNCLAIMED, plot.id.x + ";" + plot.id.y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -83,6 +89,7 @@ public class Info extends SubCommand {
|
|||||||
info = info.replaceAll("%time%", plot.settings.getChangeTime() ? plot.settings.getTime() + "" : "default");
|
info = info.replaceAll("%time%", plot.settings.getChangeTime() ? plot.settings.getTime() + "" : "default");
|
||||||
info = info.replaceAll("%weather%", plot.settings.getRain() ? "rain" : "default");
|
info = info.replaceAll("%weather%", plot.settings.getRain() ? "rain" : "default");
|
||||||
info = info.replaceAll("%helpers%", getPlayerList(plot.helpers));
|
info = info.replaceAll("%helpers%", getPlayerList(plot.helpers));
|
||||||
|
info = info.replaceAll("%trusted%", getPlayerList(plot.trusted));
|
||||||
info = info.replaceAll("%denied%", getPlayerList(plot.denied));
|
info = info.replaceAll("%denied%", getPlayerList(plot.denied));
|
||||||
info = info.replaceAll("%flags%", StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), ",") : "none");
|
info = info.replaceAll("%flags%", StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), ",") : "none");
|
||||||
PlayerFunctions.sendMessage(player, PlayerFunctions.getTopPlot(player.getWorld(), plot).id.toString());
|
PlayerFunctions.sendMessage(player, PlayerFunctions.getTopPlot(player.getWorld(), plot).id.toString());
|
||||||
|
@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) IntellectualCrafters - 2014.
|
||||||
|
* You are not allowed to distribute and/or monetize any of our intellectual property.
|
||||||
|
* IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB.
|
||||||
|
*
|
||||||
|
* >> File = Trusted.java
|
||||||
|
* >> Generated by: Citymonstret at 2014-08-09 01:41
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.C;
|
||||||
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
||||||
|
import com.intellectualcrafters.plot.Plot;
|
||||||
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.events.PlayerPlotTrustedEvent;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public class Trusted extends SubCommand {
|
||||||
|
|
||||||
|
public Trusted() {
|
||||||
|
super(Command.TRUSTED, "Manage trusted users for a plot", "trusted {add|remove} {player}", CommandCategory.ACTIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasBeenOnServer(String name) {
|
||||||
|
Player plr;
|
||||||
|
if ((plr = Bukkit.getPlayer(name)) == null) {
|
||||||
|
OfflinePlayer oplr = Bukkit.getOfflinePlayer(name);
|
||||||
|
if (oplr == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return oplr.hasPlayedBefore();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (plr.isOnline()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return plr.hasPlayedBefore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(Player plr, String... args) {
|
||||||
|
if (args.length < 2) {
|
||||||
|
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!PlayerFunctions.isInPlot(plr)) {
|
||||||
|
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
||||||
|
if ((plot.owner == null) || !plot.hasRights(plr)) {
|
||||||
|
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("add")) {
|
||||||
|
if (args[1].equalsIgnoreCase("*")) {
|
||||||
|
UUID uuid = DBFunc.everyone;
|
||||||
|
plot.addTrusted(uuid);
|
||||||
|
DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
||||||
|
PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!hasBeenOnServer(args[1])) {
|
||||||
|
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
UUID uuid = null;
|
||||||
|
if ((Bukkit.getPlayer(args[1]) != null) && Bukkit.getPlayer(args[1]).isOnline()) {
|
||||||
|
uuid = Bukkit.getPlayer(args[1]).getUniqueId();
|
||||||
|
} else {
|
||||||
|
uuid = Bukkit.getOfflinePlayer(args[1]).getUniqueId();
|
||||||
|
}
|
||||||
|
plot.addTrusted(uuid);
|
||||||
|
DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
||||||
|
PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED);
|
||||||
|
} else if (args[0].equalsIgnoreCase("remove")) {
|
||||||
|
if (args[1].equalsIgnoreCase("*")) {
|
||||||
|
UUID uuid = DBFunc.everyone;
|
||||||
|
if (!plot.trusted.contains(uuid)) {
|
||||||
|
PlayerFunctions.sendMessage(plr, C.T_WAS_NOT_ADDED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
plot.removeTrusted(uuid);
|
||||||
|
DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
||||||
|
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!hasBeenOnServer(args[1])) {
|
||||||
|
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
UUID uuid = null;
|
||||||
|
if (Bukkit.getPlayer(args[1]).isOnline()) {
|
||||||
|
uuid = Bukkit.getPlayer(args[1]).getUniqueId();
|
||||||
|
} else {
|
||||||
|
uuid = Bukkit.getOfflinePlayer(args[1]).getUniqueId();
|
||||||
|
}
|
||||||
|
if (!plot.trusted.contains(uuid)) {
|
||||||
|
PlayerFunctions.sendMessage(plr, C.T_WAS_NOT_ADDED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
plot.removeTrusted(uuid);
|
||||||
|
DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
||||||
|
PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, false);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
|
||||||
|
} else {
|
||||||
|
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -100,6 +100,7 @@ public class DBFunc {
|
|||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
stmt.addBatch("ALTER TABLE `plot_settings` ADD CONSTRAINT `plot_settings_ibfk_1` FOREIGN KEY (`plot_plot_id`) REFERENCES `plot` (`id`) ON DELETE CASCADE");
|
stmt.addBatch("ALTER TABLE `plot_settings` ADD CONSTRAINT `plot_settings_ibfk_1` FOREIGN KEY (`plot_plot_id`) REFERENCES `plot` (`id`) ON DELETE CASCADE");
|
||||||
|
|
||||||
@ -107,6 +108,7 @@ public class DBFunc {
|
|||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot` (" + "`id` INTEGER(11) PRIMARY KEY," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP)");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot` (" + "`id` INTEGER(11) PRIMARY KEY," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP)");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
|
||||||
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
|
||||||
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)" + ")");
|
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)" + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +139,10 @@ public class DBFunc {
|
|||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
stmt = connection.prepareStatement("DELETE FROM `plot_trusted` WHERE `plot_plot_id` = ?");
|
||||||
|
stmt.setInt(1, id);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
stmt.close();
|
||||||
stmt = connection.prepareStatement("DELETE FROM `plot` WHERE `id` = ?");
|
stmt = connection.prepareStatement("DELETE FROM `plot` WHERE `id` = ?");
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
@ -270,6 +276,7 @@ public class DBFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<UUID> helpers = plotHelpers(id);
|
ArrayList<UUID> helpers = plotHelpers(id);
|
||||||
|
ArrayList<UUID> trusted = plotTrusted(id);
|
||||||
ArrayList<UUID> denied = plotDenied(id);
|
ArrayList<UUID> denied = plotDenied(id);
|
||||||
// boolean changeTime = ((Short) settings.get("custom_time") ==
|
// boolean changeTime = ((Short) settings.get("custom_time") ==
|
||||||
// 0) ? false : true;
|
// 0) ? false : true;
|
||||||
@ -309,7 +316,7 @@ public class DBFunc {
|
|||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
merged[3-i] = (merged_int & (1 << i)) != 0;
|
merged[3-i] = (merged_int & (1 << i)) != 0;
|
||||||
}
|
}
|
||||||
p = new Plot(plot_id, owner, plotBiome, helpers, denied, /* changeTime */false, time, rain, alias, position, flags, worldname, merged);
|
p = new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, /* changeTime */false, time, rain, alias, position, flags, worldname, merged);
|
||||||
if (plots.containsKey(worldname)) {
|
if (plots.containsKey(worldname)) {
|
||||||
plots.get(worldname).put((plot_id), p);
|
plots.get(worldname).put((plot_id), p);
|
||||||
} else {
|
} else {
|
||||||
@ -559,6 +566,29 @@ public class DBFunc {
|
|||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static ArrayList<UUID> plotTrusted(int id) {
|
||||||
|
ArrayList<UUID> l = new ArrayList<UUID>();
|
||||||
|
Statement stmt = null;
|
||||||
|
try {
|
||||||
|
stmt = connection.createStatement();
|
||||||
|
ResultSet r = stmt.executeQuery("SELECT `user_uuid` FROM `plot_trusted` WHERE `plot_plot_id` = " + id);
|
||||||
|
UUID u;
|
||||||
|
while (r.next()) {
|
||||||
|
u = UUID.fromString(r.getString("user_uuid"));
|
||||||
|
l.add(u);
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.add(LogLevel.WARNING, "Failed to load trusted users for plot: " + id);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot
|
* @param plot
|
||||||
@ -581,6 +611,28 @@ public class DBFunc {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param plot
|
||||||
|
* @param player
|
||||||
|
*/
|
||||||
|
public static void removeTrusted(final String world, final Plot plot, final OfflinePlayer player) {
|
||||||
|
runTask(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = connection.prepareStatement("DELETE FROM `plot_trusted` WHERE `plot_plot_id` = ? AND `user_uuid` = ?");
|
||||||
|
statement.setInt(1, getId(world, plot.id));
|
||||||
|
statement.setString(2, player.getUniqueId().toString());
|
||||||
|
statement.executeUpdate();
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Logger.add(LogLevel.WARNING, "Failed to remove trusted user for plot " + plot.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot
|
* @param plot
|
||||||
@ -603,6 +655,28 @@ public class DBFunc {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param plot
|
||||||
|
* @param player
|
||||||
|
*/
|
||||||
|
public static void setTrusted(final String world, final Plot plot, final OfflinePlayer player) {
|
||||||
|
runTask(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = connection.prepareStatement("INSERT INTO `plot_trusted` (`plot_plot_id`, `user_uuid`) VALUES(?,?)");
|
||||||
|
statement.setInt(1, getId(world, plot.id));
|
||||||
|
statement.setString(2, player.getUniqueId().toString());
|
||||||
|
statement.executeUpdate();
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.add(LogLevel.WARNING, "Failed to set plot trusted for plot " + plot.id);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot
|
* @param plot
|
||||||
|
@ -40,7 +40,6 @@ public class PlotMeConverter {
|
|||||||
if (plots!=null) {
|
if (plots!=null) {
|
||||||
|
|
||||||
// TODO generate configuration based on PlotMe config
|
// TODO generate configuration based on PlotMe config
|
||||||
// TODO
|
|
||||||
// - Plugin doesn't display a message if database is not setup at all
|
// - Plugin doesn't display a message if database is not setup at all
|
||||||
|
|
||||||
PlotMain.sendConsoleSenderMessage("Converting " + plots.size() + " plots for '" + world.toString() + "'...");
|
PlotMain.sendConsoleSenderMessage("Converting " + plots.size() + " plots for '" + world.toString() + "'...");
|
||||||
@ -48,6 +47,7 @@ public class PlotMeConverter {
|
|||||||
PlayerList denied = null;
|
PlayerList denied = null;
|
||||||
PlayerList added = null;
|
PlayerList added = null;
|
||||||
ArrayList<UUID> psAdded = new ArrayList<>();
|
ArrayList<UUID> psAdded = new ArrayList<>();
|
||||||
|
ArrayList<UUID> psTrusted = new ArrayList<>();
|
||||||
ArrayList<UUID> psDenied = new ArrayList<>();
|
ArrayList<UUID> psDenied = new ArrayList<>();
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
world = Bukkit.getWorld("world");
|
world = Bukkit.getWorld("world");
|
||||||
@ -81,7 +81,7 @@ public class PlotMeConverter {
|
|||||||
}
|
}
|
||||||
stream.println(eR3040bl230);
|
stream.println(eR3040bl230);
|
||||||
PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1]));
|
PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1]));
|
||||||
com.intellectualcrafters.plot.Plot pl = new com.intellectualcrafters.plot.Plot(id, plot.getOwnerId(), plot.getBiome(), psAdded, psDenied, false, 8000l, false, "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] {false, false, false, false} );
|
com.intellectualcrafters.plot.Plot pl = new com.intellectualcrafters.plot.Plot(id, plot.getOwnerId(), plot.getBiome(), psAdded, psTrusted, psDenied, false, 8000l, false, "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] {false, false, false, false} );
|
||||||
|
|
||||||
// TODO createPlot doesn't add helpers / denied users
|
// TODO createPlot doesn't add helpers / denied users
|
||||||
|
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
package com.intellectualcrafters.plot.events;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.Plot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Citymonstret on 2014-08-16.
|
||||||
|
*/
|
||||||
|
public class PlayerPlotTrustedEvent extends Event {
|
||||||
|
private static HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private Plot plot;
|
||||||
|
private Player initiator;
|
||||||
|
private boolean added;
|
||||||
|
private UUID player;
|
||||||
|
/**
|
||||||
|
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
|
||||||
|
* @param initiator
|
||||||
|
* @param plot
|
||||||
|
* @param player
|
||||||
|
* @param added
|
||||||
|
*/
|
||||||
|
public PlayerPlotTrustedEvent(Player initiator, Plot plot, UUID player, boolean added) {
|
||||||
|
this.initiator = initiator;
|
||||||
|
this.plot = plot;
|
||||||
|
this.added = added;
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a player was added
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean wasAdded() {
|
||||||
|
return this.added;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* The UUID added/removed
|
||||||
|
* @return UUID
|
||||||
|
*/
|
||||||
|
public UUID getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* The plot involved
|
||||||
|
* @return Plot
|
||||||
|
*/
|
||||||
|
public Plot getPlot() {
|
||||||
|
return this.plot;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* The player initiating the action
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
|
public Player getInitiator() {
|
||||||
|
return this.initiator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package com.intellectualcrafters.plot.listeners;
|
package com.intellectualcrafters.plot.listeners;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.*;
|
import com.intellectualcrafters.plot.*;
|
||||||
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -115,7 +117,7 @@ public class WorldEditListener implements Listener {
|
|||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
} else if (msg.startsWith("/up") || msg.startsWith("//up") || msg.startsWith("/worldedit:up") || msg.startsWith("/worldedit:/up")) {
|
} else if (msg.startsWith("/up") || msg.startsWith("//up") || msg.startsWith("/worldedit:up") || msg.startsWith("/worldedit:/up")) {
|
||||||
Plot plot = PlayerFunctions.getCurrentPlot(p);
|
Plot plot = PlayerFunctions.getCurrentPlot(p);
|
||||||
if ((p == null) || !plot.hasRights(p)) {
|
if ((p == null) || !(plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,7 +134,7 @@ public class WorldEditListener implements Listener {
|
|||||||
if (((e.getAction() == Action.LEFT_CLICK_BLOCK) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) && (p.getItemInHand() != null) && (p.getItemInHand().getType() != Material.AIR)) {
|
if (((e.getAction() == Action.LEFT_CLICK_BLOCK) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) && (p.getItemInHand() != null) && (p.getItemInHand().getType() != Material.AIR)) {
|
||||||
Block b = e.getClickedBlock();
|
Block b = e.getClickedBlock();
|
||||||
Plot plot = PlotHelper.getCurrentPlot(b.getLocation());
|
Plot plot = PlotHelper.getCurrentPlot(b.getLocation());
|
||||||
if ((plot != null) && plot.hasRights(p)) {
|
if ((plot != null) && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) {
|
||||||
PWE.setMask(p, b.getLocation());
|
PWE.setMask(p, b.getLocation());
|
||||||
} else {
|
} else {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user