Skip to content

Commit

Permalink
인첸트된 아이템 지원을 위해 데이터 타입을 변경함
Browse files Browse the repository at this point in the history
  • Loading branch information
7sat committed Feb 23, 2022
1 parent 1ff96b7 commit 57b0cc7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>xyz.jpenilla</groupId>
<artifactId>DynamicShop-Graph</artifactId>
<version>0.2.5-custom</version>
<version>0.2.6-custom</version>
<packaging>jar</packaging>

<name>DynamicShop Graph</name>
Expand Down Expand Up @@ -156,7 +156,7 @@
<dependency>
<groupId>com.github.7sat</groupId>
<artifactId>SSDynamicShop</artifactId>
<version>60050cbd4d</version>
<version>f99e33d4e4</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/xyz/jpenilla/dsgraph/DSGraph.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.jpenilla.dsgraph;

import co.aikar.commands.PaperCommandManager;
import org.bukkit.command.ConsoleCommandSender;
import xyz.jpenilla.dsgraph.command.CommandDSGraph;
import xyz.jpenilla.dsgraph.command.CommandHelper;
import xyz.jpenilla.dsgraph.config.Config;
Expand All @@ -22,6 +23,8 @@ public final class DSGraph extends JavaPlugin {
@Setter
private PaperCommandManager commandManager;

public static ConsoleCommandSender console;

@Override
public void onEnable() {
instance = this;
Expand All @@ -40,6 +43,8 @@ public void onEnable() {
int pluginId = 7828;
Metrics metrics = new Metrics(this, pluginId);
metrics.addCustomChart(new Metrics.SimplePie("amount_of_items_tracked", () -> String.valueOf(cfg.getFiles().size())));

console = getServer().getConsoleSender();
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/xyz/jpenilla/dsgraph/ShopListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ public class ShopListener implements Listener {
public void onShop(ShopBuySellEvent e) {
if (DSGraph.getInstance().getTaskManager().getRecordDataTask() != null) {
DSGraph.getInstance().getCfg().getFiles().forEach(stockConfig -> {
if (e.getMaterial().equals(stockConfig.getMaterial()) && e.getShopName().equals(stockConfig.getShopName())) {
DSGraph.getInstance().getTaskManager().getRecordDataTask().queue(stockConfig);
if (e.getItemStack().getType().equals(stockConfig.getMaterial()) && e.getShopName().equals(stockConfig.getShopName()))
{
if(e.getItemStack().getItemMeta().equals(stockConfig.getItemMeta()))
{
DSGraph.getInstance().getTaskManager().getRecordDataTask().queue(stockConfig);
}
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/xyz/jpenilla/dsgraph/config/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.jpenilla.dsgraph.config;

import org.bukkit.inventory.meta.ItemMeta;
import xyz.jpenilla.dsgraph.DSGraph;
import lombok.Getter;
import lombok.experimental.FieldNameConstants;
Expand Down Expand Up @@ -40,8 +41,9 @@ public void load() {
config.getConfigurationSection(Fields.files).getKeys(false).forEach(key -> {
String shopName = config.getString(Fields.files + "." + key + "." + StockConfig.Fields.shopName);
Material material = Material.getMaterial(config.getString(Fields.files + "." + key + "." + StockConfig.Fields.material));
ItemMeta itemMeta = (ItemMeta) config.get(Fields.files + "." + key + ".itemStack");
if (material != null) {
files.add(new StockConfig(shopName, key, material));
files.add(new StockConfig(shopName, key, material, itemMeta));
}
});

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/xyz/jpenilla/dsgraph/config/StockConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;
import org.bukkit.inventory.meta.ItemMeta;
import xyz.jpenilla.dsgraph.DSGraph;
import xyz.jpenilla.dsgraph.StockEntry;
import lombok.Getter;
Expand All @@ -25,14 +26,17 @@ public class StockConfig {
@Getter
private final Material material;
@Getter
private final ItemMeta itemMeta;
@Getter
private final String shopName;
@Getter
private final String path;
public static final String folderPath = DSGraph.getInstance().getDataFolder() + "/web/data/";

public StockConfig(String shopName, String name, Material material) {
public StockConfig(String shopName, String name, Material material, ItemMeta itemMeta) {
this.name = name;
this.material = material;
this.itemMeta = itemMeta;
this.shopName = shopName;
this.path = folderPath + name + ".csv";
}
Expand Down Expand Up @@ -83,7 +87,10 @@ public void update() {
}
}

StockEntry newEntry = new StockEntry(shopName, new ItemStack(material));
ItemStack is = new ItemStack(material);
is.setItemMeta(itemMeta);

StockEntry newEntry = new StockEntry(shopName, is);
if (!newEntry.equals(lastEntry) || DSGraph.getInstance().getCfg().isSaveUnchangedData()) {
try {
CSVWriter writer = new CSVWriter(new FileWriter(path, true));
Expand Down

0 comments on commit 57b0cc7

Please sign in to comment.