pull/6/head
commit
7c354ccc57
11 changed files with 718 additions and 0 deletions
@ -0,0 +1,113 @@ |
||||
# User-specific stuff |
||||
.idea/ |
||||
|
||||
*.iml |
||||
*.ipr |
||||
*.iws |
||||
|
||||
# IntelliJ |
||||
out/ |
||||
|
||||
# Compiled class file |
||||
*.class |
||||
|
||||
# Log file |
||||
*.log |
||||
|
||||
# BlueJ files |
||||
*.ctxt |
||||
|
||||
# Package Files # |
||||
*.jar |
||||
*.war |
||||
*.nar |
||||
*.ear |
||||
*.zip |
||||
*.tar.gz |
||||
*.rar |
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml |
||||
hs_err_pid* |
||||
|
||||
*~ |
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file |
||||
.fuse_hidden* |
||||
|
||||
# KDE directory preferences |
||||
.directory |
||||
|
||||
# Linux trash folder which might appear on any partition or disk |
||||
.Trash-* |
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed |
||||
.nfs* |
||||
|
||||
# General |
||||
.DS_Store |
||||
.AppleDouble |
||||
.LSOverride |
||||
|
||||
# Icon must end with two \r |
||||
Icon |
||||
|
||||
# Thumbnails |
||||
._* |
||||
|
||||
# Files that might appear in the root of a volume |
||||
.DocumentRevisions-V100 |
||||
.fseventsd |
||||
.Spotlight-V100 |
||||
.TemporaryItems |
||||
.Trashes |
||||
.VolumeIcon.icns |
||||
.com.apple.timemachine.donotpresent |
||||
|
||||
# Directories potentially created on remote AFP share |
||||
.AppleDB |
||||
.AppleDesktop |
||||
Network Trash Folder |
||||
Temporary Items |
||||
.apdisk |
||||
|
||||
# Windows thumbnail cache files |
||||
Thumbs.db |
||||
Thumbs.db:encryptable |
||||
ehthumbs.db |
||||
ehthumbs_vista.db |
||||
|
||||
# Dump file |
||||
*.stackdump |
||||
|
||||
# Folder config file |
||||
[Dd]esktop.ini |
||||
|
||||
# Recycle Bin used on file shares |
||||
$RECYCLE.BIN/ |
||||
|
||||
# Windows Installer files |
||||
*.cab |
||||
*.msi |
||||
*.msix |
||||
*.msm |
||||
*.msp |
||||
|
||||
# Windows shortcuts |
||||
*.lnk |
||||
|
||||
target/ |
||||
|
||||
pom.xml.tag |
||||
pom.xml.releaseBackup |
||||
pom.xml.versionsBackup |
||||
pom.xml.next |
||||
|
||||
release.properties |
||||
dependency-reduced-pom.xml |
||||
buildNumber.properties |
||||
.mvn/timing.properties |
||||
.mvn/wrapper/maven-wrapper.jar |
||||
.flattened-pom.xml |
||||
|
||||
# Common working directory |
||||
run/ |
||||
@ -0,0 +1,137 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<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>xyz.soukup</groupId> |
||||
<artifactId>ecocraftcore</artifactId> |
||||
<version>1.0-SNAPSHOT</version> |
||||
<packaging>jar</packaging> |
||||
|
||||
<name>ecocraftcore</name> |
||||
|
||||
<properties> |
||||
<java.version>21</java.version> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
</properties> |
||||
|
||||
<build> |
||||
<defaultGoal>clean package</defaultGoal> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<version>3.13.0</version> |
||||
<configuration> |
||||
<source>${java.version}</source> |
||||
<target>${java.version}</target> |
||||
</configuration> |
||||
</plugin> |
||||
|
||||
<plugin> |
||||
<groupId>io.ebean</groupId> |
||||
<artifactId>ebean-maven-plugin</artifactId> |
||||
<version>14.1.0</version> |
||||
<executions> |
||||
<execution> |
||||
<id>main</id> |
||||
<phase>process-classes</phase> |
||||
<goals> |
||||
<goal>enhance</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
<configuration> |
||||
<packages>xyz.soukup.ecoCraftCore.objects.**</packages> |
||||
</configuration> |
||||
</plugin> |
||||
|
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-shade-plugin</artifactId> |
||||
<version>3.5.3</version> |
||||
<executions> |
||||
<execution> |
||||
<phase>package</phase> |
||||
<goals> |
||||
<goal>shade</goal> |
||||
</goals> |
||||
<configuration> |
||||
<relocations> |
||||
<relocation> |
||||
<pattern>io.ebean</pattern> |
||||
<shadedPattern>xyz.soukup.shaded.io.ebean</shadedPattern> |
||||
</relocation> |
||||
<relocation> |
||||
<pattern>io.ebeaninternal</pattern> |
||||
<shadedPattern>xyz.soukup.shaded.io.ebeaninternal</shadedPattern> |
||||
</relocation> |
||||
<relocation> |
||||
<pattern>org.avaje</pattern> |
||||
<shadedPattern>xyz.soukup.shaded.org.avaje</shadedPattern> |
||||
</relocation> |
||||
</relocations> |
||||
<transformers> |
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> |
||||
</transformers> |
||||
<createDependencyReducedPom>false</createDependencyReducedPom> |
||||
<minimizeJar>false</minimizeJar> |
||||
</configuration> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
</plugins> |
||||
|
||||
<resources> |
||||
<resource> |
||||
<directory>src/main/resources</directory> |
||||
<filtering>true</filtering> |
||||
</resource> |
||||
</resources> |
||||
</build> |
||||
|
||||
<repositories> |
||||
<repository> |
||||
<id>papermc-repo</id> |
||||
<url>https://repo.papermc.io/repository/maven-public/</url> |
||||
</repository> |
||||
<repository> |
||||
<id>sonatype</id> |
||||
<url>https://oss.sonatype.org/content/groups/public/</url> |
||||
</repository> |
||||
</repositories> |
||||
|
||||
<dependencies> |
||||
|
||||
<dependency> |
||||
<groupId>com.j256.ormlite</groupId> |
||||
<artifactId>ormlite-core</artifactId> |
||||
<version>6.1</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.j256.ormlite</groupId> |
||||
<artifactId>ormlite-jdbc</artifactId> |
||||
<version>6.1</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.mysql</groupId> |
||||
<artifactId>mysql-connector-j</artifactId> |
||||
<version>9.3.0</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>io.github.odalita-developments.odalitamenus</groupId> |
||||
<artifactId>core</artifactId> |
||||
<version>0.6.2</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>io.papermc.paper</groupId> |
||||
<artifactId>paper-api</artifactId> |
||||
<version>1.21.3-R0.1-SNAPSHOT</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
||||
@ -0,0 +1,68 @@ |
||||
package xyz.soukup.ecoCraftCore; |
||||
|
||||
import com.j256.ormlite.dao.DaoManager; |
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource; |
||||
import com.j256.ormlite.support.ConnectionSource; |
||||
import com.j256.ormlite.table.TableUtils; |
||||
import org.bukkit.plugin.java.JavaPlugin; |
||||
import xyz.soukup.ecoCraftCore.commands.TransactionCommand; |
||||
import xyz.soukup.ecoCraftCore.objects.Shop; |
||||
import xyz.soukup.ecoCraftCore.objects.Transaction; |
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; |
||||
import xyz.soukup.ecoCraftCore.objects.VirtualChest; |
||||
import xyz.soukup.ecoCraftCore.utilities.DaoRegistry; |
||||
|
||||
import java.sql.SQLException; |
||||
import java.util.logging.Level; |
||||
import java.util.logging.Logger; |
||||
|
||||
public final class EcoCraftCore extends JavaPlugin { |
||||
|
||||
public static ConnectionSource connectionSource; |
||||
|
||||
@Override |
||||
public void onEnable() { |
||||
this.getLogger().info("plugin starting out"); |
||||
|
||||
try { |
||||
prepareDatabase(); |
||||
registerCommands(); |
||||
} catch (SQLException e) { |
||||
e.printStackTrace(); |
||||
getLogger().severe("Failed to initialize database."); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onDisable() { |
||||
try { |
||||
if (connectionSource != null) { |
||||
connectionSource.close(); |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
private void prepareDatabase() throws SQLException { |
||||
String databaseUrl = "jdbc:mysql://localhost:3306/ecc"; |
||||
connectionSource = new JdbcConnectionSource(databaseUrl, "ecc", ""); |
||||
Logger.getLogger("com.j256.ormlite.table.TableUtils").setLevel(Level.OFF); |
||||
|
||||
|
||||
TableUtils.createTableIfNotExists(connectionSource, Transaction.class); |
||||
TableUtils.createTableIfNotExists(connectionSource, Shop.class); |
||||
TableUtils.createTableIfNotExists(connectionSource, VirtualChest.class); |
||||
|
||||
DaoRegistry.setTransactionDao(DaoManager.createDao(connectionSource, Transaction.class)); |
||||
DaoRegistry.setShopDao(DaoManager.createDao(connectionSource, Shop.class)); |
||||
DaoRegistry.setVirtualChestDao(DaoManager.createDao(connectionSource, VirtualChest.class)); |
||||
|
||||
} |
||||
|
||||
private void registerCommands() { |
||||
this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, |
||||
event -> event.registrar().register(TransactionCommand.createCommand().build()) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,41 @@ |
||||
package xyz.soukup.ecoCraftCore.commands; |
||||
|
||||
import com.j256.ormlite.dao.Dao; |
||||
import com.j256.ormlite.dao.DaoManager; |
||||
import com.mojang.brigadier.arguments.DoubleArgumentType; |
||||
import com.mojang.brigadier.arguments.StringArgumentType; |
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
||||
import com.mojang.brigadier.context.CommandContext; |
||||
import io.papermc.paper.command.brigadier.CommandSourceStack; |
||||
import io.papermc.paper.command.brigadier.Commands; |
||||
import xyz.soukup.ecoCraftCore.EcoCraftCore; |
||||
import xyz.soukup.ecoCraftCore.objects.Transaction; |
||||
|
||||
public class TransactionCommand { |
||||
|
||||
public static LiteralArgumentBuilder<CommandSourceStack> createCommand() { |
||||
return Commands.literal("transaction") |
||||
.then(Commands.literal("simulate") |
||||
.then(Commands.argument("sender", StringArgumentType.word()) |
||||
.then(Commands.argument("receiver", StringArgumentType.word()) |
||||
.then(Commands.argument("amount", DoubleArgumentType.doubleArg(0.1)) |
||||
.executes(TransactionCommand::simulateTransaction))))); |
||||
} |
||||
|
||||
private static int simulateTransaction(CommandContext<CommandSourceStack> ctx) { |
||||
String sender = StringArgumentType.getString(ctx, "sender"); |
||||
String receiver = StringArgumentType.getString(ctx, "receiver"); |
||||
double amount = DoubleArgumentType.getDouble(ctx, "amount"); |
||||
|
||||
try { |
||||
Dao<Transaction, Long> dao = DaoManager.createDao(EcoCraftCore.connectionSource, Transaction.class); |
||||
Transaction tx = new Transaction(amount, "player", sender, "player", receiver, "command"); |
||||
dao.create(tx); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
return 0; |
||||
} |
||||
|
||||
return 1; |
||||
} |
||||
} |
||||
@ -0,0 +1,141 @@ |
||||
package xyz.soukup.ecoCraftCore.objects; |
||||
import com.j256.ormlite.field.DatabaseField; |
||||
import com.j256.ormlite.table.DatabaseTable; |
||||
import org.bukkit.entity.Player; |
||||
import org.bukkit.inventory.ItemStack; |
||||
import xyz.soukup.ecoCraftCore.utilities.DaoRegistry; |
||||
import xyz.soukup.ecoCraftCore.utilities.JSONConverter; |
||||
|
||||
import java.sql.SQLException; |
||||
import java.sql.Timestamp; |
||||
|
||||
@DatabaseTable(tableName = "shops") |
||||
public class Shop { |
||||
|
||||
@DatabaseField(generatedId = true) |
||||
private long id; |
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private String owner; |
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private String ownerType; |
||||
|
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private String itemName; |
||||
|
||||
@DatabaseField(canBeNull = false, columnName = "itemstack") |
||||
private String itemStackJson; |
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private int amount; |
||||
|
||||
@DatabaseField |
||||
private float priceBuy; |
||||
|
||||
@DatabaseField |
||||
private float priceSell; |
||||
|
||||
@DatabaseField(canBeNull = false, defaultValue = "0") |
||||
private int stock; |
||||
|
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private int virtualChestID; |
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private Timestamp created = new Timestamp(System.currentTimeMillis()); |
||||
|
||||
public Shop() { |
||||
|
||||
} |
||||
|
||||
public Shop(Player player, ItemStack itemStack, int stock, int amount, float priceBuy, float priceSell, int virtualChestID) { |
||||
this.ownerType = "player"; |
||||
this.owner = player.getName(); |
||||
this.itemStackJson = JSONConverter.itemStackToJson(itemStack); |
||||
this.itemName = itemStack.getType().toString(); |
||||
this.stock = stock; |
||||
this.amount = amount; |
||||
this.priceBuy = priceBuy; |
||||
this.priceSell = priceSell; |
||||
this.virtualChestID = virtualChestID; |
||||
} |
||||
|
||||
public void setItemName(String itemName) { |
||||
this.itemName = itemName; |
||||
} |
||||
|
||||
public void setItemStackJson(String itemStackJson) { |
||||
this.itemStackJson = itemStackJson; |
||||
} |
||||
|
||||
public void setAmount(int amount) { |
||||
this.amount = amount; |
||||
} |
||||
|
||||
public void setPriceBuy(float priceBuy) { |
||||
this.priceBuy = priceBuy; |
||||
} |
||||
|
||||
public void setPriceSell(float priceSell) { |
||||
this.priceSell = priceSell; |
||||
} |
||||
|
||||
public void setStock(int stock) { |
||||
this.stock = stock; |
||||
} |
||||
|
||||
public static Shop findById(int id) { |
||||
try { |
||||
return DaoRegistry.getShopDao().queryForId(id); |
||||
} catch (SQLException e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public ItemStack getItemStack() { |
||||
return JSONConverter.itemStackFromJson(this.itemStackJson); |
||||
} |
||||
|
||||
public long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public String getOwner() { |
||||
return owner; |
||||
} |
||||
|
||||
public String getOwnerType() { |
||||
return ownerType; |
||||
} |
||||
|
||||
public String getItemName() { |
||||
return itemName; |
||||
} |
||||
|
||||
public int getAmount() { |
||||
return amount; |
||||
} |
||||
|
||||
public float getPriceBuy() { |
||||
return priceBuy; |
||||
} |
||||
|
||||
public float getPriceSell() { |
||||
return priceSell; |
||||
} |
||||
|
||||
public int getStock() { |
||||
return stock; |
||||
} |
||||
|
||||
public int getVirtualChestID() { |
||||
return virtualChestID; |
||||
} |
||||
|
||||
public Timestamp getCreated() { |
||||
return created; |
||||
} |
||||
} |
||||
@ -0,0 +1,76 @@ |
||||
package xyz.soukup.ecoCraftCore.objects; |
||||
|
||||
import com.j256.ormlite.field.DatabaseField; |
||||
import com.j256.ormlite.table.DatabaseTable; |
||||
|
||||
import java.sql.Timestamp; |
||||
|
||||
@DatabaseTable(tableName = "transactions") |
||||
public class Transaction { |
||||
|
||||
@DatabaseField(generatedId = true) |
||||
private long id; |
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private double amount; |
||||
|
||||
@DatabaseField(canBeNull = false, columnName = "sender_type") |
||||
private String senderType; |
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private String sender; |
||||
|
||||
@DatabaseField(canBeNull = false, columnName = "receiver_type") |
||||
private String receiverType; |
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private String receiver; |
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private String type; |
||||
|
||||
@DatabaseField(columnName = "primary_info") |
||||
private String primaryInfo; |
||||
|
||||
@DatabaseField(columnName = "secondary_info") |
||||
private String secondaryInfo; |
||||
|
||||
@DatabaseField(canBeNull = false) |
||||
private Timestamp timestamp = new Timestamp(System.currentTimeMillis()); |
||||
|
||||
|
||||
public Transaction() { |
||||
// ORMLite requires a no-arg constructor
|
||||
} |
||||
|
||||
public Transaction(double amount, String senderType, String sender, String receiverType, String receiver, String type) { |
||||
this.amount = amount; |
||||
this.senderType = senderType; |
||||
this.sender = sender; |
||||
this.receiverType = receiverType; |
||||
this.receiver = receiver; |
||||
this.type = type; |
||||
} |
||||
|
||||
public Transaction(double amount, String senderType, String sender, String receiverType, String receiver, String type, String primaryInfo) { |
||||
this(amount, senderType, sender, receiverType, receiver, type); |
||||
this.primaryInfo = primaryInfo; |
||||
} |
||||
|
||||
public Transaction(double amount, String senderType, String sender, String receiverType, String receiver, String type, String primaryInfo, String secondaryInfo) { |
||||
this(amount, senderType, sender, receiverType, receiver, type, primaryInfo); |
||||
this.secondaryInfo = secondaryInfo; |
||||
} |
||||
|
||||
// Getters
|
||||
public long getId() { return id; } |
||||
public Timestamp getTimestamp() { return timestamp; } |
||||
public double getAmount() { return amount; } |
||||
public String getSenderType() { return senderType; } |
||||
public String getSender() { return sender; } |
||||
public String getReceiverType() { return receiverType; } |
||||
public String getReceiver() { return receiver; } |
||||
public String getType() { return type; } |
||||
public String getPrimaryInfo() { return primaryInfo; } |
||||
public String getSecondaryInfo() { return secondaryInfo; } |
||||
} |
||||
@ -0,0 +1,20 @@ |
||||
package xyz.soukup.ecoCraftCore.objects; |
||||
|
||||
import com.j256.ormlite.field.DataType; |
||||
import com.j256.ormlite.field.DatabaseField; |
||||
import com.j256.ormlite.table.DatabaseTable; |
||||
import org.bukkit.inventory.ItemStack; |
||||
|
||||
@DatabaseTable(tableName = "virtual_chests") |
||||
public class VirtualChest { |
||||
|
||||
@DatabaseField(generatedId = true) |
||||
private long id; |
||||
|
||||
@DatabaseField |
||||
private String type; |
||||
|
||||
@DatabaseField(dataType = DataType.SERIALIZABLE, columnName = "data") |
||||
private ItemStack[] itemStacks; |
||||
|
||||
} |
||||
@ -0,0 +1,37 @@ |
||||
package xyz.soukup.ecoCraftCore.utilities; |
||||
|
||||
import com.j256.ormlite.dao.Dao; |
||||
import xyz.soukup.ecoCraftCore.objects.Shop; |
||||
import xyz.soukup.ecoCraftCore.objects.Transaction; |
||||
import xyz.soukup.ecoCraftCore.objects.VirtualChest; |
||||
|
||||
public class DaoRegistry { |
||||
private static Dao<Shop, Integer> shopDao; |
||||
private static Dao<Transaction, Integer> transactionDao; |
||||
private static Dao<VirtualChest, Integer> virtualChestDao; |
||||
|
||||
|
||||
public static Dao<Shop, Integer> getShopDao() { |
||||
return shopDao; |
||||
} |
||||
|
||||
public static void setShopDao(Dao<Shop, Integer> shopDao) { |
||||
DaoRegistry.shopDao = shopDao; |
||||
} |
||||
|
||||
public static Dao<Transaction, Integer> getTransactionDao() { |
||||
return transactionDao; |
||||
} |
||||
|
||||
public static void setTransactionDao(Dao<Transaction, Integer> transactionDao) { |
||||
DaoRegistry.transactionDao = transactionDao; |
||||
} |
||||
|
||||
public static Dao<VirtualChest, Integer> getVirtualChestDao() { |
||||
return virtualChestDao; |
||||
} |
||||
|
||||
public static void setVirtualChestDao(Dao<VirtualChest, Integer> virtualChestDao) { |
||||
DaoRegistry.virtualChestDao = virtualChestDao; |
||||
} |
||||
} |
||||
@ -0,0 +1,36 @@ |
||||
package xyz.soukup.ecoCraftCore.utilities; |
||||
|
||||
import com.google.common.reflect.TypeToken; |
||||
import com.google.gson.Gson; |
||||
import org.bukkit.inventory.ItemStack; |
||||
|
||||
import java.lang.reflect.Type; |
||||
import java.util.Map; |
||||
|
||||
|
||||
public class JSONConverter { |
||||
|
||||
public static String itemStackToJson(ItemStack item) { |
||||
try { |
||||
Map<String, Object> map = item.serialize(); |
||||
return new Gson().toJson(map); // or use your JSON library of choice
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public static ItemStack itemStackFromJson(String json) { |
||||
try { |
||||
Type type = new TypeToken<Map<String, Object>>() {}.getType(); |
||||
Map<String, Object> map = new Gson().fromJson(json, type); |
||||
return ItemStack.deserialize(map); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,45 @@ |
||||
package xyz.soukup.ecoCraftCore.utilities; |
||||
|
||||
import org.bukkit.NamespacedKey; |
||||
import org.bukkit.inventory.ItemStack; |
||||
import org.bukkit.inventory.meta.ItemMeta; |
||||
import org.bukkit.persistence.PersistentDataContainer; |
||||
import org.bukkit.persistence.PersistentDataType; |
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"}) |
||||
public class PDC { |
||||
public static ItemStack setItemStackString(ItemStack itemStack, String key, String value){ |
||||
return setItemStack(itemStack, key, value, PersistentDataType.STRING); |
||||
} |
||||
public static ItemStack setItemStackBoolean(ItemStack itemStack, String key, Boolean value){ |
||||
return setItemStack(itemStack, key, value, PersistentDataType.BOOLEAN); |
||||
} |
||||
|
||||
public static Boolean retrieveBooleanFromItemStack(ItemStack itemStack, String key){ |
||||
return (Boolean) retrieveFromItemStack(itemStack, key, PersistentDataType.BOOLEAN); |
||||
} |
||||
|
||||
public static String retrieveStringFromItemStack(ItemStack itemStack, String key){ |
||||
return (String) retrieveFromItemStack(itemStack, key, PersistentDataType.STRING); |
||||
} |
||||
|
||||
private static Object retrieveFromItemStack(ItemStack itemStack, String key, PersistentDataType persistentDataType){ |
||||
ItemMeta itemMeta = itemStack.getItemMeta(); |
||||
PersistentDataContainer persistentDataContainer = itemMeta.getPersistentDataContainer(); |
||||
|
||||
NamespacedKey namespacedKey = new NamespacedKey("ecc", key); |
||||
|
||||
return persistentDataContainer.get(namespacedKey, persistentDataType); |
||||
} |
||||
|
||||
private static ItemStack setItemStack(ItemStack itemStack, String key, Object value, PersistentDataType persistentDataType){ |
||||
ItemMeta itemMeta = itemStack.getItemMeta(); |
||||
PersistentDataContainer persistentDataContainer = itemMeta.getPersistentDataContainer(); |
||||
|
||||
NamespacedKey namespacedKey = new NamespacedKey("ecc", key); |
||||
persistentDataContainer.set(namespacedKey, persistentDataType, value); |
||||
itemStack.setItemMeta(itemMeta); |
||||
|
||||
return itemStack; |
||||
} |
||||
} |
||||
@ -0,0 +1,4 @@ |
||||
name: EcoCraftCore |
||||
version: '1.0-SNAPSHOT' |
||||
main: xyz.soukup.ecoCraftCore.EcoCraftCore |
||||
api-version: '1.21' |
||||
Loading…
Reference in new issue