mirror of
https://github.com/songoda/EpicFurnaces.git
synced 2025-02-11 17:11:40 +01:00
Refactored the FurnaceManager and fixed some enums.
This commit is contained in:
parent
e67f476724
commit
97b242f825
@ -70,6 +70,13 @@
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.13.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.milkbowl</groupId>
|
||||
<artifactId>vault</artifactId>
|
||||
|
@ -15,6 +15,7 @@ import com.songoda.epicfurnaces.utils.BukkitEnums;
|
||||
import com.songoda.epicfurnaces.utils.Methods;
|
||||
import com.songoda.epicfurnaces.utils.StringUtils;
|
||||
import com.songoda.epicfurnaces.utils.gui.FastInv;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -25,6 +26,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.FurnaceRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@ -56,9 +58,9 @@ public class EpicFurnaces extends JavaPlugin {
|
||||
private Locale locale;
|
||||
private Storage storage;
|
||||
private HologramManager hologramManager;
|
||||
private Economy economy;
|
||||
private int currentVersion;
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Bukkit.getConsoleSender().sendMessage(StringUtils.formatText("&a============================="));
|
||||
@ -106,12 +108,14 @@ public class EpicFurnaces extends JavaPlugin {
|
||||
this.levelManager = new LevelManager(this);
|
||||
this.hookManager = new HookManager(this);
|
||||
|
||||
setupEconomy();
|
||||
checkStorage();
|
||||
Bukkit.getScheduler().runTaskLater(this, furnaceManager::loadFurnaces, 10);
|
||||
|
||||
levelManager.loadLevelManager();
|
||||
setupRecipes();
|
||||
|
||||
int timeout = getConfig().getInt("Main.Auto Save Interval In Seconds") * 60 * 20;
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(this, furnaceManager::loadFurnaces, 10);
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, timeout, timeout);
|
||||
|
||||
// Start Tasks
|
||||
@ -236,7 +240,6 @@ public class EpicFurnaces extends JavaPlugin {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void save(String configuration) {
|
||||
try {
|
||||
File configurationFile = new File(getDataFolder(), configuration + ".yml");
|
||||
@ -246,6 +249,15 @@ public class EpicFurnaces extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
}
|
||||
|
||||
return (economy != null);
|
||||
}
|
||||
|
||||
private boolean checkVersion() {
|
||||
String version = getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
currentVersion = Integer.parseInt(version.split("_")[1]);
|
||||
@ -334,4 +346,8 @@ public class EpicFurnaces extends JavaPlugin {
|
||||
public Storage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ public class CommandGive extends AbstractCommand {
|
||||
|
||||
level = instance.getLevelManager().getLevel(Integer.parseInt(args[2]));
|
||||
}
|
||||
player.getInventory().addItem(instance.furnaceManager.createLeveledFurnace(level.getLevel(), 0, instance));
|
||||
player.getInventory().addItem(instance.getFurnaceManager().createLeveledFurnace(level.getLevel(), 0, instance));
|
||||
player.sendMessage(instance.getLocale().getPrefix() + instance.getLocale().getMessage("command.give.success", level.getLevel()));
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
|
@ -59,7 +59,6 @@ public class BlockListeners implements Listener {
|
||||
ItemStack item = event.getItemInHand();
|
||||
Location location = event.getBlock().getLocation();
|
||||
|
||||
// if (instance.getFurnaceManager().getFurnaceLevel(item) != 1) {
|
||||
if (instance.getBlacklistHandler().isBlacklisted(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -75,7 +74,6 @@ public class BlockListeners implements Listener {
|
||||
event.getPlayer().getUniqueId());
|
||||
|
||||
instance.getFurnaceManager().addFurnace(location, furnaceObject);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -87,7 +85,7 @@ public class BlockListeners implements Listener {
|
||||
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (block.getType() != Material.FURNACE) {
|
||||
if (block.getType() != Material.FURNACE && block.getType() != instance.getBukkitEnums().getMaterial("BURNING_FURNACE").getType()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -95,13 +93,13 @@ public class BlockListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
FurnaceObject furnace = instance.getFurnaceManager().getFurnace(block);
|
||||
int level = instance.getFurnaceManager().getFurnace(block).getLevel().getLevel();
|
||||
FurnaceObject furnace = instance.getFurnaceManager().getFurnace(block.getLocation()).orElseGet(() -> instance.getFurnaceManager().createFurnace(block.getLocation()));
|
||||
int level = furnace.getLevel().getLevel();
|
||||
|
||||
if (level != 0) {
|
||||
event.setCancelled(true);
|
||||
|
||||
ItemStack item = instance.furnaceManager.createLeveledFurnace(level, furnace.getUses(), instance);
|
||||
ItemStack item = instance.getFurnaceManager().createLeveledFurnace(level, furnace.getUses(), instance);
|
||||
|
||||
event.getBlock().setType(Material.AIR);
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), item);
|
||||
|
@ -9,6 +9,8 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.FurnaceBurnEvent;
|
||||
import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/26/2017.
|
||||
*/
|
||||
@ -29,10 +31,10 @@ public class FurnaceListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
FurnaceObject furnace = instance.getFurnaceManager().getFurnace(b.getLocation());
|
||||
Optional<FurnaceObject> furnace = instance.getFurnaceManager().getFurnace(event.getBlock().getLocation());
|
||||
|
||||
if (furnace != null && event.getSource().getType() != instance.getBukkitEnums().getMaterial("WET_SPONGE").getType()) {
|
||||
furnace.plus(event);
|
||||
if (furnace.isPresent() && event.getSource().getType() != instance.getBukkitEnums().getMaterial("WET_SPONGE").getType()) {
|
||||
furnace.get().plus(event);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,8 +44,8 @@ public class FurnaceListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
FurnaceObject furnace = instance.getFurnaceManager().getFurnace(event.getBlock().getLocation());
|
||||
Level level = furnace != null ? furnace.getLevel() : instance.getLevelManager().getLowestLevel();
|
||||
Optional<FurnaceObject> furnace = instance.getFurnaceManager().getFurnace(event.getBlock().getLocation());
|
||||
Level level = furnace.isPresent() ? furnace.get().getLevel() : instance.getLevelManager().getLowestLevel();
|
||||
|
||||
if (level.getFuelDuration() != 0) {
|
||||
return;
|
||||
|
@ -35,7 +35,7 @@ public class InteractListeners implements Listener {
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
if (!player.hasPermission("EpicFurnaces.overview")
|
||||
|| !instance.canBuild(player, event.getClickedBlock().getLocation())
|
||||
|| !instance.getHookManager().canBuild(player, event.getClickedBlock().getLocation())
|
||||
|| event.getAction() != Action.LEFT_CLICK_BLOCK
|
||||
|| player.isSneaking()
|
||||
|| (block.getType() != Material.FURNACE && block.getType() != instance.getBukkitEnums().getMaterial("BURNING_FURNACE").getType())
|
||||
@ -44,7 +44,6 @@ public class InteractListeners implements Listener {
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
instance.getFurnaceManager().getFurnace(block.getLocation()).openOverview(player);
|
||||
instance.getFurnaceManager().getFurnace(block.getLocation()).orElseGet(() -> instance.getFurnaceManager().createFurnace(block.getLocation())).openOverview(player);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicfurnaces.listeners;
|
||||
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.objects.FurnaceObject;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Furnace;
|
||||
@ -33,7 +34,7 @@ public class InventoryListeners implements Listener {
|
||||
|| event.getDestination().getItem(0).getAmount() != 1) {
|
||||
return;
|
||||
}
|
||||
instance.getFurnaceManager().getFurnace(((Furnace) event.getDestination().getHolder()).getLocation()).updateCook();
|
||||
instance.getFurnaceManager().getFurnace(((Furnace) event.getDestination().getHolder()).getLocation()).ifPresent(FurnaceObject::updateCook);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -43,7 +44,7 @@ public class InventoryListeners implements Listener {
|
||||
&& event.getSlotType() == CRAFTING) {
|
||||
Block block;
|
||||
block = ((Furnace) event.getInventory().getHolder()).getLocation().getBlock();
|
||||
instance.getFurnaceManager().getFurnace(block).updateCook();
|
||||
instance.getFurnaceManager().getFurnace(block.getLocation()).ifPresent(FurnaceObject::updateCook);
|
||||
}
|
||||
|
||||
if (event.getSlot() == 64537 || event.getInventory().getType() != ANVIL || event.getAction() == NOTHING) {
|
||||
|
@ -10,7 +10,6 @@ import com.songoda.epicfurnaces.utils.Methods;
|
||||
import com.songoda.epicfurnaces.utils.gui.ItemBuilder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
@ -26,24 +25,22 @@ public class FurnaceManager {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void addFurnace(Location location, FurnaceObject furnace) {
|
||||
public FurnaceObject addFurnace(Location location, FurnaceObject furnace) {
|
||||
instance.getHologramManager().updateHologram(furnace);
|
||||
registeredFurnaces.put(roundLocation(location), furnace);
|
||||
return furnace;
|
||||
}
|
||||
|
||||
public FurnaceObject createFurnace(Location location) {
|
||||
return addFurnace(location, new FurnaceObject(instance, location, instance.getLevelManager().getLowestLevel(), null, 0, 0, new ArrayList<>(), null));
|
||||
}
|
||||
|
||||
public void removeFurnace(Location location) {
|
||||
instance.getHologramManager().updateHologram(registeredFurnaces.remove(location));
|
||||
instance.getHologramManager().remove(registeredFurnaces.remove(location));
|
||||
}
|
||||
|
||||
public FurnaceObject getFurnace(Location location) {
|
||||
if (!registeredFurnaces.containsKey(location)) {
|
||||
addFurnace(location, new FurnaceObject(instance, location, instance.getLevelManager().getLowestLevel(), null, 0, 0, new ArrayList<>(), null));
|
||||
}
|
||||
return registeredFurnaces.get(location);
|
||||
}
|
||||
|
||||
public FurnaceObject getFurnace(Block block) {
|
||||
return getFurnace(block.getLocation());
|
||||
public Optional<FurnaceObject> getFurnace(Location location) {
|
||||
return Optional.ofNullable(registeredFurnaces.get(location));
|
||||
}
|
||||
|
||||
public int getFurnaceLevel(ItemStack item) {
|
||||
@ -57,7 +54,6 @@ public class FurnaceManager {
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
public int getFurnaceUses(ItemStack item) {
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.block.Furnace;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class HologramManager {
|
||||
private final Map<FurnaceObject, Hologram> hologramMap;
|
||||
@ -72,9 +73,10 @@ public class HologramManager {
|
||||
Hologram hologram;
|
||||
|
||||
if (!hologramMap.containsKey(furnaceObject)) {
|
||||
boolean inFront = instance.getConfig().getBoolean("Main.Hologram in front");
|
||||
BlockFace direction = ((org.bukkit.material.Furnace) furnaceBlock.getData()).getFacing();
|
||||
Location location = inFront ? furnaceObject.getLocation().getBlock().getRelative(direction).getLocation().add(0.5, 0.8, 0.5) : furnaceBlock.getLocation().add(0.5, 1.8, 0.5);
|
||||
Location location = instance.getConfig().getBoolean("Main.Hologram in front") ?
|
||||
furnaceObject.getLocation().getBlock().getRelative(direction).getLocation().add(0.5, 0.8, 0.5) :
|
||||
furnaceBlock.getLocation().add(0.5, 1.8, 0.5);
|
||||
hologram = HologramsAPI.createHologram(instance, location);
|
||||
} else {
|
||||
hologram = hologramMap.get(furnaceObject);
|
||||
@ -92,6 +94,10 @@ public class HologramManager {
|
||||
});
|
||||
}
|
||||
|
||||
public void remove(FurnaceObject furnaceObject) {
|
||||
Optional.ofNullable(hologramMap.remove(furnaceObject)).ifPresent(Hologram::delete);
|
||||
}
|
||||
|
||||
|
||||
public void clearAll() {
|
||||
hologramMap.values().forEach(Hologram::delete);
|
||||
|
@ -12,8 +12,6 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.songoda.epicfurnaces.EpicFurnaces.save;
|
||||
|
||||
public class HookManager {
|
||||
private final EpicFurnaces instance;
|
||||
private Set<ProtectionPluginHook> protectionHooks;
|
||||
@ -43,7 +41,7 @@ public class HookManager {
|
||||
configuration.addDefault("hooks." + hookPlugin.getName(), true);
|
||||
if (!configuration.getBoolean("hooks." + hookPlugin.getName(), true)) return;
|
||||
configuration.options().copyDefaults(true);
|
||||
save(instance, "hooks");
|
||||
instance.save("hooks");
|
||||
|
||||
protectionHooks.add(hook);
|
||||
instance.getLogger().info("Registered protection hook for plugin: " + hook.getPlugin().getName() + " v" + hook.getPlugin().getDescription().getVersion());
|
||||
|
@ -4,7 +4,6 @@ import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.menus.OverviewMenu;
|
||||
import com.songoda.epicfurnaces.utils.NMSUtil;
|
||||
import com.songoda.epicfurnaces.utils.StringUtils;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
@ -13,11 +12,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
||||
import org.bukkit.inventory.FurnaceInventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
@ -103,7 +98,7 @@ public class FurnaceObject {
|
||||
if (rand >= num
|
||||
|| e.getResult().getType().equals(Material.SPONGE)
|
||||
|| instance.getConfig().getBoolean("Main.No Rewards From Custom Recipes")
|
||||
&& instance.getFurnaceRecipeFile().getConfig().contains("Recipes." + i.getSmelting().getType().toString())) {
|
||||
&& instance.getConfiguration("Furnace Recipes").contains("Recipes." + i.getSmelting().getType().toString())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -128,37 +123,28 @@ public class FurnaceObject {
|
||||
if (!instance.getLevelManager().getLevels().containsKey(this.level.getLevel() + 1))
|
||||
return;
|
||||
|
||||
int cost;
|
||||
if (type.equals("XP")) {
|
||||
cost = level.getCostExperience();
|
||||
} else {
|
||||
cost = level.getCostEconomy();
|
||||
}
|
||||
int cost = type.equals("XP") ? level.getCostExperience() : level.getCostEconomy();
|
||||
Level level = instance.getLevelManager().getLevel(this.level.getLevel() + 1);
|
||||
|
||||
if (type.equals("ECO")) {
|
||||
if (instance.getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
if (econ.has(player, cost)) {
|
||||
econ.withdrawPlayer(player, cost);
|
||||
upgradeFinal(level, player);
|
||||
} else {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("Vault is not installed.");
|
||||
}
|
||||
} else if (type.equals("XP")) {
|
||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setLevel(player.getLevel() - cost);
|
||||
}
|
||||
if (instance.getEconomy().has(player, cost)) {
|
||||
instance.getEconomy().withdrawPlayer(player, cost);
|
||||
upgradeFinal(level, player);
|
||||
} else {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
return;
|
||||
}
|
||||
player.sendMessage(instance.getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setLevel(player.getLevel() - cost);
|
||||
}
|
||||
upgradeFinal(level, player);
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(instance.getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
}
|
||||
|
||||
private void upgradeFinal(Level level, Player player) {
|
||||
@ -171,14 +157,17 @@ public class FurnaceObject {
|
||||
}
|
||||
|
||||
Location loc = location.clone().add(.5, .5, .5);
|
||||
player.getWorld().playEffect(loc, Effect.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), 200);
|
||||
player.getWorld().playEffect(loc, instance.getBukkitEnums().getParticle(instance.getConfig().getString("Main.Upgrade Particle Type")), 200);
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Use Sounds")) {
|
||||
if (instance.getLevelManager().getHighestLevel() == level) {
|
||||
//TODO: Sound
|
||||
player.playSound(player.getLocation(), instance.getBukkitEnums().getLevelUp(), 0.6F, 15.0F);
|
||||
player.playSound(player.getLocation(), instance.getBukkitEnums().getSound("ENTITY_PLAYER_LEVELUP"), 0.6F, 15.0F);
|
||||
} else {
|
||||
player.playSound(player.getLocation(), instance.getBukkitEnums().getLevelUp(), 2F, 25.0F);
|
||||
player.playSound(player.getLocation(), instance.getBukkitEnums().getSound("ENTITY_PLAYER_LEVELUP"), 2F, 25.0F);
|
||||
player.playSound(player.getLocation(), instance.getBukkitEnums().getSound("BLOCK_NOTE_BLOCK_CHIME"), 2F, 25.0F);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), instance.getBukkitEnums().getSound("BLOCK_NOTE_BLOCK_CHIME"), 1.2F, 35.0F), 5L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), instance.getBukkitEnums().getSound("BLOCK_NOTE_BLOCK_CHIME"), 1.8F, 35.0F), 10L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -240,44 +229,47 @@ public class FurnaceObject {
|
||||
|
||||
|
||||
public List<Location> getRadius(boolean overHeat) {
|
||||
if (overHeat)
|
||||
if (overHeat) {
|
||||
return radiusOverheat.isEmpty() ? null : Collections.unmodifiableList(radiusOverheat);
|
||||
else
|
||||
} else {
|
||||
return radiusFuelShare.isEmpty() ? null : Collections.unmodifiableList(radiusFuelShare);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addToRadius(Location location, boolean overHeat) {
|
||||
if (overHeat)
|
||||
if (overHeat) {
|
||||
radiusOverheat.add(location);
|
||||
else
|
||||
} else {
|
||||
radiusFuelShare.add(location);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void clearRadius(boolean overHeat) {
|
||||
if (overHeat)
|
||||
if (overHeat) {
|
||||
radiusOverheat.clear();
|
||||
else
|
||||
} else {
|
||||
radiusFuelShare.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getRadiusLast(boolean overHeat) {
|
||||
if (overHeat)
|
||||
if (overHeat) {
|
||||
return radiusOverheatLast;
|
||||
else
|
||||
} else {
|
||||
return radiusFuelShareLast;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setRadiusLast(int radiusLast, boolean overHeat) {
|
||||
if (overHeat)
|
||||
if (overHeat) {
|
||||
this.radiusOverheatLast = radiusLast;
|
||||
else
|
||||
} else {
|
||||
this.radiusFuelShareLast = radiusLast;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -318,20 +310,7 @@ public class FurnaceObject {
|
||||
|
||||
|
||||
public int getPerformanceTotal() {
|
||||
try {
|
||||
String equation = "(" + level.getPerformance() + " / 100) * 200";
|
||||
if (!cache.containsKey(equation)) {
|
||||
ScriptEngineManager mgr = new ScriptEngineManager();
|
||||
ScriptEngine engine = mgr.getEngineByName("JavaScript");
|
||||
int num = (int) Math.round(Double.parseDouble(engine.eval("(" + level.getPerformance() + " / 100) * 200").toString()));
|
||||
cache.put(equation, num);
|
||||
return num;
|
||||
}
|
||||
return cache.get(equation);
|
||||
} catch (ScriptException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
return (int) Math.round((level.getPerformance() / 100.0) * 200);
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,30 +6,31 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class FurnaceTask extends BukkitRunnable {
|
||||
|
||||
private static FurnaceTask instance;
|
||||
|
||||
private final EpicFurnaces plugin;
|
||||
private static FurnaceTask plugin;
|
||||
private final EpicFurnaces instance;
|
||||
|
||||
private FurnaceTask(EpicFurnaces plugin) {
|
||||
this.plugin = plugin;
|
||||
this.instance = plugin;
|
||||
}
|
||||
|
||||
public static void startTask(EpicFurnaces plugin) {
|
||||
if (instance == null) {
|
||||
instance = new FurnaceTask(plugin);
|
||||
instance.runTaskTimer(plugin, 0, plugin.getConfig().getInt("Main.Furnace Tick Speed"));
|
||||
if (FurnaceTask.plugin == null) {
|
||||
FurnaceTask.plugin = new FurnaceTask(plugin);
|
||||
FurnaceTask.plugin.runTaskTimer(plugin, 0, plugin.getConfig().getInt("Main.Furnace Tick Speed"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (FurnaceObject furnace : plugin.getFurnaceManager().getFurnaces().values()) {
|
||||
for (FurnaceObject furnace : instance.getFurnaceManager().getFurnaces().values()) {
|
||||
Location furnaceLocation = furnace.getLocation();
|
||||
|
||||
if (furnaceLocation == null) {
|
||||
@ -37,7 +38,7 @@ public class FurnaceTask extends BukkitRunnable {
|
||||
}
|
||||
|
||||
if (furnaceLocation.getWorld() == null) {
|
||||
plugin.getFurnaceManager().removeFurnace(furnaceLocation);
|
||||
instance.getFurnaceManager().removeFurnace(furnaceLocation);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -49,11 +50,11 @@ public class FurnaceTask extends BukkitRunnable {
|
||||
}
|
||||
|
||||
if (furnace.getLocation().getBlock().getType() != Material.FURNACE &&
|
||||
furnace.getLocation().getBlock().getType() != plugin.getBukkitEnums().getMaterial("BURNING_FURNACE").getType()) {
|
||||
furnace.getLocation().getBlock().getType() != instance.getBukkitEnums().getMaterial("BURNING_FURNACE").getType()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (((org.bukkit.block.Furnace) furnaceLocation.getBlock().getState()).getBurnTime() == 0) {
|
||||
if (((Furnace) furnaceLocation.getBlock().getState()).getBurnTime() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -114,14 +115,14 @@ public class FurnaceTask extends BukkitRunnable {
|
||||
|
||||
Block block = location.getBlock();
|
||||
|
||||
if (block.getType() != Material.FURNACE && block.getType() != plugin.getBukkitEnums().getMaterial("BURNING_FURNACE").getType()) {
|
||||
if (block.getType() != Material.FURNACE && block.getType() != instance.getBukkitEnums().getMaterial("BURNING_FURNACE").getType()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FurnaceObject other = plugin.getFurnaceManager().getFurnace(block);
|
||||
Optional<FurnaceObject> other = instance.getFurnaceManager().getFurnace(block.getLocation());
|
||||
|
||||
if (furnace != other) {
|
||||
org.bukkit.block.Furnace furnaceBlock = ((org.bukkit.block.Furnace) block.getState());
|
||||
if (other.isPresent() && furnace.equals(other.get())) {
|
||||
Furnace furnaceBlock = ((Furnace) block.getState());
|
||||
|
||||
if (furnaceBlock.getBurnTime() == 0) {
|
||||
furnaceBlock.setBurnTime((short) 100);
|
||||
@ -157,9 +158,8 @@ public class FurnaceTask extends BukkitRunnable {
|
||||
float px = (float) (0 + (Math.random() * 1));
|
||||
float pz = (float) (0 + (Math.random() * 1));
|
||||
|
||||
if (plugin.getConfig().getBoolean("Main.Overheat Particles")) {
|
||||
//TODO: Particles
|
||||
// Arconix.pl().getApi().packetLibrary.getParticleManager().broadcastParticle(location, px, .5F, pz, 0, "SMOKE_NORMAL", 25);
|
||||
if (instance.getConfig().getBoolean("Main.Overheat Particles")) {
|
||||
location.getWorld().playEffect(location, instance.getBukkitEnums().getParticle("SMOKE_NORMAL"), 25);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ public class HologramTask extends BukkitRunnable {
|
||||
public static void startTask(EpicFurnaces plugin) {
|
||||
if (task == null) {
|
||||
task = new HologramTask(plugin);
|
||||
task.runTaskTimer(plugin, 0, 20);
|
||||
task.runTaskTimer(plugin, 0, 20L);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,55 @@
|
||||
package com.songoda.epicfurnaces.utils;
|
||||
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BukkitEnums {
|
||||
private final EpicFurnaces instance;
|
||||
private final Map<String, String> soundMap = new HashMap<String, String>() {{
|
||||
put("ENTITY_PLAYER_LEVELUP", "LEVEL_UP");
|
||||
put("BLOCK_NOTE_BLOCK_CHIME", "NOTE_PLING");
|
||||
put("NAN", "NAN");
|
||||
}};
|
||||
|
||||
private final Map<String, String> particleMap = new HashMap<String, String>() {{
|
||||
put("SMOKE", "SMOKE_NORMAL");
|
||||
put("SPELL_WITCH", "MOBSPAWNER_FLAMES");
|
||||
put("NAN", "NAN");
|
||||
}};
|
||||
|
||||
public BukkitEnums(EpicFurnaces instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public Sound getLevelUp() {
|
||||
return Sound.valueOf(instance.getCurrentVersion() > 9 ? "PLAYER_LEVEL_UP" : "LEVEL_UP");
|
||||
public Sound getSound(String name) {
|
||||
if (Arrays.stream(Sound.values()).anyMatch(s -> s.toString().equalsIgnoreCase(name))) {
|
||||
return Sound.valueOf(name.toUpperCase());
|
||||
}
|
||||
|
||||
if (Arrays.stream(Sound.values()).anyMatch(s -> s.toString().equalsIgnoreCase(soundMap.getOrDefault(name, "NAN")))) {
|
||||
return Sound.valueOf(soundMap.get(name.toUpperCase()));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Effect getParticle(String name) {
|
||||
if (Arrays.stream(Effect.values()).anyMatch(s -> s.toString().equalsIgnoreCase(name))) {
|
||||
return Effect.valueOf(name.toUpperCase());
|
||||
}
|
||||
|
||||
if (Arrays.stream(Effect.values()).anyMatch(s -> s.toString().equalsIgnoreCase(particleMap.getOrDefault(name, "NAN")))) {
|
||||
return Effect.valueOf(particleMap.get(name.toUpperCase()));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getMaterial(String string) {
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.songoda.epicfurnaces.utils;
|
||||
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@ -23,9 +23,9 @@ public class Methods {
|
||||
ItemStack glass;
|
||||
|
||||
if (rainbow) {
|
||||
glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) randomNum);
|
||||
glass = new ItemStack(instance.getBukkitEnums().getMaterial("WHITE_STAINED_GLASS_PANE").getType(), 1, (short) randomNum);
|
||||
} else {
|
||||
glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) type);
|
||||
glass = new ItemStack(instance.getBukkitEnums().getMaterial("WHITE_STAINED_GLASS_PANE").getType(), 1, (short) type);
|
||||
}
|
||||
|
||||
ItemMeta glassMeta = glass.getItemMeta();
|
||||
@ -34,18 +34,6 @@ public class Methods {
|
||||
return glass;
|
||||
}
|
||||
|
||||
public static void particles(Block b, Player p) {
|
||||
EpicFurnaces plugin = instance;
|
||||
if (plugin.getConfig().getBoolean("settings.On-upgrade-particles")) {
|
||||
Location location = b.getLocation();
|
||||
location.setX(location.getX() + .5);
|
||||
location.setY(location.getY() + .5);
|
||||
location.setZ(location.getZ() + .5);
|
||||
//TODO: particles
|
||||
//p.getWorld().spawnParticle(org.bukkit.Particle.valueOf(plugin.getConfig().getString("Main.Upgrade Particle Type")), location, 200, .5, .5, .5);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getBackgroundGlass(boolean type) {
|
||||
if (type) {
|
||||
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.songoda.epicfurnaces.hook;
|
||||
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface CraftBukkitHook {
|
||||
void broadcastParticle(Location location, String name, int amount);
|
||||
}
|
@ -25,5 +25,7 @@
|
||||
<module>griefprevention</module>
|
||||
<module>worldguard6</module>
|
||||
<module>worldguard7</module>
|
||||
<!--<module>craftbukkit-1-8</module>-->
|
||||
<!--<module>craftbukkit-1-13</module>-->
|
||||
</modules>
|
||||
</project>
|
9
pom.xml
9
pom.xml
@ -12,15 +12,6 @@
|
||||
<module>hooks</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.13.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<plugins>
|
||||
|
Loading…
Reference in New Issue
Block a user