Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/main/java/com/yourorg/servershop/ServerShopPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ public final class ServerShopPlugin extends JavaPlugin {
saveResource("messages.yml", false);
saveResource("shop.yml", false);
if (!setupEconomy()) {
getLogger().severe("Vault economy not found. Disabling.");
Bukkit.getPluginManager().disablePlugin(this);
return;
getLogger().warning("Vault economy not found. Buy/Sell disabled.");
}
this.categorySettings = new CategorySettings(this);
this.catalog = new Catalog(this); catalog.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public final class SellAllCommand implements CommandExecutor {

@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player p)) { sender.sendMessage(plugin.prefixed(plugin.getConfig().getString("messages.not-a-player"))); return true; }
if (plugin.economy() == null) { p.sendMessage(plugin.prefixed(plugin.getConfig().getString("messages.no-economy"))); return true; }
plugin.menus().openSell(p);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public final class SellCommand implements CommandExecutor {

@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player p)) { sender.sendMessage(plugin.prefixed(plugin.getConfig().getString("messages.not-a-player"))); return true; }
if (plugin.economy() == null) { p.sendMessage(plugin.prefixed(plugin.getConfig().getString("messages.no-economy"))); return true; }
if (args.length < 2) { p.sendMessage(plugin.prefixed("/sell <material> <qty>")); return true; }
Material mat = Util.parseMaterial(args[1]);
int qty; try { qty = Math.max(1, Integer.parseInt(args.length > 2 ? args[2] : "1")); } catch (Exception e) { qty = 1; }
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/yourorg/servershop/gui/ItemsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public final class ItemsMenu implements MenuView {
p.sendMessage(plugin.prefixed(m.name()+": $"+String.format("%.2f", buy)));
return;
}
if (plugin.economy() == null) {
p.sendMessage(plugin.prefixed(plugin.getConfig().getString("messages.no-economy")));
return;
}
int qty = e.isShiftClick() ? 16 : 1;
plugin.shop().buy(p, m, qty).ifPresent(err -> p.sendMessage(plugin.prefixed(err)));
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/yourorg/servershop/gui/MenuManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ public final class MenuManager implements Listener {
public void openCategories(Player p) { open(p, new CategoryMenu(plugin)); }
public void openItems(Player p, String category) { open(p, new ItemsMenu(plugin, category)); }
public void openWeekly(Player p) { if (p!=null) open(p, new WeeklyMenu(plugin)); }
public void openSell(Player p) { open(p, new SellMenu(plugin)); }
public void openSell(Player p) {
if (plugin.economy() == null) {
p.sendMessage(plugin.prefixed(plugin.getConfig().getString("messages.no-economy")));
return;
}
open(p, new SellMenu(plugin));
}
public void openSearch(Player p, String query, java.util.List<org.bukkit.Material> results) { open(p, new SearchMenu(plugin, query, results, 0)); }
public void openSearch(Player p, String query, java.util.List<org.bukkit.Material> results, int page) { open(p, new SearchMenu(plugin, query, results, page)); }

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/yourorg/servershop/gui/SearchMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public SearchMenu(ServerShopPlugin plugin, String query, List<Material> results,
var m = org.bukkit.Material.matchMaterial(org.bukkit.ChatColor.stripColor(it.getItemMeta().getDisplayName()));
if (m == null) return;
if (e.isRightClick()) { double buy = plugin.shop().priceBuy(m); p.sendMessage(plugin.prefixed(m.name()+": $"+String.format("%.2f", buy))); return; }
if (plugin.economy() == null) { p.sendMessage(plugin.prefixed(plugin.getConfig().getString("messages.no-economy"))); return; }
int qty = e.isShiftClick() ? 16 : 1;
plugin.shop().buy(p, m, qty).ifPresent(err -> p.sendMessage(plugin.prefixed(err)));
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/yourorg/servershop/gui/SellMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class SellMenu implements MenuView {
if (!(e.getWhoClicked() instanceof Player p)) return;
var it = e.getCurrentItem(); if (it == null) return;
var m = it.getType(); if (m == Material.AIR) return;
if (plugin.economy() == null) { p.sendMessage(plugin.prefixed(plugin.getConfig().getString("messages.no-economy"))); return; }
if (it.getItemMeta() != null && org.bukkit.ChatColor.stripColor(it.getItemMeta().getDisplayName()).equalsIgnoreCase("Sell All")) {
sellAll(p); return;
}
Expand Down Expand Up @@ -52,6 +53,7 @@ public void refresh(Player p) {
}

private void sellAll(Player p) {
if (plugin.economy() == null) { p.sendMessage(plugin.prefixed(plugin.getConfig().getString("messages.no-economy"))); return; }
double total = 0.0; int stacks = 0;
for (int i = 0; i < p.getInventory().getSize(); i++) {
ItemStack s = p.getInventory().getItem(i);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/yourorg/servershop/gui/WeeklyMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public final class WeeklyMenu implements MenuView {
var it = e.getCurrentItem(); if (it == null) return;
var m = org.bukkit.Material.matchMaterial(org.bukkit.ChatColor.stripColor(it.getItemMeta().getDisplayName()));
if (m == null) return;
if (plugin.economy() == null) { p.sendMessage(plugin.prefixed(plugin.getConfig().getString("messages.no-economy"))); return; }
int qty = e.isShiftClick() ? 16 : 1;
plugin.shop().buy(p, m, qty).ifPresent(err -> p.sendMessage(plugin.prefixed(err)));
}
Expand Down
Loading