mirror of
https://github.com/songoda/EpicHoppers.git
synced 2025-01-25 00:51:26 +01:00
Added an autosell feature.
This commit is contained in:
parent
31c915f4d4
commit
0afbb26338
@ -51,6 +51,8 @@ public interface Level {
|
||||
boolean isTeleport();
|
||||
|
||||
|
||||
int getAutoSell();
|
||||
|
||||
int getLinkAmount();
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@ public interface LevelManager {
|
||||
* @param filter Whether or not access to the filter is allowed.
|
||||
* @param teleport Whether or not teleporting through hoppers is allowed.
|
||||
*/
|
||||
void addLevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, int linkAmount, ArrayList<Module> modules);
|
||||
void addLevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, int linkAmount, int autoSell, ArrayList<Module> modules);
|
||||
|
||||
/**
|
||||
* Get {@link Level} by corresponding integer value.
|
||||
|
@ -23,6 +23,7 @@ import com.songoda.epichoppers.hopper.EHopper;
|
||||
import com.songoda.epichoppers.hopper.EHopperManager;
|
||||
import com.songoda.epichoppers.hopper.levels.ELevelManager;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoSell;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.ModuleBlockBreak;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.ModuleSuction;
|
||||
import com.songoda.epichoppers.listeners.*;
|
||||
@ -168,6 +169,8 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
List<ItemStack> blackList = row.get("blacklist").asItemStackList();
|
||||
List<ItemStack> voidList = row.get("void").asItemStackList();
|
||||
|
||||
int autoSell = row.get("autosell").asInt();
|
||||
|
||||
Material autoCrafting = Material.valueOf(row.get("autocrafting").asString() == null ? "AIR" : row.get("autocrafting").asString());
|
||||
|
||||
String blackLoc = row.get("black").asString();
|
||||
@ -350,6 +353,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
boolean teleport = levels.getBoolean("Teleport");
|
||||
int costExperiance = levels.getInt("Cost-xp", -1);
|
||||
int costEconomy = levels.getInt("Cost-eco", -1);
|
||||
int autoSell = levels.getInt("AutoSell");
|
||||
|
||||
ArrayList<Module> modules = new ArrayList<>();
|
||||
|
||||
@ -360,10 +364,12 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
modules.add(new ModuleBlockBreak(levels.getInt("BlockBreak")));
|
||||
} else if (key.equals("AutoCrafting")) {
|
||||
modules.add(new ModuleAutoCrafting());
|
||||
} else if (key.equals("AutoSell")) {
|
||||
modules.add(new ModuleAutoSell(autoSell));
|
||||
}
|
||||
|
||||
}
|
||||
levelManager.addLevel(level, costExperiance, costEconomy, radius, amount, filter, teleport, linkAmount, modules);
|
||||
levelManager.addLevel(level, costExperiance, costEconomy, radius, amount, filter, teleport, linkAmount, autoSell, modules);
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,6 +419,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
levels.set("Level-6.BlockBreak", 2);
|
||||
levels.set("Level-6.Filter", true);
|
||||
levels.set("Level-6.Teleport", true);
|
||||
levels.set("Level-6.AutoSell", 60);
|
||||
levels.set("Level-6.Link-amount", 3);
|
||||
levels.set("Level-6.Cost-xp", 45);
|
||||
levels.set("Level-6.Cost-eco", 20000);
|
||||
@ -423,6 +430,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
levels.set("Level-7.BlockBreak", 2);
|
||||
levels.set("Level-7.Filter", true);
|
||||
levels.set("Level-7.Teleport", true);
|
||||
levels.set("Level-7.AutoSell", 30);
|
||||
levels.set("Level-7.AutoCrafting", true);
|
||||
levels.set("Level-7.Link-amount", 4);
|
||||
levels.set("Level-7.Cost-xp", 50);
|
||||
|
@ -19,10 +19,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/14/2017.
|
||||
@ -38,6 +35,7 @@ public class EHopper implements Hopper {
|
||||
private TeleportTrigger teleportTrigger;
|
||||
private Material autoCrafting;
|
||||
private org.bukkit.block.Hopper hopper;
|
||||
private int autoSellTimer = 0;
|
||||
|
||||
public EHopper(Location location, Level level, UUID lastPlayer, UUID placedBy, List<Location> linkedBlocks, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) {
|
||||
this.location = location;
|
||||
@ -110,6 +108,17 @@ public class EHopper implements Hopper {
|
||||
craftingmeta.setLore(lorecrafting);
|
||||
crafting.setItemMeta(craftingmeta);
|
||||
|
||||
ItemStack sell = new ItemStack(Material.SUNFLOWER, 1);
|
||||
ItemMeta sellmeta = sell.getItemMeta();
|
||||
sellmeta.setDisplayName(instance.getLocale().getMessage("interface.hopper.selltitle"));
|
||||
ArrayList<String> loresell = new ArrayList<>();
|
||||
parts = instance.getLocale().getMessage("interface.hopper.selllore", autoSellTimer == -9999 ? "\u221E" : Math.floor(autoSellTimer / 20)).split("\\|");
|
||||
for (String line : parts) {
|
||||
loresell.add(Methods.formatText(line));
|
||||
}
|
||||
sellmeta.setLore(loresell);
|
||||
sell.setItemMeta(sellmeta);
|
||||
|
||||
|
||||
ItemStack item = new ItemStack(Material.HOPPER, 1);
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
@ -174,24 +183,46 @@ public class EHopper implements Hopper {
|
||||
nu++;
|
||||
}
|
||||
|
||||
Map<Integer, Integer[]> layouts = new HashMap<>();
|
||||
layouts.put(1, new Integer[]{22});
|
||||
layouts.put(2, new Integer[]{22, 4});
|
||||
layouts.put(3, new Integer[]{22, 3, 5});
|
||||
layouts.put(4, new Integer[]{23, 3, 5, 21});
|
||||
layouts.put(5, new Integer[]{23, 3, 5, 21, 22});
|
||||
|
||||
int amount = 1;
|
||||
|
||||
boolean canFilter = level.isFilter() || player.hasPermission("EpicHoppers.Filter");
|
||||
boolean canTeleport = level.isTeleport() || player.hasPermission("EpicHoppers.Teleport");
|
||||
if (!canFilter && canTeleport)
|
||||
i.setItem(4, perl);
|
||||
else if (!canTeleport && canFilter)
|
||||
i.setItem(4, filter);
|
||||
else if (canFilter) {
|
||||
i.setItem(3, perl);
|
||||
i.setItem(5, filter);
|
||||
boolean canCraft = level.getRegisteredModules().removeIf(e -> e.getName().equals("AutoCrafting"));
|
||||
boolean canAutoSell = level.getAutoSell() != 0;
|
||||
if (canFilter) amount ++;
|
||||
if (canTeleport) amount ++;
|
||||
if (canAutoSell) amount ++;
|
||||
if (canCraft) amount ++;
|
||||
|
||||
Integer[] layout = layouts.get(amount);
|
||||
|
||||
for (int ii = 0; ii < amount; ii ++) {
|
||||
int slot = layout[ii];
|
||||
|
||||
if (ii == 0) {
|
||||
i.setItem(slot, hook);
|
||||
} else if (canTeleport) {
|
||||
i.setItem(slot, perl);
|
||||
canTeleport = false;
|
||||
} else if (canFilter) {
|
||||
i.setItem(slot, filter);
|
||||
canFilter = false;
|
||||
} else if (canCraft) {
|
||||
i.setItem(slot, crafting);
|
||||
canCraft = false;
|
||||
} else if (canAutoSell) {
|
||||
i.setItem(slot, sell);
|
||||
canAutoSell = false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean canCraft = level.getRegisteredModules().removeIf(e -> e.getName().equals("AutoCrafting"));
|
||||
if (!canCraft)
|
||||
i.setItem(22, hook);
|
||||
else if (canFilter) {
|
||||
i.setItem(23, hook);
|
||||
i.setItem(21, crafting);
|
||||
}
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Upgrade With XP") && player.hasPermission("EpicHoppers.Upgrade.XP") && level.getCostExperience() != -1) {
|
||||
i.setItem(11, itemXP);
|
||||
@ -637,6 +668,14 @@ public class EHopper implements Hopper {
|
||||
return teleportTrigger;
|
||||
}
|
||||
|
||||
public int getAutoSellTimer() {
|
||||
return autoSellTimer;
|
||||
}
|
||||
|
||||
public void setAutoSellTimer(int autoSellTimer) {
|
||||
this.autoSellTimer = autoSellTimer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTeleportTrigger(TeleportTrigger teleportTrigger) {
|
||||
this.teleportTrigger = teleportTrigger;
|
||||
|
@ -11,13 +11,13 @@ public class ELevel implements Level {
|
||||
|
||||
private final ArrayList<Module> registeredModules;
|
||||
|
||||
private int level, costExperience, costEconomy, range, amount, linkAmount;
|
||||
private int level, costExperience, costEconomy, range, amount, linkAmount, autoSell;
|
||||
|
||||
private boolean filter, teleport;
|
||||
|
||||
private final List<String> description = new ArrayList<>();
|
||||
|
||||
ELevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, int linkAmount, ArrayList<Module> registeredModules) {
|
||||
ELevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, int linkAmount, int autoSell, ArrayList<Module> registeredModules) {
|
||||
this.level = level;
|
||||
this.costExperience = costExperience;
|
||||
this.costEconomy = costEconomy;
|
||||
@ -26,6 +26,7 @@ public class ELevel implements Level {
|
||||
this.filter = filter;
|
||||
this.teleport = teleport;
|
||||
this.linkAmount = linkAmount;
|
||||
this.autoSell = autoSell;
|
||||
this.registeredModules = registeredModules;
|
||||
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
@ -35,6 +36,7 @@ public class ELevel implements Level {
|
||||
if (linkAmount != 1) description.add(instance.getLocale().getMessage("interface.hopper.linkamount", linkAmount));
|
||||
if (filter) description.add(instance.getLocale().getMessage("interface.hopper.filter", true));
|
||||
if (teleport) description.add(instance.getLocale().getMessage("interface.hopper.teleport", true));
|
||||
if (autoSell != 0) description.add(instance.getLocale().getMessage("interface.hopper.autosell", autoSell));
|
||||
|
||||
for (Module module : registeredModules) {
|
||||
description.add(module.getDescription());
|
||||
@ -67,6 +69,11 @@ public class ELevel implements Level {
|
||||
return teleport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAutoSell() {
|
||||
return autoSell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLinkAmount() {
|
||||
return linkAmount;
|
||||
|
@ -11,8 +11,8 @@ public class ELevelManager implements LevelManager {
|
||||
private final NavigableMap<Integer, ELevel> registeredLevels = new TreeMap<>();
|
||||
|
||||
@Override
|
||||
public void addLevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, int linkAmount, ArrayList<Module> modules) {
|
||||
registeredLevels.put(level, new ELevel(level, costExperience, costEconomy, range, amount, filter, teleport, linkAmount, modules));
|
||||
public void addLevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, int linkAmount, int autoSell, ArrayList<Module> modules) {
|
||||
registeredLevels.put(level, new ELevel(level, costExperience, costEconomy, range, amount, filter, teleport, linkAmount, autoSell, modules));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,80 @@
|
||||
package com.songoda.epichoppers.hopper.levels.modules;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.EpicHoppers;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.Module;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModuleAutoSell implements Module {
|
||||
|
||||
private int timeOut;
|
||||
private int hopperTickRate;
|
||||
|
||||
public ModuleAutoSell(int timeOut) {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
this.timeOut = timeOut * 20;
|
||||
this.hopperTickRate = (int)instance.getConfig().getLong("Main.Amount of Ticks Between Hops");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "AutoSell";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Hopper hopper) {
|
||||
org.bukkit.block.Hopper hopperBlock = hopper.getHopper();
|
||||
if (hopperBlock == null || hopperBlock.getInventory() == null) return;
|
||||
|
||||
if (((EHopper)hopper).getAutoSellTimer() == -9999) return;
|
||||
|
||||
if (((EHopper)hopper).getAutoSellTimer() <= 0) {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
|
||||
if (instance.getServer().getPluginManager().getPlugin("Vault") == null) return;
|
||||
RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
|
||||
List<String> list = (List<String>)EpicHoppersPlugin.getInstance().getConfig().getList("Main.AutoSell Prices");
|
||||
|
||||
for (String line : list) {
|
||||
try {
|
||||
String[] split = line.split(",");
|
||||
|
||||
Material material = Material.valueOf(split[0]);
|
||||
double price = Double.valueOf(split[1]);
|
||||
|
||||
for (ItemStack itemStack : hopperBlock.getInventory().getContents()) {
|
||||
if (itemStack.getType() == material) {
|
||||
econ.depositPlayer(Bukkit.getOfflinePlayer(hopper.getPlacedBy()), price * itemStack.getAmount());
|
||||
}
|
||||
hopperBlock.getInventory().removeItem(itemStack);
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
((EHopper)hopper).setAutoSellTimer(timeOut);
|
||||
}
|
||||
((EHopper)hopper).setAutoSellTimer(((EHopper)hopper).getAutoSellTimer() - hopperTickRate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.autosell", timeOut);
|
||||
}
|
||||
}
|
@ -116,6 +116,13 @@ public class InventoryListeners implements Listener {
|
||||
}
|
||||
} else if (event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.craftingtitle"))) {
|
||||
((EHopper) hopper).crafting(player);
|
||||
} else if (event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.selltitle"))) {
|
||||
if (((EHopper)hopper).getAutoSellTimer() == -9999) {
|
||||
((EHopper)hopper).setAutoSellTimer(0);
|
||||
} else {
|
||||
((EHopper)hopper).setAutoSellTimer(-9999);
|
||||
}
|
||||
((EHopper) hopper).overview(player);
|
||||
} else if (event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.synchopper"))) {
|
||||
if (event.isRightClick()) {
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.desync"));
|
||||
|
@ -188,6 +188,8 @@ public class SettingsManager implements Listener {
|
||||
SOUNDS("Main.Sounds Enabled", true),
|
||||
BLOCKBREAK_PARTICLE("Main.BlockBreak Particle Type", "LAVA"),
|
||||
BLACKLIST("Main.BlockBreak Blacklisted Blocks", Arrays.asList("BEDROCK")),
|
||||
AUTOSELL_PRICES("Main.AutoSell Prices", Arrays.asList("STONE,0.50", "COBBLESTONE,0.20", "IRON_ORE,0.35", "COAL_ORE,0.20")),
|
||||
|
||||
RAINBOW("Interfaces.Replace Glass Type 1 With Rainbow Glass", false),
|
||||
ECO_ICON("Interfaces.Economy Icon", "SUNFLOWER"),
|
||||
XP_ICON("Interfaces.XP Icon", "EXPERIENCE_BOTTLE"),
|
||||
|
@ -22,6 +22,7 @@ interface.hopper.teleport = "&7Teleport: &6%enabled%"
|
||||
interface.hopper.filter = "&7Filter: &6%enabled%"
|
||||
interface.hopper.crafting = "&7AutoCrafting: &6%enabled%"
|
||||
interface.hopper.suction = "&7Suction: &6%suction%"
|
||||
interface.hopper.autosell = "&7AutoSell: Every &6%seconds%s"
|
||||
interface.hopper.linkamount = "&7Link Overflow: &6%amount%"
|
||||
interface.hopper.blockbreak = "&7Block Break: &6Every %ticks% ticks"
|
||||
interface.hopper.alreadymaxed = "&7This hopper is already maxed out!"
|
||||
@ -30,8 +31,10 @@ interface.hopper.perltitle = "&6Click to Teleport"
|
||||
interface.hopper.perllore2 = "|&7Left-Click to teleport to|&7the end of the chain.||&7Right-Click to switch the|&7teleport trigger mode.|&7Currently set to: &a%type%&7."
|
||||
interface.hopper.filtertitle = "&cClick to Filter"
|
||||
interface.hopper.filterlore = "|&7This allows you to choose|&7which items go where."
|
||||
interface.hopper.craftingtitle = "&cClick to setup AutoCrafting"
|
||||
interface.hopper.craftingtitle = "&cClick to Setup AutoCrafting"
|
||||
interface.hopper.craftinglore = "|&7This allows you to choose|&7which item this hopper|&7will automaticly craft."
|
||||
interface.hopper.selltitle = "&6Click to Toggle AutoSelling"
|
||||
interface.hopper.selllore = "|&7Selling in &6%timeleft%s&7."
|
||||
interface.hopper.synchopper = "&6Click to Link This hopper"
|
||||
interface.hopper.rejectsync = "&6Click to Link Rejected Items"
|
||||
interface.filter.infotitle = "&aFilter Guide"
|
||||
|
Loading…
Reference in New Issue
Block a user