Files
src
build.gradle
settings.gradle
Code
7 527
src/main/java/com/killa/cartofiasmpshop/CartofiaSmpShop.java
package com.killa.cartofiasmpshop;
import com.killa.cartofiasmpshop.gui.ShopGUIManager;
import com.killa.cartofiasmpshop.listener.ShopListener;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class CartofiaSmpShop extends JavaPlugin implements CommandExecutor {
private ShopGUIManager guiManager;
@Override
public void onEnable() {
Economy economy = getEconomy();
if (economy == null) {
getLogger().warning("Nu a fost găsit încă un provider de economie Vault. Magazinul va fi deschis, dar cumpărăturile vor fi blocate până când economia este disponibilă.");
}
this.guiManager = new ShopGUIManager(economy);
getServer().getPluginManager().registerEvents(new ShopListener(guiManager), this);
getServer().getScheduler().runTask(this, () -> guiManager.setEconomy(getEconomy()));
if (getCommand("shop") != null) {
getCommand("shop").setExecutor(this);
}
if (getCommand("sell") != null) {
getCommand("sell").setExecutor(this);
}
}
private Economy getEconomy() {
RegisteredServiceProvider<Economy> registration = getServer().getServicesManager()
.getRegistration(Economy.class);
return registration == null ? null : registration.getProvider();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("Doar jucătorii pot folosi această comandă.");
return true;
}
String commandName = command.getName().toLowerCase();
String permission = commandName.equals("sell")
? "cartofiasmpshop.sell"
: "cartofiasmpshop.use";
if (!player.hasPermission(permission)) {
player.sendMessage("§cNu ai permisiunea să folosești această comandă.");
return true;
}
if (commandName.equals("sell")) {
guiManager.openSellMenu(player);
} else {
guiManager.openMainMenu(player);
}
return true;
}
}