Compare commits
62 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2f3260854 | |||
| 48648c5632 | |||
| 10f2a66e3a | |||
| e196507634 | |||
| b208dc8592 | |||
| f2f2fb3353 | |||
| 5429c91498 | |||
| 40febaf7e2 | |||
| 9039dcc9ad | |||
| 8f1a1de252 | |||
| d107835455 | |||
| a09dad30ec | |||
| 18a1991af9 | |||
| 6e03ffa962 | |||
| 66a95c48fa | |||
| 51559f12ed | |||
| 605d7f44d5 | |||
| 75668031e0 | |||
| 3248ad9e8d | |||
| c59e37ef68 | |||
| db4255a0ad | |||
| 5e2ae5ba0a | |||
| afeb22422e | |||
| 9b84b18952 | |||
| 3e32e3af32 | |||
| da6fe6cb33 | |||
| 37538a9632 | |||
| e0b63ee2e4 | |||
| d4b5aa350f | |||
| b34d74a62e | |||
| 1f36b22916 | |||
| e19378d815 | |||
| 4720f3b4b6 | |||
| 4832b259a5 | |||
| 0ea27c815c | |||
| 8510e601d9 | |||
| 603ece2f7b | |||
| 2e9c2b2579 | |||
| bd47187b95 | |||
| 4d94218e22 | |||
| 2c8260191f | |||
| 85b6aa8d88 | |||
| 6f5b7d7fcf | |||
| 49a2057705 | |||
| 25b3716fdc | |||
| 1d84f5ffe7 | |||
| 9313fb2e7a | |||
| 2426d4654f | |||
| 5284253ce8 | |||
| d3a17ff5f1 | |||
| fbdd42a856 | |||
| 12786cb553 | |||
| 0e99638960 | |||
| 4f476e478e | |||
| e7a90e5a82 | |||
| b5b8142584 | |||
| e32d6e42c3 | |||
| 239ab594a2 | |||
| 26fbaae057 | |||
| 633c73cbb9 | |||
| 361d25ee5c | |||
| 043cd1feb2 |
64
IngameShopSpigot/pom.xml
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||||
|
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>de.mviper</groupId>
|
||||||
|
<artifactId>IngameShopSpigot</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>IngameShopSpigot</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Spigot API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.20.1-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Vault fEconomy -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.milkbowl.vault</groupId>
|
||||||
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<!-- Compiler Plugin -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.11.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>17</source>
|
||||||
|
<target>17</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- Shade Plugin optional fAbh-->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals><goal>shade</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<relocations>
|
||||||
|
<!-- optional -->
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,495 @@
|
|||||||
|
package de.mviper.spigot;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
public class IngameShopSpigot extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
|
private static Economy econ = null;
|
||||||
|
private String wpBase;
|
||||||
|
private String wpUrlPending;
|
||||||
|
private String wpUrlExecute;
|
||||||
|
private String wpUrlComplete;
|
||||||
|
private String wpUrlCancel; // NEU
|
||||||
|
|
||||||
|
private Gson gson = new Gson();
|
||||||
|
private boolean debug = false;
|
||||||
|
private BukkitTask task;
|
||||||
|
|
||||||
|
private String currency = "Coins";
|
||||||
|
private String targetServer = "survival";
|
||||||
|
|
||||||
|
private Map<Integer, OrderData> orderCache = new HashMap<>();
|
||||||
|
private Map<UUID, Integer> activeOrderIds = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
if (!setupEconomy()) {
|
||||||
|
getLogger().severe("Kein Economy-Plugin (Vault) gefunden! Shop deaktiviert.");
|
||||||
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
saveDefaultConfig();
|
||||||
|
reloadConfig();
|
||||||
|
|
||||||
|
String domain = getConfig().getString("wordpress-url", "http://localhost/Windelgeschichten.org");
|
||||||
|
if (domain.endsWith("/")) {
|
||||||
|
domain = domain.substring(0, domain.length() - 1);
|
||||||
|
}
|
||||||
|
wpBase = domain + "/wp-json/wis/v1";
|
||||||
|
|
||||||
|
wpUrlPending = wpBase + "/pending_orders";
|
||||||
|
wpUrlExecute = wpBase + "/execute_order";
|
||||||
|
wpUrlComplete = wpBase + "/complete_order";
|
||||||
|
wpUrlCancel = wpBase + "/cancel_order"; // NEU
|
||||||
|
|
||||||
|
this.targetServer = getConfig().getString("server-name", "survival").toLowerCase();
|
||||||
|
this.currency = getConfig().getString("currency-name", "Coins");
|
||||||
|
|
||||||
|
int intervalSeconds = getConfig().getInt("check-interval", 10);
|
||||||
|
long pollInterval = intervalSeconds * 20L;
|
||||||
|
debug = getConfig().getBoolean("debug-mode", false);
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
startPolling(pollInterval);
|
||||||
|
|
||||||
|
getLogger().info("=== IngameShopSpigot v6.2 (Cancel Logic) CONFIG ===");
|
||||||
|
getLogger().info("Domain: " + domain);
|
||||||
|
getLogger().info("Target Server: " + this.targetServer);
|
||||||
|
getLogger().info("Currency: " + this.currency);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setupEconomy() {
|
||||||
|
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
|
if (rsp == null) return false;
|
||||||
|
econ = rsp.getProvider();
|
||||||
|
return econ != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startPolling(long intervalTicks) {
|
||||||
|
this.task = new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
try {
|
||||||
|
String urlString = wpUrlPending + "?player=" + p.getName();
|
||||||
|
URL url = new URL(urlString);
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("GET");
|
||||||
|
conn.setRequestProperty("Content-Type", "application/json");
|
||||||
|
conn.setConnectTimeout(5000);
|
||||||
|
conn.setReadTimeout(5000);
|
||||||
|
|
||||||
|
if (conn.getResponseCode() == 200) {
|
||||||
|
BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)
|
||||||
|
);
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
response.append(line);
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
|
||||||
|
JsonObject json = JsonParser.parseString(response.toString()).getAsJsonObject();
|
||||||
|
JsonArray orders = json.getAsJsonArray("orders");
|
||||||
|
|
||||||
|
if (orders != null && orders.size() > 0) {
|
||||||
|
for (int i = 0; i < orders.size(); i++) {
|
||||||
|
JsonObject order = orders.get(i).getAsJsonObject();
|
||||||
|
|
||||||
|
int id = order.get("id").getAsInt();
|
||||||
|
String orderServer = order.has("server") ? order.get("server").getAsString().toLowerCase() : "";
|
||||||
|
|
||||||
|
if (!orderServer.equals(targetServer)) {
|
||||||
|
if (debug) getLogger().info("Order #" + id + " ist für Server '" + orderServer + "'. Ignoriere.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String jsonResponse = order.has("response") ? order.get("response").getAsString() : "[]";
|
||||||
|
String itemTitle = order.get("item_title").getAsString();
|
||||||
|
double price = order.get("price").getAsDouble();
|
||||||
|
String status = order.get("status").getAsString();
|
||||||
|
|
||||||
|
if ("pending".equals(status)) {
|
||||||
|
OrderData data = new OrderData(id, "multi_item", itemTitle, price, 1, jsonResponse);
|
||||||
|
orderCache.put(id, data);
|
||||||
|
activeOrderIds.put(p.getUniqueId(), id);
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTask(IngameShopSpigot.this, () -> {
|
||||||
|
openConfirmGUI(p, id, itemTitle, price);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (debug) Bukkit.getLogger().log(Level.WARNING, "Polling Fehler", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(IngameShopSpigot.this);
|
||||||
|
}
|
||||||
|
}.runTaskTimer(this, 20L, intervalTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openConfirmGUI(Player player, int orderId, String itemTitle, double price) {
|
||||||
|
Inventory gui = Bukkit.createInventory(null, 27, "§eKauf bestätigen?");
|
||||||
|
|
||||||
|
ItemStack info = new ItemStack(Material.WRITTEN_BOOK);
|
||||||
|
ItemMeta infoMeta = info.getItemMeta();
|
||||||
|
infoMeta.setDisplayName(ChatColor.GOLD + itemTitle);
|
||||||
|
infoMeta.setLore(java.util.Arrays.asList(
|
||||||
|
ChatColor.WHITE + "Preis: " + price + " " + currency
|
||||||
|
));
|
||||||
|
info.setItemMeta(infoMeta);
|
||||||
|
|
||||||
|
ItemStack yes = new ItemStack(Material.LIME_WOOL);
|
||||||
|
ItemMeta yesMeta = yes.getItemMeta();
|
||||||
|
yesMeta.setDisplayName(ChatColor.GREEN + "§lJA, kaufen!");
|
||||||
|
yes.setItemMeta(yesMeta);
|
||||||
|
|
||||||
|
ItemStack no = new ItemStack(Material.RED_WOOL);
|
||||||
|
ItemMeta noMeta = no.getItemMeta();
|
||||||
|
noMeta.setDisplayName(ChatColor.RED + "§lNEIN, abbrechen");
|
||||||
|
no.setItemMeta(noMeta);
|
||||||
|
|
||||||
|
ItemStack pane = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
|
||||||
|
ItemMeta paneMeta = pane.getItemMeta();
|
||||||
|
paneMeta.setDisplayName(" ");
|
||||||
|
pane.setItemMeta(paneMeta);
|
||||||
|
|
||||||
|
for (int i = 0; i < 27; i++) gui.setItem(i, pane);
|
||||||
|
gui.setItem(13, info);
|
||||||
|
gui.setItem(11, yes);
|
||||||
|
gui.setItem(15, no);
|
||||||
|
|
||||||
|
player.openInventory(gui);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
|
if (!event.getView().getTitle().contains("Kauf bestätigen?")) return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||||
|
|
||||||
|
Player p = (Player) event.getWhoClicked();
|
||||||
|
int slot = event.getRawSlot();
|
||||||
|
|
||||||
|
if (slot == 11) { // JA
|
||||||
|
Integer orderId = activeOrderIds.get(p.getUniqueId());
|
||||||
|
if (orderId != null) {
|
||||||
|
processOrder(p, orderId);
|
||||||
|
p.closeInventory();
|
||||||
|
activeOrderIds.remove(p.getUniqueId());
|
||||||
|
} else {
|
||||||
|
p.sendMessage(ChatColor.RED + "❌ Fehler: Kauf abgelaufen.");
|
||||||
|
p.closeInventory();
|
||||||
|
}
|
||||||
|
} else if (slot == 15) { // NEIN
|
||||||
|
Integer orderId = activeOrderIds.get(p.getUniqueId());
|
||||||
|
if (orderId != null) {
|
||||||
|
cancelOrder(p, orderId); // NEU
|
||||||
|
p.closeInventory();
|
||||||
|
activeOrderIds.remove(p.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processOrder(Player player, int orderId) {
|
||||||
|
OrderData data = orderCache.get(orderId);
|
||||||
|
if (data == null) {
|
||||||
|
player.sendMessage(ChatColor.RED + "❌ Fehler: Daten nicht gefunden.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
String jsonInputString = "{\"id\":\"" + orderId + "\"}";
|
||||||
|
URL url = new URL(wpUrlExecute);
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("POST");
|
||||||
|
conn.setRequestProperty("Content-Type", "application/json");
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
|
||||||
|
try(OutputStream os = conn.getOutputStream()) {
|
||||||
|
byte[] input = jsonInputString.getBytes("utf-8");
|
||||||
|
os.write(input, 0, input.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
int responseCode = conn.getResponseCode();
|
||||||
|
if (responseCode == 200) {
|
||||||
|
Bukkit.getScheduler().runTask(IngameShopSpigot.this, () -> executeShopLogic(player, data, orderId));
|
||||||
|
} else {
|
||||||
|
if (debug) getLogger().warning("Execute Order API Code: " + responseCode);
|
||||||
|
Bukkit.getScheduler().runTask(IngameShopSpigot.this, () -> {
|
||||||
|
player.sendMessage(ChatColor.RED + "❌ Server-Fehler beim Starten des Kaufs.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
getLogger().log(Level.SEVERE, "Fehler bei /execute_order", e);
|
||||||
|
Bukkit.getScheduler().runTask(IngameShopSpigot.this, () -> {
|
||||||
|
player.sendMessage(ChatColor.RED + "❌ Interner Fehler beim Kauf.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================================================
|
||||||
|
// NEU: ABBRECHEN LOGIC
|
||||||
|
// ===========================================================
|
||||||
|
private void cancelOrder(Player player, int orderId) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
String jsonInputString = "{\"id\":\"" + orderId + "\"}";
|
||||||
|
URL url = new URL(wpUrlCancel);
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("POST");
|
||||||
|
conn.setRequestProperty("Content-Type", "application/json");
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
|
||||||
|
try(OutputStream os = conn.getOutputStream()) {
|
||||||
|
byte[] input = jsonInputString.getBytes("utf-8");
|
||||||
|
os.write(input, 0, input.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
int responseCode = conn.getResponseCode();
|
||||||
|
|
||||||
|
if (responseCode == 200) {
|
||||||
|
orderCache.remove(orderId);
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "❌ Kauf abgebrochen.");
|
||||||
|
if (debug) getLogger().info("✅ Order #" + orderId + " successfully cancelled");
|
||||||
|
} else {
|
||||||
|
if (debug) getLogger().warning("⚠️ Cancel Order API returned code: " + responseCode);
|
||||||
|
player.sendMessage(ChatColor.RED + "❌ Fehler beim Abbrechen des Kaufs.");
|
||||||
|
// Fallback: Cache leeren damit es nicht als Loop erscheint
|
||||||
|
orderCache.remove(orderId);
|
||||||
|
activeOrderIds.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
getLogger().log(Level.WARNING, "Fehler bei /cancel_order", e);
|
||||||
|
// Fallback: Cache leeren
|
||||||
|
orderCache.remove(orderId);
|
||||||
|
activeOrderIds.remove(player.getUniqueId());
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "❌ Kauf abgebrochen (lokale Bestätigung).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeShopLogic(Player player, OrderData data, int orderId) {
|
||||||
|
try {
|
||||||
|
if (econ.getBalance(player) < data.price) {
|
||||||
|
player.sendMessage(ChatColor.RED + "❌ Du hast nicht genug Geld! (Benötigt: " + data.price + " " + currency + ")");
|
||||||
|
// Wenn der Kauf fehlschagt (Geld), sollte die Bestellung abgebrochen werden
|
||||||
|
cancelOrder(player, orderId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
econ.withdrawPlayer(player, data.price);
|
||||||
|
player.sendMessage(ChatColor.GREEN + "💰 " + data.price + " " + currency + " abgezogen.");
|
||||||
|
|
||||||
|
try {
|
||||||
|
JsonElement root = gson.fromJson(data.jsonPayload, JsonElement.class);
|
||||||
|
JsonArray items;
|
||||||
|
|
||||||
|
if (root.isJsonObject()) {
|
||||||
|
items = root.getAsJsonObject().getAsJsonArray("items");
|
||||||
|
} else {
|
||||||
|
items = root.getAsJsonArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalItemsGiven = 0;
|
||||||
|
|
||||||
|
for (JsonElement e : items) {
|
||||||
|
JsonObject itemObj = e.getAsJsonObject();
|
||||||
|
String itemId = itemObj.get("id").getAsString();
|
||||||
|
int amount = itemObj.get("amount").getAsInt();
|
||||||
|
|
||||||
|
ItemStack item = parseItem(itemId);
|
||||||
|
if (item != null) {
|
||||||
|
int remaining = amount;
|
||||||
|
while (remaining > 0) {
|
||||||
|
int stackSize = Math.min(remaining, item.getMaxStackSize());
|
||||||
|
ItemStack stack = item.clone();
|
||||||
|
stack.setAmount(stackSize);
|
||||||
|
|
||||||
|
if (player.getInventory().firstEmpty() == -1) {
|
||||||
|
player.getWorld().dropItemNaturally(player.getLocation(), stack);
|
||||||
|
} else {
|
||||||
|
player.getInventory().addItem(stack);
|
||||||
|
}
|
||||||
|
remaining -= stackSize;
|
||||||
|
}
|
||||||
|
totalItemsGiven++;
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.RED + "❌ Item '" + itemId + "' konnte nicht gefunden werden.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalItemsGiven > 0) {
|
||||||
|
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
|
||||||
|
player.sendMessage(ChatColor.GREEN + "✅ Kauf erfolgreich abgeschlossen!");
|
||||||
|
}
|
||||||
|
|
||||||
|
markOrderCompleted(orderId);
|
||||||
|
orderCache.remove(orderId);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
getLogger().log(Level.SEVERE, "Fehler beim Verarbeiten der JSON-Items", e);
|
||||||
|
player.sendMessage(ChatColor.RED + "❌ Fehler beim Verteilen der Items. Bitte Admin kontaktieren.");
|
||||||
|
markOrderCompleted(orderId);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
getLogger().log(Level.SEVERE, "Fehler bei Shop-Logik", e);
|
||||||
|
player.sendMessage(ChatColor.RED + "❌ Interner Fehler.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void markOrderCompleted(int orderId) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
String jsonInputString = "{\"id\":\"" + orderId + "\"}";
|
||||||
|
|
||||||
|
if (debug) getLogger().info("🔄 Marking order #" + orderId + " as completed...");
|
||||||
|
|
||||||
|
URL url = new URL(wpUrlComplete);
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("POST");
|
||||||
|
conn.setRequestProperty("Content-Type", "application/json");
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
|
||||||
|
try(OutputStream os = conn.getOutputStream()) {
|
||||||
|
byte[] input = jsonInputString.getBytes("utf-8");
|
||||||
|
os.write(input, 0, input.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
int responseCode = conn.getResponseCode();
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
if (responseCode == 200) {
|
||||||
|
getLogger().info("✅ Order #" + orderId + " successfully marked as completed");
|
||||||
|
} else {
|
||||||
|
getLogger().warning("⚠️ Complete Order API returned code: " + responseCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
getLogger().log(Level.WARNING, "Complete Order Error for #" + orderId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack parseItem(String itemId) {
|
||||||
|
try {
|
||||||
|
String cleanId = itemId.toUpperCase().trim().replace("MINECRAFT:", "").replace("MC:", "");
|
||||||
|
String materialName = numericIdToMaterial(cleanId);
|
||||||
|
if (materialName == null) materialName = cleanId;
|
||||||
|
|
||||||
|
if (materialName.equalsIgnoreCase("VIP") || materialName.startsWith("VIP")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material material = Material.matchMaterial(materialName);
|
||||||
|
if (material != null && material.isItem()) {
|
||||||
|
return new ItemStack(material,1);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
getLogger().log(Level.WARNING, "parseItem Fehler: " + itemId, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String numericIdToMaterial(String id) {
|
||||||
|
if (!id.matches("\\d+")) return null;
|
||||||
|
switch (id) {
|
||||||
|
case "352": return "BONE_MEAL";
|
||||||
|
case "264": return "EMERALD";
|
||||||
|
case "388": return "EMERALD_BLOCK";
|
||||||
|
case "357": return "GOLDEN_APPLE";
|
||||||
|
case "322": return "GOLDEN_CARROT";
|
||||||
|
case "348": return "GOLD_INGOT";
|
||||||
|
case "133": return "EMERALD_ORE";
|
||||||
|
case "41": return "GOLD_ORE";
|
||||||
|
case "14": return "GOLD_BLOCK";
|
||||||
|
case "289": return "COOKIE";
|
||||||
|
case "1": return "STONE";
|
||||||
|
case "5": return "PLANKS";
|
||||||
|
case "17": return "OAK_LOG";
|
||||||
|
case "260": return "BONE_BLOCK";
|
||||||
|
case "287": return "TOTEM_OF_UNDYING";
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class OrderData {
|
||||||
|
int id;
|
||||||
|
String itemId;
|
||||||
|
String itemTitle;
|
||||||
|
double price;
|
||||||
|
int quantity;
|
||||||
|
String jsonPayload;
|
||||||
|
|
||||||
|
OrderData(int id, String itemId, String itemTitle, double price, int quantity, String jsonPayload) {
|
||||||
|
this.id = id;
|
||||||
|
this.itemId = itemId;
|
||||||
|
this.itemTitle = itemTitle;
|
||||||
|
this.price = price;
|
||||||
|
this.quantity = quantity;
|
||||||
|
this.jsonPayload = jsonPayload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
if (task != null) {
|
||||||
|
task.cancel();
|
||||||
|
}
|
||||||
|
getLogger().info("IngameShopSpigot gestoppt");
|
||||||
|
}
|
||||||
|
}
|
||||||
15
IngameShopSpigot/src/main/resources/config.yml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Hier nur die Domain eingeben (ohne /wp-json am Ende)
|
||||||
|
wordpress-url: "<Wordpress URL>"
|
||||||
|
|
||||||
|
# WICHTIG: Der Name des Servers, wie er in WordPress hinterlegt ist (Slug).
|
||||||
|
# Damit wird verhindert, dass ein Spieler auf Lobby etwas für Survival kauft und es dort erhält.
|
||||||
|
server-name: "Lobby"
|
||||||
|
|
||||||
|
# Name der Währung (ersetze Coins durch deinen Namen, z.B. Dollar, Points, etc.)
|
||||||
|
currency-name: "Euro"
|
||||||
|
|
||||||
|
# Alle wie viel Sekunden (ticks) nach neuen Bestellungen gesucht werden soll (Standard: 10 Sekunden)
|
||||||
|
check-interval: 5
|
||||||
|
|
||||||
|
# Debug Modus (true/false)
|
||||||
|
debug-mode: true
|
||||||
25
IngameShopSpigot/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: IngameShopSpigot
|
||||||
|
main: de.mviper.spigot.IngameShopSpigot
|
||||||
|
version: 1.0
|
||||||
|
api-version: "1.20"
|
||||||
|
author: M_Viper
|
||||||
|
description: Ingame-Shop Plugin (Spigot) empfPlugin-Messages vom Bungee und vergibt Items / zieht Geld via Vault.
|
||||||
|
|
||||||
|
# Vault ist optional, daher softdepend
|
||||||
|
softdepend:
|
||||||
|
- Vault
|
||||||
|
|
||||||
|
# Beispiel-Command (optional, kann in Java implementiert werden)
|
||||||
|
commands:
|
||||||
|
ingameshop:
|
||||||
|
description: oder testet den IngameShop (Admin/Debug)
|
||||||
|
usage: /ingameshop
|
||||||
|
|
||||||
|
# Beispiel-Permissions (anpassbar)
|
||||||
|
permissions:
|
||||||
|
ingameshop.admin:
|
||||||
|
description: Zugriff auf Admin-Funktionen des IngameShops
|
||||||
|
default: op
|
||||||
|
ingameshop.use:
|
||||||
|
description: Basisrecht, um Shop-Features zu nutzen
|
||||||
|
default: true
|
||||||
495
README.md
@@ -1,207 +1,382 @@
|
|||||||
# WP Ingame Shop Pro – NO RCON & CUSTOM CURRENCY
|
# WP Ingame Shop Pro
|
||||||
|
|
||||||
Vollautomatischer, Minecraft-basierter Ingame-Shop für WordPress mit Warenkorb, Daily Deal, Kategorien, Gutscheinen und eigenem Währungssystem – komplett ohne RCON, ideal für Bungee-/Proxy-Setups mit externer Ingame-Bestätigung.
|
Ein leistungsstarker, vollständig eigenständiger Ingame-Shop für WordPress, entwickelt für Minecraft-Server (Spigot/Paper).
|
||||||
|
Er bietet ein komfortables Warenkorb-System, Gutscheine, Daily Deals und eine benutzerdefinierte Währung – komplett ohne RCON.
|
||||||
|
|
||||||
## Features
|
Dieses Plugin nutzt eine eigene Datenbankstruktur für maximale Performance und vollständige Unabhängigkeit von WordPress-Beiträgen.
|
||||||
|
|
||||||
- 🛒 **Warenkorb-System**: Spieler können mehrere Items gleichzeitig kaufen, alles wird als eine Bestellung in der Datenbank gespeichert.
|
---
|
||||||
- 💾 **Saubere Order-Struktur**: Eine Bestellung = eine Zeile in `wp_wis_orders` mit JSON-Detaildaten (Items + Gutschein).
|
|
||||||
- 📋 **Detail-Ansicht im Backend**: Übersicht wie „1x Diamant, 64x Stein“ inkl. Gutschein und Debug-JSON.
|
|
||||||
- 💰 **Eigene Währung**: Frei konfigurierbarer Währungsname (z. B. Coins, Tokens) statt Euro.
|
|
||||||
- 🖼️ **Auto-Itembilder**: Bilder werden automatisch aus einer Basis-URL + Item-ID (`minecraft:diamond` → `minecraft_diamond.png`) generiert.
|
|
||||||
- 🔥 **Angebote & Sales**: Items können als Angebot markiert und mit eigenem Angebots-Preis versehen werden.
|
|
||||||
- 🎁 **Daily Deal**: Automatisches „Angebot des Tages“ mit frei einstellbarem prozentualem Rabatt, gesteuert über Cron.
|
|
||||||
- 🎫 **Smart Coupons**: Gutscheine als Festbetrag oder Prozent, optional keine Wirkung auf Angebot-Items (Sale).
|
|
||||||
- 🏷️ **Kategorien**: Eigene Taxonomie `wis_category` mit Backend-Tabs/Filter im Shop-Frontend.
|
|
||||||
- 🏆 **Top Spender**: Statistikseite mit Summe aller abgeschlossenen/cancelled Orders pro Spieler.
|
|
||||||
- 🌐 **REST API**: Endpoints für Orders, Pending Orders, Ausführung, Abschluss, Storno, Gutscheinprüfung und Bulk-Import.
|
|
||||||
- 📥 **Bulk-Import**: JSON-Import von Items (z. B. von `minecraft-ids.com`) in Batches inkl. Fortschrittsanzeige.
|
|
||||||
- 🧹 **Bulk Delete**: Massenlöschung für Items, Server und Gutscheine mit Admin-Notice.
|
|
||||||
- 🎮 **Ingame-Integration ready**: Orders werden über REST abgeholt und serverseitig (z. B. Plugin/Bot) bestätigt, kein RCON notwendig.
|
|
||||||
|
|
||||||
## Installation
|
## ✨ Highlights
|
||||||
|
|
||||||
1. Plugin-Datei (`wp-ingame-shop-pro.php` o. ä.) in den Ordner `wp-content/plugins/wp-ingame-shop-pro` legen.
|
- 🛒 **Warenkorb-System**
|
||||||
2. Im WordPress-Backend unter „Plugins“ das Plugin **aktivieren**.
|
Mehrere Items pro Bestellung.
|
||||||
3. Bei Aktivierung werden automatisch die Tabellen `wp_wis_orders` und `wp_wis_coupons` erstellt sowie Cron-Events für den Daily Deal registriert.
|
Eine Bestellung = eine saubere Datenbankzeile mit JSON-Details.
|
||||||
4. Cron muss auf dem Server funktionieren (WP-Cron oder System-Cron, der `wp-cron.php` triggert).
|
|
||||||
|
|
||||||
## Admin-Bereich
|
- ⚡ **Mehrfachbearbeitung (Bulk Edit)**
|
||||||
|
Hunderte Items gleichzeitig bearbeiten (Preis, Server, Kategorie, Status).
|
||||||
|
|
||||||
Nach der Aktivierung erscheint im Backend das Menü **„Ingame Shop“** mit mehreren Unterseiten.
|
- 💰 **Eigene Währung**
|
||||||
|
„Coins“, „Tokens“ oder beliebige virtuelle Währungen.
|
||||||
|
|
||||||
### Menüs
|
- 🖼️ **Automatische Bildzuweisung**
|
||||||
|
`minecraft:diamond` → `minecraft_diamond.png`
|
||||||
|
Ideal für große Bildsammlungen (1500+ Dateien).
|
||||||
|
|
||||||
- **Ingame Shop (Übersicht)**
|
- 🔥 **Daily Deal & Sale-System**
|
||||||
- Globale Einstellungen, Feature-Übersicht, Bulk-Import.
|
|
||||||
- **Bestellungen**
|
|
||||||
- Liste aller Orders, Detailansicht, manuelles Löschen/Abschließen.
|
|
||||||
- **Top Spender**
|
|
||||||
- Rangliste nach ausgegebenen Coins (inkl. Anzahl Bestellungen).
|
|
||||||
- **Items** (CPT `wis_item`)
|
|
||||||
- Verwaltung der Shop-Items inkl. Preis, Serverzuordnung, Kategorie, Angebot, Daily Deal.
|
|
||||||
- **Kategorien** (`wis_category`)
|
|
||||||
- Hierarchische Kategorien für Items (werden im Frontend als Tabs angezeigt).
|
|
||||||
- **Servers** (CPT `wis_server`)
|
|
||||||
- Reine Serverdefinition (Name/Slug), dient zur Filterung und Zuordnung im Shop.
|
|
||||||
- **Gutscheine** (CPT `wis_coupon`)
|
|
||||||
- Verwaltung von Gutscheincodes inkl. Typ, Wert, Limit, Ablaufdatum.
|
|
||||||
|
|
||||||
### Globale Einstellungen
|
- 🎫 **Smart Coupons**
|
||||||
|
Prozent- oder Festbetrag, optional nicht kombinierbar mit Angeboten.
|
||||||
|
|
||||||
Zu finden unter **Ingame Shop → Ingame Shop (Übersicht)**.
|
- 🌐 **REST API ohne RCON**
|
||||||
|
|
||||||
- **Shop Header Text**
|
- 📊 **Top-Spender & Umsatzstatistik**
|
||||||
- Text im grünen Info-Balken im Frontend, leer = kein Balken.
|
|
||||||
- **Währungsname**
|
|
||||||
- Anzeigeeinheit für Preise, z. B. „Coins“.
|
|
||||||
- **Bilder Basis-URL**
|
|
||||||
- Basis-URL, an die `ITEM_ID.png` angehängt wird, z. B. `https://assets.minecraft-ids.com/1_21_10/`.
|
|
||||||
- **Gutscheine bei Angeboten ausschließen**
|
|
||||||
- Wenn aktiviert, wirken Gutscheine nur auf normale Items, nicht auf als Angebot markierte Items.
|
|
||||||
- **Daily Deal aktivieren + Rabatt (%)**
|
|
||||||
- Aktiviert den täglichen Cron, der ein zufälliges Item (mit Preis > 0, bisher kein Daily Deal) auswählt und rabattiert.
|
|
||||||
|
|
||||||
## Custom Post Types & Metaboxen
|
---
|
||||||
|
|
||||||
### Shop Items (`wis_item`)
|
## 🚀 Installation
|
||||||
|
|
||||||
Unter **Ingame Shop → Items**.
|
1. Ordner `wp-ingame-shop-pro` nach:
|
||||||
|
|
||||||
Metabox **„Item Einstellungen“**:
|
wp-content/plugins/
|
||||||
|
|
||||||
- **Status-Anzeige**
|
2. Plugin im WordPress Backend aktivieren.
|
||||||
- Zeigt an, ob das Item aktiv im Shop ist (publish + Preis > 0) oder inaktiv.
|
3. Fertig.
|
||||||
- **Preis (Coins)**
|
|
||||||
- Integer > 0 macht das Item automatisch aktiv (Status publish), 0 schaltet auf Entwurf.
|
|
||||||
- **Item ID (z. B. `minecraft:diamond`)**
|
|
||||||
- Wird für die Bild-URL und das JSON-Payload (Ingame-Give) verwendet.
|
|
||||||
- **Kategorie(n)**
|
|
||||||
- Checkbox-Liste aller `wis_category`-Terms, beeinflusst die Tabs im Frontend.
|
|
||||||
- **Daily Deal (Angebot des Tages)**
|
|
||||||
- Option „manuell als Angebot des Tages setzen“, überschreibt die Automatik bis Mitternacht.
|
|
||||||
- **Angebot / Sale**
|
|
||||||
- Checkbox „Als Angebot markieren 🔥“ + optionaler Angebots-Preis.
|
|
||||||
- Angebots-Preis wird angezeigt, normaler Preis durchgestrichen.
|
|
||||||
- **Beschreibung**
|
|
||||||
- Langtext, der im Frontend unter dem Titel angezeigt wird.
|
|
||||||
- **Server zuweisen**
|
|
||||||
- Checkbox-Liste aller definierten `wis_server`, steuert Sichtbarkeit und Kaufbarkeit pro Server.
|
|
||||||
|
|
||||||
Zusätzlich existiert eine Auto-Status-Logik, die beim Speichern `publish/draft` abhängig vom Preis setzt.
|
Bei Aktivierung werden automatisch erstellt:
|
||||||
|
|
||||||
### Server (`wis_server`)
|
- Datenbanktabellen (`wp_wis_*`)
|
||||||
|
- Cron-Jobs für Daily Deals
|
||||||
|
|
||||||
Metabox „Server Einstellungen“ zeigt nur einen Hinweis, dass keine RCON-Daten notwendig sind.
|
---
|
||||||
|
|
||||||
- Der **Post-Slug** des Servers wird als Server-ID im Frontend/REST verwendet.
|
# 🖼️ Bilder-Konfiguration (Gitea Raw)
|
||||||
|
|
||||||
### Gutscheine (`wis_coupon`)
|
## 📂 Basis-URL für alle Item-Bilder
|
||||||
|
|
||||||
Metabox **„Gutschein Einstellungen“**:
|
```
|
||||||
|
https://git.viper.ipv64.net/M_Viper/WP-Ingame-Shop-Pro/raw/branch/main/images/
|
||||||
|
```
|
||||||
|
|
||||||
- **Gutschein Code** (wird automatisch in Großbuchstaben gespeichert).
|
### 🔧 Eintragen im Plugin
|
||||||
- **Rabattart**: „Festbetrag“ oder „Prozentual“.
|
|
||||||
- **Wert**: Coins oder Prozent, abhängig vom Typ.
|
|
||||||
- **Nutzungslimit**: Wie oft der Gutschein eingelöst werden darf.
|
|
||||||
- **Ablaufdatum** (optional).
|
|
||||||
- Hinweis, wenn global eingestellt ist, dass Gutscheine bei Angeboten nicht gelten.
|
|
||||||
|
|
||||||
Beim Speichern werden die Daten zusätzlich in der Tabelle `wp_wis_coupons` gespiegelt und `used_count` synchronisiert.
|
**Ingame Shop → Einstellungen → Bilder Basis-URL**
|
||||||
|
|
||||||
Beim Löschen eines Gutschein-Posts wird der Eintrag aus `wp_wis_coupons` wieder entfernt.
|
Eintragen:
|
||||||
|
|
||||||
## REST API
|
```
|
||||||
|
https://git.viper.ipv64.net/M_Viper/WP-Ingame-Shop-Pro/raw/branch/main/images/
|
||||||
|
```
|
||||||
|
|
||||||
Alle Routen liegen unter `wis/v1/…`.
|
---
|
||||||
|
|
||||||
- `POST /wis/v1/order`
|
## 📌 Automatische Bildlogik
|
||||||
- Erstellt eine neue Bestellung.
|
|
||||||
- Request-Body: `{ player, cart: [{id, quantity}], server, coupon_code? }`.
|
|
||||||
- Validiert Items (Preis > 0, Serverzuordnung, Angebot/Normal, Gutscheinlogik) und speichert Order inkl. JSON mit realen Item-IDs und ggf. Gutschein-Rabatt.
|
|
||||||
- `GET /wis/v1/pending_orders?player=Name`
|
|
||||||
- Liefert bis zu 10 offene Bestellungen (`status = pending`) eines Spielers.
|
|
||||||
- `POST /wis/v1/execute_order`
|
|
||||||
- Setzt Status einer Bestellung auf `processing` (z. B. wenn der Ingame-Executor mit der Ausgabe beginnt).
|
|
||||||
- `POST /wis/v1/complete_order`
|
|
||||||
- Setzt Status auf `completed`.
|
|
||||||
- `POST /wis/v1/cancel_order`
|
|
||||||
- Setzt Status auf `cancelled`.
|
|
||||||
- `POST /wis/v1/validate_coupon`
|
|
||||||
- Prüft einen Gutschein gegen aktuelle Cart-Daten (inkl. „nur normale Items“ Logik) und liefert Typ, Wert und Message.
|
|
||||||
- `POST /wis/v1/fetch_remote_data`
|
|
||||||
- Lädt JSON von externer URL (z. B. `https://minecraft-ids.com/data/1.21.10.json`) und gibt eine normalisierte Items-Liste zurück.
|
|
||||||
- `POST /wis/v1/import_batch`
|
|
||||||
- Importiert ein Items-Array als `wis_item`-Posts (draft, `_wis_item_id`, `_wis_price` = 0), überspringt Duplikate.
|
|
||||||
|
|
||||||
Alle REST-Endpunkte sind aktuell ohne Authentifizierung (`permission_callback => __return_true`), für öffentliche Nutzung sollte gegebenenfalls Absicherung ergänzt werden.
|
Item-ID im Shop:
|
||||||
|
|
||||||
## Frontend Shortcode
|
```
|
||||||
|
minecraft:diamond
|
||||||
|
```
|
||||||
|
|
||||||
Der Shop wird per Shortcode eingebunden:
|
Automatisch geladen wird:
|
||||||
|
|
||||||
```text
|
```
|
||||||
|
https://git.viper.ipv64.net/M_Viper/WP-Ingame-Shop-Pro/raw/branch/main/images/minecraft_diamond.png
|
||||||
|
```
|
||||||
|
|
||||||
|
Regeln:
|
||||||
|
|
||||||
|
- `:` wird zu `_`
|
||||||
|
- Dateiendung = `.png`
|
||||||
|
- Keine manuelle Bildzuweisung notwendig
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 📥 Quick JSON Import (Direkt von Gitea)
|
||||||
|
|
||||||
|
## 🔗 Import-URL
|
||||||
|
|
||||||
|
```
|
||||||
|
https://git.viper.ipv64.net/M_Viper/WP-Ingame-Shop-Pro/raw/branch/main/items.json
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ Import durchführen
|
||||||
|
|
||||||
|
1. **Ingame Shop → JSON Tools**
|
||||||
|
2. **Import**
|
||||||
|
3. URL einfügen
|
||||||
|
4. Import starten
|
||||||
|
|
||||||
|
Ideal für:
|
||||||
|
|
||||||
|
- Kompletten Shop-Aufbau in Sekunden
|
||||||
|
- Regelmäßige Synchronisation
|
||||||
|
- Kombination mit Bulk Edit
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 🛠️ Admin-Bereich
|
||||||
|
|
||||||
|
## 1️⃣ Einstellungen
|
||||||
|
|
||||||
|
- Shop Header Text
|
||||||
|
- Währungsname (z.B. Coins)
|
||||||
|
- Bilder Basis-URL
|
||||||
|
- Daily Deal (% Rabatt)
|
||||||
|
- Gutscheine auf Sale-Items erlauben / verbieten
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2️⃣ Items Verwaltung
|
||||||
|
|
||||||
|
### Einzelbearbeitung
|
||||||
|
|
||||||
|
- Item ID (`minecraft:diamond`)
|
||||||
|
- Preis
|
||||||
|
- Angebotspreis
|
||||||
|
- Server-Zuweisung
|
||||||
|
- Kategorie
|
||||||
|
- Status (`publish` / `draft`)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 Bulk Edit (Mehrfachbearbeitung)
|
||||||
|
|
||||||
|
Beispiel: 100 Items einem Server zuweisen.
|
||||||
|
|
||||||
|
1. Items anhaken
|
||||||
|
2. „Massenaktionen“ wählen:
|
||||||
|
- Server zuweisen
|
||||||
|
- Preis ändern
|
||||||
|
- Kategorie setzen
|
||||||
|
- Status ändern
|
||||||
|
3. Anwenden
|
||||||
|
4. Änderungen speichern
|
||||||
|
|
||||||
|
Überschreibt bestehende Server-/Kategorie-Zuweisungen.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3️⃣ Weitere Bereiche
|
||||||
|
|
||||||
|
### 📦 Bestellungen
|
||||||
|
|
||||||
|
- Bestellungen anzeigen
|
||||||
|
- Manuell abschließen
|
||||||
|
- Stornieren
|
||||||
|
|
||||||
|
Status:
|
||||||
|
|
||||||
|
```
|
||||||
|
pending
|
||||||
|
processing
|
||||||
|
completed
|
||||||
|
cancelled
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🌐 Server
|
||||||
|
|
||||||
|
Beispiel:
|
||||||
|
|
||||||
|
```
|
||||||
|
lobby
|
||||||
|
survival
|
||||||
|
skyblock
|
||||||
|
```
|
||||||
|
|
||||||
|
Frontend-Filter werden automatisch generiert.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 📂 Kategorien
|
||||||
|
|
||||||
|
Beispiel:
|
||||||
|
|
||||||
|
```
|
||||||
|
Blöcke
|
||||||
|
Waffen
|
||||||
|
Rüstung
|
||||||
|
Ranks
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🎫 Gutscheine
|
||||||
|
|
||||||
|
- `fixed` (Festbetrag)
|
||||||
|
- `percent` (Prozent)
|
||||||
|
- Ablaufdatum
|
||||||
|
- Nutzungslimit
|
||||||
|
- Ausschluss bei Angeboten
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 📊 Top Spender
|
||||||
|
|
||||||
|
Automatische Auswertung der Bestellungen.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 🎮 Frontend Nutzung
|
||||||
|
|
||||||
|
Shortcode:
|
||||||
|
|
||||||
|
```
|
||||||
[ingame_shop_form]
|
[ingame_shop_form]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Layout & Funktionen
|
---
|
||||||
|
|
||||||
- Modernes Grid mit Karten (Bild, Name, Preis, Server, Badges, Menge).
|
## Spieler-Funktionen
|
||||||
- Filter: Suche, „Nur Angebote“, Server-Auswahl und Kategorie-Tabs.
|
|
||||||
- Badges:
|
|
||||||
- „🔥 Angebot“ für Sale-Items.
|
|
||||||
- „🎁 Angebot des Tages“ für den aktiven Daily Deal.
|
|
||||||
- Mengensteuerung je Item (Buttons + Input).
|
|
||||||
- Warenkorb-Button (Badge mit Gesamtanzahl der Items) öffnet ein Modal.
|
|
||||||
- Gutscheincode-Feld im Checkout mit Live-Validierung via `validate_coupon`.
|
|
||||||
- Dynamische Berechnung:
|
|
||||||
- Normaler Teil des Warenkorbs, ggf. rabattiert.
|
|
||||||
- Angebots-Items, die optional von Gutscheinen ausgenommen sind.
|
|
||||||
- Validierung:
|
|
||||||
- Alle ausgewählten Items müssen für den gewählten Server freigeschaltet sein.
|
|
||||||
- Spielername und Server sind Pflichtfelder.
|
|
||||||
- Beim Abschließen des Kaufs wird `POST /wis/v1/order` aufgerufen, die Antwort wird im Modal angezeigt und der Warenkorb geleert.
|
|
||||||
|
|
||||||
## Datenbank-Struktur
|
- Suche
|
||||||
|
- Server-Filter
|
||||||
|
- Kategorie-Tabs
|
||||||
|
- Warenkorb
|
||||||
|
- Gutschein-Eingabe
|
||||||
|
- Server-Validierung beim Checkout
|
||||||
|
|
||||||
### Tabelle `wp_wis_orders`
|
---
|
||||||
|
|
||||||
- `id` – Auto-Increment.
|
# 📡 REST API
|
||||||
- `player_name` – Spielername.
|
|
||||||
- `server` – Server-Slug (`wis_server` Postname).
|
|
||||||
- `item_id` – Hier für den Warenkorb pauschal `multi_item_cart`.
|
|
||||||
- `item_title` – Lesbare Zusammenfassung (z. B. „Warenkorb: 1x Diamant, 64x Stein…“).
|
|
||||||
- `price` – Endpreis nach Rabatt.
|
|
||||||
- `quantity` – Anzahl der unterschiedlichen Items im Warenkorb.
|
|
||||||
- `status` – `pending`, `processing`, `completed`, `cancelled`, `failed`.
|
|
||||||
- `response` – JSON mit `items` (real Item IDs + Mengen) und optionalem `coupon`.
|
|
||||||
- `created_at` – Timestamp.
|
|
||||||
|
|
||||||
### Tabelle `wp_wis_coupons`
|
Basis:
|
||||||
|
|
||||||
- `id` – Auto-Increment.
|
```
|
||||||
- `code` – Gutschein-Code (unique).
|
/wp-json/wis/v1/
|
||||||
- `value` – Wert (Coins oder Prozent).
|
```
|
||||||
- `type` – `fixed` oder `percent`.
|
|
||||||
- `usage_limit` – Maximal verwendbar.
|
|
||||||
- `used_count` – Bisherige Verwendung.
|
|
||||||
- `expiry` – Ablaufdatum.
|
|
||||||
- `created_at` – Timestamp.
|
|
||||||
|
|
||||||
## Cron & Daily Deal
|
---
|
||||||
|
|
||||||
- Beim Aktivieren wird ein tägliches Event `wis_daily_deal_event` registriert.
|
## Bestellung erstellen
|
||||||
- Callback `WIS_Activator::run_daily_deal()`:
|
|
||||||
- Deaktiviert das aktuelle Daily-Deal-Item (`_wis_daily_deal` → 0).
|
|
||||||
- Wählt ein random `wis_item` mit `_wis_price > 0` und ohne `_wis_daily_deal`-Meta.
|
|
||||||
- Berechnet den Rabatt basierend auf `wis_daily_deal_discount` und setzt `_wis_is_offer` + `_wis_offer_price`.
|
|
||||||
|
|
||||||
## Bulk Import
|
```
|
||||||
|
POST /wis/v1/order
|
||||||
|
```
|
||||||
|
|
||||||
- Im Admin-Overview vorhanden.
|
```json
|
||||||
- Eingabefeld für die Import-URL (Default: `https://minecraft-ids.com/data/1.21.10.json`).
|
{
|
||||||
- Button „Daten laden“ → lädt via REST `fetch_remote_data` und zeigt Anzahl Items an.
|
"player": "Name",
|
||||||
- Button „Import starten“ → ruft wiederholt `import_batch` mit Batches von 20 Items auf und zeigt Fortschritt an.
|
"server": "survival",
|
||||||
- Vorhandene Items (gleiche `_wis_item_id`) werden übersprungen, neue Items als Draft mit Preis 0 angelegt.
|
"cart": [
|
||||||
|
{ "id": "item_id", "quantity": 1 }
|
||||||
|
],
|
||||||
|
"coupon_code": "CODE"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Für eine GitHub-README kannst du diesen Text direkt verwenden oder nur einzelne Abschnitte übernehmen und oben ggf. Screenshots/GIFs ergänzen.
|
---
|
||||||
|
|
||||||
|
## Offene Bestellungen abrufen
|
||||||
|
|
||||||
|
```
|
||||||
|
GET /wis/v1/pending_orders?player=Name
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Status ändern
|
||||||
|
|
||||||
|
```
|
||||||
|
POST /wis/v1/execute_order
|
||||||
|
POST /wis/v1/complete_order
|
||||||
|
POST /wis/v1/cancel_order
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Gutschein validieren
|
||||||
|
|
||||||
|
```
|
||||||
|
POST /wis/v1/validate_coupon
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 💾 Datenbank-Struktur
|
||||||
|
|
||||||
|
## `wp_wis_items`
|
||||||
|
|
||||||
|
| Feld | Beschreibung |
|
||||||
|
|------|-------------|
|
||||||
|
| item_id | minecraft:diamond |
|
||||||
|
| name | Anzeigename |
|
||||||
|
| price | Standardpreis |
|
||||||
|
| offer_price | Angebotspreis |
|
||||||
|
| is_offer | 0 / 1 |
|
||||||
|
| servers | JSON Array |
|
||||||
|
| categories | JSON Array |
|
||||||
|
| status | publish / draft |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## `wp_wis_orders`
|
||||||
|
|
||||||
|
| Feld | Beschreibung |
|
||||||
|
|------|-------------|
|
||||||
|
| player_name | Minecraft Name |
|
||||||
|
| server | Zielserver |
|
||||||
|
| item_title | Zusammenfassung |
|
||||||
|
| price | Gesamtpreis |
|
||||||
|
| response | JSON |
|
||||||
|
| status | pending / processing / completed / cancelled |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## `wp_wis_coupons`
|
||||||
|
|
||||||
|
| Feld | Beschreibung |
|
||||||
|
|------|-------------|
|
||||||
|
| code | Gutschein |
|
||||||
|
| type | fixed / percent |
|
||||||
|
| value | Rabattwert |
|
||||||
|
| usage_limit | Limit |
|
||||||
|
| used_count | Nutzung |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## `wp_wis_servers`
|
||||||
|
|
||||||
|
Serverdefinitionen
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## `wp_wis_categories`
|
||||||
|
|
||||||
|
Kategoriedefinitionen
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# ⚡ Performance Empfehlung
|
||||||
|
|
||||||
|
Bei 1500+ PNG-Dateien:
|
||||||
|
|
||||||
|
- CDN empfohlen
|
||||||
|
- PNG verlustfrei komprimieren
|
||||||
|
- Gitea Caching aktivieren
|
||||||
|
- Optional WebP-Versionen erstellen
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 🔐 Sicherheitshinweis
|
||||||
|
|
||||||
|
Aktuell sind API-Endpunkte öffentlich (`__return_true`).
|
||||||
|
|
||||||
|
Für Produktion empfohlen:
|
||||||
|
|
||||||
|
- API-Key Header
|
||||||
|
- Bearer Token
|
||||||
|
- IP Whitelisting
|
||||||
|
- Nonce/Signature System
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 📦 Meta
|
||||||
|
|
||||||
|
Version: 2.1.0
|
||||||
|
Autor: M_Viper
|
||||||
|
Lizenz: GPL-2.0-or-later
|
||||||
|
|||||||
BIN
images/minecraft_acacia_boat.png
Normal file
|
After Width: | Height: | Size: 932 B |
BIN
images/minecraft_acacia_button.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
images/minecraft_acacia_chest_boat.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
images/minecraft_acacia_door.png
Normal file
|
After Width: | Height: | Size: 580 B |
BIN
images/minecraft_acacia_fence.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
images/minecraft_acacia_fence_gate.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
images/minecraft_acacia_hanging_sign.png
Normal file
|
After Width: | Height: | Size: 781 B |
BIN
images/minecraft_acacia_leaves.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
images/minecraft_acacia_log.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
images/minecraft_acacia_planks.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
images/minecraft_acacia_pressure_plate.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
images/minecraft_acacia_sapling.png
Normal file
|
After Width: | Height: | Size: 873 B |
BIN
images/minecraft_acacia_shelf.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
images/minecraft_acacia_sign.png
Normal file
|
After Width: | Height: | Size: 721 B |
BIN
images/minecraft_acacia_slab.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
images/minecraft_acacia_stairs.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
images/minecraft_acacia_trapdoor.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
images/minecraft_acacia_wood.png
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
images/minecraft_activator_rail.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
images/minecraft_air.png
Normal file
|
After Width: | Height: | Size: 390 B |
BIN
images/minecraft_allay_spawn_egg.png
Normal file
|
After Width: | Height: | Size: 895 B |
BIN
images/minecraft_allium.png
Normal file
|
After Width: | Height: | Size: 658 B |
BIN
images/minecraft_amethyst_block.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
images/minecraft_amethyst_cluster.png
Normal file
|
After Width: | Height: | Size: 903 B |
BIN
images/minecraft_amethyst_shard.png
Normal file
|
After Width: | Height: | Size: 764 B |
BIN
images/minecraft_ancient_debris.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
images/minecraft_andesite.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
images/minecraft_andesite_slab.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
images/minecraft_andesite_stairs.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
images/minecraft_andesite_wall.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
images/minecraft_angler_pottery_sherd.png
Normal file
|
After Width: | Height: | Size: 825 B |
BIN
images/minecraft_anvil.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
images/minecraft_apple.png
Normal file
|
After Width: | Height: | Size: 790 B |
BIN
images/minecraft_archer_pottery_sherd.png
Normal file
|
After Width: | Height: | Size: 833 B |
BIN
images/minecraft_armadillo_scute.png
Normal file
|
After Width: | Height: | Size: 648 B |
BIN
images/minecraft_armadillo_spawn_egg.png
Normal file
|
After Width: | Height: | Size: 846 B |
BIN
images/minecraft_armor_stand.png
Normal file
|
After Width: | Height: | Size: 744 B |
BIN
images/minecraft_arms_up_pottery_sherd.png
Normal file
|
After Width: | Height: | Size: 844 B |
BIN
images/minecraft_arrow.png
Normal file
|
After Width: | Height: | Size: 635 B |
BIN
images/minecraft_axolotl_bucket.png
Normal file
|
After Width: | Height: | Size: 977 B |
BIN
images/minecraft_axolotl_spawn_egg.png
Normal file
|
After Width: | Height: | Size: 808 B |
BIN
images/minecraft_azalea.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
images/minecraft_azalea_leaves.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
images/minecraft_azure_bluet.png
Normal file
|
After Width: | Height: | Size: 711 B |
BIN
images/minecraft_baked_potato.png
Normal file
|
After Width: | Height: | Size: 804 B |
BIN
images/minecraft_bamboo.png
Normal file
|
After Width: | Height: | Size: 683 B |
BIN
images/minecraft_bamboo_block.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
images/minecraft_bamboo_button.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
images/minecraft_bamboo_chest_raft.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
images/minecraft_bamboo_door.png
Normal file
|
After Width: | Height: | Size: 879 B |
BIN
images/minecraft_bamboo_fence.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
images/minecraft_bamboo_fence_gate.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
images/minecraft_bamboo_hanging_sign.png
Normal file
|
After Width: | Height: | Size: 963 B |
BIN
images/minecraft_bamboo_mosaic.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
images/minecraft_bamboo_mosaic_slab.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
images/minecraft_bamboo_mosaic_stairs.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
images/minecraft_bamboo_planks.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
images/minecraft_bamboo_pressure_plate.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
images/minecraft_bamboo_raft.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
images/minecraft_bamboo_shelf.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
images/minecraft_bamboo_sign.png
Normal file
|
After Width: | Height: | Size: 909 B |
BIN
images/minecraft_bamboo_slab.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
images/minecraft_bamboo_stairs.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
BIN
images/minecraft_bamboo_trapdoor.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
images/minecraft_barrel.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
images/minecraft_barrier.png
Normal file
|
After Width: | Height: | Size: 566 B |
BIN
images/minecraft_basalt.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
images/minecraft_bat_spawn_egg.png
Normal file
|
After Width: | Height: | Size: 787 B |
BIN
images/minecraft_beacon.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
images/minecraft_bedrock.png
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
images/minecraft_bee_nest.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
images/minecraft_bee_spawn_egg.png
Normal file
|
After Width: | Height: | Size: 840 B |
BIN
images/minecraft_beef.png
Normal file
|
After Width: | Height: | Size: 789 B |
BIN
images/minecraft_beehive.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
images/minecraft_beetroot.png
Normal file
|
After Width: | Height: | Size: 731 B |
BIN
images/minecraft_beetroot_seeds.png
Normal file
|
After Width: | Height: | Size: 614 B |
BIN
images/minecraft_beetroot_soup.png
Normal file
|
After Width: | Height: | Size: 656 B |
BIN
images/minecraft_bell.png
Normal file
|
After Width: | Height: | Size: 786 B |
BIN
images/minecraft_big_dripleaf.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
images/minecraft_birch_boat.png
Normal file
|
After Width: | Height: | Size: 937 B |
BIN
images/minecraft_birch_button.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
images/minecraft_birch_chest_boat.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
images/minecraft_birch_door.png
Normal file
|
After Width: | Height: | Size: 625 B |
BIN
images/minecraft_birch_fence.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
images/minecraft_birch_fence_gate.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
images/minecraft_birch_hanging_sign.png
Normal file
|
After Width: | Height: | Size: 805 B |
BIN
images/minecraft_birch_leaves.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
images/minecraft_birch_log.png
Normal file
|
After Width: | Height: | Size: 5.6 KiB |
BIN
images/minecraft_birch_planks.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
images/minecraft_birch_pressure_plate.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
images/minecraft_birch_sapling.png
Normal file
|
After Width: | Height: | Size: 854 B |
BIN
images/minecraft_birch_shelf.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
images/minecraft_birch_sign.png
Normal file
|
After Width: | Height: | Size: 736 B |
BIN
images/minecraft_birch_slab.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
images/minecraft_birch_stairs.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |