First try at shopgui+ integration.

This commit is contained in:
Brianna 2019-06-04 18:39:13 -04:00
parent 4c0275dc45
commit b0562c7ed1
3 changed files with 27 additions and 13 deletions

View File

@ -103,5 +103,10 @@
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.brcdev</groupId>
<artifactId>ShopGUIPlus</artifactId>
<version>1.19.1</version>
</dependency>
</dependencies>
</project>

View File

@ -5,8 +5,11 @@ import com.songoda.epichoppers.hopper.Hopper;
import com.songoda.epichoppers.tasks.HopTask;
import com.songoda.epichoppers.utils.Methods;
import com.songoda.epichoppers.utils.ServerVersion;
import com.songoda.epichoppers.utils.settings.Setting;
import net.brcdev.shopgui.ShopGuiPlusApi;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -46,23 +49,24 @@ public class ModuleAutoSell implements Module {
List<String> list = instance.getConfig().getStringList("Main.AutoSell Prices");
for (String line : list) {
try {
String[] split = line.split(",");
OfflinePlayer player = Bukkit.getOfflinePlayer(hopper.getPlacedBy());
Material material = Material.valueOf(split[0]);
double price = Double.valueOf(split[1]);
for (ItemStack itemStack : hopperInventory.getContents()) {
if (itemStack == null) continue;
for (ItemStack itemStack : hopperInventory.getContents()) {
if (itemStack == null || itemStack.getType() != material) continue;
double value;
if (Setting.AUTOSELL_SHOPGUIPLUS.getBoolean() && player.isOnline())
value = ShopGuiPlusApi.getItemStackPriceSell(player.getPlayer(), itemStack);
else
value = Double.valueOf(list.stream().filter(line -> Material.valueOf(line.split(",")[0])
== itemStack.getType()).findFirst().orElse("0"));
instance.getEconomy().deposit(Bukkit.getOfflinePlayer(hopper.getPlacedBy()), price * itemStack.getAmount());
hopperInventory.removeItem(itemStack);
if (value == 0) continue;
updateComparators = true;
}
} catch (Exception ignored) {
}
instance.getEconomy().deposit(player, value * itemStack.getAmount());
hopperInventory.removeItem(itemStack);
updateComparators = true;
}
hopper.setAutoSellTimer(timeOut);

View File

@ -58,6 +58,11 @@ public enum Setting {
Arrays.asList("STONE,0.50", "COBBLESTONE,0.20", "IRON_ORE,0.35", "COAL_ORE,0.20"),
"These are the prices used by the auto sell module."),
AUTOSELL_SHOPGUIPLUS("Main.Use ShopGuiPlus for Prices", false,
"Should prices be grabbed from ShopGuiPlus?",
"If ShopGuiPlus is not enabled or the player is offline the default price list will be used.",
"If this is something that you do not want then you should empty the default list."),
VAULT_ECONOMY("Economy.Use Vault Economy", true,
"Should Vault be used?"),