1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Reduced technical debt

This commit is contained in:
TheBusyBiscuit 2019-08-30 01:11:33 +02:00
parent a83266104e
commit 07271edc47
11 changed files with 48 additions and 39 deletions

View File

@ -1,6 +1,6 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import org.bukkit.Material;
@ -32,7 +32,7 @@ public abstract class CropGrowthAccelerator extends SlimefunItem {
private static final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
public static final Map<Material, Integer> crops = new HashMap<>();
public static final Map<Material, Integer> crops = new EnumMap<>(Material.class);
static {
crops.put(Material.WHEAT, 7);
@ -41,6 +41,7 @@ public abstract class CropGrowthAccelerator extends SlimefunItem {
crops.put(Material.NETHER_WART, 3);
crops.put(Material.BEETROOTS, 3);
crops.put(Material.COCOA, 8);
crops.put(Material.SWEET_BERRY_BUSH, 3);
}
public CropGrowthAccelerator(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe) {

View File

@ -1,7 +1,7 @@
package me.mrCookieSlime.Slimefun.Setup;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
@ -23,7 +23,7 @@ public final class SlimefunManager {
public static SlimefunStartup plugin;
public static String PREFIX;
public static Map<EntityType, List<ItemStack>> drops = new HashMap<>();
public static Map<EntityType, List<ItemStack>> drops = new EnumMap<>(EntityType.class);
public static void registerArmorSet(ItemStack baseComponent, ItemStack[] items, String idSyntax, PotionEffect[][] effects, boolean special, boolean slimefun) {
String[] components = new String[] {"_HELMET", "_CHESTPLATE", "_LEGGINGS", "_BOOTS"};
@ -33,10 +33,12 @@ public final class SlimefunManager {
recipes.add(new ItemStack[] {baseComponent, null, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent});
recipes.add(new ItemStack[] {baseComponent, baseComponent, baseComponent, baseComponent, null, baseComponent, baseComponent, null, baseComponent});
recipes.add(new ItemStack[] {null, null, null, baseComponent, null, baseComponent, baseComponent, null, baseComponent});
for (int i = 0; i < 4; i++) {
if ((effects.length - 1) >= i) if (effects[i].length > 0) {
if (i < effects.length && effects[i].length > 0) {
new SlimefunArmorPiece(cat, items[i], idSyntax + components[i], RecipeType.ARMOR_FORGE, recipes.get(i), effects[i]).register(slimefun);
} else {
}
else {
new SlimefunItem(cat, items[i], idSyntax + components[i], RecipeType.ARMOR_FORGE, recipes.get(i)).register(slimefun);
}
}
@ -50,10 +52,12 @@ public final class SlimefunManager {
recipes.add(new ItemStack[] {baseComponent, null, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent});
recipes.add(new ItemStack[] {baseComponent, baseComponent, baseComponent, baseComponent, null, baseComponent, baseComponent, null, baseComponent});
recipes.add(new ItemStack[] {null, null, null, baseComponent, null, baseComponent, baseComponent, null, baseComponent});
for (int i = 0; i < 4; i++) {
if (vanilla) {
new VanillaItem(cat, items[i], idSyntax + components[i], RecipeType.ARMOR_FORGE, recipes.get(i)).register(slimefun);
} else {
}
else {
new SlimefunItem(cat, items[i], idSyntax + components[i], RecipeType.ARMOR_FORGE, recipes.get(i)).register(slimefun);
}
}

View File

@ -2102,10 +2102,11 @@ public final class SlimefunSetup {
SlimefunStartup.instance.getUtilities().blocks.add(block.getUniqueId());
}
for (Entity n: ground.getChunk().getEntities()) {
if (n instanceof LivingEntity && n.getLocation().distance(ground) <= 2.0D && n.getUniqueId() != p.getUniqueId()) {
if (n instanceof LivingEntity && n.getLocation().distance(ground) <= 2.0D && !n.getUniqueId().equals(p.getUniqueId())) {
Vector vector = n.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().multiply(1.4);
vector.setY(0.9);
n.setVelocity(vector);
if (p.getWorld().getPVP()) {
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, n, DamageCause.ENTITY_ATTACK, 6D);
Bukkit.getPluginManager().callEvent(event);
@ -2414,9 +2415,10 @@ public final class SlimefunSetup {
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack item) {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.SCROLL_OF_DIMENSIONAL_TELEPOSITION, true)) {
for (Entity n: p.getNearbyEntities(10.0, 10.0, 10.0)) {
if (n instanceof LivingEntity && !(n instanceof ArmorStand) &&n.getUniqueId() != p.getUniqueId()) {
if (n instanceof LivingEntity && !(n instanceof ArmorStand) && !n.getUniqueId().equals(p.getUniqueId())) {
float yaw = n.getLocation().getYaw() + 180.0F;
if (yaw > 360.0F) yaw = yaw - 360.0F;
n.teleport(new Location(n.getWorld(), n.getLocation().getX(), n.getLocation().getY(), n.getLocation().getZ(), yaw, n.getLocation().getPitch()));
}
}

View File

@ -80,7 +80,6 @@ public final class SlimefunStartup extends JavaPlugin {
public static SlimefunStartup instance;
private static PluginUtils utils;
private static Config researches;
private static Config items;
private static Config whitelist;
@ -142,7 +141,7 @@ public final class SlimefunStartup extends JavaPlugin {
System.out.println("[Slimefun] Loading Config...");
utils = new PluginUtils(this);
PluginUtils utils = new PluginUtils(this);
utils.setupConfig();
// Loading all extra configs

View File

@ -89,7 +89,8 @@ public class BlockStorage {
File f = new File(path_blocks + w.getName());
if (f.exists()) {
long total = f.listFiles().length, start = System.currentTimeMillis();
long total = f.listFiles().length;
long start = System.currentTimeMillis();
long done = 0;
long timestamp = System.currentTimeMillis();
long totalBlocks = 0;
@ -525,7 +526,9 @@ public class BlockStorage {
if (item != null && item.isTicking()) {
String chunk_string = locationToChunkString(l);
if (value != null) {
Set<Location> locations = ticking_chunks.containsKey(chunk_string) ? ticking_chunks.get(chunk_string): new HashSet<>();
Set<Location> locations = ticking_chunks.get(chunk_string);
if (locations == null) locations = new HashSet<>();
locations.add(l);
ticking_chunks.put(chunk_string, locations);
if (!loaded_tickers.contains(chunk_string)) loaded_tickers.add(chunk_string);
@ -723,6 +726,6 @@ public class BlockStorage {
public boolean hasUniversalInventory(Location l) {
String id = checkID(l);
return id == null ? false: hasUniversalInventory(id);
return id != null && hasUniversalInventory(id);
}
}

View File

@ -162,9 +162,7 @@ public abstract class Network {
}
public void display() {
SlimefunStartup.instance.getServer().getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() {
@Override
public void run() {
SlimefunStartup.instance.getServer().getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
for(Location l: connectedLocations) {
try {
ParticleEffect.REDSTONE.display(l.clone().add(0.5, 0.5, 0.5), 0, 0, 0, 1, 1);
@ -172,7 +170,6 @@ public abstract class Network {
e.printStackTrace();
}
}
}
});
}

View File

@ -34,9 +34,7 @@ public final class CargoHologram {
}
if (!createIfNonExists) return null;
ArmorStand hologram = ArmorStandFactory.createHidden(l);
return hologram;
else return ArmorStandFactory.createHidden(l);
}
}

View File

@ -41,9 +41,7 @@ public final class EnergyHologram {
}
if (!createIfNonExists) return null;
ArmorStand hologram = ArmorStandFactory.createHidden(l);
return hologram;
else return ArmorStandFactory.createHidden(l);
}
}

View File

@ -64,7 +64,7 @@ public class DamageListener implements Listener {
Soul.storeItem(e.getEntity().getUniqueId(), item);
drops.remove();
}
else if (SlimefunItem.getByItem(removeEnchantments(item)) != null && SlimefunItem.getByItem(removeEnchantments(item)) instanceof SoulboundItem) {
else if (SlimefunItem.getByItem(removeEnchantments(item)) instanceof SoulboundItem) {
Soul.storeItem(e.getEntity().getUniqueId(), item);
drops.remove();
}

View File

@ -329,7 +329,8 @@ public class ItemListener implements Listener {
}
else if (item.getType() == Material.POTION) {
SlimefunItem sfItem = SlimefunItem.getByItem(item);
if (sfItem != null && sfItem instanceof Juice) {
if (sfItem instanceof Juice) {
// Fix for Saturation on potions is no longer working
for (PotionEffect effect : ((PotionMeta) item.getItemMeta()).getCustomEffects()) {
if (effect.getType().equals(PotionEffectType.SATURATION)) {
@ -401,10 +402,10 @@ public class ItemListener implements Listener {
}
}
else if (e.getEntity() instanceof Wither) {
SlimefunItem item = BlockStorage.check(e.getBlock());
if (item != null) {
if (item.getID().equals("WITHER_PROOF_OBSIDIAN")) e.setCancelled(true);
else if (item.getID().equals("WITHER_PROOF_GLASS")) e.setCancelled(true);
String id = BlockStorage.checkID(e.getBlock());
if (id != null) {
if (id.equals("WITHER_PROOF_OBSIDIAN")) e.setCancelled(true);
else if (id.equals("WITHER_PROOF_GLASS")) e.setCancelled(true);
}
}
}
@ -414,11 +415,14 @@ public class ItemListener implements Listener {
if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.ANVIL) {
ItemStack slot0 = e.getInventory().getContents()[0];
ItemStack slot1 = e.getInventory().getContents()[1];
if (SlimefunManager.isItemSimiliar(slot0, SlimefunItems.ELYTRA, true)) return;
if (SlimefunItem.getByItem(slot0) != null && !SlimefunItem.isDisabled(slot0)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
} else if (SlimefunItem.getByItem(slot1) != null && !SlimefunItem.isDisabled(slot1)) {
}
else if (SlimefunItem.getByItem(slot1) != null && !SlimefunItem.isDisabled(slot1)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
}
@ -427,7 +431,8 @@ public class ItemListener implements Listener {
if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.BOOK), true)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
} else if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.CHEST), true)) {
}
else if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.CHEST), true)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
}
@ -435,7 +440,8 @@ public class ItemListener implements Listener {
if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.BOOK), true)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
} else if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.CHEST), true)) {
}
else if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.CHEST), true)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
}

View File

@ -52,7 +52,8 @@ public class TalismanListener implements Listener {
((Player) ((EntityDamageByEntityEvent) e).getDamager()).playSound(((EntityDamageByEntityEvent) e).getDamager().getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.7F, 0.7F);
((Player) ((EntityDamageByEntityEvent) e).getDamager()).addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 1));
}
if (e.getEntity() instanceof Player && !e.isCancelled()) {
if (e.getEntity() instanceof Player) {
if (e.getCause() == DamageCause.LAVA) Talisman.checkFor(e, SlimefunItem.getByID("LAVA_TALISMAN"));
if (e.getCause() == DamageCause.DROWNING) Talisman.checkFor(e, SlimefunItem.getByID("WATER_TALISMAN"));
if (e.getCause() == DamageCause.FALL) Talisman.checkFor(e, SlimefunItem.getByID("ANGEL_TALISMAN"));