Skip to content

Commit

Permalink
merge PR #99
Browse files Browse the repository at this point in the history
  • Loading branch information
LordTuxn committed Jul 16, 2022
2 parents 1347a2f + defed55 commit e27e146
Show file tree
Hide file tree
Showing 18 changed files with 1,021 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package com.alpsbte.plotsystem.commands;

import com.alpsbte.plotsystem.core.menus.CompanionMenu;
import com.alpsbte.plotsystem.core.menus.companion.CompanionMenu;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.io.language.LangPaths;
import com.alpsbte.plotsystem.utils.io.language.LangUtil;
Expand All @@ -37,7 +37,7 @@ public class CMD_Companion extends BaseCommand {
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
if (sender.hasPermission(getPermission())) {
if (getPlayer(sender) != null) {
new CompanionMenu((Player) sender);
CompanionMenu.open((Player) sender);
}
} else {
sender.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(sender, LangPaths.Message.Error.PLAYER_HAS_NO_PERMISSIONS)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import com.alpsbte.plotsystem.commands.SubCommand;
import com.alpsbte.plotsystem.core.system.Country;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.enums.Continent;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;

Expand Down Expand Up @@ -128,10 +130,17 @@ public CMD_Setup_Country_Add(BaseCommand baseCommand, SubCommand subCommand) {

@Override
public void onCommand(CommandSender sender, String[] args) {
if (args.length > 2 && Utils.TryParseInt(args[1]) != null) {
if (args.length > 3 && Utils.TryParseInt(args[1]) != null) {
if (args[2].length() <= 45) {
Continent continent;
try {
Country.addCountry(Integer.parseInt(args[1]), args[2]);
continent = Continent.valueOf(args[3].toUpperCase());
}catch(IllegalArgumentException e) {
sender.sendMessage(Utils.getErrorMessageFormat("Unknown continent! " + Arrays.toString(Continent.values())));
return;
}
try {
Country.addCountry(Integer.parseInt(args[1]), args[2], continent);
sender.sendMessage(Utils.getInfoMessageFormat("Successfully added country!"));
} catch (SQLException ex) {
sender.sendMessage(Utils.getErrorMessageFormat("An error occurred while executing command!"));
Expand All @@ -157,7 +166,7 @@ public String getDescription() {

@Override
public String[] getParameter() {
return new String[] { "Server-ID", "Name" };
return new String[] { "Server-ID", "Name", "Continent" };
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.core.system.plot.world.PlotWorld;
import com.alpsbte.plotsystem.core.menus.companion.CompanionMenu;
import com.alpsbte.plotsystem.utils.io.config.ConfigPaths;
import com.alpsbte.plotsystem.core.system.plot.PlotManager;
import com.alpsbte.plotsystem.core.menus.CompanionMenu;
import com.alpsbte.plotsystem.core.menus.ReviewMenu;
import com.alpsbte.plotsystem.core.database.DatabaseConnection;
import com.alpsbte.plotsystem.core.system.plot.Plot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public static List<String> getTables() {
"KEY `fkIdx_38` (`server_id`)," +
"CONSTRAINT `FK_37` FOREIGN KEY `fkIdx_38` (`server_id`) REFERENCES `plotsystem_servers` (`id`)" +
");",
"ALTER TABLE plotsystem_countries ADD COLUMN IF NOT EXISTS `continent` enum('europe', 'asia', 'africa', 'oceania', 'south america', 'north america') NOT NULL;",

// City Projects
"CREATE TABLE IF NOT EXISTS `plotsystem_city_projects`" +
Expand Down Expand Up @@ -326,7 +327,52 @@ public static List<String> getTables() {
");",
"ALTER TABLE plotsystem_plots ADD COLUMN IF NOT EXISTS outline longtext NULL DEFAULT NULL;",
"ALTER TABLE plotsystem_plots ADD COLUMN IF NOT EXISTS type int NOT NULL DEFAULT 1;",
"ALTER TABLE plotsystem_plots ADD COLUMN IF NOT EXISTS version DOUBLE NULL DEFAULT NULL;"
"ALTER TABLE plotsystem_plots ADD COLUMN IF NOT EXISTS version DOUBLE NULL DEFAULT NULL;",

// API Keys
"CREATE TABLE IF NOT EXISTS `api_keys`" +
"(" +
" `api_key` varchar(32) NOT NULL ," +
" `created_at` timestamp NOT NULL ," +
"PRIMARY KEY (`api_key`)" +
");",

// Build-Teams
"CREATE TABLE IF NOT EXISTS `plotsystem_buildteams`" +
"(" +
" `id` int NOT NULL AUTO_INCREMENT ," +
" `name` varchar(45) NOT NULL ," +
" `api_key` varchar(32) NOT NULL ," +
"PRIMARY KEY (`id`)," +
"KEY `FK_132` (`api_key`)," +
"CONSTRAINT `FK_130` FOREIGN KEY `FK_132` (`api_key`) REFERENCES `api_keys` (`api_key`)" +
");",

// Build-Team has Countries
"CREATE TABLE IF NOT EXISTS `plotsystem_buildteam_has_countries`" +
"(" +
" `id` int NOT NULL ," +
" `country_id` int NOT NULL ," +
" `buildteam_id` int NOT NULL ," +
"PRIMARY KEY (`id`)," +
"KEY `FK_115` (`buildteam_id`)," +
"CONSTRAINT `FK_113` FOREIGN KEY `FK_115` (`buildteam_id`) REFERENCES `plotsystem_buildteams` (`id`)," +
"KEY `FK_118` (`country_id`)," +
"CONSTRAINT `FK_116` FOREIGN KEY `FK_118` (`country_id`) REFERENCES `plotsystem_countries` (`id`)" +
");",

// Builder Is Reviewer
"CREATE TABLE IF NOT EXISTS `plotsystem_builder_is_reviewer`" +
"(" +
" `id` int NOT NULL AUTO_INCREMENT ," +
" `builder_uuid` varchar(36) NOT NULL ," +
" `buildteam_id` int NOT NULL ," +
"PRIMARY KEY (`id`)," +
"KEY `FK_138` (`builder_uuid`)," +
"CONSTRAINT `FK_136` FOREIGN KEY `FK_138` (`builder_uuid`) REFERENCES `plotsystem_builders` (`uuid`)," +
"KEY `FK_141` (`buildteam_id`)," +
"CONSTRAINT `FK_139` FOREIGN KEY `FK_141` (`buildteam_id`) REFERENCES `plotsystem_buildteams` (`id`)" +
");"
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@
public abstract class AbstractPaginatedMenu extends AbstractMenu {

private final int maxItemsPerPage;
private final int totalItemsAmount;
private int totalItemsAmount;
private int currentPage = 0;

public AbstractPaginatedMenu(int rows, int pagedRows, String title, Player menuPlayer) {
super(rows, title, menuPlayer, false);

this.maxItemsPerPage = pagedRows * 9;
this.totalItemsAmount = getSource().size();

reloadMenuAsync();
}
Expand Down Expand Up @@ -91,14 +90,15 @@ protected void setPage(int index) {
* @return item sources for the current page
*/
private List<?> getItemSources() {
return getSource().subList(getMinIndex(), Math.min(getMaxIndex(), totalItemsAmount));
List<?> source = getSource();
return source.subList(getMinIndex(), Math.min(getMaxIndex(), source.size()));
}

/**
* @return true if there is a next page
*/
protected boolean hasNextPage() {
return getMaxIndex() < totalItemsAmount;
return getMaxIndex() < getSource().size();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
import org.ipvp.canvas.mask.BinaryMask;
import org.ipvp.canvas.mask.Mask;

import java.util.function.Consumer;

public class SettingsMenu extends AbstractMenu {
private Consumer<Player> onBack = (player) -> player.performCommand("companion");

public SettingsMenu(Player player) {
super(3, LangUtil.get(player, LangPaths.MenuTitle.SETTINGS), player);
}
public SettingsMenu(Player player, Consumer<Player> onBack) {
this(player);
this.onBack = onBack;
}

@Override
protected void setMenuItemsAsync() {
Expand Down Expand Up @@ -55,7 +63,7 @@ protected void setItemClickEventsAsync() {
}));

// Set click event for back item
getMenu().getSlot(22).setClickHandler((clickPlayer, clickInformation) -> clickPlayer.performCommand("companion"));
getMenu().getSlot(22).setClickHandler((clickPlayer, clickInformation) -> onBack.accept(clickPlayer));
}

@Override
Expand Down
Loading

0 comments on commit e27e146

Please sign in to comment.