Merge branch 'development'

This commit is contained in:
Brianna 2020-10-23 13:14:57 -05:00
commit 575b573b39
8 changed files with 380 additions and 5 deletions

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId>
<artifactId>EpicHoppers</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>4.6.14</version>
<version>4.6.15</version>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>EpicHoppers-${project.version}</finalName>
@ -103,7 +103,7 @@
<dependency>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore</artifactId>
<version>LATEST</version>
<version>2.4.17</version>
<scope>compile</scope>
</dependency>
<dependency>
@ -121,7 +121,7 @@
<dependency>
<groupId>com.songoda</groupId>
<artifactId>EpicFarming</artifactId>
<version>2.3.1</version>
<version>3.0.24</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -28,7 +28,9 @@ import com.songoda.epichoppers.hopper.levels.LevelManager;
import com.songoda.epichoppers.hopper.levels.modules.Module;
import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoSell;
import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoSmelter;
import com.songoda.epichoppers.hopper.levels.modules.ModuleBlockBreak;
import com.songoda.epichoppers.hopper.levels.modules.ModuleMobHopper;
import com.songoda.epichoppers.hopper.levels.modules.ModuleSuction;
import com.songoda.epichoppers.listeners.BlockListeners;
import com.songoda.epichoppers.listeners.EntityListeners;
@ -222,6 +224,10 @@ public class EpicHoppers extends SongodaPlugin {
modules.add(new ModuleAutoCrafting(this));
} else if (key.equals("AutoSell")) {
modules.add(new ModuleAutoSell(this, autoSell));
} else if (key.equals("MobHopper")) {
modules.add(new ModuleMobHopper(this, levels.getInt("MobHopper")));
} else if (key.equals("AutoSmelting")) {
modules.add(new ModuleAutoSmelter(this, levels.getInt("AutoSmelting")));
}
}

View File

@ -0,0 +1,109 @@
package com.songoda.epichoppers.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.utils.TextUtils;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.hopper.Hopper;
import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoSmelter;
import com.songoda.epichoppers.settings.Settings;
import com.songoda.epichoppers.utils.Methods;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class GUISmeltable extends Gui {
private final EpicHoppers plugin;
private final Hopper hopper;
private int maxPages;
private ModuleAutoSmelter moduleAutoSmelter;
private static List<CompatibleMaterial> burnables = Arrays.stream(CompatibleMaterial.values())
.filter(m -> m.getBurnResult() != null).collect(Collectors.toList());
public GUISmeltable(ModuleAutoSmelter moduleAutoSmelter, EpicHoppers plugin, Hopper hopper) {
this.plugin = plugin;
this.hopper = hopper;
this.moduleAutoSmelter = moduleAutoSmelter;
int smeltables = burnables.size();
maxPages = (int) Math.ceil(smeltables / 32.);
setTitle(Methods.formatName(hopper.getLevel().getLevel()) + TextUtils.formatText(" &7-&f Smelting"));
setRows(6);
this.setOnPage((event) -> showPage());
showPage();
}
void showPage() {
ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial());
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial());
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial());
setDefaultItem(glass1);
GuiUtils.mirrorFill(this, 0, 0, true, true, glass2);
GuiUtils.mirrorFill(this, 0, 1, true, true, glass2);
GuiUtils.mirrorFill(this, 0, 2, true, true, glass3);
GuiUtils.mirrorFill(this, 1, 0, true, true, glass2);
int smeltableIndex = page == 1 ? 0 : 32 * (page - 1);
for (int i = 9; i < 45; i++) {
if (i == 9 || i == 17 || i == 44 || i == 36) continue;
setItem(i, null);
clearActions(i);
if (smeltableIndex >= (burnables.size() - 1)) continue;
CompatibleMaterial burnable = burnables.get(smeltableIndex);
setButton(i, getItemStack(burnable, moduleAutoSmelter.isSmeltable(hopper, burnable)), (event) -> {
moduleAutoSmelter.toggleSmeltable(hopper, burnable);
setItem(event.slot, getItemStack(burnable, moduleAutoSmelter.isSmeltable(hopper, burnable)));
});
smeltableIndex++;
}
clearActions(51);
if (page < maxPages) {
setButton(51, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
plugin.getLocale().getMessage("general.nametag.next").getMessage()),
(event) -> {
page++;
showPage();
});
}
clearActions(47);
if (page > 1) {
setButton(47, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
plugin.getLocale().getMessage("general.nametag.back").getMessage()),
(event) -> {
page--;
showPage();
});
}
setButton(49, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR,
plugin.getLocale().getMessage("general.nametag.exit").getMessage()),
(event) -> hopper.overview(plugin.getGuiManager(), event.player));
}
public ItemStack getItemStack(CompatibleMaterial material, boolean enabled) {
ItemStack item = material.getItem();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(TextUtils.formatText("&e" + material.name()));
meta.setLore(Arrays.asList(TextUtils.formatText(" &7-> &e" + material.getBurnResult().name()),
TextUtils.formatText("&7Enabled: &6" + String.valueOf(enabled).toLowerCase() + "&7."),
"",
plugin.getLocale().getMessage("interface.hopper.toggle").getMessage()));
item.setItemMeta(meta);
return item;
}
}

