mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-22 10:15:43 +01:00
Lots of code cleaned up.
Started work on a module API.
This commit is contained in:
parent
b5b80b38bc
commit
ef08449afb
@ -1,8 +1,8 @@
|
||||
package com.songoda.epichoppers.api;
|
||||
|
||||
import com.songoda.epichoppers.api.hopper.HopperManager;
|
||||
import com.songoda.epichoppers.api.hopper.Level;
|
||||
import com.songoda.epichoppers.api.hopper.LevelManager;
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.api.hopper.levels.LevelManager;
|
||||
import com.songoda.epichoppers.api.utils.ProtectionPluginHook;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.epichoppers.api.hopper;
|
||||
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -9,6 +10,8 @@ import java.util.UUID;
|
||||
|
||||
public interface Hopper {
|
||||
|
||||
org.bukkit.block.Hopper getHopper();
|
||||
|
||||
/**
|
||||
* This will sync this hopper with another hopper.
|
||||
*
|
||||
|
@ -1,18 +1,12 @@
|
||||
package com.songoda.epichoppers.api.hopper;
|
||||
package com.songoda.epichoppers.api.hopper.levels;
|
||||
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.ModuleAbstract;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface Level {
|
||||
|
||||
/**
|
||||
* Get a list of strings describing the various
|
||||
* levels and their details that are currently
|
||||
* unlocked with this level.
|
||||
*
|
||||
* @return list of levels
|
||||
*/
|
||||
List<String> getDescription();
|
||||
|
||||
/**
|
||||
* Get the current level in numerical format.
|
||||
*
|
||||
@ -38,16 +32,6 @@ public interface Level {
|
||||
*/
|
||||
int getAmount();
|
||||
|
||||
/**
|
||||
* Get the tick speed of the BlockBreaking ability
|
||||
* for this level.
|
||||
*
|
||||
* 0 means disabled.
|
||||
*
|
||||
* @return BlockBreak tick speed
|
||||
*/
|
||||
int getBlockBreak();
|
||||
|
||||
/**
|
||||
* Whether or not the filter is enabled with this
|
||||
* level.
|
||||
@ -66,22 +50,6 @@ public interface Level {
|
||||
*/
|
||||
boolean isTeleport();
|
||||
|
||||
/**
|
||||
* Whether or not hopper crafting is enabled with
|
||||
* this level.
|
||||
*
|
||||
* @return true if crafting is enabled false
|
||||
* otherwise
|
||||
*/
|
||||
boolean isCrafting();
|
||||
|
||||
/**
|
||||
* Get the distance in which a hopper with this
|
||||
* level will suck items into them.
|
||||
*
|
||||
* @return suction amount
|
||||
*/
|
||||
int getSuction();
|
||||
|
||||
/**
|
||||
* Get the cost in experience in order to upgrade
|
||||
@ -98,4 +66,10 @@ public interface Level {
|
||||
* @return economy upgrade cost
|
||||
*/
|
||||
int getCostEconomy();
|
||||
|
||||
List<String> getDescription();
|
||||
|
||||
ArrayList<ModuleAbstract> getRegisteredModules();
|
||||
|
||||
void addModule(ModuleAbstract module);
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package com.songoda.epichoppers.api.hopper;
|
||||
package com.songoda.epichoppers.api.hopper.levels;
|
||||
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.ModuleAbstract;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
public interface LevelManager {
|
||||
@ -14,13 +17,10 @@ public interface LevelManager {
|
||||
* @param costEconomy The cost in economy to upgrade the hopper
|
||||
* @param range The range in which this hopper will need to be in order to sync with another hopper
|
||||
* @param amount The amount of items this hopper will transfer at a single time
|
||||
* @param suction The distance in which this hopper will suck items into it
|
||||
* @param blockBreak The tick frequency in which this hopper will break blocks placed directly above it.
|
||||
* @param filter Whether or not access to the filter is allowed.
|
||||
* @param teleport Whether or not teleporting through hoppers is allowed.
|
||||
* @param crafting Whether or not crafting with hoppers is allowed.
|
||||
*/
|
||||
void addLevel(int level, int costExperience, int costEconomy, int range, int amount, int suction, int blockBreak, boolean filter, boolean teleport, boolean crafting);
|
||||
void addLevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, ArrayList<ModuleAbstract> modules);
|
||||
|
||||
/**
|
||||
* Get {@link Level} by corresponding integer value.
|
@ -0,0 +1,18 @@
|
||||
package com.songoda.epichoppers.api.hopper.levels.modules;
|
||||
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ModuleAbstract {
|
||||
|
||||
String getName();
|
||||
|
||||
void run(Hopper hopper);
|
||||
|
||||
List<Material> getBlockedItems(Hopper hopper);
|
||||
|
||||
String getDescription();
|
||||
|
||||
}
|
@ -7,6 +7,9 @@ import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epichoppers.api.EpicHoppers;
|
||||
import com.songoda.epichoppers.api.EpicHoppersAPI;
|
||||
import com.songoda.epichoppers.api.hopper.*;
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.api.hopper.levels.LevelManager;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.ModuleAbstract;
|
||||
import com.songoda.epichoppers.api.utils.ClaimableProtectionPluginHook;
|
||||
import com.songoda.epichoppers.api.utils.ProtectionPluginHook;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
@ -19,7 +22,10 @@ import com.songoda.epichoppers.hooks.*;
|
||||
import com.songoda.epichoppers.hopper.EFilter;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import com.songoda.epichoppers.hopper.EHopperManager;
|
||||
import com.songoda.epichoppers.hopper.ELevelManager;
|
||||
import com.songoda.epichoppers.hopper.levels.ELevelManager;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.ModuleBlockBreak;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.ModuleSuction;
|
||||
import com.songoda.epichoppers.listeners.BlockListeners;
|
||||
import com.songoda.epichoppers.listeners.HopperListeners;
|
||||
import com.songoda.epichoppers.listeners.InteractListeners;
|
||||
@ -40,6 +46,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
@ -82,7 +89,6 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
settingsManager = new SettingsManager(this);
|
||||
boostManager = new BoostManager();
|
||||
setupConfig();
|
||||
loadDataFile();
|
||||
enchantmentHandler = new EnchantmentHandler();
|
||||
playerDataManager = new PlayerDataManager();
|
||||
|
||||
@ -214,14 +220,15 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
continue;
|
||||
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(hopper.getLocation());
|
||||
|
||||
ConfigurationSection sync = dataFile.getConfig().getConfigurationSection("data.sync." + locationStr);
|
||||
ConfigurationSection sync = dataFile.getConfig().createSection("data.sync." + locationStr);
|
||||
|
||||
sync.set(".level", hopper.getLevel().getLevel());
|
||||
sync.set(".block", hopper.getSyncedBlock() == null ? null : Arconix.pl().getApi().serialize().serializeLocation(hopper.getSyncedBlock().getLocation()));
|
||||
sync.set(".player", hopper.getLastPlayer() == null ? null : hopper.getLastPlayer().toString());
|
||||
sync.set(".placedBy", hopper.getPlacedBy() == null ? null : hopper.getPlacedBy().toString());
|
||||
sync.set(".teleportTrigger", hopper.getTeleportTrigger().toString());
|
||||
sync.set(".autoCrafting", hopper.getAutoCrafting() == Material.AIR ? null : hopper.getAutoCrafting().name());
|
||||
|
||||
sync.set(".autoCrafting", hopper.getAutoCrafting() == null || hopper.getAutoCrafting() == Material.AIR ? null : hopper.getAutoCrafting().name());
|
||||
sync.set(".whitelist", hopper.getFilter().getWhiteList());
|
||||
sync.set(".blacklist", hopper.getFilter().getBlackList());
|
||||
sync.set(".void", hopper.getFilter().getVoidList());
|
||||
@ -251,87 +258,91 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
for (String levelName : getConfig().getConfigurationSection("settings.levels").getKeys(false)) {
|
||||
int level = Integer.valueOf(levelName.split("-")[1]);
|
||||
|
||||
ConfigurationSection levels = getConfig().getConfigurationSection("settings.levels");
|
||||
ConfigurationSection levels = getConfig().getConfigurationSection("settings.levels." + levelName);
|
||||
|
||||
int radius = levels.getInt("Range");
|
||||
int amount = levels.getInt("Amount");
|
||||
boolean filter = levels.getBoolean("Filter");
|
||||
boolean teleport = levels.getBoolean("Teleport");
|
||||
int costExperiance = levels.getInt("Cost-xp");
|
||||
int costEconomy = levels.getInt("Cost-eco");
|
||||
|
||||
int radius = levels.getInt(levelName + ".Range");
|
||||
int amount = levels.getInt(levelName + ".Amount");
|
||||
int suction = levels.getInt(levelName + ".Suction");
|
||||
int blockBreak = levels.getInt(levelName + ".BlockBreak");
|
||||
boolean filter = levels.getBoolean(levelName + ".Filter");
|
||||
boolean teleport = levels.getBoolean(levelName + ".Teleport");
|
||||
boolean crafting = levels.getBoolean(levelName + ".AutoCrafting");
|
||||
int costExperiance = levels.getInt(levelName + ".Cost-xp");
|
||||
int costEconomy = levels.getInt(levelName + ".Cost-eco");
|
||||
levelManager.addLevel(level, costExperiance, costEconomy, radius, amount, suction, blockBreak, filter, teleport, crafting);
|
||||
ArrayList<ModuleAbstract> modules = new ArrayList<>();
|
||||
|
||||
for (String key : levels.getKeys(false)) {
|
||||
if (key.equals("Suction") && levels.getInt("Suction") != 0) {
|
||||
modules.add(new ModuleSuction(levels.getInt("Suction")));
|
||||
} else if (key.equals("BlockBreak") && levels.getInt("BlockBreak") != 0) {
|
||||
modules.add(new ModuleBlockBreak(levels.getInt("BlockBreak")));
|
||||
} else if (key.equals("AutoCrafting")) {
|
||||
modules.add(new ModuleAutoCrafting());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
levelManager.addLevel(level, costExperiance, costEconomy, radius, amount, filter, teleport, modules);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupConfig() {
|
||||
settingsManager.updateSettings();
|
||||
|
||||
ConfigurationSection levels = getConfig().getConfigurationSection("settings.levels");
|
||||
ConfigurationSection levels = getConfig().createSection("settings.levels");
|
||||
|
||||
if (levels.contains("Level-1")) {
|
||||
levels.addDefault("Level-1.Range", 10);
|
||||
levels.addDefault("Level-1.Amount", 1);
|
||||
levels.addDefault("Level-1.Cost-xp", 20);
|
||||
levels.addDefault("Level-1.Cost-eco", 5000);
|
||||
if (!levels.contains("Level-1")) {
|
||||
levels.set("Level-1.Range", 10);
|
||||
levels.set("Level-1.Amount", 1);
|
||||
levels.set("Level-1.Cost-xp", 20);
|
||||
levels.set("Level-1.Cost-eco", 5000);
|
||||
|
||||
levels.addDefault("Level-2.Range", 20);
|
||||
levels.addDefault("Level-2.Amount", 2);
|
||||
levels.addDefault("Level-2.Cost-xp", 25);
|
||||
levels.addDefault("Level-2.Cost-eco", 7500);
|
||||
levels.set("Level-2.Range", 20);
|
||||
levels.set("Level-2.Amount", 2);
|
||||
levels.set("Level-2.Cost-xp", 25);
|
||||
levels.set("Level-2.Cost-eco", 7500);
|
||||
|
||||
levels.addDefault("Level-3.Range", 30);
|
||||
levels.addDefault("Level-3.Amount", 3);
|
||||
levels.addDefault("Level-3.Suction", 1);
|
||||
levels.addDefault("Level-3.Cost-xp", 30);
|
||||
levels.addDefault("Level-3.Cost-eco", 10000);
|
||||
levels.set("Level-3.Range", 30);
|
||||
levels.set("Level-3.Amount", 3);
|
||||
levels.set("Level-3.Suction", 1);
|
||||
levels.set("Level-3.Cost-xp", 30);
|
||||
levels.set("Level-3.Cost-eco", 10000);
|
||||
|
||||
levels.addDefault("Level-4.Range", 40);
|
||||
levels.addDefault("Level-4.Amount", 4);
|
||||
levels.addDefault("Level-4.Suction", 2);
|
||||
levels.addDefault("Level-4.BlockBreak", 4);
|
||||
levels.addDefault("Level-4.Cost-xp", 35);
|
||||
levels.addDefault("Level-4.Cost-eco", 12000);
|
||||
levels.set("Level-4.Range", 40);
|
||||
levels.set("Level-4.Amount", 4);
|
||||
levels.set("Level-4.Suction", 2);
|
||||
levels.set("Level-4.BlockBreak", 4);
|
||||
levels.set("Level-4.Cost-xp", 35);
|
||||
levels.set("Level-4.Cost-eco", 12000);
|
||||
|
||||
levels.addDefault("Level-5.Range", 50);
|
||||
levels.addDefault("Level-5.Amount", 5);
|
||||
levels.addDefault("Level-5.Suction", 3);
|
||||
levels.addDefault("Level-5.BlockBreak", 2);
|
||||
levels.addDefault("Level-5.Cost-xp", 40);
|
||||
levels.addDefault("Level-5.Cost-eco", 15000);
|
||||
levels.set("Level-5.Range", 50);
|
||||
levels.set("Level-5.Amount", 5);
|
||||
levels.set("Level-5.Suction", 3);
|
||||
levels.set("Level-5.BlockBreak", 2);
|
||||
levels.set("Level-5.Cost-xp", 40);
|
||||
levels.set("Level-5.Cost-eco", 15000);
|
||||
|
||||
levels.addDefault("Level-6.Range", 60);
|
||||
levels.addDefault("Level-6.Amount", 5);
|
||||
levels.addDefault("Level-6.Suction", 3);
|
||||
levels.addDefault("Level-6.BlockBreak", 2);
|
||||
levels.addDefault("Level-6.Filter", true);
|
||||
levels.addDefault("Level-6.Teleport", true);
|
||||
levels.addDefault("Level-6.Cost-xp", 45);
|
||||
levels.addDefault("Level-6.Cost-eco", 20000);
|
||||
levels.set("Level-6.Range", 60);
|
||||
levels.set("Level-6.Amount", 5);
|
||||
levels.set("Level-6.Suction", 3);
|
||||
levels.set("Level-6.BlockBreak", 2);
|
||||
levels.set("Level-6.Filter", true);
|
||||
levels.set("Level-6.Teleport", true);
|
||||
levels.set("Level-6.Cost-xp", 45);
|
||||
levels.set("Level-6.Cost-eco", 20000);
|
||||
|
||||
levels.addDefault("Level-7.Range", 70);
|
||||
levels.addDefault("Level-7.Amount", 5);
|
||||
levels.addDefault("Level-7.Suction", 3);
|
||||
levels.addDefault("Level-7.BlockBreak", 2);
|
||||
levels.addDefault("Level-7.Filter", true);
|
||||
levels.addDefault("Level-7.Teleport", true);
|
||||
levels.addDefault("Level-7.AutoCrafting", true);
|
||||
levels.addDefault("Level-7.Cost-xp", 50);
|
||||
levels.addDefault("Level-7.Cost-eco", 30000);
|
||||
levels.set("Level-7.Range", 70);
|
||||
levels.set("Level-7.Amount", 5);
|
||||
levels.set("Level-7.Suction", 3);
|
||||
levels.set("Level-7.BlockBreak", 2);
|
||||
levels.set("Level-7.Filter", true);
|
||||
levels.set("Level-7.Teleport", true);
|
||||
levels.set("Level-7.AutoCrafting", true);
|
||||
levels.set("Level-7.Cost-xp", 50);
|
||||
levels.set("Level-7.Cost-eco", 30000);
|
||||
|
||||
}
|
||||
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void loadDataFile() {
|
||||
dataFile.getConfig().options().copyDefaults(true);
|
||||
dataFile.saveConfig();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
locale.reloadMessages();
|
||||
references = new References();
|
||||
@ -424,6 +435,10 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
this.registerProtectionHook(hookSupplier.get());
|
||||
}
|
||||
|
||||
public ConfigWrapper getDataFile() {
|
||||
return dataFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerProtectionHook(ProtectionPluginHook hook) {
|
||||
Preconditions.checkNotNull(hook, "Cannot register null hook");
|
||||
|
@ -2,7 +2,7 @@ package com.songoda.epichoppers.command.commands;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Level;
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.command.AbstractCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epichoppers.handlers;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.ModuleAbstract;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -21,7 +22,6 @@ import java.util.*;
|
||||
*/
|
||||
public class HopHandler {
|
||||
|
||||
public Map<Block, Integer> blockTick = new HashMap<>();
|
||||
private EpicHoppersPlugin instance;
|
||||
|
||||
public HopHandler(EpicHoppersPlugin instance) {
|
||||
@ -38,17 +38,14 @@ public class HopHandler {
|
||||
|
||||
private void hopperCleaner() {
|
||||
try {
|
||||
if (instance.dataFile.getConfig().contains("data.sync")) {
|
||||
ConfigurationSection cs = instance.dataFile.getConfig().getConfigurationSection("data.sync");
|
||||
for (String key : cs.getKeys(false)) {
|
||||
if (Arconix.pl().getApi().serialize().unserializeLocation(key).getWorld() != null) {
|
||||
Block b = Arconix.pl().getApi().serialize().unserializeLocation(key).getBlock();
|
||||
if (b == null || !(b.getState() instanceof Hopper)) {
|
||||
instance.dataFile.getConfig().getConfigurationSection("data.sync").set(key, null);
|
||||
instance.getLogger().info("EpicHoppers Removing non-hopper entry: " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
ConfigurationSection data = instance.getConfig().createSection("data");
|
||||
if (!data.contains("sync")) return;
|
||||
for (String key : data.getConfigurationSection("sync").getKeys(false)) {
|
||||
if (Arconix.pl().getApi().serialize().unserializeLocation(key).getWorld() == null) continue;
|
||||
Block block = Arconix.pl().getApi().serialize().unserializeLocation(key).getBlock();
|
||||
if (block != null && block.getState() instanceof Hopper) continue;
|
||||
data.getConfigurationSection("sync").set(key, null);
|
||||
instance.getLogger().info("EpicHoppers Removing non-hopper entry: " + key);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
@ -57,8 +54,6 @@ public class HopHandler {
|
||||
|
||||
private void hopperRunner() {
|
||||
try {
|
||||
Set<Entity> metaItems = new HashSet<>();
|
||||
|
||||
for (com.songoda.epichoppers.api.hopper.Hopper hopper : instance.getHopperManager().getHoppers().values()) {
|
||||
|
||||
Location location = hopper.getLocation();
|
||||
@ -81,91 +76,24 @@ public class HopHandler {
|
||||
instance.getLogger().info("EpicHoppers Removing non-hopper entry: " + location.toString());
|
||||
}
|
||||
|
||||
org.bukkit.block.Hopper hopperBlock = (org.bukkit.block.Hopper) (block != null ? block.getState() : null);
|
||||
Hopper hopperBlock = hopper.getHopper();
|
||||
|
||||
ItemStack[] is = hopperBlock.getInventory().getContents();
|
||||
|
||||
if (hopper.getAutoCrafting() != null && canMove(hopperBlock.getInventory(), new ItemStack(hopper.getAutoCrafting()))) {
|
||||
main:
|
||||
for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(hopper.getAutoCrafting()))) {
|
||||
if (!(recipe instanceof ShapedRecipe)) continue;
|
||||
Map<Character, ItemStack> ingredientMap = ((ShapedRecipe) recipe).getIngredientMap();
|
||||
if (hopperBlock.getInventory().getSize() == 0) continue;
|
||||
List<ItemStack> needed = stackItems(new ArrayList<>(ingredientMap.values()));
|
||||
List<Material> materials = new ArrayList<>();
|
||||
|
||||
for (ModuleAbstract module : hopper.getLevel().getRegisteredModules()) {
|
||||
|
||||
// Run Module
|
||||
module.run(hopper);
|
||||
|
||||
// Add banned materials to list.
|
||||
if (module.getBlockedItems(hopper) == null) continue;
|
||||
materials.addAll(module.getBlockedItems(hopper));
|
||||
|
||||
for (ItemStack item : needed) {
|
||||
if (!hopperBlock.getInventory().contains(item.getType(), item.getAmount())) continue main;
|
||||
}
|
||||
for (ItemStack item : needed) {
|
||||
hopperBlock.getInventory().removeItem(item);
|
||||
}
|
||||
hopperBlock.getInventory().addItem(new ItemStack(hopper.getAutoCrafting()));
|
||||
}
|
||||
}
|
||||
|
||||
if (hopper.getLevel().getBlockBreak() != 0) {
|
||||
int amt = hopper.getLevel().getBlockBreak();
|
||||
if (!blockTick.containsKey(block)) {
|
||||
blockTick.put(block, 1);
|
||||
} else {
|
||||
int tick = blockTick.get(block);
|
||||
int put = tick + 1;
|
||||
blockTick.put(block, put);
|
||||
if (tick >= amt) {
|
||||
Block above = block.getRelative(0, 1, 0);
|
||||
if (above.getType() != Material.AIR && !instance.getConfig().getStringList("Main.BlockBreak Blacklisted Blocks").contains(above.getType().name())) {
|
||||
above.getWorld().playSound(above.getLocation(), Sound.BLOCK_STONE_BREAK, 1F, 1F);
|
||||
Location locationAbove = above.getLocation();
|
||||
locationAbove.add(.5, .5, .5);
|
||||
|
||||
float ox = (float) (0 + (Math.random() * .5));
|
||||
float oy = (float) (0 + (Math.random() * .5));
|
||||
float oz = (float) (0 + (Math.random() * .5));
|
||||
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(locationAbove, ox, oy, oz, 0, instance.getConfig().getString("Main.BlockBreak Particle Type"), 15);
|
||||
|
||||
above.breakNaturally();
|
||||
}
|
||||
blockTick.remove(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hopper.getLevel().getSuction() != 0) {
|
||||
int suck = hopper.getLevel().getSuction();
|
||||
double radius = suck + .5;
|
||||
|
||||
Collection<Entity> nearbyEntite = block.getLocation().getWorld().getNearbyEntities(block.getLocation().add(0.5, 0.5, 0.5), radius, radius, radius);
|
||||
|
||||
for (Entity e : nearbyEntite) {
|
||||
if (!(e instanceof Item) || e.getTicksLived() < 10 || e.getLocation().getBlock().getType() == Material.HOPPER) {
|
||||
continue;
|
||||
}
|
||||
ItemStack hopItem = ((Item) e).getItemStack().clone();
|
||||
if (hopItem.getType().name().contains("SHULKER_BOX"))
|
||||
continue;
|
||||
if (hopItem.hasItemMeta() && hopItem.getItemMeta().hasDisplayName() &&
|
||||
StringUtils.substring(hopItem.getItemMeta().getDisplayName(), 0, 3).equals("***")) {
|
||||
continue; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/
|
||||
}
|
||||
if (e.hasMetadata("grabbed"))
|
||||
continue;
|
||||
ItemStack item = ((Item) e).getItemStack();
|
||||
if (!canHop(hopperBlock.getInventory(), item, 1)) {
|
||||
continue;
|
||||
}
|
||||
((Item) e).setPickupDelay(999);
|
||||
e.setMetadata("grabbed", new FixedMetadataValue(instance, ""));
|
||||
metaItems.add(e);
|
||||
if (!e.isOnGround())
|
||||
continue;
|
||||
float xx = (float) (0 + (Math.random() * .3));
|
||||
float yy = (float) (0 + (Math.random() * .3));
|
||||
float zz = (float) (0 + (Math.random() * .3));
|
||||
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(e.getLocation(), xx, yy, zz, 0, "FLAME", 5);
|
||||
e.remove();
|
||||
hopperBlock.getInventory().addItem(hopItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hopper.getSyncedBlock() == null) continue;
|
||||
Location dest = hopper.getSyncedBlock().getLocation();
|
||||
if (dest == null) {
|
||||
@ -191,18 +119,6 @@ public class HopHandler {
|
||||
|
||||
List<ItemStack> blackList = hopper.getFilter().getBlackList();
|
||||
|
||||
List<Material> materials = new ArrayList<>();
|
||||
if (hopper.getAutoCrafting() != null) {
|
||||
for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(hopper.getAutoCrafting()))) {
|
||||
if (recipe instanceof ShapedRecipe) {
|
||||
for (ItemStack itemStack : ((ShapedRecipe) recipe).getIngredientMap().values()) {
|
||||
if (itemStack == null) continue;
|
||||
materials.add(itemStack.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int num = 0;
|
||||
while (num != 5) {
|
||||
ItemStack it = null;
|
||||
@ -230,31 +146,12 @@ public class HopHandler {
|
||||
}
|
||||
num++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ItemStack> stackItems(List<ItemStack> items) {
|
||||
Map<Material, Integer> materials = new HashMap<>();
|
||||
for (ItemStack itemStack : items) {
|
||||
if (itemStack == null) continue;
|
||||
if (materials.containsKey(itemStack.getType())) {
|
||||
materials.put(itemStack.getType(), materials.get(itemStack.getType()) + itemStack.getAmount());
|
||||
continue;
|
||||
}
|
||||
materials.put(itemStack.getType(), itemStack.getAmount());
|
||||
}
|
||||
List<ItemStack> stacked = new ArrayList<>();
|
||||
for (Map.Entry<Material, Integer> entry : materials.entrySet()) {
|
||||
stacked.add(new ItemStack(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
return stacked;
|
||||
}
|
||||
|
||||
private void doBlacklist(Hopper hopperBlock, com.songoda.epichoppers.api.hopper.Hopper hopper, ItemStack item, ItemStack[] isS, int amt, int place) {
|
||||
try {
|
||||
@ -315,7 +212,7 @@ public class HopHandler {
|
||||
|
||||
if (b2.getType().equals(Material.ENDER_CHEST)) {
|
||||
try {
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(UUID.fromString(instance.dataFile.getConfig().getString("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(b2))));
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(UUID.fromString(instance.getDataFile().getConfig().getString("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(b2))));
|
||||
if (op.isOnline() && canHop(op.getPlayer().getEnderChest(), newItem, amt)) {
|
||||
if (!ovoid.contains(it.getType())) {
|
||||
op.getPlayer().getEnderChest().addItem(newItem);
|
||||
@ -368,21 +265,6 @@ public class HopHandler {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean canMove(Inventory inventory, ItemStack item) {
|
||||
try {
|
||||
if (inventory.firstEmpty() != -1) return true;
|
||||
|
||||
for (ItemStack stack : inventory.getContents()) {
|
||||
if (stack.isSimilar(item) && stack.getAmount() < stack.getMaxStackSize()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canHop(Inventory i, ItemStack item, int hop) {
|
||||
try {
|
||||
if (i.firstEmpty() != -1) {
|
||||
|
@ -6,9 +6,10 @@ import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Filter;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.Level;
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
|
||||
import com.songoda.epichoppers.boost.BoostData;
|
||||
import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoCrafting;
|
||||
import com.songoda.epichoppers.player.MenuType;
|
||||
import com.songoda.epichoppers.player.PlayerData;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
@ -32,7 +33,7 @@ import java.util.UUID;
|
||||
public class EHopper implements Hopper {
|
||||
|
||||
private Location location;
|
||||
private com.songoda.epichoppers.api.hopper.Level level;
|
||||
private Level level;
|
||||
private UUID lastPlayer;
|
||||
private UUID placedBy;
|
||||
private Block syncedBlock;
|
||||
@ -41,7 +42,7 @@ public class EHopper implements Hopper {
|
||||
private Material autoCrafting;
|
||||
|
||||
|
||||
public EHopper(Location location, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) {
|
||||
public EHopper(Location location, Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) {
|
||||
this.location = location;
|
||||
this.level = level;
|
||||
this.syncedBlock = syncedBlock;
|
||||
@ -52,7 +53,7 @@ public class EHopper implements Hopper {
|
||||
this.autoCrafting = autoCrafting;
|
||||
}
|
||||
|
||||
public EHopper(Block block, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) {
|
||||
public EHopper(Block block, Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) {
|
||||
this(block.getLocation(), level, lastPlayer, placedBy, syncedBlock, filter, teleportTrigger, autoCrafting);
|
||||
}
|
||||
|
||||
@ -67,7 +68,7 @@ public class EHopper implements Hopper {
|
||||
|
||||
instance.getPlayerDataManager().getPlayerData(player).setLastHopper(this);
|
||||
|
||||
com.songoda.epichoppers.api.hopper.Level nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel() + 1) : null;
|
||||
Level nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel() + 1) : null;
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, Methods.formatName(level.getLevel(), false));
|
||||
|
||||
@ -177,7 +178,7 @@ public class EHopper implements Hopper {
|
||||
i.setItem(5, filter);
|
||||
}
|
||||
|
||||
boolean canCraft = level.isCrafting() || player.hasPermission("EpicHoppers.Crafting");
|
||||
boolean canCraft = level.getRegisteredModules().removeIf(e -> e.getName().equals("AutoCrafting"));
|
||||
if (!canCraft)
|
||||
i.setItem(22, hook);
|
||||
else if (canFilter) {
|
||||
@ -434,7 +435,7 @@ public class EHopper implements Hopper {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
if (instance.getLevelManager().getLevels().containsKey(this.level.getLevel() + 1)) {
|
||||
|
||||
com.songoda.epichoppers.api.hopper.Level level = instance.getLevelManager().getLevel(this.level.getLevel() + 1);
|
||||
Level level = instance.getLevelManager().getLevel(this.level.getLevel() + 1);
|
||||
int cost;
|
||||
if (type.equals("XP")) {
|
||||
cost = level.getCostExperience();
|
||||
@ -471,7 +472,7 @@ public class EHopper implements Hopper {
|
||||
}
|
||||
}
|
||||
|
||||
public void upgradeFinal(com.songoda.epichoppers.api.hopper.Level level, Player player) {
|
||||
public void upgradeFinal(Level level, Player player) {
|
||||
try {
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
this.level = level;
|
||||
@ -515,6 +516,11 @@ public class EHopper implements Hopper {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.Hopper getHopper() {
|
||||
return (org.bukkit.block.Hopper) (location.getBlock() != null ? location.getBlock().getState() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync(Block toSync, boolean filtered, Player player) {
|
||||
try {
|
||||
|
@ -1,45 +1,43 @@
|
||||
package com.songoda.epichoppers.hopper;
|
||||
package com.songoda.epichoppers.hopper.levels;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Level;
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.ModuleAbstract;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ELevel implements Level {
|
||||
|
||||
private int level, costExperience, costEconomy, range, amount, blockBreak, suction;
|
||||
private final ArrayList<ModuleAbstract> registeredModules;
|
||||
|
||||
private boolean filter, teleport, crafting;
|
||||
private int level, costExperience, costEconomy, range, amount;
|
||||
|
||||
private List<String> description = new ArrayList<>();
|
||||
private boolean filter, teleport;
|
||||
|
||||
public ELevel(int level, int costExperience, int costEconomy, int range, int amount, int suction, int blockBreak, boolean filter, boolean teleport, boolean crafting) {
|
||||
private final List<String> description = new ArrayList<>();
|
||||
|
||||
ELevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, ArrayList<ModuleAbstract> registeredModules) {
|
||||
this.level = level;
|
||||
this.costExperience = costExperience;
|
||||
this.costEconomy = costEconomy;
|
||||
this.range = range;
|
||||
this.amount = amount;
|
||||
this.blockBreak = blockBreak;
|
||||
this.suction = suction;
|
||||
this.filter = filter;
|
||||
this.teleport = teleport;
|
||||
this.crafting = crafting;
|
||||
this.registeredModules = registeredModules;
|
||||
|
||||
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
|
||||
|
||||
description.add(instance.getLocale().getMessage("interface.hopper.range", range));
|
||||
description.add(instance.getLocale().getMessage("interface.hopper.amount", amount));
|
||||
if (suction != 0) description.add(instance.getLocale().getMessage("interface.hopper.suction", suction));
|
||||
if (blockBreak != 0) description.add(instance.getLocale().getMessage("interface.hopper.blockbreak", blockBreak));
|
||||
if (filter) description.add(instance.getLocale().getMessage("interface.hopper.filter", true));
|
||||
if (teleport) description.add(instance.getLocale().getMessage("interface.hopper.teleport", true));
|
||||
if (crafting) description.add(instance.getLocale().getMessage("interface.hopper.crafting", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDescription() {
|
||||
return new ArrayList<>(description);
|
||||
for (ModuleAbstract module : registeredModules) {
|
||||
description.add(module.getDescription());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,11 +55,6 @@ public class ELevel implements Level {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockBreak() {
|
||||
return blockBreak;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFilter() {
|
||||
return filter;
|
||||
@ -72,16 +65,6 @@ public class ELevel implements Level {
|
||||
return teleport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCrafting() {
|
||||
return crafting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSuction() {
|
||||
return suction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCostExperience() {
|
||||
return costExperience;
|
||||
@ -91,5 +74,21 @@ public class ELevel implements Level {
|
||||
public int getCostEconomy() {
|
||||
return costEconomy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDescription() {
|
||||
return new ArrayList<>(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<ModuleAbstract> getRegisteredModules() {
|
||||
return new ArrayList<>(registeredModules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addModule(ModuleAbstract module) {
|
||||
registeredModules.add(module);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,20 +1,18 @@
|
||||
package com.songoda.epichoppers.hopper;
|
||||
package com.songoda.epichoppers.hopper.levels;
|
||||
|
||||
import com.songoda.epichoppers.api.hopper.Level;
|
||||
import com.songoda.epichoppers.api.hopper.LevelManager;
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.api.hopper.levels.LevelManager;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.ModuleAbstract;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
|
||||
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, int suction, int blockBreak, boolean filter, boolean teleport, boolean crafting) {
|
||||
registeredLevels.put(level, new ELevel(level, costExperience, costEconomy, range, amount, suction, blockBreak, filter, teleport, crafting));
|
||||
public void addLevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, ArrayList<ModuleAbstract> modules) {
|
||||
registeredLevels.put(level, new ELevel(level, costExperience, costEconomy, range, amount, filter, teleport, modules));
|
||||
}
|
||||
|
||||
@Override
|
@ -0,0 +1,97 @@
|
||||
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.ModuleAbstract;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModuleAutoCrafting implements ModuleAbstract {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "AutoCrafting";
|
||||
}
|
||||
|
||||
public void run(Hopper hopper) {
|
||||
if (hopper.getAutoCrafting() != null && canMove(hopper.getHopper().getInventory(), new ItemStack(hopper.getAutoCrafting()))) {
|
||||
org.bukkit.block.Hopper hopperBlock = hopper.getHopper();
|
||||
main:
|
||||
for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(hopper.getAutoCrafting()))) {
|
||||
if (!(recipe instanceof ShapedRecipe)) continue;
|
||||
Map<Character, ItemStack> ingredientMap = ((ShapedRecipe) recipe).getIngredientMap();
|
||||
if (hopperBlock.getInventory().getSize() == 0) continue;
|
||||
List<ItemStack> needed = stackItems(new ArrayList<>(ingredientMap.values()));
|
||||
|
||||
for (ItemStack item : needed) {
|
||||
if (!hopperBlock.getInventory().contains(item.getType(), item.getAmount())) continue main;
|
||||
}
|
||||
for (ItemStack item : needed) {
|
||||
hopperBlock.getInventory().removeItem(item);
|
||||
}
|
||||
hopperBlock.getInventory().addItem(new ItemStack(hopper.getAutoCrafting()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
List<Material> materials = new ArrayList<>();
|
||||
if (hopper.getAutoCrafting() != null) {
|
||||
for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(hopper.getAutoCrafting()))) {
|
||||
if (!(recipe instanceof ShapedRecipe)) continue;
|
||||
for (ItemStack itemStack : ((ShapedRecipe) recipe).getIngredientMap().values()) {
|
||||
if (itemStack == null) continue;
|
||||
materials.add(itemStack.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
return materials;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.crafting", true);
|
||||
}
|
||||
|
||||
private List<ItemStack> stackItems(List<ItemStack> items) {
|
||||
Map<Material, Integer> materials = new HashMap<>();
|
||||
for (ItemStack itemStack : items) {
|
||||
if (itemStack == null) continue;
|
||||
if (materials.containsKey(itemStack.getType())) {
|
||||
materials.put(itemStack.getType(), materials.get(itemStack.getType()) + itemStack.getAmount());
|
||||
continue;
|
||||
}
|
||||
materials.put(itemStack.getType(), itemStack.getAmount());
|
||||
}
|
||||
List<ItemStack> stacked = new ArrayList<>();
|
||||
for (Map.Entry<Material, Integer> entry : materials.entrySet()) {
|
||||
stacked.add(new ItemStack(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
return stacked;
|
||||
}
|
||||
|
||||
private boolean canMove(Inventory inventory, ItemStack item) {
|
||||
try {
|
||||
if (inventory.firstEmpty() != -1) return true;
|
||||
|
||||
for (ItemStack stack : inventory.getContents()) {
|
||||
if (stack.isSimilar(item) && stack.getAmount() < stack.getMaxStackSize()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.songoda.epichoppers.hopper.levels.modules;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.ModuleAbstract;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModuleBlockBreak implements ModuleAbstract {
|
||||
|
||||
private Map<Block, Integer> blockTick = new HashMap<>();
|
||||
|
||||
private final int amount;
|
||||
|
||||
public ModuleBlockBreak(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BlockBreak";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Hopper hopper) {
|
||||
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) return;
|
||||
Block above = block.getRelative(0, 1, 0);
|
||||
if (above.getType() != Material.AIR && !EpicHoppersPlugin.getInstance().getConfig().getStringList("Main.BlockBreak Blacklisted Blocks").contains(above.getType().name())) {
|
||||
above.getWorld().playSound(above.getLocation(), Sound.BLOCK_STONE_BREAK, 1F, 1F);
|
||||
Location locationAbove = above.getLocation();
|
||||
locationAbove.add(.5, .5, .5);
|
||||
|
||||
float ox = (float) (0 + (Math.random() * .5));
|
||||
float oy = (float) (0 + (Math.random() * .5));
|
||||
float oz = (float) (0 + (Math.random() * .5));
|
||||
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(locationAbove, ox, oy, oz, 0, EpicHoppersPlugin.getInstance().getConfig().getString("Main.BlockBreak Particle Type"), 15);
|
||||
above.breakNaturally();
|
||||
}
|
||||
blockTick.remove(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.blockbreak", true);
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package com.songoda.epichoppers.hopper.levels.modules;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.levels.modules.ModuleAbstract;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleSuction implements ModuleAbstract {
|
||||
|
||||
private final int amount;
|
||||
|
||||
public ModuleSuction(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Suction";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Hopper hopper) {
|
||||
double radius = amount + .5;
|
||||
|
||||
org.bukkit.block.Hopper hopperBlock = hopper.getHopper();
|
||||
|
||||
Collection<Entity> nearbyEntite = hopper.getLocation().getWorld().getNearbyEntities(hopper.getLocation().add(0.5, 0.5, 0.5), radius, radius, radius);
|
||||
|
||||
for (Entity e : nearbyEntite) {
|
||||
if (!(e instanceof Item) || e.getTicksLived() < 10 || e.getLocation().getBlock().getType() == Material.HOPPER) {
|
||||
continue;
|
||||
}
|
||||
ItemStack hopItem = ((Item) e).getItemStack().clone();
|
||||
if (hopItem.getType().name().contains("SHULKER_BOX"))
|
||||
continue;
|
||||
if (hopItem.hasItemMeta() && hopItem.getItemMeta().hasDisplayName() &&
|
||||
StringUtils.substring(hopItem.getItemMeta().getDisplayName(), 0, 3).equals("***")) {
|
||||
continue; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/
|
||||
}
|
||||
if (e.hasMetadata("grabbed"))
|
||||
continue;
|
||||
ItemStack item = ((Item) e).getItemStack();
|
||||
if (!canMove(hopperBlock.getInventory(), item)) {
|
||||
continue;
|
||||
}
|
||||
((Item) e).setPickupDelay(999);
|
||||
e.setMetadata("grabbed", new FixedMetadataValue(EpicHoppersPlugin.getInstance(), ""));
|
||||
if (!e.isOnGround())
|
||||
continue;
|
||||
float xx = (float) (0 + (Math.random() * .3));
|
||||
float yy = (float) (0 + (Math.random() * .3));
|
||||
float zz = (float) (0 + (Math.random() * .3));
|
||||
Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(e.getLocation(), xx, yy, zz, 0, "FLAME", 5);
|
||||
e.remove();
|
||||
hopperBlock.getInventory().addItem(hopItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return EpicHoppersPlugin.getInstance().getLocale().getMessage("interface.hopper.suction", true);
|
||||
}
|
||||
|
||||
private boolean canMove(Inventory inventory, ItemStack item) {
|
||||
try {
|
||||
if (inventory.firstEmpty() != -1) return true;
|
||||
|
||||
for (ItemStack stack : inventory.getContents()) {
|
||||
if (stack.isSimilar(item) && stack.getAmount() < stack.getMaxStackSize()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package com.songoda.epichoppers.listeners;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.Level;
|
||||
import com.songoda.epichoppers.api.hopper.levels.Level;
|
||||
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
|
||||
import com.songoda.epichoppers.hopper.EFilter;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
@ -39,7 +39,7 @@ public class BlockListeners implements Listener {
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
try {
|
||||
if (e.getBlock().getType().equals(Material.ENDER_CHEST)) {
|
||||
instance.dataFile.getConfig().set("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(e.getBlock()), e.getPlayer().getUniqueId().toString());
|
||||
instance.getDataFile().getConfig().set("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(e.getBlock()), e.getPlayer().getUniqueId().toString());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ public class BlockListeners implements Listener {
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
try {
|
||||
if (event.getBlock().getType().equals(Material.ENDER_CHEST)) {
|
||||
instance.dataFile.getConfig().set("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(event.getBlock()), null);
|
||||
instance.getDataFile().getConfig().set("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(event.getBlock()), null);
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
|
Loading…
Reference in New Issue
Block a user