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-28 10:59:20 +02:00
parent dc1cff31f5
commit e0316453d9
38 changed files with 196 additions and 229 deletions

View File

@ -13,8 +13,8 @@ public class MultiBlock {
public static List<MultiBlock> list = new ArrayList<>();
Material[] blocks;
Material trigger;
private Material[] blocks;
private Material trigger;
public MultiBlock(Material[] build, Material trigger) {
this.blocks = build;

View File

@ -7,7 +7,7 @@ import org.bukkit.inventory.ItemStack;
public class DamagableChargableItem extends SlimefunItem {
String chargeType;
private String chargeType;
public DamagableChargableItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, String chargeType) {
super(category, item, id, recipeType, recipe);
@ -19,6 +19,8 @@ public class DamagableChargableItem extends SlimefunItem {
this.chargeType = chargeType;
}
public String getChargeType() { return this.chargeType; }
public String getChargeType() {
return this.chargeType;
}
}

View File

@ -1,18 +1,21 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.SlimefunStartup;
import me.mrCookieSlime.Slimefun.Lists.Categories;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import java.util.Random;
import org.bukkit.block.Block;
import org.bukkit.block.Furnace;
import org.bukkit.inventory.ItemStack;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Lists.Categories;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
public class EnhancedFurnace extends SlimefunItem {
int speed, efficiency, fortune;
private int speed;
private int efficiency;
private int fortune;
public EnhancedFurnace(int speed, int efficiency, int fortune, ItemStack item, String id, ItemStack[] recipe) {
super(Categories.MACHINES_1, item, id, RecipeType.ENHANCED_CRAFTING_TABLE, recipe);
@ -59,7 +62,7 @@ public class EnhancedFurnace extends SlimefunItem {
public int getOutput() {
int fortune = this.fortune;
fortune = SlimefunStartup.randomize(fortune + 2) - 1;
fortune = new Random().nextInt(fortune + 2) - 1;
if (fortune <= 0) fortune = 0;
fortune++;
return fortune;

View File

@ -7,7 +7,7 @@ import org.bukkit.inventory.ItemStack;
public class JetBoots extends DamagableChargableItem {
double speed;
private double speed;
public JetBoots(ItemStack item, String id, ItemStack[] recipe, double speed) {
super(Categories.TECH, item, id, RecipeType.ENHANCED_CRAFTING_TABLE, recipe, "Jet Boots");

View File

@ -7,7 +7,7 @@ import org.bukkit.inventory.ItemStack;
public class Jetpack extends DamagableChargableItem {
double thrust;
private double thrust;
public Jetpack(ItemStack item, String id, ItemStack[] recipe, double thrust) {
super(Categories.TECH, item, id, RecipeType.ENHANCED_CRAFTING_TABLE, recipe, "Jetpack");

View File

@ -11,7 +11,7 @@ import org.bukkit.inventory.ItemStack;
public class MultiTool extends DamagableChargableItem {
List<Integer> modes;
private List<Integer> modes;
public MultiTool(ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, String[] keys, Object[] values) {
super(Categories.TECH, item, id, recipeType, recipe, "Multi Tool", keys, values);
@ -19,7 +19,7 @@ public class MultiTool extends DamagableChargableItem {
@Override
public void create() {
List<Integer> list = new ArrayList<Integer>();
List<Integer> list = new ArrayList<>();
for (int i = 0; i < 50; i++) {
if (Slimefun.getItemValue(this.getID(), "mode." + i + ".enabled") != null) {
if ((Boolean) Slimefun.getItemValue(this.getID(), "mode." + i + ".enabled")) list.add(i);

View File

@ -8,7 +8,7 @@ import org.bukkit.potion.PotionEffect;
public class SlimefunArmorPiece extends SlimefunItem {
PotionEffect[] effects;
private PotionEffect[] effects;
public SlimefunArmorPiece(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) {
super(category, item, id, recipeType, recipe);
@ -20,6 +20,8 @@ public class SlimefunArmorPiece extends SlimefunItem {
this.effects = effects;
}
public PotionEffect[] getEffects() { return this.effects; }
public PotionEffect[] getEffects() {
return this.effects;
}
}

View File

@ -10,13 +10,15 @@ import org.bukkit.inventory.ItemStack;
public class SlimefunGadget extends SlimefunItem {
List<ItemStack[]> recipes;
List<ItemStack> display_recipes;
private List<ItemStack[]> recipes;
private List<ItemStack> display_recipes;
public SlimefunGadget(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, ItemStack[] machineRecipes) {
super(category, item, id, recipeType, recipe);
this.recipes = new ArrayList<ItemStack[]>();
this.display_recipes = new ArrayList<ItemStack>();
this.recipes = new ArrayList<>();
this.display_recipes = new ArrayList<>();
for (ItemStack i: machineRecipes) {
this.recipes.add(new ItemStack[] {i});
this.display_recipes.add(i);
@ -25,8 +27,9 @@ public class SlimefunGadget extends SlimefunItem {
public SlimefunGadget(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, ItemStack[] machineRecipes, String[] keys, Object[] values) {
super(category, item, id, recipeType, recipe, keys, values);
this.recipes = new ArrayList<ItemStack[]>();
this.display_recipes = new ArrayList<ItemStack>();
this.recipes = new ArrayList<>();
this.display_recipes = new ArrayList<>();
for (ItemStack i: machineRecipes) {
this.recipes.add(new ItemStack[] {i});
this.display_recipes.add(i);

View File

@ -349,7 +349,7 @@ public class SlimefunItem {
if (recipeType.toItem().isSimilar(RecipeType.MOB_DROP.toItem())) {
try {
EntityType entity = EntityType.valueOf(ChatColor.stripColor(recipe[4].getItemMeta().getDisplayName()).toUpperCase().replace(" ", "_"));
List<ItemStack> dropping = new ArrayList<ItemStack>();
List<ItemStack> dropping = new ArrayList<>();
if (SlimefunManager.drops.containsKey(entity)) dropping = SlimefunManager.drops.get(entity);
dropping.add(output);
SlimefunManager.drops.put(entity, dropping);

View File

@ -255,8 +255,8 @@ public abstract class AContainer extends SlimefunItem {
}
else {
MachineRecipe r = null;
Map<Integer, Integer> found = new HashMap<Integer, Integer>();
outer:
Map<Integer, Integer> found = new HashMap<>();
for (MachineRecipe recipe: recipes) {
for (ItemStack input: recipe.getInput()) {
slots:
@ -269,7 +269,7 @@ public abstract class AContainer extends SlimefunItem {
}
if (found.size() == recipe.getInput().length) {
r = recipe;
break outer;
break;
}
else found.clear();
}

View File

@ -118,7 +118,7 @@ public abstract class ADrill extends AContainer {
ItemMeta im = item.getItemMeta();
((Damageable) im).setDamage(MachineHelper.getDurability(item, timeleft, processing.get(b).getTicks()));
im.setDisplayName(" ");
List<String> lore = new ArrayList<String>();
List<String> lore = new ArrayList<>();
lore.add(MachineHelper.getProgress(timeleft, processing.get(b).getTicks()));
lore.add("");
lore.add(MachineHelper.getTimeLeft(timeleft / 2));

View File

@ -6,6 +6,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import org.bukkit.Bukkit;
@ -264,7 +265,7 @@ public abstract class AReactor extends SlimefunItem {
public void register(boolean slimefun) {
addItemHandler(new EnergyTicker() {
Set<Location> explode = new HashSet<Location>();
private Set<Location> explode = new HashSet<>();
@Override
public double generateEnergy(final Location l, SlimefunItem sf, Config data) {
@ -284,13 +285,13 @@ public abstract class AReactor extends SlimefunItem {
progress.put(l, timeleft - 1);
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
if (!l.getBlock().getRelative(cooling[CSCoreLib.randomizer().nextInt(cooling.length)]).isLiquid()) explode.add(l);
if (!l.getBlock().getRelative(cooling[new Random().nextInt(cooling.length)]).isLiquid()) explode.add(l);
});
ItemStack item = getProgressBar().clone();
ItemMeta im = item.getItemMeta();
im.setDisplayName(" ");
List<String> lore = new ArrayList<String>();
List<String> lore = new ArrayList<>();
lore.add(MachineHelper.getProgress(timeleft, processing.get(l).getTicks()));
lore.add(MachineHelper.getCoolant(timeleft, processing.get(l).getTicks()));
lore.add("");
@ -353,7 +354,7 @@ public abstract class AReactor extends SlimefunItem {
}
else {
MachineFuel r = null;
Map<Integer, Integer> found = new HashMap<Integer, Integer>();
Map<Integer, Integer> found = new HashMap<>();
if (port != null) {
refill:
@ -384,6 +385,7 @@ public abstract class AReactor extends SlimefunItem {
for (Map.Entry<Integer, Integer> entry: found.entrySet()) {
BlockStorage.getInventory(l).replaceExistingItem(entry.getKey(), InvUtils.decreaseItem(BlockStorage.getInventory(l).getItemInSlot(entry.getKey()), entry.getValue()));
}
processing.put(l, r);
progress.put(l, r.getTicks());
}

View File

@ -4,9 +4,9 @@ import org.bukkit.inventory.ItemStack;
public class MachineRecipe {
int ticks;
ItemStack[] input;
ItemStack[] output;
private int ticks;
private ItemStack[] input;
private ItemStack[] output;
public MachineRecipe(int seconds, ItemStack[] input, ItemStack[] output) {
this.ticks = seconds * 2;

View File

@ -61,7 +61,7 @@ public abstract class AutoAnvil extends AContainer {
ItemMeta im = item.getItemMeta();
((Damageable) im).setDamage(MachineHelper.getDurability(item, timeleft, processing.get(b).getTicks()));
im.setDisplayName(" ");
List<String> lore = new ArrayList<String>();
List<String> lore = new ArrayList<>();
lore.add(MachineHelper.getProgress(timeleft, processing.get(b).getTicks()));
lore.add("");
lore.add(MachineHelper.getTimeLeft(timeleft / 2));

View File

@ -62,7 +62,7 @@ public class AutoDisenchanter extends AContainer {
ItemMeta im = item.getItemMeta();
((Damageable) im).setDamage(MachineHelper.getDurability(item, timeleft, processing.get(b).getTicks()));
im.setDisplayName(" ");
List<String> lore = new ArrayList<String>();
List<String> lore = new ArrayList<>();
lore.add(MachineHelper.getProgress(timeleft, processing.get(b).getTicks()));
lore.add("");
lore.add(MachineHelper.getTimeLeft(timeleft / 2));
@ -88,8 +88,8 @@ public class AutoDisenchanter extends AContainer {
}
else {
MachineRecipe r = null;
Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>();
Set<ItemEnchantment> enchantments2 = new HashSet<ItemEnchantment>();
Map<Enchantment, Integer> enchantments = new HashMap<>();
Set<ItemEnchantment> enchantments2 = new HashSet<>();
slots:
for (int slot: getInputSlots()) {
ItemStack target = BlockStorage.getInventory(b).getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1]: getInputSlots()[0]);

View File

@ -64,7 +64,7 @@ public class AutoEnchanter extends AContainer {
ItemMeta im = item.getItemMeta();
((Damageable) im).setDamage(MachineHelper.getDurability(item, timeleft, processing.get(b).getTicks()));
im.setDisplayName(" ");
List<String> lore = new ArrayList<String>();
List<String> lore = new ArrayList<>();
lore.add(MachineHelper.getProgress(timeleft, processing.get(b).getTicks()));
lore.add("");
lore.add(MachineHelper.getTimeLeft(timeleft / 2));
@ -101,8 +101,8 @@ public class AutoEnchanter extends AContainer {
// Enchant
if (item != null && item.getType() == Material.ENCHANTED_BOOK && target != null) {
Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>();
Set<ItemEnchantment> enchantments2 = new HashSet<ItemEnchantment>();
Map<Enchantment, Integer> enchantments = new HashMap<>();
Set<ItemEnchantment> enchantments2 = new HashSet<>();
int amount = 0;
int special_amount = 0;
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();

View File

@ -41,7 +41,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem {
private static final int[] border_in = {9, 10, 11, 12, 13, 18, 22, 27, 31, 36, 40, 45, 46, 47, 48, 49};
private static final int[] border_out = {23, 24, 25, 26, 32, 35, 41, 42, 43, 44};
public static Map<String, ItemStack> recipes = new HashMap<String, ItemStack>();
public static Map<String, ItemStack> recipes = new HashMap<>();
public AutomatedCraftingChamber(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, name, recipeType, recipe);

View File

@ -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<Material, Integer>();
public static final Map<Material, Integer> crops = new HashMap<>();
static {
crops.put(Material.WHEAT, 7);

View File

@ -51,7 +51,7 @@ public abstract class ElectricGoldPan extends AContainer {
ItemMeta im = item.getItemMeta();
((Damageable) im).setDamage(MachineHelper.getDurability(item, timeleft, processing.get(b).getTicks()));
im.setDisplayName(" ");
List<String> lore = new ArrayList<String>();
List<String> lore = new ArrayList<>();
lore.add(MachineHelper.getProgress(timeleft, processing.get(b).getTicks()));
lore.add("");
lore.add(MachineHelper.getTimeLeft(timeleft / 2));

View File

@ -36,8 +36,8 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class FluidPump extends SlimefunItem{
public static Map<Block, MachineRecipe> processing = new HashMap<Block, MachineRecipe>();
public static Map<Block, Integer> progress = new HashMap<Block, Integer>();
public static Map<Block, MachineRecipe> processing = new HashMap<>();
public static Map<Block, Integer> progress = new HashMap<>();
private static final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 13, 31, 36, 37, 38, 39, 40, 41, 42, 43, 44, 22};
private static final int[] border_in = {9, 10, 11, 12, 18, 21, 27, 28, 29, 30};
@ -124,13 +124,13 @@ public class FluidPump extends SlimefunItem{
ItemStack output = new ItemStack(Material.LAVA_BUCKET);
if (!fits(b, new ItemStack[] {output})) return;
if (!fits(b, output)) return;
ChargableBlock.addCharge(b, -getEnergyConsumption());
BlockStorage.getInventory(b).replaceExistingItem(slot, InvUtils.decreaseItem(BlockStorage.getInventory(b).getItemInSlot(slot), 1));
pushItems(b, new ItemStack[] {output});
pushItems(b, output);
List<Location> list = new ArrayList<Location>();
List<Location> list = new ArrayList<>();
list.add(fluid.getLocation());
Vein.calculate(fluid.getLocation(), fluid.getLocation(), list, 64);
list.get(list.size() - 1).getBlock().setType(Material.AIR);
@ -146,11 +146,11 @@ public class FluidPump extends SlimefunItem{
ItemStack output = new ItemStack(Material.WATER_BUCKET);
if (!fits(b, new ItemStack[] {output})) return;
if (!fits(b, output)) return;
ChargableBlock.addCharge(b, -getEnergyConsumption());
BlockStorage.getInventory(b).replaceExistingItem(slot, InvUtils.decreaseItem(BlockStorage.getInventory(b).getItemInSlot(slot), 1));
pushItems(b, new ItemStack[] {output});
pushItems(b, output);
fluid.setType(Material.AIR);
@ -198,11 +198,11 @@ public class FluidPump extends SlimefunItem{
return inv;
}
protected boolean fits(Block b, ItemStack[] items) {
protected boolean fits(Block b, ItemStack... items) {
return inject(b).addItem(items).isEmpty();
}
protected void pushItems(Block b, ItemStack[] items) {
protected void pushItems(Block b, ItemStack... items) {
Inventory inv = inject(b);
inv.addItem(items);

View File

@ -63,7 +63,7 @@ public abstract class HeatedPressureChamber extends AContainer {
public int[] getSlotsAccessedByItemTransport(BlockMenu menu, ItemTransportFlow flow, ItemStack item) {
if (flow.equals(ItemTransportFlow.WITHDRAW)) return getOutputSlots();
List<Integer> slots = new ArrayList<Integer>();
List<Integer> slots = new ArrayList<>();
for (int slot: getInputSlots()) {
if (SlimefunManager.isItemSimiliar(menu.getItemInSlot(slot), item, true)) {
@ -98,8 +98,8 @@ public abstract class HeatedPressureChamber extends AContainer {
registerRecipe(30, new ItemStack[] {SlimefunItems.BLISTERING_INGOT, SlimefunItems.CARBONADO}, new ItemStack[] {SlimefunItems.BLISTERING_INGOT_2});
registerRecipe(60, new ItemStack[] {SlimefunItems.BLISTERING_INGOT_2, new ItemStack(Material.NETHER_STAR)}, new ItemStack[] {SlimefunItems.BLISTERING_INGOT_3});
registerRecipe(90, new ItemStack[] {SlimefunItems.PLUTONIUM, SlimefunItems.URANIUM}, new ItemStack[] {SlimefunItems.BOOSTED_URANIUM});
registerRecipe(60, new ItemStack[]{SlimefunItems.NETHER_ICE, SlimefunItems.PLUTONIUM}, new ItemStack[]{new CustomItem(SlimefunItems.ENRICHED_NETHER_ICE, 4)});
registerRecipe(45, new ItemStack[]{SlimefunItems.ENRICHED_NETHER_ICE}, new ItemStack[]{new CustomItem(SlimefunItems.NETHER_ICE_COOLANT_CELL, 8)});
registerRecipe(60, new ItemStack[] {SlimefunItems.NETHER_ICE, SlimefunItems.PLUTONIUM}, new ItemStack[]{new CustomItem(SlimefunItems.ENRICHED_NETHER_ICE, 4)});
registerRecipe(45, new ItemStack[] {SlimefunItems.ENRICHED_NETHER_ICE}, new ItemStack[]{new CustomItem(SlimefunItems.NETHER_ICE_COOLANT_CELL, 8)});
}
public String getInventoryTitle() {
@ -148,7 +148,7 @@ public abstract class HeatedPressureChamber extends AContainer {
ItemMeta im = item.getItemMeta();
im.setDisplayName(" ");
((Damageable) im).setDamage(MachineHelper.getDurability(item, timeleft, processing.get(b).getTicks()));
List<String> lore = new ArrayList<String>();
List<String> lore = new ArrayList<>();
lore.add(MachineHelper.getProgress(timeleft, processing.get(b).getTicks()));
lore.add("");
lore.add(MachineHelper.getTimeLeft(timeleft / 2));
@ -174,8 +174,8 @@ public abstract class HeatedPressureChamber extends AContainer {
}
else {
MachineRecipe r = null;
Map<Integer, Integer> found = new HashMap<Integer, Integer>();
outer:
Map<Integer, Integer> found = new HashMap<>();
for (MachineRecipe recipe: recipes) {
for (ItemStack input: recipe.getInput()) {
slots:
@ -188,7 +188,7 @@ public abstract class HeatedPressureChamber extends AContainer {
}
if (found.size() == recipe.getInput().length) {
r = recipe;
break outer;
break;
}
else found.clear();
}

View File

@ -91,7 +91,7 @@ public abstract class OilPump extends AContainer {
ItemMeta im = item.getItemMeta();
((Damageable) im).setDamage(MachineHelper.getDurability(item, timeleft, processing.get(b).getTicks()));
im.setDisplayName(" ");
List<String> lore = new ArrayList<String>();
List<String> lore = new ArrayList<>();
lore.add(MachineHelper.getProgress(timeleft, processing.get(b).getTicks()));
lore.add("");
lore.add(MachineHelper.getTimeLeft(timeleft / 2));

View File

@ -53,7 +53,7 @@ public abstract class Refinery extends AContainer {
ItemMeta im = item.getItemMeta();
((Damageable) im).setDamage(MachineHelper.getDurability(item, timeleft, processing.get(b).getTicks()));
im.setDisplayName(" ");
List<String> lore = new ArrayList<String>();
List<String> lore = new ArrayList<>();
lore.add(MachineHelper.getProgress(timeleft, processing.get(b).getTicks()));
lore.add("");
lore.add(MachineHelper.getTimeLeft(timeleft / 2));

View File

@ -34,19 +34,20 @@ public final class Files {
}
}
public static void delete(File folder) {
public static boolean delete(File folder) {
File[] files = folder.listFiles();
if (files != null) {
for (File current: files) {
if (current.isDirectory()) {
delete(current);
if (!delete(current)) return false;;
}
else {
current.delete();
if (!current.delete()) return false;
}
}
}
folder.delete();
return folder.delete();
}
}

View File

@ -1196,7 +1196,7 @@ public final class SlimefunSetup {
public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
if (SlimefunManager.isItemSimiliar(e.getPlayer().getInventory().getItemInMainHand(), SlimefunItems.LUMBER_AXE, true)) {
if (MaterialHelper.isLog( e.getBlock().getType())) {
List<Location> logs = new ArrayList<Location>();
List<Location> logs = new ArrayList<>();
TreeCalculator.getTree(e.getBlock().getLocation(), e.getBlock().getLocation(), logs);
if (logs.contains(e.getBlock().getLocation())) logs.remove(e.getBlock().getLocation());
@ -1541,9 +1541,10 @@ public final class SlimefunSetup {
return false;
}
Chest chest = (Chest) chestBlock.getState();
Chest chest = (Chest) chestBlock.getState();
final Inventory inv = chest.getInventory();
List<Location> ores = new ArrayList<Location>();
List<Location> ores = new ArrayList<>();
for (int x = b.getX() - 4; x <= b.getX() + 4; x++) {
for (int z = b.getZ() - 4; z <= b.getZ() + 4; z++) {
for (int y = b.getY(); y > 0; y--) {
@ -1599,9 +1600,10 @@ public final class SlimefunSetup {
return false;
}
Chest chest = (Chest) chestBlock.getState();
Chest chest = (Chest) chestBlock.getState();
final Inventory inv = chest.getInventory();
List<Location> ores = new ArrayList<Location>();
List<Location> ores = new ArrayList<>();
for (int x = b.getX() - 6; x <= b.getX() + 6; x++) {
for (int z = b.getZ() - 6; z <= b.getZ() + 6; z++) {
for (int y = b.getY(); y > 0; y--) {
@ -1789,15 +1791,19 @@ public final class SlimefunSetup {
new ItemStack[] {new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT), new ItemStack(Material.GRAVEL), new ItemStack(Material.CLAY_BALL), new ItemStack(Material.GRAVEL), SlimefunItems.SIFTED_ORE}, Material.OAK_TRAPDOOR)
.register(true, new MultiBlockInteractionHandler() {
private Random random = new Random();
@Override
public boolean onInteract(final Player p, MultiBlock mb, final Block b) {
if (mb.isMultiBlock(SlimefunItem.getByID("AUTOMATED_PANNING_MACHINE"))) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
final ItemStack input = p.getInventory().getItemInMainHand();
ItemStack output = null;
if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("GOLD_PAN", "chance.SIFTED_ORE"))) output = SlimefunItems.SIFTED_ORE;
else if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("GOLD_PAN", "chance.CLAY"))) output = new ItemStack(Material.CLAY_BALL);
else if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("GOLD_PAN", "chance.FLINT"))) output = new ItemStack(Material.FLINT);
if (random.nextInt(100) < (Integer) Slimefun.getItemValue("GOLD_PAN", "chance.SIFTED_ORE")) output = SlimefunItems.SIFTED_ORE;
else if (random.nextInt(100) < (Integer) Slimefun.getItemValue("GOLD_PAN", "chance.CLAY")) output = new ItemStack(Material.CLAY_BALL);
else if (random.nextInt(100) < (Integer) Slimefun.getItemValue("GOLD_PAN", "chance.FLINT")) output = new ItemStack(Material.FLINT);
final ItemStack drop = output;
if (input != null) {
if (input.getType() == Material.GRAVEL) {
@ -1815,6 +1821,7 @@ public final class SlimefunSetup {
return true;
}
}
Messages.local.sendTranslation(p, "machines.wrong-item", true);
return true;
}
@ -1864,7 +1871,7 @@ public final class SlimefunSetup {
}
if (e.getPlayer().getInventory().getItemInMainHand().getEnchantments().containsKey(Enchantment.DURABILITY)) {
if (SlimefunStartup.randomize(100) <= (60 + 40 / (e.getPlayer().getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.DURABILITY) + 1))) PlayerInventory.damageItemInHand(e.getPlayer());
if (new Random().nextInt(100) <= (60 + 40 / (e.getPlayer().getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.DURABILITY) + 1))) PlayerInventory.damageItemInHand(e.getPlayer());
}
else PlayerInventory.damageItemInHand(e.getPlayer());
@ -2108,7 +2115,7 @@ public final class SlimefunSetup {
public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
if (SlimefunManager.isItemSimiliar(e.getPlayer().getInventory().getItemInMainHand(), SlimefunItems.PICKAXE_OF_VEIN_MINING, true)) {
if (e.getBlock().getType().toString().endsWith("_ORE")) {
List<Location> blocks = new ArrayList<Location>();
List<Location> blocks = new ArrayList<>();
Vein.calculate(e.getBlock().getLocation(), e.getBlock().getLocation(), blocks, 16);
for (Location block: blocks) {
Block b = block.getBlock();
@ -2555,7 +2562,8 @@ public final class SlimefunSetup {
PlayerInventory.consumeItemInHand(e.getPlayer());
FireworkShow.launchRandom(e.getPlayer(), 2);
List<ItemStack> gifts = new ArrayList<ItemStack>();
List<ItemStack> gifts = new ArrayList<>();
for (int i = 0; i < 2; i++) {
gifts.add(new CustomItem(SlimefunItems.EASTER_CARROT_PIE, 4));
gifts.add(new CustomItem(SlimefunItems.CHRISTMAS_APPLE_PIE, 4));

View File

@ -289,10 +289,10 @@ public final class SlimefunGuide {
clearHistory(p.getUniqueId());
if (book) {
List<TellRawMessage> pages = new ArrayList<TellRawMessage>();
List<String> texts = new ArrayList<String>();
List<String> tooltips = new ArrayList<String>();
List<PlayerRunnable> actions = new ArrayList<PlayerRunnable>();
List<TellRawMessage> pages = new ArrayList<>();
List<String> texts = new ArrayList<>();
List<String> tooltips = new ArrayList<>();
List<PlayerRunnable> actions = new ArrayList<>();
int tier = 0;
@ -501,7 +501,7 @@ public final class SlimefunGuide {
index++;
}
else {
List<String> parents = new ArrayList<String>();
List<String> parents = new ArrayList<>();
parents.add("");
parents.add(ChatColor.translateAlternateColorCodes('&', "&rYou need to unlock all Items"));
parents.add(ChatColor.translateAlternateColorCodes('&', "&rfrom the following Categories first:"));
@ -549,10 +549,10 @@ public final class SlimefunGuide {
if (category == null) return;
if (book && category.getItems().size() < 250) {
List<TellRawMessage> pages = new ArrayList<TellRawMessage>();
List<String> texts = new ArrayList<String>();
List<String> tooltips = new ArrayList<String>();
List<PlayerRunnable> actions = new ArrayList<PlayerRunnable>();
List<TellRawMessage> pages = new ArrayList<>();
List<String> texts = new ArrayList<>();
List<String> tooltips = new ArrayList<>();
List<PlayerRunnable> actions = new ArrayList<>();
for (final SlimefunItem item: category.getItems()) {
if (Slimefun.hasPermission(p, item, false)) {

View File

@ -100,7 +100,7 @@ public class SlimefunStartup extends JavaPlugin {
private boolean coreProtect = false;
// Supported Versions of Minecraft
final String[] supported = {"v1_14_"};
private final String[] supported = {"v1_14_"};
@Override
public void onEnable() {

View File

@ -4,8 +4,8 @@ import org.bukkit.block.Block;
public class AndroidObject {
ProgrammableAndroid android;
Block b;
private ProgrammableAndroid android;
private Block b;
public AndroidObject(ProgrammableAndroid android, Block b) {
this.android = android;

View File

@ -273,80 +273,67 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
ScriptPart part = ScriptPart.valueOf(script[index]);
if (getAndroidType().isType(part.getRequiredType())) {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
double damage = getTier() < 2 ? 20D : 4D * getTier();
switch (part) {
case GO_DOWN: {
case GO_DOWN:
try {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(BlockFace.DOWN);
move(b, face, block);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
case GO_FORWARD: {
case GO_FORWARD:
try {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(face);
move(b, face, block);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
case GO_UP: {
case GO_UP:
try {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(BlockFace.UP);
move(b, face, block);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
case REPEAT: {
case REPEAT:
BlockStorage.addBlockInfo(b, "index", String.valueOf(0));
break;
}
case TURN_LEFT: {
int rotIndex = directions.indexOf(BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"))) - 1;
if (rotIndex < 0) rotIndex = directions.size() - 1;
BlockFace dir = directions.get(rotIndex);
Rotatable blockData = (Rotatable) b.getBlockData();
blockData.setRotation(dir);
b.setBlockData(blockData);
BlockStorage.addBlockInfo(b, "rotation", dir.toString());
case TURN_LEFT:
int indexLeft = directions.indexOf(BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"))) - 1;
if (indexLeft < 0) indexLeft = directions.size() - 1;
Rotatable rotatableLeft = (Rotatable) b.getBlockData();
rotatableLeft.setRotation(directions.get(indexLeft));
b.setBlockData(rotatableLeft);
BlockStorage.addBlockInfo(b, "rotation", directions.get(indexLeft).toString());
break;
}
case TURN_RIGHT: {
int rotIndex = directions.indexOf(BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"))) + 1;
if (rotIndex == directions.size()) rotIndex = 0;
BlockFace dir = directions.get(rotIndex);
Rotatable blockData = (Rotatable) b.getBlockData();
blockData.setRotation(dir);
b.setBlockData(blockData);
BlockStorage.addBlockInfo(b, "rotation", dir.toString());
int indexRight = directions.indexOf(BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"))) + 1;
if (indexRight == directions.size()) indexRight = 0;
Rotatable rotatableRight = (Rotatable) b.getBlockData();
rotatableRight.setRotation(directions.get(indexRight));
b.setBlockData(rotatableRight);
BlockStorage.addBlockInfo(b, "rotation", directions.get(indexRight).toString());
break;
}
case DIG_FORWARD: {
Block block = b.getRelative(BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation")));
mine(b, block);
case DIG_FORWARD:
mine(b, b.getRelative(face));
break;
}
case DIG_UP: {
Block block = b.getRelative(BlockFace.UP);
mine(b, block);
case DIG_UP:
mine(b, b.getRelative(BlockFace.UP));
break;
}
case DIG_DOWN: {
Block block = b.getRelative(BlockFace.DOWN);
mine(b, block);
case DIG_DOWN:
mine(b, b.getRelative(BlockFace.DOWN));
break;
}
case CATCH_FISH: {
Block block = b.getRelative(BlockFace.DOWN);
if (block.getType().equals(Material.WATER)) {
block.getWorld().playSound(block.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
case CATCH_FISH:
Block water = b.getRelative(BlockFace.DOWN);
if (water.getType().equals(Material.WATER)) {
water.getWorld().playSound(water.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
if (CSCoreLib.randomizer().nextInt(100) < 10 * getTier()) {
ItemStack drop = fish[CSCoreLib.randomizer().nextInt(fish.length)];
if (fits(b, drop)) pushItems(b, drop);
@ -354,30 +341,19 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
}
break;
}
case MOVE_AND_DIG_FORWARD: {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(face);
movedig(b, face, block);
case MOVE_AND_DIG_FORWARD:
movedig(b, face, b.getRelative(face));
break;
}
case MOVE_AND_DIG_UP: {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(BlockFace.UP);
movedig(b, face, block);
movedig(b, face, b.getRelative(BlockFace.UP));
break;
}
case MOVE_AND_DIG_DOWN: {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(BlockFace.DOWN);
movedig(b, face, block);
case MOVE_AND_DIG_DOWN:
movedig(b, face, b.getRelative(BlockFace.DOWN));
break;
}
case INTERFACE_ITEMS: {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(face);
if (BlockStorage.check(block, "ANDROID_INTERFACE_ITEMS") && block.getState() instanceof Dispenser) {
Dispenser d = (Dispenser) block.getState();
case INTERFACE_ITEMS:
if (BlockStorage.check(b.getRelative(face), "ANDROID_INTERFACE_ITEMS") && b.getRelative(face).getState() instanceof Dispenser) {
Dispenser d = (Dispenser) b.getRelative(face).getState();
for (int slot: getOutputSlots()) {
ItemStack stack = BlockStorage.getInventory(b).getItemInSlot(slot);
if (stack != null) {
@ -393,12 +369,9 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
}
}
break;
}
case INTERFACE_FUEL: {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(face);
if (BlockStorage.check(block, "ANDROID_INTERFACE_FUEL") && block.getState() instanceof Dispenser) {
Dispenser d = (Dispenser) block.getState();
case INTERFACE_FUEL:
if (BlockStorage.check(b.getRelative(face), "ANDROID_INTERFACE_FUEL") && b.getRelative(face).getState() instanceof Dispenser) {
Dispenser d = (Dispenser) b.getRelative(face).getState();
for (int slot = 0; slot < 9; slot++) {
ItemStack item = d.getInventory().getItem(slot);
if (item != null) {
@ -420,36 +393,23 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
}
}
break;
}
case FARM_FORWARD: {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(face);
farm(b, block);
case FARM_FORWARD:
farm(b, b.getRelative(face));
break;
}
case FARM_DOWN: {
Block block = b.getRelative(BlockFace.DOWN);
farm(b, block);
case FARM_DOWN:
farm(b, b.getRelative(BlockFace.DOWN));
break;
}
case FARM_EXOTIC_FORWARD: {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(face);
exoticFarm(b, block);
case FARM_EXOTIC_FORWARD:
exoticFarm(b, b.getRelative(face));
break;
}
case FARM_EXOTIC_DOWN: {
Block block = b.getRelative(BlockFace.DOWN);
exoticFarm(b, block);
case FARM_EXOTIC_DOWN:
exoticFarm(b, b.getRelative(BlockFace.DOWN));
break;
}
case CHOP_TREE: {
BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
Block block = b.getRelative(face);
if (MaterialHelper.isLog( block.getType())) {
List<Location> list = new ArrayList<Location>();
list.add(block.getLocation());
TreeCalculator.getTree(block.getLocation(), block.getLocation(), list);
case CHOP_TREE:
if (MaterialHelper.isLog(b.getRelative(face).getType())) {
List<Location> list = new ArrayList<>();
list.add(b.getRelative(face).getLocation());
TreeCalculator.getTree(b.getRelative(face).getLocation(), b.getRelative(face).getLocation(), list);
if (!list.isEmpty()) {
refresh = false;
Block log = list.get(list.size() - 1).getBlock();
@ -460,7 +420,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
if (fits(b, items)) {
pushItems(b, items);
log.getWorld().playEffect(log.getLocation(), Effect.STEP_SOUND, log.getType());
if (log.getY() == block.getY()) {
if (log.getY() == b.getRelative(face).getY()) {
log.setType(MaterialHelper.getSaplingFromLog(log.getType()));
}
else log.setType(Material.AIR);
@ -470,10 +430,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
}
}
break;
}
case ATTACK_MOBS_ANIMALS: {
double damage = getTier() < 2 ? 20D : 4D * getTier();
case ATTACK_MOBS_ANIMALS:
entities:
for (Entity n: AndroidStatusHologram.getNearbyEntities(b, 4D + getTier())) {
switch (BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"))) {
@ -522,10 +479,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
}
}
break;
}
case ATTACK_MOBS: {
double damage = getTier() < 2 ? 20D : 4D * getTier();
case ATTACK_MOBS:
entities:
for (Entity n: AndroidStatusHologram.getNearbyEntities(b, 4D + getTier())) {
if (n instanceof Animals) continue;
@ -575,11 +529,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
}
}
break;
}
case ATTACK_ANIMALS: {
double damage = getTier() < 2 ? 20D : 4D * getTier();
case ATTACK_ANIMALS:
entities:
for (Entity n: AndroidStatusHologram.getNearbyEntities(b, 4D + getTier())) {
if (n instanceof Monster) continue;
@ -629,11 +579,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
}
}
break;
}
case ATTACK_ANIMALS_ADULT: {
double damage = getTier() < 2 ? 20D : 4D * getTier();
case ATTACK_ANIMALS_ADULT:
entities:
for (Entity n: AndroidStatusHologram.getNearbyEntities(b, 4D + getTier())) {
if (n instanceof Monster) continue;
@ -684,7 +630,6 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
}
}
break;
}
default:
break;
}

View File

@ -259,7 +259,7 @@ public class Slimefun {
* @return the list of all the IDs of the enabled items.
*/
public static List<String> listIDs() {
List<String> ids = new ArrayList<String>();
List<String> ids = new ArrayList<>();
for (SlimefunItem item: SlimefunItem.list()) {
ids.add(item.getID());
}
@ -273,7 +273,7 @@ public class Slimefun {
* @see #current_categories
*/
public static List<ItemStack> listCategories() {
List<ItemStack> items = new ArrayList<ItemStack>();
List<ItemStack> items = new ArrayList<>();
for (Category c: Category.list()) {
items.add(c.getItem());
}
@ -348,6 +348,6 @@ public class Slimefun {
}
public static List<GuideHandler> getGuideHandlers(int tier) {
return guide_handlers.containsKey(tier) ? guide_handlers.get(tier): new ArrayList<GuideHandler>();
return guide_handlers.containsKey(tier) ? guide_handlers.get(tier): new ArrayList<>();
}
}

View File

@ -26,9 +26,9 @@ public class EnergyNet extends Network {
private static final int RANGE = 6;
public static Set<String> machines_input = new HashSet<String>();
public static Set<String> machines_storage = new HashSet<String>();
public static Set<String> machines_output = new HashSet<String>();
public static Set<String> machines_input = new HashSet<>();
public static Set<String> machines_storage = new HashSet<>();
public static Set<String> machines_output = new HashSet<>();
public static NetworkComponent getComponent(Block b) {
return getComponent(b.getLocation());
@ -79,9 +79,9 @@ public class EnergyNet extends Network {
return energy_network;
}
private Set<Location> input = new HashSet<Location>();
private Set<Location> storage = new HashSet<Location>();
private Set<Location> output = new HashSet<Location>();
private Set<Location> input = new HashSet<>();
private Set<Location> storage = new HashSet<>();
private Set<Location> output = new HashSet<>();
protected EnergyNet(Location l) {
super(l);

View File

@ -12,8 +12,8 @@ import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
public class UniversalBlockMenu extends DirtyChestMenu {
BlockMenuPreset preset;
ItemManipulationEvent event;
private BlockMenuPreset preset;
private ItemManipulationEvent event;
public UniversalBlockMenu(BlockMenuPreset preset) {
super(preset.getTitle());

View File

@ -202,7 +202,7 @@ public class CargoManager {
boolean data = blockInfo.getString("filter-durability").equals("true");
if (blockInfo.getString("filter-type").equals("whitelist")) {
List<ItemStack> items = new ArrayList<ItemStack>();
List<ItemStack> items = new ArrayList<>();
for (int slot: slots) {
ItemStack template = menu.getItemInSlot(slot);
if (template != null) items.add(new CustomItem(template, 1));

View File

@ -33,6 +33,7 @@ import me.mrCookieSlime.Slimefun.api.network.Network;
import me.mrCookieSlime.Slimefun.holograms.CargoHologram;
public class CargoNet extends Network {
public static boolean EXTRA_CHANNELS = false;
private static final int RANGE = 5;
@ -67,15 +68,15 @@ public class CargoNet extends Network {
return getNetworkFromLocation(b.getLocation()) != null;
}
private Set<Location> inputNodes = new HashSet<Location>();
private Set<Location> outputNodes = new HashSet<Location>();
private Set<Location> advancedOutputNodes = new HashSet<Location>();
private Set<Location> inputNodes = new HashSet<>();
private Set<Location> outputNodes = new HashSet<>();
private Set<Location> advancedOutputNodes = new HashSet<>();
//Chest Terminal Stuff
final Set<Location> terminals = new HashSet<Location>();
final Set<Location> imports = new HashSet<Location>();
final Set<Location> exports = new HashSet<Location>();
private final Set<Location> terminals = new HashSet<>();
private final Set<Location> imports = new HashSet<>();
private final Set<Location> exports = new HashSet<>();
protected CargoNet(Location l) {
super(l);

View File

@ -5,10 +5,10 @@ import org.bukkit.inventory.ItemStack;
public class ItemRequest {
ItemStack item;
ItemTransportFlow flow;
Location terminal;
int slot;
private ItemStack item;
private ItemTransportFlow flow;
private Location terminal;
private int slot;
public ItemRequest(Location terminal, int slot, ItemStack item, ItemTransportFlow flow) {
this.terminal = terminal;

View File

@ -22,7 +22,7 @@ public class SlimefunTabCompleter implements TabCompleter {
return createReturnList(Slimefun.listIDs(), args[2]);
}
else if (args[0].equalsIgnoreCase("research")) {
List<String> researches = new ArrayList<String>();
List<String> researches = new ArrayList<>();
for (Research res : Research.list()) {
researches.add(res.getName().toUpperCase().replace(" ", "_"));
}

View File

@ -119,7 +119,7 @@ public class DamageListener implements Listener {
if (!e.getEntity().getCanPickupItems() && Talisman.checkFor(e, SlimefunItem.getByID("HUNTER_TALISMAN")) && !(e.getEntity() instanceof Player)) {
List<ItemStack> newDrops = new ArrayList<ItemStack>();
List<ItemStack> newDrops = new ArrayList<>();
for (ItemStack drop : e.getDrops()) {
newDrops.add(drop);
}

View File

@ -15,7 +15,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
public class TeleporterListener implements Listener {
BlockFace[] faces = {BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST};
private final BlockFace[] faces = {BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST};
public TeleporterListener(SlimefunStartup plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);