use of com.alpsbte.plotsystem.core.system.Builder in project Plot-System by AlpsBTE.
the class EventListener method onPlayerJoinEvent.
@EventHandler
public void onPlayerJoinEvent(PlayerJoinEvent event) {
// Teleport Player to the spawn
event.getPlayer().teleport(Utils.getSpawnLocation());
// User has joined for the first time
// Adding user to the database
Bukkit.getScheduler().runTaskAsynchronously(PlotSystem.getPlugin(), () -> {
// Add Items
if (!event.getPlayer().getInventory().contains(CompanionMenu.getMenuItem(event.getPlayer()))) {
event.getPlayer().getInventory().setItem(8, CompanionMenu.getMenuItem(event.getPlayer()));
}
if (event.getPlayer().hasPermission("plotsystem.review") && !event.getPlayer().getInventory().contains(ReviewMenu.getMenuItem(event.getPlayer()))) {
event.getPlayer().getInventory().setItem(7, ReviewMenu.getMenuItem(event.getPlayer()));
}
// Check if player even exists in database.
try (ResultSet rs = DatabaseConnection.createStatement("SELECT * FROM plotsystem_builders WHERE uuid = ?").setValue(event.getPlayer().getUniqueId().toString()).executeQuery()) {
if (!rs.first()) {
DatabaseConnection.createStatement("INSERT INTO plotsystem_builders (uuid, name) VALUES (?, ?)").setValue(event.getPlayer().getUniqueId().toString()).setValue(event.getPlayer().getName()).executeUpdate();
}
DatabaseConnection.closeResultSet(rs);
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
// Inform player about update
if (event.getPlayer().hasPermission("plotsystem.admin") && PlotSystem.UpdateChecker.updateAvailable() && PlotSystem.getPlugin().getConfigManager().getConfig().getBoolean(ConfigPaths.CHECK_FOR_UPDATES)) {
event.getPlayer().sendMessage(Utils.getInfoMessageFormat("There is a new update for the Plot-System available. Check your console for more information!"));
event.getPlayer().playSound(event.getPlayer().getLocation(), Utils.CreatePlotSound, 1f, 1f);
}
// Check if player has changed his name
try {
Builder builder = new Builder(event.getPlayer().getUniqueId());
if (!builder.getName().equals(event.getPlayer().getName())) {
DatabaseConnection.createStatement("UPDATE plotsystem_builders SET name = ? WHERE uuid = ?").setValue(event.getPlayer().getName()).setValue(event.getPlayer().getUniqueId().toString()).executeUpdate();
}
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
// Informing player about new feedback
try {
List<Plot> plots = PlotManager.getPlots(new Builder(event.getPlayer().getUniqueId()), Status.completed, Status.unfinished);
List<Plot> reviewedPlots = new ArrayList<>();
for (Plot plot : plots) {
if (plot.isReviewed() && !plot.getReview().isFeedbackSent() && plot.getPlotOwner().getPlayer().equals(event.getPlayer())) {
reviewedPlots.add(plot);
plot.getReview().setFeedbackSent(true);
}
}
if (reviewedPlots.size() >= 1) {
PlotHandler.sendFeedbackMessage(reviewedPlots, event.getPlayer());
event.getPlayer().sendTitle("", "§6§l" + reviewedPlots.size() + " §a§lPlot" + (reviewedPlots.size() == 1 ? " " : "s ") + (reviewedPlots.size() == 1 ? "has" : "have") + " been reviewed!", 20, 150, 20);
}
} catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "An error occurred while trying to inform the player about his plot feedback!", ex);
}
// Informing player about unfinished plots
try {
List<Plot> plots = PlotManager.getPlots(new Builder(event.getPlayer().getUniqueId()), Status.unfinished);
if (plots.size() >= 1) {
PlotHandler.sendUnfinishedPlotReminderMessage(plots, event.getPlayer());
event.getPlayer().sendMessage("");
}
} catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "An error occurred while trying to inform the player about his unfinished plots!", ex);
}
// Informing reviewer about new reviews
if (event.getPlayer().hasPermission("plotsystem.review")) {
try {
List<Plot> unreviewedPlots = PlotManager.getPlots(Status.unreviewed);
if (unreviewedPlots.size() != 0) {
PlotHandler.sendUnreviewedPlotsReminderMessage(unreviewedPlots, event.getPlayer());
}
} catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "An error occurred while trying to inform the player about unreviewed plots!", ex);
}
}
});
}
use of com.alpsbte.plotsystem.core.system.Builder in project Plot-System by AlpsBTE.
the class CompanionMenu method setCityProjectItems.
/**
* Sets city project items asynchronously in the menu
* @throws SQLException When querying database
*/
private void setCityProjectItems() throws SQLException {
for (int i = 0; i < cityProjects.size(); i++) {
if (i <= 28) {
CityProject cp = cityProjects.get(i);
ItemStack cpItem = cp.getCountry().getHead();
try {
PlotDifficulty cpPlotDifficulty = selectedPlotDifficulty != null ? selectedPlotDifficulty : PlotManager.getPlotDifficultyForBuilder(cp.getID(), new Builder(getMenuPlayer().getUniqueId())).get();
int plotsOpen = PlotManager.getPlots(cp.getID(), Status.unclaimed).size();
int plotsInProgress = PlotManager.getPlots(cp.getID(), Status.unfinished, Status.unreviewed).size();
int plotsCompleted = PlotManager.getPlots(cp.getID(), Status.completed).size();
int plotsUnclaimed = PlotManager.getPlots(cp.getID(), cpPlotDifficulty, Status.unclaimed).size();
getMenu().getSlot(9 + cityProjects.indexOf(cp)).setItem(new ItemBuilder(cpItem).setName("§b§l" + cp.getName()).setLore(new LoreBuilder().addLines(cp.getDescription(), "", "§6" + plotsOpen + " §7" + LangUtil.get(getMenuPlayer(), LangPaths.CityProject.PROJECT_OPEN), "§8---------------------", "§6" + plotsInProgress + " §7" + LangUtil.get(getMenuPlayer(), LangPaths.CityProject.PROJECT_IN_PROGRESS), "§6" + plotsCompleted + " §7" + LangUtil.get(getMenuPlayer(), LangPaths.CityProject.PROJECT_COMPLETED), "", plotsUnclaimed != 0 ? Utils.getFormattedDifficulty(cpPlotDifficulty) : "§f§l" + LangUtil.get(getMenuPlayer(), LangPaths.CityProject.PROJECT_NO_PLOTS)).build()).build());
} catch (SQLException | ExecutionException | InterruptedException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
getMenu().getSlot(9 + cityProjects.indexOf(cp)).setItem(MenuItems.errorItem(getMenuPlayer()));
}
}
}
}
use of com.alpsbte.plotsystem.core.system.Builder in project Plot-System by AlpsBTE.
the class PlotActionsMenu method setItemClickEventsAsync.
@Override
protected void setItemClickEventsAsync() {
// Set click event for submit or undo submit plot item
getMenu().getSlot(10).setClickHandler((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
try {
clickPlayer.performCommand("plot " + (plot.getStatus().equals(Status.unreviewed) ? "undosubmit " : "submit ") + plot.getID());
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
});
// Set click event for teleport to plot item
getMenu().getSlot(hasFeedback ? 12 : 13).setClickHandler((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
plot.getWorld().teleportPlayer(clickPlayer);
});
// Set click event for abandon plot item
getMenu().getSlot(hasFeedback ? 14 : 16).setClickHandler((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
clickPlayer.performCommand("plot abandon " + plot.getID());
});
// Set click event for feedback menu button
if (hasFeedback) {
getMenu().getSlot(16).setClickHandler((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
clickPlayer.performCommand("plot feedback " + plot.getID());
});
}
// Set click event for plot members item
getMenu().getSlot(22).setClickHandler((clickPlayer, clickInformation) -> {
try {
if (!plot.isReviewed()) {
if (plot.getStatus() == Status.unfinished) {
FileConfiguration config = PlotSystem.getPlugin().getConfigManager().getConfig();
if ((getMenuPlayer() == plot.getPlotOwner().getPlayer() || getMenuPlayer().hasPermission("plotsystem.admin")) && config.getBoolean(ConfigPaths.ENABLE_GROUP_SUPPORT)) {
clickPlayer.closeInventory();
new PlotMemberMenu(plot, clickPlayer);
} else if (plot.getPlotMembers().stream().anyMatch(m -> m.getUUID().equals(getMenuPlayer().getUniqueId()))) {
// Leave Plot
plot.removePlotMember(new Builder(clickPlayer.getUniqueId()));
clickPlayer.sendMessage(Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.LEFT_PLOT, Integer.toString(plot.getID()))));
clickPlayer.closeInventory();
}
} else {
clickPlayer.closeInventory();
clickPlayer.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.CAN_ONLY_MANAGE_MEMBERS_UNFINISHED)));
}
}
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
});
}
use of com.alpsbte.plotsystem.core.system.Builder in project Plot-System by AlpsBTE.
the class PlotMemberMenu method setItemClickEventsAsync.
@Override
protected void setItemClickEventsAsync() {
// Set click event for member slots
for (int i = 12; i < 15; i++) {
int itemSlot = i;
getMenu().getSlot(i).setClickHandler((clickPlayer, clickInformation) -> {
if (!getMenu().getSlot(itemSlot).getItem(clickPlayer).equals(emptyMemberSlotItem)) {
Builder builder = builders.get(itemSlot - 12);
try {
plot.removePlotMember(builder);
clickPlayer.sendMessage(Utils.getInfoMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Info.REMOVED_PLOT_MEMBER, builder.getName(), Integer.toString(plot.getID()))));
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
reloadMenuAsync();
}
});
}
// Set click event for add plot member item
getMenu().getSlot(16).setClickHandler((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
new AnvilGUI.Builder().onComplete((player, text) -> {
try {
if (Builder.getBuilderByName(text) != null) {
Builder builder = Builder.getBuilderByName(text);
if (builder.isOnline()) {
// Check if player is owner of plot
if (builder.getPlayer() == plot.getPlotOwner().getPlayer()) {
player.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.PLAYER_IS_PLOT_OWNER)));
return AnvilGUI.Response.text(LangUtil.get(getMenuPlayer(), LangPaths.Note.Anvil.PLAYER_IS_OWNER));
}
// Check if player is already a member of the plot
for (Builder item : plot.getPlotMembers()) {
if (builder.getPlayer() == item.getPlayer()) {
player.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.PLAYER_IS_PLOT_MEMBER)));
return AnvilGUI.Response.text(LangUtil.get(getMenuPlayer(), LangPaths.Note.Anvil.PLAYER_ALREADY_ADDED));
}
}
new Invitation(builder.getPlayer(), plot);
return AnvilGUI.Response.close();
} else {
// Builder isn't online, thus can't be asked if he/she wants to be added
player.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.PLAYER_IS_NOT_ONLINE)));
return AnvilGUI.Response.text(LangUtil.get(getMenuPlayer(), LangPaths.Note.Anvil.PLAYER_NOT_ONLINE));
}
}
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
// Input was invalid or Player hasn't joined the server yet
player.sendMessage(Utils.getErrorMessageFormat(LangUtil.get(getMenuPlayer(), LangPaths.Message.Error.PLAYER_NOT_FOUND)));
return AnvilGUI.Response.text(LangUtil.get(getMenuPlayer(), LangPaths.Note.Anvil.INVALID_INPUT));
}).text(LangUtil.get(getMenuPlayer(), LangPaths.Note.Anvil.ENTER_PLAYER_NAME)).itemLeft(new ItemStack(Material.NAME_TAG)).itemRight(new ItemStack(Material.SKULL)).title(LangUtil.get(getMenuPlayer(), LangPaths.MenuTitle.ENTER_PLAYER_NAME)).plugin(PlotSystem.getPlugin()).open(clickPlayer);
});
// Set click event for back item
getMenu().getSlot(22).setClickHandler((clickPlayer, clickInformation) -> {
try {
new PlotActionsMenu(clickPlayer, plot);
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
});
}
use of com.alpsbte.plotsystem.core.system.Builder in project Plot-System by AlpsBTE.
the class PlotMemberMenu method setMenuItemsAsync.
@Override
protected void setMenuItemsAsync() {
// Set plot owner item
try {
getMenu().getSlot(10).setItem(new ItemBuilder(Utils.getPlayerHead(plot.getPlotOwner().getUUID())).setName("§6§l" + LangUtil.get(getMenuPlayer(), LangPaths.Plot.OWNER)).setLore(new LoreBuilder().addLine(plot.getPlotOwner().getName()).build()).build());
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
// Set plot member items
try {
builders = plot.getPlotMembers();
for (int i = 12; i < 15; i++) {
if (builders.size() >= (i - 11)) {
Builder builder = builders.get(i - 12);
getMenu().getSlot(i).setItem(new ItemBuilder(Utils.getPlayerHead(builder.getUUID())).setName("§b§l" + LangUtil.get(getMenuPlayer(), LangPaths.Plot.MEMBER)).setLore(new LoreBuilder().addLines(builder.getName(), "", Utils.getActionFormat(LangUtil.get(getMenuPlayer(), LangPaths.Note.Action.CLICK_TO_REMOVE_PLOT_MEMBER))).build()).build());
}
}
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
// Set add plot member item
ItemStack whitePlus = Utils.getItemHead(Utils.CustomHead.ADD_BUTTON);
getMenu().getSlot(16).setItem(new ItemBuilder(whitePlus).setName("§6§l" + LangUtil.get(getMenuPlayer(), LangPaths.MenuTitle.ADD_MEMBER_TO_PLOT)).setLore(new LoreBuilder().addLines(LangUtil.get(getMenuPlayer(), LangPaths.MenuDescription.ADD_MEMBER_TO_PLOT), "", Utils.getNoteFormat(LangUtil.get(getMenuPlayer(), LangPaths.Note.PLAYER_HAS_TO_BE_ONLINE))).build()).build());
// Set back item
getMenu().getSlot(22).setItem(MenuItems.backMenuItem(getMenuPlayer()));
}
Aggregations