Hooked BlockBreakBlackList and AutoSellPrices to Settings

This commit is contained in:
Wertík 2020-03-19 18:39:50 +01:00 committed by Brianna
parent cd601a8b7f
commit fab8fc5a2c
3 changed files with 13 additions and 20 deletions

View File

@ -26,16 +26,12 @@ public class ModuleAutoSell extends Module {
private final int timeOut;
private final int hopperTickRate;
// TODO: Cached Sell prices are not updated on plugin reload, same with any other module
private static List<String> cachedSellPrices = null;
private static final Map<Hopper, Boolean> cachedNotifications = new ConcurrentHashMap<>();
public ModuleAutoSell(EpicHoppers plugin, int timeOut) {
super(plugin);
this.timeOut = timeOut * 20;
this.hopperTickRate = Settings.HOP_TICKS.getInt();
if (cachedSellPrices == null)
cachedSellPrices = plugin.getConfig().getStringList("Main.AutoSell Prices");
}
@Override
@ -89,7 +85,7 @@ public class ModuleAutoSell extends Module {
value = 0;
}
} else
value = cachedSellPrices.stream().filter(line -> Material.valueOf(line.split(",")[0]) == itemStack.getType()).findFirst()
value = Settings.AUTOSELL_PRICES.getStringList().stream().filter(line -> Material.valueOf(line.split(",")[0]) == itemStack.getType()).findFirst()
.map(s -> Double.valueOf(s.split(",")[1])).orElse(0.0);
if (value == 0) continue;

View File

@ -3,6 +3,7 @@ package com.songoda.epichoppers.hopper.levels.modules;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.hopper.Hopper;
import com.songoda.epichoppers.settings.Settings;
import com.songoda.epichoppers.utils.Methods;
import com.songoda.epichoppers.utils.StorageContainerCache;
import org.bukkit.Location;
@ -28,22 +29,10 @@ public class ModuleBlockBreak extends Module {
private final int ticksPerBreak;
private final Map<Hopper, Integer> blockTick = new HashMap<>();
private static final Map<Hopper, Boolean> cachedBlocks = new ConcurrentHashMap<>();
private static Particle cachedParticleEffectType = null;
private static final List<String> cachedBlacklistTypes = new ArrayList<>();
public ModuleBlockBreak(EpicHoppers plugin, int amount) {
super(plugin);
this.ticksPerBreak = amount;
if (cachedBlacklistTypes.isEmpty()) {
cachedBlacklistTypes.addAll(plugin.getConfig().getStringList("Main.BlockBreak Blacklisted Blocks"));
}
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9) && cachedParticleEffectType == null) {
try {
cachedParticleEffectType = Particle.valueOf(plugin.getConfig().getString("Main.BlockBreak Particle Type"));
} catch (Exception e) {
cachedParticleEffectType = Particle.LAVA;
}
}
}
@Override
@ -81,7 +70,7 @@ public class ModuleBlockBreak extends Module {
return;
// don't break blacklisted blocks, fluids, or containers
if (cachedBlacklistTypes.contains(above.getType().name())
if (Settings.BLOCKBREAK_BLACKLIST.getStringList().contains(above.getType().name())
|| above.getType() == Material.WATER
|| above.getType() == Material.LAVA
|| above.getType() == Material.AIR
@ -99,7 +88,15 @@ public class ModuleBlockBreak extends Module {
float xx = (float) (0 + (Math.random() * .5));
float yy = (float) (0 + (Math.random() * .5));
float zz = (float) (0 + (Math.random() * .5));
above.getWorld().spawnParticle(cachedParticleEffectType, locationAbove, 15, xx, yy, zz);
Particle particle;
try {
particle = Particle.valueOf(Settings.BLOCKBREAK_PARTICLE.getString());
} catch (Exception e) {
particle = Particle.LAVA;
}
above.getWorld().spawnParticle(particle, locationAbove, 15, xx, yy, zz);
}
boolean waterlogged = false;

View File

@ -62,7 +62,7 @@ public class Settings {
public static final ConfigSetting BLOCKBREAK_PARTICLE = new ConfigSetting(config, "Main.BlockBreak Particle Type", "LAVA",
"The particle shown when the block break module performs a block break.");
public static final ConfigSetting BLACKLIST = new ConfigSetting(config, "Main.BlockBreak Blacklisted Blocks",
public static final ConfigSetting BLOCKBREAK_BLACKLIST = new ConfigSetting(config, "Main.BlockBreak Blacklisted Blocks",
Arrays.asList("BEDROCK", "END_PORTAL", "ENDER_PORTAL", "END_PORTAL_FRAME", "ENDER_PORTAL_FRAME", "PISTON_HEAD", "PISTON_EXTENSION", "RAIL", "RAILS", "ACTIVATOR_RAIL", "DETECTOR_RAIL", "POWERED_RAIL"),
"Anything listed here will not be broken by the block break module.");