mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
Piston stuff
Pretty help menu
This commit is contained in:
parent
182f4cbd22
commit
9309855df2
@ -361,12 +361,18 @@ public enum C {
|
|||||||
/*
|
/*
|
||||||
* Help
|
* Help
|
||||||
*/
|
*/
|
||||||
|
HELP_HEADER("&c----------[ &6PlotSquared Help &c]----------"),
|
||||||
|
HELP_CATEGORY("&cCategory: &6%category%&c, Page: &6%current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
|
||||||
|
HELP_INFO("&6You have to specify a category"),
|
||||||
|
HELP_INFO_ITEM("&6/plots help %category% &c- &6%category_desc%"),
|
||||||
|
HELP_ITEM("&6%usage% [%alias%]\n &c%desc%\n"),
|
||||||
|
/*
|
||||||
HELP_CATEGORY("&6Current Category&c: &l%category%"),
|
HELP_CATEGORY("&6Current Category&c: &l%category%"),
|
||||||
HELP_INFO("&6You need to specify a help category"),
|
HELP_INFO("&6You need to specify a help category"),
|
||||||
HELP_INFO_ITEM("&6/plots help %category% &c- &6%category_desc%"),
|
HELP_INFO_ITEM("&6/plots help %category% &c- &6%category_desc%"),
|
||||||
HELP_PAGE("&c>> &6%usage% &c[&6%alias%&c]\n" + "&c>> &6%desc%\n"),
|
HELP_PAGE("&c>> &6%usage% &c[&6%alias%&c]\n" + "&c>> &6%desc%\n"),
|
||||||
HELP_ITEM_SEPARATOR("&c%lines"),
|
HELP_ITEM_SEPARATOR("&c%lines"),
|
||||||
HELP_HEADER("&c(Page &6%cur&c/&6%max&c) &6Help for Plots"),
|
HELP_HEADER("&c(Page &6%cur&c/&6%max&c) &6Help for Plots"),*/
|
||||||
/*
|
/*
|
||||||
* Direction
|
* Direction
|
||||||
*/
|
*/
|
||||||
@ -375,6 +381,8 @@ public enum C {
|
|||||||
* Custom
|
* Custom
|
||||||
*/
|
*/
|
||||||
CUSTOM_STRING("-");
|
CUSTOM_STRING("-");
|
||||||
|
private static TranslationManager manager;
|
||||||
|
private static TranslationFile defaultFile;
|
||||||
/**
|
/**
|
||||||
* Default
|
* Default
|
||||||
*/
|
*/
|
||||||
@ -406,6 +414,26 @@ public enum C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setupTranslations() {
|
||||||
|
if (manager == null) {
|
||||||
|
manager = new TranslationManager();
|
||||||
|
}
|
||||||
|
if (defaultFile == null) {
|
||||||
|
defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getPlugin(PlotMain.class)), TranslationLanguage.englishAmerican, "PlotSquared", manager)
|
||||||
|
.read();
|
||||||
|
}
|
||||||
|
// register everything in this class
|
||||||
|
for (C c : values()) {
|
||||||
|
manager.addTranslationObject(
|
||||||
|
new TranslationObject(c.toString(), c.d, "", "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveTranslations() {
|
||||||
|
manager.saveAll(defaultFile).saveFile(defaultFile);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default string
|
* Get the default string
|
||||||
*
|
*
|
||||||
@ -442,27 +470,4 @@ public enum C {
|
|||||||
public String translated() {
|
public String translated() {
|
||||||
return ChatColor.translateAlternateColorCodes('&', this.s());
|
return ChatColor.translateAlternateColorCodes('&', this.s());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TranslationManager manager;
|
|
||||||
private static TranslationFile defaultFile;
|
|
||||||
|
|
||||||
public static void setupTranslations() {
|
|
||||||
if (manager == null) {
|
|
||||||
manager = new TranslationManager();
|
|
||||||
}
|
|
||||||
if (defaultFile == null) {
|
|
||||||
defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getPlugin(PlotMain.class)), TranslationLanguage.englishAmerican, "PlotSquared", manager)
|
|
||||||
.read();
|
|
||||||
}
|
|
||||||
// register everything in this class
|
|
||||||
for (C c : values()) {
|
|
||||||
manager.addTranslationObject(
|
|
||||||
new TranslationObject(c.toString(), c.d, "", "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void saveTranslations() {
|
|
||||||
manager.saveAll(defaultFile).saveFile(defaultFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,7 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Citymonstret on 2014-08-11.
|
|
||||||
*/
|
|
||||||
public class Help extends SubCommand {
|
public class Help extends SubCommand {
|
||||||
public Help() {
|
public Help() {
|
||||||
super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false);
|
super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false);
|
||||||
|
@ -31,7 +31,6 @@ import org.bukkit.command.CommandExecutor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.ChatPaginator;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -60,6 +59,66 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final Player player) {
|
||||||
|
final List<SubCommand> cmds = new ArrayList<>();
|
||||||
|
for (final SubCommand c : subCommands) {
|
||||||
|
if ((c.category.equals(category)) && c.permission.hasPermission(player)) {
|
||||||
|
cmds.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cmds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> helpMenu(final Player player, final SubCommand.CommandCategory category, int page) {
|
||||||
|
final List<SubCommand> commands = getCommands(category, player);
|
||||||
|
// final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
|
||||||
|
// 100));
|
||||||
|
final int perPage = 5;
|
||||||
|
final int totalPages = (int) Math.ceil(commands.size() / perPage);
|
||||||
|
if (page > totalPages) {
|
||||||
|
page = totalPages;
|
||||||
|
}
|
||||||
|
int max = (page * perPage) + perPage;
|
||||||
|
if (max > commands.size()) {
|
||||||
|
max = commands.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> help = new ArrayList<>();
|
||||||
|
|
||||||
|
help.add(C.HELP_HEADER.s());
|
||||||
|
// HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
|
||||||
|
help.add(C.HELP_CATEGORY.s()
|
||||||
|
.replace("%category%", category.toString())
|
||||||
|
.replace("%current%", "" + (page + 1))
|
||||||
|
.replace("%max%", "" + (totalPages + 1))
|
||||||
|
.replace("%dis%", "" + perPage)
|
||||||
|
.replace("%total%", "" + commands.size())
|
||||||
|
);
|
||||||
|
|
||||||
|
SubCommand cmd;
|
||||||
|
|
||||||
|
final int start = page * perPage;
|
||||||
|
for (int x = start; x < max; x++) {
|
||||||
|
cmd = commands.get(x);
|
||||||
|
String s = t(C.HELP_ITEM.s());
|
||||||
|
s = s
|
||||||
|
.replace("%alias%", cmd.alias)
|
||||||
|
.replace("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage)
|
||||||
|
.replace("%cmd%", cmd.cmd)
|
||||||
|
.replace("%desc%", cmd.description)
|
||||||
|
;
|
||||||
|
help.add(s);
|
||||||
|
}
|
||||||
|
if (help.size() < 2) {
|
||||||
|
help.add(t(C.NO_COMMANDS.s()));
|
||||||
|
}
|
||||||
|
return help;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String t(final String s) {
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', s);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, 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;
|
final Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||||
@ -120,8 +179,8 @@ 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()));
|
||||||
return PlayerFunctions.sendMessage(player, help.toString());
|
//return PlayerFunctions.sendMessage(player, help.toString());
|
||||||
} else {
|
} else {
|
||||||
for (final SubCommand command : subCommands) {
|
for (final SubCommand command : subCommands) {
|
||||||
if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.equalsIgnoreCase(args[0])) {
|
if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.equalsIgnoreCase(args[0])) {
|
||||||
@ -150,63 +209,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
return PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command);
|
return PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command);
|
||||||
//PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch());
|
//PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch());
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
|
|
||||||
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final Player player) {
|
|
||||||
final List<SubCommand> cmds = new ArrayList<>();
|
|
||||||
for (final SubCommand c : subCommands) {
|
|
||||||
if ((c.category.equals(category)) && c.permission.hasPermission(player)) {
|
|
||||||
cmds.add(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cmds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<String> helpMenu(final Player player, final SubCommand.CommandCategory category, int page) {
|
|
||||||
final List<SubCommand> commands = getCommands(category, player);
|
|
||||||
// final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
|
|
||||||
// 100));
|
|
||||||
final int perPage = 5;
|
|
||||||
final int totalPages = (int) Math.ceil(commands.size() / perPage);
|
|
||||||
if (page > totalPages) {
|
|
||||||
page = totalPages;
|
|
||||||
}
|
|
||||||
int max = (page * perPage) + perPage;
|
|
||||||
if (max > commands.size()) {
|
|
||||||
max = commands.size();
|
|
||||||
}
|
|
||||||
final ArrayList<String> help = new ArrayList<>(Arrays.asList(t(C.HELP_HEADER.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "")), t(C.HELP_CATEGORY.s().replaceAll("%category%", category.toString()))));
|
|
||||||
SubCommand cmd;
|
|
||||||
|
|
||||||
String lines = "";
|
|
||||||
for (int x = 0; x < (ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH * 0.75); x++) {
|
|
||||||
lines += "-";
|
|
||||||
}
|
|
||||||
|
|
||||||
final int start = page * perPage;
|
|
||||||
for (int x = start; x < max; x++) {
|
|
||||||
cmd = commands.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)) {
|
|
||||||
help.add(t(C.HELP_ITEM_SEPARATOR.s().replaceAll("%lines", lines)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (help.size() < 2) {
|
|
||||||
help.add(t(C.NO_COMMANDS.s()));
|
|
||||||
}
|
|
||||||
return help;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String t(final String s) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,19 +72,6 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChangeWorld(final PlayerChangedWorldEvent event) {
|
|
||||||
/*
|
|
||||||
* if (isPlotWorld(event.getFrom()) &&
|
|
||||||
* (Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1)) {
|
|
||||||
* event.getPlayer().setResourcePack("");
|
|
||||||
* }
|
|
||||||
* else {
|
|
||||||
* textures(event.getPlayer());
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public static void PlayerMove(final PlayerMoveEvent event) {
|
public static void PlayerMove(final PlayerMoveEvent event) {
|
||||||
try {
|
try {
|
||||||
@ -167,26 +154,6 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
|
||||||
public void BlockCreate(final BlockPlaceEvent event) {
|
|
||||||
final World world = event.getPlayer().getWorld();
|
|
||||||
if (!isPlotWorld(world)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (PlotMain.hasPermission(event.getPlayer(), "plots.admin")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isInPlot(event.getBlock().getLocation())) {
|
|
||||||
final Plot plot = getCurrentPlot(event.getBlockPlaced().getLocation());
|
|
||||||
if (!plot.hasRights(event.getPlayer())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (PlayerFunctions.getPlot(event.getBlockPlaced().getLocation()) == null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public static void onBigBoom(final EntityExplodeEvent event) {
|
public static void onBigBoom(final EntityExplodeEvent event) {
|
||||||
final World world = event.getLocation().getWorld();
|
final World world = event.getLocation().getWorld();
|
||||||
@ -304,6 +271,13 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
|||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public static void onBlockPistonExtend(final BlockPistonExtendEvent e) {
|
public static void onBlockPistonExtend(final BlockPistonExtendEvent e) {
|
||||||
if (isInPlot(e.getBlock().getLocation())) {
|
if (isInPlot(e.getBlock().getLocation())) {
|
||||||
|
for (Block block : e.getBlocks()) {
|
||||||
|
if (!isInPlot(block.getLocation())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*if (isInPlot(e.getBlock().getLocation())) {
|
||||||
|
|
||||||
e.getDirection();
|
e.getDirection();
|
||||||
final int modifier = e.getBlocks().size();
|
final int modifier = e.getBlocks().size();
|
||||||
@ -348,7 +322,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
@ -730,4 +704,37 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChangeWorld(final PlayerChangedWorldEvent event) {
|
||||||
|
/*
|
||||||
|
* if (isPlotWorld(event.getFrom()) &&
|
||||||
|
* (Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1)) {
|
||||||
|
* event.getPlayer().setResourcePack("");
|
||||||
|
* }
|
||||||
|
* else {
|
||||||
|
* textures(event.getPlayer());
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void BlockCreate(final BlockPlaceEvent event) {
|
||||||
|
final World world = event.getPlayer().getWorld();
|
||||||
|
if (!isPlotWorld(world)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (PlotMain.hasPermission(event.getPlayer(), "plots.admin")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isInPlot(event.getBlock().getLocation())) {
|
||||||
|
final Plot plot = getCurrentPlot(event.getBlockPlaced().getLocation());
|
||||||
|
if (!plot.hasRights(event.getPlayer())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (PlayerFunctions.getPlot(event.getBlockPlaced().getLocation()) == null) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user