View File

@ -125,9 +125,8 @@ public class ModuleAutoSell extends Module {
.processPlaceholder("timeleft", getTime(hopper) == -9999 ? "\u221E" : (int) Math.floor(getTime(hopper) / 20))
.processPlaceholder("state", isNotifying(hopper)).getMessage().split("\\|");
for (String line : parts) {
for (String line : parts)
loreSell.add(TextUtils.formatText(line));
}
sellMeta.setLore(loreSell);
sellItem.setItemMeta(sellMeta);

View File

@ -0,0 +1,146 @@
package com.songoda.epichoppers.hopper.levels.modules;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.utils.TextUtils;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.gui.GUISmeltable;
import com.songoda.epichoppers.hopper.Hopper;
import com.songoda.epichoppers.settings.Settings;
import com.songoda.epichoppers.utils.StorageContainerCache;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ModuleAutoSmelter extends Module {
private final int timeOut;
private final int hopperTickRate;
public ModuleAutoSmelter(EpicHoppers plugin, int timeOut) {
super(plugin);
this.timeOut = timeOut * 20;
this.hopperTickRate = Settings.HOP_TICKS.getInt();
}
@Override
public String getName() {
return "AutoSmelter";
}
@Override
public void run(Hopper hopper, StorageContainerCache.Cache hopperCache) {
if (!isEnabled(hopper)) return;
int currentTime = getTime(hopper);
if (currentTime == -9999) return;
int subtract = currentTime - hopperTickRate;
if (subtract <= 0) {
for (int i = 0; i < 5; i++) {
final ItemStack itemStack = hopperCache.cachedInventory[i];
if (itemStack == null) continue;
CompatibleMaterial material = CompatibleMaterial.getMaterial(itemStack);
if (!isSmeltable(hopper, material)) continue;
CompatibleMaterial result = CompatibleMaterial.getMaterial(itemStack).getBurnResult();
if (hopperCache.addItem(result.getItem())) {
if (itemStack.getAmount() == 1) {
hopperCache.setItem(i, null);
} else {
itemStack.setAmount(itemStack.getAmount() - 1);
hopperCache.dirty = hopperCache.cacheChanged[i] = true;
}
break;
}
}
modifyDataCache(hopper, "time", timeOut);
return;
}
modifyDataCache(hopper, "time", subtract);
}
@Override
public ItemStack getGUIButton(Hopper hopper) {
ItemStack block = CompatibleMaterial.IRON_INGOT.getItem();
ItemMeta blockmeta = block.getItemMeta();
blockmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.smelttitle").getMessage());
ArrayList<String> loreblock = new ArrayList<>();
String[] parts = plugin.getLocale().getMessage("interface.hopper.smeltlore").processPlaceholder("timeleft",
getTime(hopper) == -9999 ? "\u221E" : (int) Math.floor(getTime(hopper) / 20)).processPlaceholder("enabled",
isEnabled(hopper) ? EpicHoppers.getInstance().getLocale().getMessage("general.word.enabled").getMessage()
: EpicHoppers.getInstance().getLocale().getMessage("general.word.disabled").getMessage()).getMessage().split("\\|");
for (String line : parts) {
loreblock.add(TextUtils.formatText(line));
}
blockmeta.setLore(loreblock);
block.setItemMeta(blockmeta);
return block;
}
public void runButtonPress(Player player, Hopper hopper, ClickType type) {
if (type == ClickType.LEFT)
EpicHoppers.getInstance().getGuiManager().showGUI(player, new GUISmeltable(this, plugin, hopper));
else if (type == ClickType.RIGHT)
toggleEnabled(hopper);
}
@Override
public List<Material> getBlockedItems(Hopper hopper) {
if (getTime(hopper) == -9999)
return Collections.EMPTY_LIST;
List<Material> blockedItems = new ArrayList<>();
for (CompatibleMaterial material : CompatibleMaterial.values())
if (material.getBurnResult() != null && isSmeltable(hopper, material))
blockedItems.add(material.getMaterial());
return blockedItems;
}
@Override
public String getDescription() {
return plugin.getLocale().getMessage("interface.hopper.autosmelt")
.processPlaceholder("ticks", (int) Math.floor(timeOut / 20)).getMessage();
}
private int getTime(Hopper hopper) {
Object time = getData(hopper, "time");
if (time == null) return -9999;
return (int) time;
}
private boolean isEnabled(Hopper hopper) {
Object obj = getData(hopper, "time");
if (obj == null) return false;
return ((int) obj) != -9999;
}
public boolean isSmeltable(Hopper hopper, CompatibleMaterial material) {
Object obj = getData(hopper, material.name());
if (obj == null) return false;
return ((boolean) obj);
}
private void toggleEnabled(Hopper hopper) {
if (isEnabled(hopper))
saveData(hopper, "time", -9999);
else
saveData(hopper, "time", timeOut);
}
public void toggleSmeltable(Hopper hopper, CompatibleMaterial material) {
saveData(hopper, material.name(), !isSmeltable(hopper, material));
}
}

View File

@ -0,0 +1,100 @@
package com.songoda.epichoppers.hopper.levels.modules;
import com.songoda.core.utils.TextUtils;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.hopper.Hopper;
import com.songoda.epichoppers.utils.StorageContainerCache;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
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;
public class ModuleMobHopper extends Module {
private final int amount;
private final Map<Block, Integer> blockTick = new HashMap<>();
public ModuleMobHopper(EpicHoppers plugin, int amount) {
super(plugin);
this.amount = amount;
}
@Override
public String getName() {
return "MobHopper";
}
@Override
public void run(Hopper hopper, StorageContainerCache.Cache hopperCache) {
Block block = hopper.getLocation().getBlock();
if (!blockTick.containsKey(block)) {
blockTick.put(block, 1);
return;
}
int tick = blockTick.get(block);
int put = tick + 1;
blockTick.put(block, put);
if (tick < amount || !isEnabled(hopper)) return;
hopper.getWorld().getNearbyEntities(hopper.getLocation(), 5, 5, 5).stream()
.filter(entity -> entity instanceof LivingEntity && !(entity instanceof Player) &&
!(entity instanceof ArmorStand)).limit(1).forEach(entity -> {
Location location = hopper.getLocation().add(.5, 1, .5);
if (location.getBlock().getType() != Material.AIR) return;
entity.teleport(location);
((LivingEntity) entity).damage(99999999);
});
blockTick.remove(block);
}
@Override
public ItemStack getGUIButton(Hopper hopper) {
ItemStack block = new ItemStack(Material.ROTTEN_FLESH, 1);
ItemMeta blockmeta = block.getItemMeta();
blockmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.mobtitle").getMessage());
ArrayList<String> loreblock = new ArrayList<>();
String[] parts = plugin.getLocale().getMessage("interface.hopper.moblore").processPlaceholder("enabled",
isEnabled(hopper) ? EpicHoppers.getInstance().getLocale().getMessage("general.word.enabled").getMessage()
: EpicHoppers.getInstance().getLocale().getMessage("general.word.disabled").getMessage()).getMessage().split("\\|");
for (String line : parts) {
loreblock.add(TextUtils.formatText(line));
}
blockmeta.setLore(loreblock);
block.setItemMeta(blockmeta);
return block;
}
@Override
public void runButtonPress(Player player, Hopper hopper, ClickType type) {
saveData(hopper, "mobhopper", !isEnabled(hopper));
}
@Override
public List<Material> getBlockedItems(Hopper hopper) {
return null;
}
@Override
public String getDescription() {
return plugin.getLocale().getMessage("interface.hopper.mobhopper")
.processPlaceholder("ticks", amount).getMessage();
}
public boolean isEnabled(Hopper hopper) {
Object isMobHopper = getData(hopper, "mobhopper");
return isMobHopper != null && (boolean) isMobHopper;
}
}

View File

@ -5,6 +5,7 @@ general:
prefix: '&7[&6EpicHoppers&7]'
next: '&9Next'
back: '&9Back'
exit: '&cExit'
nameformat: '&eLevel %level% &fHopper'
lore: ''
word:
@ -47,6 +48,14 @@ interface:
suctionlore: '|&7Left-Click to toggle suction |&7(&6%status%&7).||&7Right-Click to set radius |&7(&6%radius%&7).'
synchopper: '&6Click to Link This hopper'
rejectsync: '&6Click to Link Rejected Items'
mobhopper: '&7Mob Hopper: &6Every %ticks% ticks'
mobtitle: '&6Click to Toggle MobHopper'
moblore: '|&7MobHopper is set to &6%enabled%&7.'
autosmelt: '&7Auto Smelting: &6Every %ticks% ticks'
smelttitle: '&6AutoSmelting'
smeltlore: '&7Smelting in &6%timeleft%s&7.||&7Left-Click to toggle AutoSmelting|&7for specific items.||&7Right-Click to toggle AutoSmelting.||&7AutoSmelting is set to &6%enabled%&7.'
toggle: '&7Click to toggle if this item can be smelted.'
filter:
infotitle: '&aFilter Guide'
infolore: '&7Items placed in the leftmost column|&7space will be whitelisted.||&7Items placed in the rightmost column|&7will be void.||&7Items placed in the middle column|&7will be blacklisted.'

View File

@ -29,6 +29,8 @@ Level-5:
Suction: 3
BlockBreak: 2
Link-amount: 3
MobHopper: 9
AutoSmelting: 30
Cost-xp: 40
Cost-eco: 15000
Level-6:
@ -40,6 +42,8 @@ Level-6:
Teleport: true
AutoSell: 60
Link-amount: 3
MobHopper: 6
AutoSmelting: 20
Cost-xp: 45
Cost-eco: 20000
Level-7:
@ -52,5 +56,7 @@ Level-7:
AutoSell: 30
AutoCrafting: true
Link-amount: 4
MobHopper: 3
AutoSmelting: 10
Cost-xp: 50
Cost-eco: 30000