mirror of
https://github.com/songoda/EpicHoppers.git
synced 2025-01-07 16:37:58 +01:00
Enhanced Module API.
This commit is contained in:
parent
57b734f09a
commit
aa9d8d8d21
@ -2,7 +2,9 @@ package com.songoda.epichoppers.api.hopper.levels.modules;
|
||||
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -12,6 +14,10 @@ public interface Module {
|
||||
|
||||
void run(Hopper hopper, Inventory hopperInventory);
|
||||
|
||||
ItemStack getGUIButton(Hopper hopper);
|
||||
|
||||
void runButtonPress(Player player, Hopper hopper);
|
||||
|
||||
List<Material> getBlockedItems(Hopper hopper);
|
||||
|
||||
String getDescription();
|
||||
|
@ -295,11 +295,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
}
|
||||
|
||||
private void loadLevelManager() {
|
||||
File folder = getDataFolder();
|
||||
File voucherFile = new File(folder, "levels.yml");
|
||||
if (!voucherFile.exists()) {
|
||||
saveResource("levels.yml", true);
|
||||
}
|
||||
saveResource("levels.yml", false);
|
||||
|
||||
// Load an instance of LevelManager
|
||||
levelManager = new ELevelManager();
|
||||
|
@ -16,10 +16,10 @@ public class GUICrafting extends AbstractGUI {
|
||||
private final EpicHoppersPlugin plugin;
|
||||
private final EHopper hopper;
|
||||
|
||||
public GUICrafting(EpicHoppersPlugin plugin, EHopper hopper, Player player) {
|
||||
public GUICrafting(EpicHoppersPlugin plugin, Hopper hopper, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.hopper = hopper;
|
||||
this.hopper = (EHopper)hopper;
|
||||
|
||||
init(Methods.formatText(Methods.formatName(hopper.getLevel().getLevel(), false) + " &8-&f Crafting"), 27);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.CostType;
|
||||
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.Module;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import com.songoda.epichoppers.player.SyncType;
|
||||
@ -20,6 +21,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GUIOverview extends AbstractGUI {
|
||||
|
||||
@ -68,39 +70,6 @@ public class GUIOverview extends AbstractGUI {
|
||||
filtermeta.setLore(lorefilter);
|
||||
filter.setItemMeta(filtermeta);
|
||||
|
||||
ItemStack crafting = new ItemStack(Material.CRAFTING_TABLE, 1);
|
||||
ItemMeta craftingmeta = crafting.getItemMeta();
|
||||
craftingmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.craftingtitle"));
|
||||
ArrayList<String> lorecrafting = new ArrayList<>();
|
||||
parts = plugin.getLocale().getMessage("interface.hopper.craftinglore").split("\\|");
|
||||
for (String line : parts) {
|
||||
lorecrafting.add(Methods.formatText(line));
|
||||
}
|
||||
craftingmeta.setLore(lorecrafting);
|
||||
crafting.setItemMeta(craftingmeta);
|
||||
|
||||
ItemStack sell = new ItemStack(Material.SUNFLOWER, 1);
|
||||
ItemMeta sellmeta = sell.getItemMeta();
|
||||
sellmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.selltitle"));
|
||||
ArrayList<String> loresell = new ArrayList<>();
|
||||
parts = plugin.getLocale().getMessage("interface.hopper.selllore", hopper.getAutoSellTimer() == -9999 ? "\u221E" : (int) Math.floor(hopper.getAutoSellTimer() / 20)).split("\\|");
|
||||
for (String line : parts) {
|
||||
loresell.add(Methods.formatText(line));
|
||||
}
|
||||
sellmeta.setLore(loresell);
|
||||
sell.setItemMeta(sellmeta);
|
||||
|
||||
ItemStack block = new ItemStack(Material.IRON_ORE, 1);
|
||||
ItemMeta blockmeta = block.getItemMeta();
|
||||
blockmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.blocktitle"));
|
||||
ArrayList<String> loreblock = new ArrayList<>();
|
||||
parts = plugin.getLocale().getMessage("interface.hopper.blocklore", hopper.isAutoBreaking() ? plugin.getLocale().getMessage("general.word.enabled") : plugin.getLocale().getMessage("general.word.disabled")).split("\\|");
|
||||
for (String line : parts) {
|
||||
loreblock.add(Methods.formatText(line));
|
||||
}
|
||||
blockmeta.setLore(loreblock);
|
||||
block.setItemMeta(blockmeta);
|
||||
|
||||
|
||||
ItemStack item = new ItemStack(Material.HOPPER, 1);
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
@ -172,19 +141,20 @@ public class GUIOverview extends AbstractGUI {
|
||||
layouts.put(4, new Integer[]{23, 3, 5, 21});
|
||||
layouts.put(5, new Integer[]{23, 3, 5, 21, 22});
|
||||
layouts.put(6, new Integer[]{23, 3, 4, 5, 21, 22});
|
||||
layouts.put(7, new Integer[]{23, 3, 4, 5, 21, 22, 12});
|
||||
layouts.put(8, new Integer[]{23, 3, 4, 5, 21, 22, 12, 14});
|
||||
|
||||
int amount = 1;
|
||||
|
||||
boolean canFilter = level.isFilter() || player.hasPermission("EpicHoppers.Filter");
|
||||
boolean canTeleport = level.isTeleport() || player.hasPermission("EpicHoppers.Teleport");
|
||||
boolean canCraft = level.getRegisteredModules().removeIf(e -> e.getName().equals("AutoCrafting"));
|
||||
boolean canAutoSell = level.getAutoSell() != 0;
|
||||
boolean canBreak = level.getRegisteredModules().removeIf(e -> e.getName().equals("BlockBreak"));
|
||||
if (canFilter) amount++;
|
||||
if (canTeleport) amount++;
|
||||
if (canAutoSell) amount++;
|
||||
if (canCraft) amount++;
|
||||
if (canBreak) amount++;
|
||||
|
||||
List<Module> modules = level.getRegisteredModules().stream().filter(module ->
|
||||
module.getGUIButton(hopper) != null).collect(Collectors.toList());
|
||||
|
||||
amount += modules.size();
|
||||
|
||||
Integer[] layout = layouts.get(amount);
|
||||
|
||||
@ -199,15 +169,11 @@ public class GUIOverview extends AbstractGUI {
|
||||
} else if (canFilter) {
|
||||
inventory.setItem(slot, filter);
|
||||
canFilter = false;
|
||||
} else if (canCraft) {
|
||||
inventory.setItem(slot, crafting);
|
||||
canCraft = false;
|
||||
} else if (canAutoSell) {
|
||||
inventory.setItem(slot, sell);
|
||||
canAutoSell = false;
|
||||
} else if (canBreak) {
|
||||
inventory.setItem(slot, block);
|
||||
canBreak = false;
|
||||
} else {
|
||||
if (modules.isEmpty()) break;
|
||||
Module module = modules.get(0);
|
||||
modules.remove(module);
|
||||
inventory.setItem(slot, module.getGUIButton(hopper));
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,21 +230,14 @@ public class GUIOverview extends AbstractGUI {
|
||||
}));
|
||||
|
||||
registerClickable(3, 23, ((player, inventory, cursor, slot, type) -> {
|
||||
if (inventory.getItem(slot).getItemMeta()
|
||||
.getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.selltitle"))) {
|
||||
if (hopper.getAutoSellTimer() == -9999) {
|
||||
hopper.setAutoSellTimer(0);
|
||||
} else {
|
||||
hopper.setAutoSellTimer(-9999);
|
||||
}
|
||||
for (Module module : hopper.getLevel().getRegisteredModules()) {
|
||||
if (module.getGUIButton(hopper) != null && !module.getGUIButton(hopper).getItemMeta()
|
||||
.getDisplayName().equalsIgnoreCase(inventory.getItem(slot).getItemMeta().getDisplayName()))
|
||||
continue;
|
||||
|
||||
} else if (inventory.getItem(slot).getItemMeta()
|
||||
.getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.craftingtitle"))) {
|
||||
new GUICrafting(plugin, hopper, player);
|
||||
} else if (inventory.getItem(slot).getItemMeta()
|
||||
.getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.blocktitle"))) {
|
||||
hopper.toggleAutoBreaking();
|
||||
} else if (inventory.getItem(slot).getItemMeta()
|
||||
module.runButtonPress(player, hopper);
|
||||
}
|
||||
if (inventory.getItem(slot).getItemMeta()
|
||||
.getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.filtertitle"))) {
|
||||
new GUIFilter(plugin, hopper, player);
|
||||
} else if (inventory.getItem(slot).getItemMeta()
|
||||
|
@ -26,19 +26,27 @@ public class ELevel implements Level {
|
||||
this.autoSell = autoSell;
|
||||
this.registeredModules = registeredModules;
|
||||
|
||||
buildDescription();
|
||||
|
||||
}
|
||||
|
||||
public void buildDescription() {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
|
||||
description.clear();
|
||||
|
||||
description.add(instance.getLocale().getMessage("interface.hopper.range", range));
|
||||
description.add(instance.getLocale().getMessage("interface.hopper.amount", amount));
|
||||
if (linkAmount != 1)
|
||||
description.add(instance.getLocale().getMessage("interface.hopper.linkamount", linkAmount));
|
||||
if (filter) description.add(instance.getLocale().getMessage("interface.hopper.filter", EpicHoppersPlugin.getInstance().getLocale().getMessage("general.word.enabled")));
|
||||
if (teleport) description.add(instance.getLocale().getMessage("interface.hopper.teleport", EpicHoppersPlugin.getInstance().getLocale().getMessage("general.word.enabled")));
|
||||
if (filter)
|
||||
description.add(instance.getLocale().getMessage("interface.hopper.filter", EpicHoppersPlugin.getInstance().getLocale().getMessage("general.word.enabled")));
|
||||
if (teleport)
|
||||
description.add(instance.getLocale().getMessage("interface.hopper.teleport", EpicHoppersPlugin.getInstance().getLocale().getMessage("general.word.enabled")));
|
||||
|
||||
for (Module module : registeredModules) {
|
||||
description.add(module.getDescription());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -99,6 +107,7 @@ public class ELevel implements Level {
|
||||
@Override
|
||||
public void addModule(Module module) {
|
||||
registeredModules.add(module);
|
||||
buildDescription();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,10 +3,14 @@ package com.songoda.epichoppers.hopper.levels.modules;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.Module;
|
||||
import com.songoda.epichoppers.gui.GUICrafting;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -98,6 +102,26 @@ public class ModuleAutoCrafting implements Module {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getGUIButton(Hopper hopper) {
|
||||
ItemStack crafting = new ItemStack(Material.CRAFTING_TABLE, 1);
|
||||
ItemMeta craftingmeta = crafting.getItemMeta();
|
||||
craftingmeta.setDisplayName(EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.craftingtitle"));
|
||||
ArrayList<String> lorecrafting = new ArrayList<>();
|
||||
String[] parts = EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.craftinglore").split("\\|");
|
||||
for (String line : parts) {
|
||||
lorecrafting.add(Methods.formatText(line));
|
||||
}
|
||||
craftingmeta.setLore(lorecrafting);
|
||||
crafting.setItemMeta(craftingmeta);
|
||||
return crafting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runButtonPress(Player player, Hopper hopper) {
|
||||
new GUICrafting(EpicHoppersPlugin.getInstance(), hopper, player);
|
||||
}
|
||||
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
List<Material> materials = new ArrayList<>();
|
||||
if (hopper.getAutoCrafting() != null) {
|
||||
|
@ -4,13 +4,17 @@ import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.Module;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleAutoSell implements Module {
|
||||
@ -65,6 +69,32 @@ public class ModuleAutoSell implements Module {
|
||||
((EHopper) hopper).setAutoSellTimer(((EHopper) hopper).getAutoSellTimer() - hopperTickRate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getGUIButton(Hopper hopper) {
|
||||
EHopper eHopper = (EHopper)hopper;
|
||||
ItemStack sell = new ItemStack(Material.SUNFLOWER, 1);
|
||||
ItemMeta sellmeta = sell.getItemMeta();
|
||||
sellmeta.setDisplayName(EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.selltitle"));
|
||||
ArrayList<String> loresell = new ArrayList<>();
|
||||
String[] parts = EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.selllore", eHopper.getAutoSellTimer() == -9999 ? "\u221E" : (int) Math.floor(eHopper.getAutoSellTimer() / 20)).split("\\|");
|
||||
for (String line : parts) {
|
||||
loresell.add(Methods.formatText(line));
|
||||
}
|
||||
sellmeta.setLore(loresell);
|
||||
sell.setItemMeta(sellmeta);
|
||||
return sell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runButtonPress(Player player, Hopper hopper) {
|
||||
EHopper eHopper = (EHopper)hopper;
|
||||
if (eHopper.getAutoSellTimer() == -9999) {
|
||||
eHopper.setAutoSellTimer(0);
|
||||
} else {
|
||||
eHopper.setAutoSellTimer(-9999);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
return null;
|
||||
|
@ -4,13 +4,18 @@ import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.Module;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -61,6 +66,28 @@ public class ModuleBlockBreak implements Module {
|
||||
blockTick.remove(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getGUIButton(Hopper hopper) {
|
||||
ItemStack block = new ItemStack(Material.IRON_ORE, 1);
|
||||
ItemMeta blockmeta = block.getItemMeta();
|
||||
blockmeta.setDisplayName(EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.blocktitle"));
|
||||
ArrayList<String> loreblock = new ArrayList<>();
|
||||
String[] parts = EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.blocklore",
|
||||
((EHopper)hopper).isAutoBreaking() ? EpicHoppersPlugin.getInstance().getLocale().getMessage("general.word.enabled")
|
||||
: EpicHoppersPlugin.getInstance().getLocale().getMessage("general.word.disabled")).split("\\|");
|
||||
for (String line : parts) {
|
||||
loreblock.add(Methods.formatText(line));
|
||||
}
|
||||
blockmeta.setLore(loreblock);
|
||||
block.setItemMeta(blockmeta);
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runButtonPress(Player player, Hopper hopper) {
|
||||
((EHopper)hopper).toggleAutoBreaking();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
return null;
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
@ -100,6 +101,16 @@ public class ModuleSuction implements Module {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getGUIButton(Hopper hopper) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runButtonPress(Player player, Hopper hopper) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user