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

[CI skip] More refactoring

This commit is contained in:
TheBusyBiscuit 2020-03-01 16:17:18 +01:00
parent 106487b2e9
commit b6e574fc1d
13 changed files with 117 additions and 104 deletions

View File

@ -18,7 +18,6 @@ public class CargoConnector extends SimpleSlimefunItem<BlockUseHandler> {
super(category, item, recipeType, recipe, recipeOutput);
}
@Override
public BlockUseHandler getItemHandler() {
return e -> {

View File

@ -25,9 +25,8 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class CargoOutputNode extends SlimefunItem {
private static final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
private final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
public CargoOutputNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, recipeType, recipe, recipeOutput);
@ -43,10 +42,12 @@ public class CargoOutputNode extends SlimefunItem {
menu.replaceExistingItem(12, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ=="), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(12, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (CargoNet.extraChannels) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(menu, b);
return false;

View File

@ -24,14 +24,14 @@ import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class ReactorAccessPort extends SlimefunItem {
private static final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 21, 23};
private static final int[] border_1 = {9, 10, 11, 18, 20, 27, 29, 36, 38, 45, 46, 47};
private static final int[] border_2 = {15, 16, 17, 24, 26, 33, 35, 42, 44, 51, 52, 53};
private static final int[] border_3 = {30, 31, 32, 39, 41, 48, 50};
private static final int INFO_SLOT = 49;
private final int[] background = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 21, 23};
private final int[] fuelBorder = {9, 10, 11, 18, 20, 27, 29, 36, 38, 45, 46, 47};
private final int[] inputBorder = {15, 16, 17, 24, 26, 33, 35, 42, 44, 51, 52, 53};
private final int[] outputBorder = {30, 31, 32, 39, 41, 48, 50};
public ReactorAccessPort(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -119,19 +119,19 @@ public class ReactorAccessPort extends SlimefunItem {
}
private void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
for (int i : background) {
preset.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : border_1) {
for (int i : fuelBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : border_2) {
for (int i : inputBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : border_3) {
for (int i : outputBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
}

View File

@ -19,8 +19,8 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
public class TrashCan extends SlimefunItem implements InventoryBlock {
private static final int[] BORDER = {0, 1, 2, 3, 5, 4, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
private static final ItemStack BACKGROUND = new CustomItem(Material.RED_STAINED_GLASS_PANE, " ");
private final int[] border = {0, 1, 2, 3, 5, 4, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
private final ItemStack background = new CustomItem(Material.RED_STAINED_GLASS_PANE, " ");
public TrashCan(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -29,8 +29,8 @@ public class TrashCan extends SlimefunItem implements InventoryBlock {
}
private void constructMenu(BlockMenuPreset preset) {
for (int i : BORDER) {
preset.addItem(i, BACKGROUND, ChestMenuUtils.getEmptyClickHandler());
for (int i : border) {
preset.addItem(i, background, ChestMenuUtils.getEmptyClickHandler());
}
}

View File

@ -27,9 +27,9 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
public class AnimalGrowthAccelerator extends SlimefunItem implements InventoryBlock, EnergyNetComponent {
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};
protected int energyConsumption = 14;
private final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
private static final int ENERGY_CONSUMPTION = 14;
public AnimalGrowthAccelerator(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -99,9 +99,9 @@ public class AnimalGrowthAccelerator extends SlimefunItem implements InventoryBl
for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), 3.0, 3.0, 3.0, n -> n instanceof Ageable && n.isValid() && !((Ageable) n).isAdult())) {
for (int slot : getInputSlots()) {
if (SlimefunManager.isItemSimilar(inv.getItemInSlot(slot), SlimefunItems.ORGANIC_FOOD, false)) {
if (ChargableBlock.getCharge(b) < energyConsumption) return;
if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) return;
ChargableBlock.addCharge(b, -energyConsumption);
ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
inv.consumeItem(slot);
((Ageable) n).setAge(((Ageable) n).getAge() + 2000);

View File

@ -27,9 +27,9 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
public class AutoBreeder extends SlimefunItem implements InventoryBlock, EnergyNetComponent {
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};
protected int energyConsumption = 60;
private final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
private static final int ENERGY_CONSUMPTION = 60;
public AutoBreeder(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -38,6 +38,7 @@ public class AutoBreeder extends SlimefunItem implements InventoryBlock, EnergyN
registerBlockHandler(getID(), (p, b, tool, reason) -> {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot : getInputSlots()) {
if (inv.getItemInSlot(slot) != null) {
@ -98,9 +99,9 @@ public class AutoBreeder extends SlimefunItem implements InventoryBlock, EnergyN
for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), 4.0, 2.0, 4.0, n -> n instanceof Animals && n.isValid() && ((Animals) n).isAdult() && !((Animals) n).isLoveMode())) {
for (int slot : getInputSlots()) {
if (SlimefunManager.isItemSimilar(inv.getItemInSlot(slot), SlimefunItems.ORGANIC_FOOD, false)) {
if (ChargableBlock.getCharge(b) < energyConsumption) return;
if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) return;
ChargableBlock.addCharge(b, -energyConsumption);
ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
inv.consumeItem(slot);
((Animals) n).setLoveModeTicks(600);

View File

@ -38,9 +38,9 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public abstract class AutomatedCraftingChamber extends SlimefunItem implements InventoryBlock, EnergyNetComponent {
private static final int[] border = {0, 1, 3, 4, 5, 7, 8, 13, 14, 15, 16, 17, 50, 51, 52, 53};
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};
private final int[] border = {0, 1, 3, 4, 5, 7, 8, 13, 14, 15, 16, 17, 50, 51, 52, 53};
private final int[] inputBorder = {9, 10, 11, 12, 13, 18, 22, 27, 31, 36, 40, 45, 46, 47, 48, 49};
private final int[] outputBorder = {23, 24, 25, 26, 32, 35, 41, 42, 43, 44};
public AutomatedCraftingChamber(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -147,11 +147,11 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
for (int i : border_in) {
for (int i : inputBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.BLUE_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
for (int i : border_out) {
for (int i : outputBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}

View File

@ -30,9 +30,9 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public abstract class ElectricSmeltery extends AContainer {
private static final int[] border = {4, 5, 6, 7, 8, 13, 31, 40, 41, 42, 43, 44};
private static final int[] border_in = {0, 1, 2, 3, 9, 12, 18, 21, 27, 30, 36, 37, 38, 39};
private static final int[] border_out = {14, 15, 16, 17, 23, 26, 32, 33, 34, 35};
private final int[] border = {4, 5, 6, 7, 8, 13, 31, 40, 41, 42, 43, 44};
private final int[] inputBorder = {0, 1, 2, 3, 9, 12, 18, 21, 27, 30, 36, 37, 38, 39};
private final int[] outputBorder = {14, 15, 16, 17, 23, 26, 32, 33, 34, 35};
public ElectricSmeltery(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -118,10 +118,12 @@ public abstract class ElectricSmeltery extends AContainer {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : border_in) {
for (int i : inputBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : border_out) {
for (int i : outputBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
}

View File

@ -32,11 +32,11 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements InventoryBlock, EnergyNetComponent {
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};
private static final int[] border_out = {14, 15, 16, 17, 23, 26, 32, 33, 34, 35};
private 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 final int[] inputBorder = {9, 10, 11, 12, 18, 21, 27, 28, 29, 30};
private final int[] outputBorder = {14, 15, 16, 17, 23, 26, 32, 33, 34, 35};
protected int energyConsumption = 32;
private static final int ENERGY_CONSUMPTION = 32;
public FluidPump(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -49,10 +49,10 @@ public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements Invent
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : border_in) {
for (int i : inputBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : border_out) {
for (int i : outputBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
}
@ -103,14 +103,14 @@ public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements Invent
output = new ItemStack(Material.WATER_BUCKET);
}
if (output != null && ChargableBlock.getCharge(b) >= energyConsumption) {
if (output != null && ChargableBlock.getCharge(b) >= ENERGY_CONSUMPTION) {
BlockMenu menu = BlockStorage.getInventory(b);
for (int slot : getInputSlots()) {
if (SlimefunManager.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.BUCKET), true)) {
if (!menu.fits(output, getOutputSlots())) return;
ChargableBlock.addCharge(b, -energyConsumption);
ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
menu.consumeItem(slot);
menu.pushItem(output, getOutputSlots());

View File

@ -33,12 +33,13 @@ import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class WitherAssembler extends SimpleSlimefunItem<BlockTicker> implements EnergyNetComponent {
private static final int[] border = {0, 2, 3, 4, 5, 6, 8, 12, 14, 21, 23, 30, 32, 39, 40, 41};
private static final int[] border_1 = {9, 10, 11, 18, 20, 27, 29, 36, 37, 38};
private static final int[] border_2 = {15, 16, 17, 24, 26, 33, 35, 42, 43, 44};
protected int energyConsumption = 4096;
private static final int ENERGY_CONSUMPTION = 4096;
private final int[] border = {0, 2, 3, 4, 5, 6, 8, 12, 14, 21, 23, 30, 32, 39, 40, 41};
private final int[] skullBorder = {9, 10, 11, 18, 20, 27, 29, 36, 37, 38};
private final int[] sandBorder = {15, 16, 17, 24, 26, 33, 35, 42, 43, 44};
private int lifetime = 0;
public WitherAssembler(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
@ -140,11 +141,11 @@ public class WitherAssembler extends SimpleSlimefunItem<BlockTicker> implements
preset.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : border_1) {
for (int i : skullBorder) {
preset.addItem(i, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : border_2) {
for (int i : sandBorder) {
preset.addItem(i, new CustomItem(Material.BROWN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
}
@ -184,7 +185,7 @@ public class WitherAssembler extends SimpleSlimefunItem<BlockTicker> implements
if (BlockStorage.getLocationInfo(b.getLocation(), "enabled").equals("false")) return;
if (lifetime % 60 == 0) {
if (ChargableBlock.getCharge(b) < energyConsumption) return;
if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) return;
int soulsand = 0;
int skulls = 0;
@ -244,7 +245,7 @@ public class WitherAssembler extends SimpleSlimefunItem<BlockTicker> implements
}
}
ChargableBlock.addCharge(b, -energyConsumption);
ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
double offset = Double.parseDouble(BlockStorage.getLocationInfo(b.getLocation(), "offset"));
Slimefun.runSync(() -> b.getWorld().spawnEntity(new Location(b.getWorld(), b.getX() + 0.5D, b.getY() + offset, b.getZ() + 0.5D), EntityType.WITHER));

View File

@ -29,9 +29,9 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
public class XPCollector extends SlimefunItem implements InventoryBlock, EnergyNetComponent {
private static final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
private final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
protected int energyConsumption = 10;
private static final int ENERGY_CONSUMPTION = 10;
public XPCollector(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -110,11 +110,11 @@ public class XPCollector extends SlimefunItem implements InventoryBlock, EnergyN
while (iterator.hasNext() && xp == 0) {
Entity n = iterator.next();
if (ChargableBlock.getCharge(b) < energyConsumption) return;
if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) return;
xp = getEXP(b) + ((ExperienceOrb) n).getExperience();
ChargableBlock.addCharge(b, -energyConsumption);
ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
n.remove();
int withdrawn = 0;

View File

@ -1,14 +1,5 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.JetBootsTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.JetpackTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.MagnetTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ParachuteTask;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -20,50 +11,63 @@ import io.github.thebusybiscuit.slimefun4.implementation.tasks.JetBootsTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.JetpackTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.MagnetTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ParachuteTask;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.Slimefun;
public class GearListener implements Listener {
public GearListener(SlimefunPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
public GearListener(SlimefunPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onToggleSneak(PlayerToggleSneakEvent e) {
if (!e.isSneaking()) return;
Player p = e.getPlayer();
@EventHandler
public void onToggleSneak(PlayerToggleSneakEvent e) {
if (e.isSneaking()) {
Player p = e.getPlayer();
if (p.getInventory().getChestplate() != null) {
SlimefunItem chestplate = SlimefunItem.getByItem(p.getInventory().getChestplate());
handleChestplate(p, chestplate);
}
if (p.getInventory().getChestplate() != null) {
SlimefunItem chestplate = SlimefunItem.getByItem(p.getInventory().getChestplate());
handleChestplate(p, chestplate);
}
if (p.getInventory().getBoots() != null) {
SlimefunItem boots = SlimefunItem.getByItem(p.getInventory().getBoots());
handleBoots(p, boots);
}
if (p.getInventory().getBoots() != null) {
SlimefunItem boots = SlimefunItem.getByItem(p.getInventory().getBoots());
handleBoots(p, boots);
}
if (SlimefunManager.containsSimilarItem(p.getInventory(), SlimefunItems.INFUSED_MAGNET, true))
new MagnetTask(p).scheduleRepeating(0, 8);
}
if (SlimefunManager.containsSimilarItem(p.getInventory(), SlimefunItems.INFUSED_MAGNET, true)) {
new MagnetTask(p).scheduleRepeating(0, 8);
}
}
}
private void handleChestplate(Player p, SlimefunItem chestplate) {
if (chestplate == null || !Slimefun.hasUnlocked(p, chestplate, true)) return;
private void handleChestplate(Player p, SlimefunItem chestplate) {
if (chestplate == null || !Slimefun.hasUnlocked(p, chestplate, true)) {
return;
}
if (chestplate instanceof Jetpack) {
double thrust = ((Jetpack) chestplate).getThrust();
if (chestplate instanceof Jetpack) {
double thrust = ((Jetpack) chestplate).getThrust();
if (thrust > 0.2) {
new JetpackTask(p, thrust).scheduleRepeating(0, 3);
}
}
else if (chestplate.getID().equals("PARACHUTE")) {
new ParachuteTask(p).scheduleRepeating(0, 3);
}
}
if (thrust > 0.2)
new JetpackTask(p, thrust).scheduleRepeating(0, 3);
} else if (chestplate.getID().equals("PARACHUTE"))
new ParachuteTask(p).scheduleRepeating(0, 3);
}
private void handleBoots(Player p, SlimefunItem boots) {
if (boots instanceof JetBoots && Slimefun.hasUnlocked(p, boots, true)) {
double speed = ((JetBoots) boots).getSpeed();
private void handleBoots(Player p, SlimefunItem boots) {
if (boots instanceof JetBoots && Slimefun.hasUnlocked(p, boots, true)) {
double speed = ((JetBoots) boots).getSpeed();
if (speed > 0.2)
new JetBootsTask(p, speed).scheduleRepeating(0, 2);
}
}
if (speed > 0.2) {
new JetBootsTask(p, speed).scheduleRepeating(0, 2);
}
}
}
}

View File

@ -27,11 +27,16 @@ public abstract class SlimefunTask implements Runnable {
@Override
public void run() {
if (isValid()) executeTask();
if (isValid()) {
executeTask();
}
}
/**
* @return True if task was cancelled.
* This method checks if this {@link SlimefunTask} should be continued or cancelled.
* It will also cancel this {@link SlimefunTask} if it became invalid.
*
* @return Whether this {@link SlimefunTask} is still valid
*/
protected boolean isValid() {
if (!p.isOnline() || !p.isValid() || p.isDead() || !p.isSneaking()) {