mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
Some improvements, I still have to test the setowner stuff, seemed a bit dangerous to give OP :3
This commit is contained in:
parent
adae7f3cf0
commit
3c5f88c0be
@ -327,7 +327,11 @@ public enum C {
|
||||
HELP_CATEGORY("&6Current Category&c: &l%category%"),
|
||||
HELP_INFO("&6You need to specify a help category"),
|
||||
HELP_INFO_ITEM("&6/plots help %category% &c- &6%category_desc%"),
|
||||
HELP_PAGE("&c>> &6%usage% &c[&6%alias%&c] &c- &6%desc%"),
|
||||
HELP_PAGE(
|
||||
"&c>> &6%usage% &c[&6%alias%&c]\n" +
|
||||
"&c>> &6%desc%\n"
|
||||
),
|
||||
HELP_ITEM_SEPARATOR("&c%lines"),
|
||||
HELP_HEADER("&c(Page &6%cur&c/&6%max&c) &6Help for Plots"),
|
||||
/*
|
||||
* Direction
|
||||
|
@ -19,6 +19,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.ChatPaginator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -49,16 +50,11 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
Player player;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
}
|
||||
else {
|
||||
player = null;
|
||||
}
|
||||
if (!PlotMain.hasPermission(player, "plots.use")) {
|
||||
Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||
|
||||
if (!PlotMain.hasPermission(player, "plots.use"))
|
||||
return no_permission(player, "plots.use");
|
||||
}
|
||||
|
||||
if ((args.length < 1)
|
||||
|| ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
||||
if (args.length < 2) {
|
||||
@ -89,14 +85,21 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
StringBuilder help = new StringBuilder();
|
||||
int page = 0;
|
||||
try {
|
||||
|
||||
boolean digit = true;
|
||||
for(char c : args[2].toCharArray())
|
||||
if(!Character.isDigit(c)) {
|
||||
digit = false;
|
||||
break;
|
||||
}
|
||||
if(digit) {
|
||||
page = Integer.parseInt(args[2]);
|
||||
--page;
|
||||
if(page < 0) page = 0;
|
||||
} catch(Exception e) {}
|
||||
for (String string : helpMenu(player, cato, page)) {
|
||||
help.append(string).append("\n");
|
||||
}
|
||||
if(--page < 0) page = 0;
|
||||
}
|
||||
|
||||
for(String string : helpMenu(player, cato, page))
|
||||
help.append(string).append("\n");
|
||||
|
||||
PlayerFunctions.sendMessage(player, help.toString());
|
||||
return true;
|
||||
}
|
||||
@ -175,10 +178,11 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
public static ArrayList<String> helpMenu(Player player, final SubCommand.CommandCategory category, int page) {
|
||||
List<SubCommand> commands = getCommands(category, player);
|
||||
//final int totalPages = ((int) Math.ceil(12 * (commands.size()) / 100));
|
||||
int totalPages = (int) Math.ceil(commands.size() / 12);
|
||||
int perPage = 5;
|
||||
int totalPages = (int) Math.ceil(commands.size() / perPage);
|
||||
if(page > totalPages)
|
||||
page = totalPages;
|
||||
int max = (page * 12) + 12;
|
||||
int max = (page * perPage) + perPage;
|
||||
if(max > commands.size())
|
||||
max = commands.size();
|
||||
ArrayList<String> help = new ArrayList<>(
|
||||
@ -187,14 +191,27 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
t(C.HELP_CATEGORY.s().replaceAll("%category%", category.toString()))
|
||||
));
|
||||
SubCommand cmd;
|
||||
for(int x = (page * 12); x < max; x++) {
|
||||
|
||||
String lines = "";
|
||||
for(int x = 0; x < ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH * 0.75; x++) {
|
||||
lines += "-";
|
||||
}
|
||||
|
||||
int start = page * perPage;
|
||||
for(int x = start; x < max; x++) {
|
||||
cmd = subCommands.get(x);
|
||||
String s = t(C.HELP_PAGE.s());
|
||||
s = s.replaceAll("%alias%", cmd.alias);
|
||||
s = s.replaceAll("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage);
|
||||
s = s.replaceAll("%cmd%", cmd.cmd);
|
||||
s = s.replaceAll("%desc%", cmd.description);
|
||||
|
||||
help.add(s);
|
||||
|
||||
if(x != start && x != max - 1) {
|
||||
help.add(t(C.HELP_ITEM_SEPARATOR.s().replaceAll("%lines", lines)));
|
||||
}
|
||||
|
||||
}
|
||||
if (help.size() < 2) {
|
||||
help.add(t(C.NO_COMMANDS.s()));
|
||||
|
@ -1,22 +1,6 @@
|
||||
package com.intellectualcrafters.plot.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.intellectualcrafters.plot.Plot;
|
||||
import com.intellectualcrafters.plot.PlotHelper;
|
||||
import com.intellectualcrafters.plot.PlotId;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.*;
|
||||
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
|
||||
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
|
||||
import com.intellectualcrafters.plot.events.PlotMergeEvent;
|
||||
@ -28,6 +12,18 @@ import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-09-24.
|
||||
@ -43,9 +39,18 @@ public class WorldGuardListener implements Listener {
|
||||
this.flags.add(flag);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeOwner(Player requester, UUID owner, World world, Plot plot) {
|
||||
boolean op = requester.isOp();
|
||||
requester.setOp(true);
|
||||
//boolean op = requester.isOp();
|
||||
//requester.setOp(true);
|
||||
|
||||
//10 ticks should be enough
|
||||
PermissionAttachment add = requester.addAttachment(PlotMain.getPlugin(PlotMain.class), 10);
|
||||
add.setPermission("worldguard.region.addowner.own.*", true);
|
||||
|
||||
PermissionAttachment remove = requester.addAttachment(PlotMain.getPlugin(PlotMain.class), 10);
|
||||
remove.setPermission("worldguard.region.removeowner.own.*", true);
|
||||
|
||||
try {
|
||||
RegionManager manager = PlotMain.worldGuard.getRegionManager(world);
|
||||
manager.getRegion(plot.id.x + "-" + plot.id.y);
|
||||
@ -53,10 +58,12 @@ public class WorldGuardListener implements Listener {
|
||||
requester.performCommand("region removeowner " + (plot.id.x + "-" + plot.id.y) + " " + UUIDHandler.getName(plot.getOwner()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
requester.setOp(op);
|
||||
//requester.setOp(op);
|
||||
|
||||
}
|
||||
finally {
|
||||
requester.setOp(op);
|
||||
add.remove();
|
||||
remove.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,11 @@
|
||||
package PlotTesting;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotHelper;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.PlotManager;
|
||||
import com.intellectualcrafters.plot.PlotWorld;
|
||||
import com.intellectualcrafters.plot.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.generator.DefaultPlotManager;
|
||||
import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test1 {
|
||||
|
Loading…
Reference in New Issue
Block a user