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-09-02 00:15:19 +02:00
parent 41bbbdd3dc
commit d51e906300
27 changed files with 192 additions and 160 deletions

View File

@ -90,6 +90,6 @@ public class GrapplingHook extends SimpleSlimefunItem<ItemInteractionHandler> {
@Override
public void postRegister() {
despawnTicks = (int) Slimefun.getItemValue("GRAPPLING_HOOK", "despawn-seconds") * 20;
despawnTicks = (int) Slimefun.getItemValue("GRAPPLING_HOOK", "despawn-seconds") * 20L;
}
}

View File

@ -9,7 +9,6 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -25,7 +24,7 @@ import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
public class StormStaff extends SimpleSlimefunItem<ItemInteractionHandler> {
private final static int MAX_USES = 8;
private static final int MAX_USES = 8;
public StormStaff(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe, getCraftedOutput());
@ -50,17 +49,17 @@ public class StormStaff extends SimpleSlimefunItem<ItemInteractionHandler> {
if (SlimefunManager.isItemSimiliar(item, getItem(), false)) {
if (!item.hasItemMeta()) return false;
ItemMeta itemM = item.getItemMeta();
if (!itemM.hasLore()) return false;
List<String> itemML = itemM.getLore();
ItemMeta itemMeta = item.getItemMeta();
if (!itemMeta.hasLore()) return false;
List<String> itemLore = itemMeta.getLore();
ItemStack SFitem = getItem();
ItemMeta SFitemM = SFitem.getItemMeta();
List<String> SFitemML = SFitemM.getLore();
ItemStack sfItem = getItem();
ItemMeta sfItemMeta = sfItem.getItemMeta();
List<String> sfItemLore = sfItemMeta.getLore();
if (itemML.size() < 6) {
if (itemLore.size() < 6) {
// Index 1 and 3 in SlimefunItems.STAFF_STORM has lores with words and stuff so we check for them.
if (itemML.get(1).equals(SFitemML.get(1)) && itemML.get(3).equals(SFitemML.get(3))) {
if (itemLore.get(1).equals(sfItemLore.get(1)) && itemLore.get(3).equals(sfItemLore.get(3))) {
if (p.getFoodLevel() >= 4 || p.getGameMode() == GameMode.CREATIVE) {
// Get a target block with max. 30 blocks of distance
Location loc = p.getTargetBlock(null, 30).getLocation();
@ -76,26 +75,19 @@ public class StormStaff extends SimpleSlimefunItem<ItemInteractionHandler> {
}
for (int i = MAX_USES; i > 0; i--) {
if (i == 1 && ChatColor.translateAlternateColorCodes('&', "&e1 Use &7left").equals(itemML.get(4))) {
if (i == 1 && ChatColor.translateAlternateColorCodes('&', "&e1 Use &7left").equals(itemLore.get(4))) {
e.setCancelled(true);
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
item.setAmount(0);
return true;
}
else if (ChatColor.translateAlternateColorCodes('&', "&e" + i + " Uses &7left").equals(itemML.get(4))) {
itemML.set(4, ChatColor.translateAlternateColorCodes('&', "&e" + (i - 1) + " " + (i > 2 ? "Uses": "Use") + " &7left"));
else if (ChatColor.translateAlternateColorCodes('&', "&e" + i + " Uses &7left").equals(itemLore.get(4))) {
itemLore.set(4, ChatColor.translateAlternateColorCodes('&', "&e" + (i - 1) + " " + (i > 2 ? "Uses": "Use") + " &7left"));
e.setCancelled(true);
// Saving the changes to lore and item.
itemM.setLore(itemML);
item.setItemMeta(itemM);
if (e.getParentEvent().getHand() == EquipmentSlot.HAND) {
p.getInventory().setItemInMainHand(item);
}
else {
p.getInventory().setItemInOffHand(item);
}
itemMeta.setLore(itemLore);
item.setItemMeta(itemMeta);
return true;
}

View File

@ -142,7 +142,7 @@ public class XPCollector extends SlimefunItem {
super.register(slimefun);
}
protected void tick(Block b) throws Exception {
protected void tick(Block b) {
Iterator<Entity> iterator = XPCollectorHologram.getArmorStand(b, true).getNearbyEntities(4D, 4D, 4D).iterator();
while (iterator.hasNext()) {
Entity n = iterator.next();

View File

@ -114,7 +114,7 @@ public class AnimalGrowthAccelerator extends SlimefunItem {
super.register(slimefun);
}
protected void tick(Block b) throws Exception {
protected void tick(Block b) {
for (Entity n : AnimalGrowthAcceleratorHologram.getArmorStand(b, true).getNearbyEntities(3D, 3D, 3D)) {
if (n instanceof Ageable && !((Ageable) n).isAdult()) {
for (int slot: getInputSlots()) {

View File

@ -81,12 +81,16 @@ public class AutoDisenchanter extends AContainer {
// Check if disenchantable
SlimefunItem sfItem = null;
if ((item != null) && (item.getType() != Material.BOOK)) { // stops endless checks of getByItem for empty book stacks.
// stops endless checks of getByItem for empty book stacks.
if ((item != null) && (item.getType() != Material.BOOK)) {
sfItem = SlimefunItem.getByItem(item);
}
if (sfItem != null && !sfItem.isDisenchantable()) return;
if (sfItem != null && !sfItem.isDisenchantable()) {
return;
}
// Disenchant
// Disenchanting
if (item != null && target != null && target.getType() == Material.BOOK) {
int amount = 0;
@ -107,6 +111,7 @@ public class AutoDisenchanter extends AContainer {
book.setAmount(1);
book.setType(Material.ENCHANTED_BOOK);
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) book.getItemMeta();
for (Map.Entry<Enchantment,Integer> e: enchantments.entrySet()) {
newItem.removeEnchantment(e.getKey());
meta.addStoredEnchant(e.getKey(), e.getValue(), true);

View File

@ -56,33 +56,36 @@ public class AutoDrier extends AContainer {
else {
MachineRecipe r = null;
int inputSlot = -1;
for (int slot: getInputSlots()) {
ItemStack item = BlockStorage.getInventory(b).getItemInSlot(slot);
if (item == null) continue;
// Checking if dryable
Material mat = item.getType();
ItemStack output;
if (mat == Material.ROTTEN_FLESH) {
output = new ItemStack(Material.LEATHER);
if (item != null) {
// Checking if dryable
Material mat = item.getType();
ItemStack output = null;
if (mat == Material.ROTTEN_FLESH) {
output = new ItemStack(Material.LEATHER);
}
else if (mat == Material.WATER_BUCKET) {
output = new ItemStack(Material.BUCKET);
}
else if (mat == Material.WET_SPONGE) {
output = new ItemStack(Material.SPONGE);
}
else if (Tag.SAPLINGS.isTagged(mat) || Tag.LEAVES.isTagged(mat)) {
output = new ItemStack(Material.STICK);
}
else if (mat.name().contains("POTION")) {
output = new ItemStack(Material.GLASS_BOTTLE);
}
if (output != null) {
r = new MachineRecipe(5, new ItemStack[] {item}, new ItemStack[] {output});
inputSlot = slot;
break;
}
}
else if (mat == Material.WATER_BUCKET) {
output = new ItemStack(Material.BUCKET);
}
else if (mat == Material.WET_SPONGE) {
output = new ItemStack(Material.SPONGE);
}
else if (Tag.SAPLINGS.isTagged(mat) || Tag.LEAVES.isTagged(mat)) {
output = new ItemStack(Material.STICK);
}
else if (mat.name().contains("POTION")) {
output = new ItemStack(Material.GLASS_BOTTLE);
}
else continue;
r = new MachineRecipe(5, new ItemStack[] {item}, new ItemStack[] {output});
inputSlot = slot;
break;
}
if (r != null) {

View File

@ -124,7 +124,7 @@ public abstract class CropGrowthAccelerator extends SlimefunItem {
super.register(slimefun);
}
protected void tick(Block b) throws Exception {
protected void tick(Block b) {
if (work(b) > 0) {
for (int slot : getInputSlots()) {
if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(b).getItemInSlot(slot), SlimefunItems.FERTILIZER, false)) {

View File

@ -17,6 +17,7 @@ public class JetpackTask extends SlimefunTask {
this.thrust = thrust;
}
@Override
public void setID(int id) {
this.id = id;
}

View File

@ -32,6 +32,7 @@ public class CSCoreLibLoader {
try {
this.url = new URL("https://api.curseforge.com/servermods/files?projectIds=88802");
} catch (MalformedURLException e) {
plugin.getLogger().log(Level.SEVERE, "The Auto-Updater URL is malformed!", e);
}
}
@ -97,18 +98,19 @@ public class CSCoreLibLoader {
connection.setInstanceFollowRedirects(false);
connection.setConnectTimeout(5000);
connection.addRequestProperty("User-Agent", "Auto Updater (by mrCookieSlime)");
switch (connection.getResponseCode()) {
case HttpURLConnection.HTTP_MOVED_PERM:
case HttpURLConnection.HTTP_MOVED_TEMP:
String loc = connection.getHeaderField("Location");
location = new URL(new URL(location), loc).toExternalForm();
continue;
int response = connection.getResponseCode();
if (response == HttpURLConnection.HTTP_MOVED_PERM || response == HttpURLConnection.HTTP_MOVED_TEMP) {
String loc = connection.getHeaderField("Location");
location = new URL(new URL(location), loc).toExternalForm();
}
else {
break;
}
break;
}
return new URL(connection.getURL().toString().replaceAll(" ", "%20"));
return new URL(connection.getURL().toString().replace(" ", "%20"));
}
private void install() {

View File

@ -26,7 +26,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.ReplacingAlloy;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunMachine;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.electric.AutomatedCraftingChamber;
import me.mrCookieSlime.Slimefun.Setup.PostSlimefunLoadingHandler;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunRecipes;
import me.mrCookieSlime.Slimefun.utils.Settings;

View File

@ -30,6 +30,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -154,6 +155,7 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockPlaceHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.Objects.handlers.BowShootHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.MultiBlockInteractionHandler;
import me.mrCookieSlime.Slimefun.Objects.tasks.RainbowTicker;
@ -1061,7 +1063,25 @@ public final class SlimefunSetup {
new SlimefunItem(Categories.PORTABLE, SlimefunItems.MEDICINE, "MEDICINE", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.VITAMINS, new ItemStack(Material.GLASS_BOTTLE), SlimefunItems.HEAVY_CREAM, null, null, null, null, null, null})
.register(true);
.register(true, new ItemConsumptionHandler() {
@Override
public boolean onConsume(PlayerItemConsumeEvent e, Player p, ItemStack item) {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MEDICINE, true)) {
if (p.hasPotionEffect(PotionEffectType.POISON)) p.removePotionEffect(PotionEffectType.POISON);
if (p.hasPotionEffect(PotionEffectType.WITHER)) p.removePotionEffect(PotionEffectType.WITHER);
if (p.hasPotionEffect(PotionEffectType.SLOW)) p.removePotionEffect(PotionEffectType.SLOW);
if (p.hasPotionEffect(PotionEffectType.SLOW_DIGGING)) p.removePotionEffect(PotionEffectType.SLOW_DIGGING);
if (p.hasPotionEffect(PotionEffectType.WEAKNESS)) p.removePotionEffect(PotionEffectType.WEAKNESS);
if (p.hasPotionEffect(PotionEffectType.CONFUSION)) p.removePotionEffect(PotionEffectType.CONFUSION);
if (p.hasPotionEffect(PotionEffectType.BLINDNESS)) p.removePotionEffect(PotionEffectType.BLINDNESS);
p.setFireTicks(0);
return true;
}
else return false;
}
});
new SlimefunArmorPiece(Categories.TECH, SlimefunItems.NIGHT_VISION_GOGGLES, "NIGHT_VISION_GOGGLES", RecipeType.ARMOR_FORGE,
new ItemStack[] {new ItemStack(Material.COAL_BLOCK), new ItemStack(Material.COAL_BLOCK), new ItemStack(Material.COAL_BLOCK), new ItemStack(Material.LIME_STAINED_GLASS_PANE), new ItemStack(Material.COAL_BLOCK), new ItemStack(Material.LIME_STAINED_GLASS_PANE), new ItemStack(Material.COAL_BLOCK), null, new ItemStack(Material.COAL_BLOCK)},

View File

@ -295,7 +295,8 @@ public final class SlimefunPlugin extends JavaPlugin {
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 400, 1));
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 400, 1));
p.setFireTicks(400);
break; // Break the loop to save some calculations
break;
// Break the loop to save some calculations
}
}
}

View File

@ -87,7 +87,8 @@ public class AncientAltarListener implements Listener {
return;
}
utilities.altarinuse.add(b.getLocation()); // make altarinuse simply because that was the last block clicked.
// Make altarinuse simply because that was the last block clicked.
utilities.altarinuse.add(b.getLocation());
e.setCancelled(true);
ItemStack catalyst = new CustomItem(e.getPlayer().getInventory().getItemInMainHand(), 1);
@ -118,7 +119,8 @@ public class AncientAltarListener implements Listener {
pedestals.forEach(block -> utilities.altarinuse.remove(block.getLocation()));
utilities.altarinuse.remove(b.getLocation()); // bad recipe, no longer in use.
// Bad recipe, no longer in use.
utilities.altarinuse.remove(b.getLocation());
}
}
else {
@ -127,13 +129,16 @@ public class AncientAltarListener implements Listener {
pedestals.forEach(block -> utilities.altarinuse.remove(block.getLocation()));
utilities.altarinuse.remove(b.getLocation()); // unkown catalyst, no longer in use
// Unknown catalyst, no longer in use
utilities.altarinuse.remove(b.getLocation());
}
}
else {
altars.remove(e.getClickedBlock());
Messages.local.sendTranslation(e.getPlayer(), "machines.ANCIENT_ALTAR.not-enough-pedestals", true, new Variable("%pedestals%", String.valueOf(pedestals.size())));
utilities.altarinuse.remove(b.getLocation()); // not a valid altar so remove from inuse
// Not a valid altar so remove from inuse
utilities.altarinuse.remove(b.getLocation());
}
}
}

View File

@ -293,7 +293,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
b.setBlockData(rotatableLeft);
BlockStorage.addBlockInfo(b, "rotation", directions.get(indexLeft).toString());
break;
case TURN_RIGHT: {
case TURN_RIGHT:
int indexRight = directions.indexOf(BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"))) + 1;
if (indexRight == directions.size()) indexRight = 0;
Rotatable rotatableRight = (Rotatable) b.getBlockData();
@ -301,7 +301,6 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
b.setBlockData(rotatableRight);
BlockStorage.addBlockInfo(b, "rotation", directions.get(indexRight).toString());
break;
}
case DIG_FORWARD:
mine(b, b.getRelative(face));
break;

View File

@ -147,7 +147,10 @@ public class BlockStorage {
long time = (System.currentTimeMillis() - start);
Slimefun.getLogger().log(Level.INFO, "Loading Blocks... 100% (FINISHED - " + time + "ms)");
Slimefun.getLogger().log(Level.INFO, "Loaded a total of " + totalBlocks + " Blocks for World \"" + world.getName() + "\"");
if (totalBlocks > 0) System.out.println("[Slimefun] Avg: " + DoubleHandler.fixDouble((double) time / (double) totalBlocks, 3) + "ms/Block");
if (totalBlocks > 0) {
Slimefun.getLogger().log(Level.INFO, "Avg: " + DoubleHandler.fixDouble((double) time / (double) totalBlocks, 3) + "ms/Block");
}
}
}
else f.mkdirs();
@ -622,7 +625,7 @@ public class BlockStorage {
if (menu != null) {
for (HumanEntity human : new ArrayList<>(menu.toInventory().getViewers())) {
// Prevents "java.lang.IllegalStateException: Asynchronous entity add!" when closing inventory while holding an item
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> human.closeInventory());
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, human::closeInventory);
}
inventories.get(l).delete(l);

View File

@ -196,7 +196,8 @@ public final class CargoManager {
String id = BlockStorage.checkID(block);
if (id.equals("CARGO_NODE_OUTPUT")) return true;
Config blockInfo = BlockStorage.getLocationInfo(block.getLocation()); // Store the returned Config instance to avoid heavy calls
// Store the returned Config instance to avoid heavy calls
Config blockInfo = BlockStorage.getLocationInfo(block.getLocation());
BlockMenu menu = BlockStorage.getInventory(block.getLocation());
boolean lore = blockInfo.getString("filter-lore").equals("true");

View File

@ -9,6 +9,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -27,6 +28,7 @@ import me.mrCookieSlime.CSCoreLibPlugin.general.Math.DoubleHandler;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
import me.mrCookieSlime.Slimefun.api.network.Network;
@ -134,6 +136,8 @@ public class CargoNet extends Network {
case "CT_EXPORT_BUS":
exports.add(l);
break;
default:
break;
}
}
}
@ -529,8 +533,11 @@ public class CargoNet extends Network {
private static int getFrequency(Location l) {
int freq = 0;
try {
freq = Integer.parseInt(BlockStorage.getLocationInfo(l).getString("frequency"));
} catch (Exception e) {}
String str = BlockStorage.getLocationInfo(l).getString("frequency");
if (str != null) freq = Integer.parseInt(str);
} catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while parsing a Cargo Node Frequency", x);
}
return freq;
}

View File

@ -2,8 +2,8 @@ package me.mrCookieSlime.Slimefun.api.item_transport;
public class ChannelIndex {
public int channel;
public int index;
private int channel;
private int index;
public ChannelIndex(int channel, int index) {
this.channel = channel;

View File

@ -4,8 +4,8 @@ import org.bukkit.inventory.ItemStack;
public class ItemSlot {
public int slot;
public ItemStack item;
private int slot;
private ItemStack item;
public ItemSlot(ItemStack item, int slot) {
this.slot = slot;

View File

@ -4,8 +4,8 @@ import org.bukkit.inventory.ItemStack;
public class StoredItem {
public int amount;
public ItemStack item;
private int amount;
private ItemStack item;
public StoredItem(ItemStack item, int amount) {
this.amount = amount;

View File

@ -41,7 +41,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunGuideLayout;
public class SlimefunCommand implements CommandExecutor, Listener {
public SlimefunPlugin plugin;
private SlimefunPlugin plugin;
private List<String> arguments = new ArrayList<>();
private List<String> descriptions = new ArrayList<>();

View File

@ -134,12 +134,13 @@ public class BlockListener implements Listener {
if (!multiblocks.isEmpty()) {
e.setCancelled(true);
MultiBlock multiblock = multiblocks.get(multiblocks.size() - 1);
for (ItemHandler handler: SlimefunItem.getHandlers("MultiBlockInteractionHandler")) {
if (((MultiBlockInteractionHandler) handler).onInteract(p, multiblocks.get(multiblocks.size() - 1), b)) continue;
if (((MultiBlockInteractionHandler) handler).onInteract(p, multiblock, b)) break;
}
MultiBlockInteractEvent event = new MultiBlockInteractEvent(p, multiblocks.get(multiblocks.size() - 1), b);
MultiBlockInteractEvent event = new MultiBlockInteractEvent(p, multiblock, b);
Bukkit.getPluginManager().callEvent(event);
}
}

View File

@ -85,20 +85,20 @@ public class DamageListener implements Listener {
if (item != null && Slimefun.hasUnlocked(p, item, true) && SlimefunManager.isItemSimiliar(item, SlimefunItem.getItem("SWORD_OF_BEHEADING"), true)) {
if (e.getEntity() instanceof Zombie) {
if (random.nextInt(100) < (Integer) Slimefun.getItemValue("SWORD_OF_BEHEADING", "chance.ZOMBIE")) {
if (random.nextInt(100) < (int) Slimefun.getItemValue("SWORD_OF_BEHEADING", "chance.ZOMBIE")) {
e.getDrops().add(new ItemStack(Material.ZOMBIE_HEAD));
}
}
else if (e.getEntity() instanceof WitherSkeleton) {
if (random.nextInt(100) < (Integer) Slimefun.getItemValue("SWORD_OF_BEHEADING", "chance.WITHER_SKELETON"))
if (random.nextInt(100) < (int) Slimefun.getItemValue("SWORD_OF_BEHEADING", "chance.WITHER_SKELETON"))
e.getDrops().add(new ItemStack(Material.WITHER_SKELETON_SKULL));
}
else if (e.getEntity() instanceof Skeleton) {
if (random.nextInt(100) < (Integer) Slimefun.getItemValue("SWORD_OF_BEHEADING", "chance.SKELETON"))
if (random.nextInt(100) < (int) Slimefun.getItemValue("SWORD_OF_BEHEADING", "chance.SKELETON"))
e.getDrops().add(new ItemStack(Material.SKELETON_SKULL));
}
else if (e.getEntity() instanceof Creeper) {
if (random.nextInt(100) < (Integer) Slimefun.getItemValue("SWORD_OF_BEHEADING", "chance.CREEPER")) {
if (random.nextInt(100) < (int) Slimefun.getItemValue("SWORD_OF_BEHEADING", "chance.CREEPER")) {
e.getDrops().add(new ItemStack(Material.CREEPER_HEAD));
}
}
@ -126,7 +126,9 @@ public class DamageListener implements Listener {
for(ItemStack invItem : ((ChestedHorse) e.getEntity()).getInventory().getStorageContents()) {
e.getDrops().remove(invItem);
}
e.getDrops().remove(new ItemStack(Material.CHEST)); //The chest is not included in getStorageContents()
//The chest is not included in getStorageContents()
e.getDrops().remove(new ItemStack(Material.CHEST));
}
}
}

View File

@ -222,6 +222,7 @@ public class ItemListener implements Listener {
else p.chat("/sf cheat");
}
else if (SlimefunManager.isItemSimiliar(e.getPlayer().getInventory().getItemInMainHand(), SlimefunItems.DEBUG_FISH, true) || SlimefunManager.isItemSimiliar(e.getPlayer().getInventory().getItemInOffHand(), SlimefunItems.DEBUG_FISH, true)) {
// Ignore the debug fish in here
}
else if (Slimefun.hasUnlocked(p, item, true)) {
for (ItemHandler handler : SlimefunItem.getHandlers("ItemInteractionHandler")) {
@ -309,18 +310,11 @@ public class ItemListener implements Listener {
if (((ItemConsumptionHandler) handler).onConsume(e, p, item)) return;
}
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.FORTUNE_COOKIE, true)) p.sendMessage(ChatColor.translateAlternateColorCodes('&', Messages.local.getTranslation("messages.fortune-cookie").get(CSCoreLib.randomizer().nextInt(Messages.local.getTranslation("messages.fortune-cookie").size()))));
else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BEEF_JERKY, true)) p.setSaturation((Integer) Slimefun.getItemValue("BEEF_JERKY", "Saturation"));
else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MEDICINE, true)) {
if (p.hasPotionEffect(PotionEffectType.POISON)) p.removePotionEffect(PotionEffectType.POISON);
if (p.hasPotionEffect(PotionEffectType.WITHER)) p.removePotionEffect(PotionEffectType.WITHER);
if (p.hasPotionEffect(PotionEffectType.SLOW)) p.removePotionEffect(PotionEffectType.SLOW);
if (p.hasPotionEffect(PotionEffectType.SLOW_DIGGING)) p.removePotionEffect(PotionEffectType.SLOW_DIGGING);
if (p.hasPotionEffect(PotionEffectType.WEAKNESS)) p.removePotionEffect(PotionEffectType.WEAKNESS);
if (p.hasPotionEffect(PotionEffectType.CONFUSION)) p.removePotionEffect(PotionEffectType.CONFUSION);
if (p.hasPotionEffect(PotionEffectType.BLINDNESS)) p.removePotionEffect(PotionEffectType.BLINDNESS);
p.setFireTicks(0);
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.FORTUNE_COOKIE, true)) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', Messages.local.getTranslation("messages.fortune-cookie").get(CSCoreLib.randomizer().nextInt(Messages.local.getTranslation("messages.fortune-cookie").size()))));
}
else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BEEF_JERKY, true)) {
p.setSaturation((int) Slimefun.getItemValue("BEEF_JERKY", "Saturation"));
}
else if (item.getType() == Material.POTION) {
SlimefunItem sfItem = SlimefunItem.getByItem(item);

View File

@ -13,10 +13,7 @@ public interface DamageableItem {
boolean isDamageable();
default void damageItem(Player p, ItemStack item) {
if (item == null || item.getType() == null || item.getType() == Material.AIR) {
return;
}
else if (item.getAmount() > 0 && isDamageable() && !item.getEnchantments().containsKey(Enchantment.DURABILITY) || Math.random() * 100 <= (60 + Math.floorDiv(40, (item.getEnchantmentLevel(Enchantment.DURABILITY) + 1)))) {
if (item != null && item.getType() != null && item.getType() != Material.AIR && item.getAmount() > 0 && isDamageable() && !item.getEnchantments().containsKey(Enchantment.DURABILITY) || Math.random() * 100 <= (60 + Math.floorDiv(40, (item.getEnchantmentLevel(Enchantment.DURABILITY) + 1)))) {
ItemMeta meta = item.getItemMeta();
Damageable damageable = (Damageable) meta;

View File

@ -6,22 +6,22 @@ import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
public final class Settings {
public boolean printOutLoading;
public final boolean printOutLoading;
public boolean researchesEnabled;
public boolean researchesFreeInCreative;
public List<String> researchesTitles;
public final boolean researchesFreeInCreative;
public final List<String> researchesTitles;
public int blocksInfoLoadingDelay;
public int blocksAutoSaveDelay;
public final int blocksInfoLoadingDelay;
public final int blocksAutoSaveDelay;
public boolean guideShowVanillaRecipes;
public final boolean guideShowVanillaRecipes;
public int emeraldEnchantsLimit;
public final int emeraldEnchantsLimit;
public boolean legacyDustWasher;
public boolean legacyOreGrinder;
public boolean legacyOreWasher;
public final boolean legacyDustWasher;
public final boolean legacyOreGrinder;
public final boolean legacyOreWasher;
public int smelteryFireBreakChance;

View File

@ -43,74 +43,74 @@ public final class Utilities {
public int vanillaItems = 0;
public Set<ItemStack> radioactiveItems = new HashSet<>();
public Map<String, Set<ItemHandler>> itemHandlers = new HashMap<>();
public Map<String, SlimefunBlockHandler> blockHandlers = new HashMap<>();
public Set<String> tickers = new HashSet<>();
public final Set<ItemStack> radioactiveItems = new HashSet<>();
public final Map<String, Set<ItemHandler>> itemHandlers = new HashMap<>();
public final Map<String, SlimefunBlockHandler> blockHandlers = new HashMap<>();
public final Set<String> tickers = new HashSet<>();
public Map<String, Integer> blocksEnergyCapacity = new HashMap<>();
public Set<String> rechargeableItems = new HashSet<>();
public Set<String> capacitorIDs = new HashSet<>();
public final Map<String, Integer> blocksEnergyCapacity = new HashMap<>();
public final Set<String> rechargeableItems = new HashSet<>();
public final Set<String> capacitorIDs = new HashSet<>();
public Set<String> energyNetInput = new HashSet<>();
public Set<String> energyNetStorage = new HashSet<>();
public Set<String> energyNetOutput = new HashSet<>();
public final Set<String> energyNetInput = new HashSet<>();
public final Set<String> energyNetStorage = new HashSet<>();
public final Set<String> energyNetOutput = new HashSet<>();
public Map<Location, Integer> roundRobin = new HashMap<>();
public Set<ItemRequest> itemRequests = new HashSet<>();
public final Map<Location, Integer> roundRobin = new HashMap<>();
public final Set<ItemRequest> itemRequests = new HashSet<>();
public Map<String, BlockMenuPreset> blockMenuPresets = new HashMap<>();
public final Map<String, BlockMenuPreset> blockMenuPresets = new HashMap<>();
public List<Category> currentlyEnabledCategories = new ArrayList<>();
public final List<Category> currentlyEnabledCategories = new ArrayList<>();
public Map<String, BlockStorage> worlds = new HashMap<>();
public Set<String> loadedTickers = new HashSet<>();
public final Map<String, BlockStorage> worlds = new HashMap<>();
public final Set<String> loadedTickers = new HashSet<>();
public Map<String, String> mapChunks = new HashMap<>();
public Map<String, Set<Location>> tickingChunks = new HashMap<>();
public Map<String, UniversalBlockMenu> universalInventories = new HashMap<>();
public final Map<String, String> mapChunks = new HashMap<>();
public final Map<String, Set<Location>> tickingChunks = new HashMap<>();
public final Map<String, UniversalBlockMenu> universalInventories = new HashMap<>();
public Map<UUID, PlayerProfile> profiles = new HashMap<>();
public final Map<UUID, PlayerProfile> profiles = new HashMap<>();
public Map<Integer, List<GuideHandler>> guideHandlers = new HashMap<>();
public List<PostSlimefunLoadingHandler> postHandlers = new ArrayList<>();
public final Map<Integer, List<GuideHandler>> guideHandlers = new HashMap<>();
public final List<PostSlimefunLoadingHandler> postHandlers = new ArrayList<>();
public Map<EntityType, List<ItemStack>> drops = new EnumMap<>(EntityType.class);
public final Map<EntityType, List<ItemStack>> drops = new EnumMap<>(EntityType.class);
public Map<UUID, Boolean> jumpState = new HashMap<>();
public Set<UUID> damage = new HashSet<>();
public Map<UUID, Entity[]> remove = new HashMap<>();
public Map<UUID, Integer> mode = new HashMap<>();
public final Map<UUID, Boolean> jumpState = new HashMap<>();
public final Set<UUID> damage = new HashSet<>();
public final Map<UUID, Entity[]> remove = new HashMap<>();
public final Map<UUID, Integer> mode = new HashMap<>();
public Map<UUID, Integer> enchanting = new HashMap<>();
public Map<UUID, ItemStack> backpack = new HashMap<>();
public final Map<UUID, Integer> enchanting = new HashMap<>();
public final Map<UUID, ItemStack> backpack = new HashMap<>();
public Set<Location> altarinuse = new HashSet<>();
public Set<AltarRecipe> altarRecipes = new HashSet<>();
public final Set<Location> altarinuse = new HashSet<>();
public final Set<AltarRecipe> altarRecipes = new HashSet<>();
public Map<UUID, Map<Integer, ItemStack>> soulbound = new HashMap<>();
public List<UUID> blocks = new ArrayList<>();
public List<UUID> cancelPlace = new ArrayList<>();
public Map<UUID, ItemStack> arrows = new HashMap<>();
public final Map<UUID, Map<Integer, ItemStack>> soulbound = new HashMap<>();
public final List<UUID> blocks = new ArrayList<>();
public final List<UUID> cancelPlace = new ArrayList<>();
public final Map<UUID, ItemStack> arrows = new HashMap<>();
public Set<UUID> elevatorUsers = new HashSet<>();
public Set<UUID> teleporterUsers = new HashSet<>();
public final Set<UUID> elevatorUsers = new HashSet<>();
public final Set<UUID> teleporterUsers = new HashSet<>();
public Map<String, OreGenResource> resources = new HashMap<>();
public final Map<String, OreGenResource> resources = new HashMap<>();
public Set<GitHubConnector> connectors = new HashSet<>();
public Map<String, String> contributorHeads = new HashMap<>();
public List<Contributor> contributors = new ArrayList<>();
public final Set<GitHubConnector> connectors = new HashSet<>();
public final Map<String, String> contributorHeads = new HashMap<>();
public final List<Contributor> contributors = new ArrayList<>();
public Map<UUID, List<Object>> guideHistory = new HashMap<>();
public final Map<UUID, List<Object>> guideHistory = new HashMap<>();
public List<CargoTransportEvent> cargoTransportEvents = new ArrayList<>();
public final List<CargoTransportEvent> cargoTransportEvents = new ArrayList<>();
/**
* Contains all the players (UUIDs) that are currently unlocking a research.
* @since 4.0
*/
public Set<UUID> researching = new HashSet<>();
public final Set<UUID> researching = new HashSet<>();
/**
* Represents the current month of the year