qShop is a customizable shop plugin for Minecraft servers with a flexible API for various in-game shops.
Add this to your pom.xml
:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.m7wq</groupId>
<artifactId>qShop</artifactId>
<version>beta-1.6</version>
</dependency>
Add this to your build.gradle
:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.m7wq:qShop:beta-1.6'
}
Initialize and load the API in your plugin's main class:
public class Plugin extends JavaPlugin{
@Override
public void onEnable(){
// Initialize the instance
QShopAPI.load();
}
}
Create a custom shop by implementing ShopAdapter
:
public class MyCustomShop extends ShopAdapter{
@Size(size = 9)
@Title(title = "Swords Shop")
@Lore(lore = {"Im Sword!","&cBUY ME, To slash Your Enemies","Cost: %cost%"})
@Override
public Shop getShop() {
return super.getShop(); // or new Shop()
}
@Override
public @NotNull Contents getContents(){
return Contents.of(
new Item[]{
new Item(new ItemStack(Material.COOKIE), 5, 1)
}
);
}
}
Create a custom payment methods to handle purchasing with data or config balance
public class MyPayment implements PaymentAdapter {
@Override
public void removeBalance(Player player, int amount) {
// Implement balance removal
}
@Override
public int getBalance(Player player) {
return 1000; // Example balance
}
}
Create and open a shop GUI with:
public class ShopGuiCommandExecutor implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Players only!");
return false;
}
ShopAdapter shopAdapter = new MyCustomShop();
Inventory shopInventory = qShopAPI.getInstance().handleShopGui(shopAdapter);
player.openInventory(shopInventory);
return true;
}
}
Process purchases with handlePurchase
:
public class ShopEventListener implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
qShopAPI.getInstance().handlePurchase(
new Messager().of("&aPurchase successful!", "&cInsufficient balance!")
Arrays.asList("&bPurchased for %cost% coins!"),
event,
Material.DIAMOND
);
}
}
public class ShopEventListener implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
qShopAPI.getInstance().handlePurchase(
new Messager().of("&aYou purchased this item!", "&cNo enough balance!")
new MyPayment(),
Arrays.asList("&bPurchased for %cost% coins!"),
event
);
}
}
Contribute by submitting pull requests or opening issues on GitHub. Feel free to adjust as needed for your specific implementation!