use of com.alpsbte.plotsystem.core.system.plot.generator.DefaultPlotGenerator in project Plot-System by AlpsBTE.
the class CompanionMenu method setItemClickEventsAsync.
@Override
protected void setItemClickEventsAsync() {
// Set click event for navigator item
getMenu().getSlot(4).setClickHandler((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
clickPlayer.performCommand(PlotSystem.getPlugin().getConfigManager().getConfig().getString(ConfigPaths.NAVIGATOR_COMMAND));
});
// Set click event for plots difficulty item
getMenu().getSlot(7).setClickHandler(((clickPlayer, clickInformation) -> {
selectedPlotDifficulty = (selectedPlotDifficulty == null ? PlotDifficulty.values()[0] : selectedPlotDifficulty.ordinal() != PlotDifficulty.values().length - 1 ? PlotDifficulty.values()[selectedPlotDifficulty.ordinal() + 1] : null);
getMenu().getSlot(7).setItem(getSelectedDifficultyItem());
clickPlayer.playSound(clickPlayer.getLocation(), Utils.Done, 1, 1);
try {
setCityProjectItems();
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
}));
// Set click event for city project items
for (int i = 0; i < cityProjects.size(); i++) {
int itemSlot = i;
getMenu().getSlot(9 + i).setClickHandler((clickPlayer, clickInformation) -> {
if (!getMenu().getSlot(9 + itemSlot).getItem(clickPlayer).equals(MenuItems.errorItem(getMenuPlayer()))) {
try {
clickPlayer.closeInventory();
Builder builder = new Builder(clickPlayer.getUniqueId());
int cityID = cityProjects.get(itemSlot).getID();
PlotDifficulty plotDifficultyForCity = selectedPlotDifficulty != null ? selectedPlotDifficulty : PlotManager.getPlotDifficultyForBuilder(cityID, builder).get();
if (PlotManager.getPlots(cityID, plotDifficultyForCity, Status.unclaimed).size() != 0) {
if (selectedPlotDifficulty != null && PlotSystem.getPlugin().getConfigManager().getConfig().getBoolean(ConfigPaths.ENABLE_SCORE_REQUIREMENT) && !PlotManager.hasPlotDifficultyScoreRequirement(builder, selectedPlotDifficulty)) {
clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(clickPlayer, LangPaths.Message.Error.PLAYER_NEEDS_HIGHER_SCORE)));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
return;
}
new DefaultPlotGenerator(cityID, plotDifficultyForCity, builder);
} else {
clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(clickPlayer, LangPaths.Message.Error.NO_PLOTS_LEFT)));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
}
} catch (SQLException | ExecutionException | InterruptedException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(clickPlayer, LangPaths.Message.Error.ERROR_OCCURRED)));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
}
} else {
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
}
});
}
// Set click event for player slot items
Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> {
for (int i = 0; i < 3; i++) {
if (slots[i] != null) {
int itemSlot = i;
getMenu().getSlot(46 + i).setClickHandler((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
try {
new PlotActionsMenu(clickPlayer, slots[itemSlot]);
} catch (SQLException ex) {
clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(clickPlayer, LangPaths.Message.Error.ERROR_OCCURRED)));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
Bukkit.getLogger().log(Level.SEVERE, "An error occurred while opening the plot actions menu!", ex);
}
});
}
}
});
// Set click event for builder utilities menu item
getMenu().getSlot(50).setClickHandler(((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
new BuilderUtilitiesMenu(clickPlayer);
}));
// Set click event for player plots menu item
getMenu().getSlot(51).setClickHandler(((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
clickPlayer.performCommand("plots " + clickPlayer.getName());
}));
// Set click event for player settings menu item
getMenu().getSlot(52).setClickHandler(((clickPlayer, clickInformation) -> new SettingsMenu(clickPlayer)));
}
use of com.alpsbte.plotsystem.core.system.plot.generator.DefaultPlotGenerator in project Plot-System by AlpsBTE.
the class CMD_Plot_Teleport method onCommand.
@Override
public void onCommand(CommandSender sender, String[] args) {
try {
if (getPlayer(sender) != null) {
if (args.length > 0 && Utils.TryParseInt(args[0]) != null) {
int plotID = Integer.parseInt(args[0]);
Plot plot;
if (PlotManager.plotExists(plotID) && (plot = new Plot(plotID)).getStatus() != Status.unclaimed) {
plot.getWorld().teleportPlayer(getPlayer(sender));
} else {
if (sender.hasPermission("plotsystem.admin") && PlotManager.plotExists(plotID)) {
new DefaultPlotGenerator(new Plot(plotID), new Builder(getPlayer(sender).getUniqueId()));
} else {
sender.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(sender, LangPaths.Message.Error.PLOT_DOES_NOT_EXIST)));
}
}
} else {
sendInfo(sender);
}
} else {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "This command can only be used as a player!");
}
} catch (SQLException ex) {
sender.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(sender, LangPaths.Message.Error.ERROR_OCCURRED)));
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
}
Aggregations