plot kick command

This commit is contained in:
boy0001 2014-09-30 21:17:55 +10:00
parent 3508431300
commit 3c74874256
10 changed files with 114 additions and 13 deletions

View File

@ -71,12 +71,20 @@ public enum C {
*/
NO_SCHEMATIC_PERMISSION("&cYou don't have the permission required to use schematic &6%s"),
NO_PERMISSION("&cYou don't have the permissions required to use this command."), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), YOU_BE_DENIED("&cYou are not allowed to enter this plot"),
NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), UNLINK_REQUIRED("&cAn unlink is required to do this."), UNLINK_IMPOSSIBLE("&cYou can only unlink a mega-plot"),
NO_MERGE_TO_MEGA("&cMega plots cannot be merged into. Please merge from the desired mega plot."),
/*
* Commands
*/
NOT_VALID_SUBCOMMAND("&cThat is not a valid subcommand."), NO_COMMANDS("&cI'm sorry, but you're not permitted to use any subcommands."), SUBCOMMAND_SET_OPTIONS_HEADER("&cPossible Values: "),
/*
* Player not found
*/
INVALID_PLAYER("&cPlayer not found: &6%player%."),
/*
*
*/
/*
* No {plot}
*/

View File

@ -31,12 +31,12 @@ public class Clear extends SubCommand {
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return true;
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 true;
return false;
}
plot.clear(plr);
return true;

View File

@ -26,7 +26,7 @@ public enum Command {
// (Rating system) (ratings can be stored as the average, and number of ratings)
// - /plot rate <number out of 10>
// - /plot list <some parameter to list the most popular, and highest rated plots>
KICK("kick","k"),
/**
*
*/

View File

@ -31,16 +31,16 @@ public class Delete extends SubCommand {
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return true;
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED);
return true;
return false;
}
if ((plot==null || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
return false;
}
boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id, true);
if (result) {

View File

@ -26,7 +26,6 @@ public class Home extends SubCommand {
public Home() {
super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT);
}
private Plot isAlias(String a) {
for (Plot p : PlotMain.getPlots()) {
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {

View File

@ -0,0 +1,58 @@
/*
* 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 = Kick.java
* >> Generated by: Citymonstret at 2014-08-09 01:41
*/
package com.intellectualcrafters.plot.commands;
import org.bukkit.Bukkit;
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 Kick extends SubCommand {
public Kick() {
super(Command.KICK, "Kick a player from your plot", "kick", 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;
}
if (args.length!=1) {
PlayerFunctions.sendMessage(plr, "&c/plot kick <player>");
return false;
}
if (Bukkit.getPlayer(args[0]) != null) {
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER.s().replaceAll("%player%", args[0]));
return false;
}
Player player = Bukkit.getPlayer(args[0]);
if (!player.getWorld().equals(plr.getWorld()) || !PlayerFunctions.isInPlot(player) || PlayerFunctions.getCurrentPlot(player)==null || !PlayerFunctions.getCurrentPlot(player).equals(plot)) {
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER.s().replaceAll("%player%", args[0]));
return false;
}
player.teleport(player.getWorld().getSpawnLocation());
return true;
}
}

View File

@ -30,7 +30,7 @@ import com.intellectualcrafters.plot.PlotMain;
*/
public class MainCommand implements CommandExecutor {
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Reload(), new Merge(), new Unlink() };
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Reload(), new Merge(), new Unlink(), new Kick() };
public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
{

View File

@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlotFlagAddEvent;
import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -23,6 +24,7 @@ import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
/**
@ -177,11 +179,15 @@ public class Set extends SubCommand{
return false;
}
String alias = args[1];
for(Plot p : PlotMain.getPlots()) {
for(Plot p : PlotMain.getPlots(plr.getWorld()).values()) {
if(p.settings.getAlias().equalsIgnoreCase(alias)) {
PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
if (Bukkit.getOfflinePlayer(alias).hasPlayedBefore()) {
PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
}
DBFunc.setAlias(plr.getWorld().getName(), plot, alias);
PlayerFunctions.sendMessage(plr, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));

View File

@ -9,6 +9,9 @@
package com.intellectualcrafters.plot.commands;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -50,7 +53,7 @@ public class TP extends SubCommand {
return false;
}
Plot temp;
if ((temp = isAlias(id)) != null) {
if ((temp = isAlias(world, id)) != null) {
PlotMain.teleportPlayer(plr, plr.getLocation(), temp);
return true;
}
@ -64,8 +67,24 @@ public class TP extends SubCommand {
return false;
}
private Plot isAlias(String a) {
for (Plot p : PlotMain.getPlots()) {
private Plot isAlias(World world, String a) {
int index = 0;
if (a.contains(":")) {
String[] split = a.split(";");
if (split[1].length()>0 && StringUtils.isNumeric(split[1])) {
index = Integer.parseInt(split[1]);
}
a = split[0];
}
Player player = Bukkit.getPlayer(a);
if (player!=null) {
Plot[] plots = PlotMain.getPlots(world, player).toArray(new Plot[0]);
if (plots.length > index) {
return plots[index];
}
return null;
}
for (Plot p : PlotMain.getPlots(world).values()) {
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
return p;
}

View File

@ -38,7 +38,7 @@ public class list extends SubCommand {
if (args.length < 1) {
StringBuilder builder = new StringBuilder();
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
builder.append(getArgumentList(new String[] { "mine", "all", "world" }));
builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all" }));
PlayerFunctions.sendMessage(plr, builder.toString());
return true;
}
@ -57,6 +57,17 @@ public class list extends SubCommand {
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "You have").replaceAll("%num%", idx + "").replaceAll("%plot%", idx == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString());
return true;
} else if (args[0].equalsIgnoreCase("shared")) {
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n");
for (Plot p : PlotMain.getPlots()) {
if (p.helpers.contains(plr.getUniqueId())) {
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id%", p.id.x + ";" + p.id.y + ";" + p.world).replaceAll("%owner%", getName(p.owner)) + "\n");
}
}
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", PlotMain.getPlots().size() + "").replaceAll("%plot%", PlotMain.getPlots().size() == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString());
return true;
} else if (args[0].equalsIgnoreCase("all")) {
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n");