From e016ea11803274e4ebe30727b5d8df026c73aaa1 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Thu, 25 Jun 2020 22:13:24 +0300 Subject: [PATCH 01/36] Explosive Bow Functionality Changed. Explosive Bow now deals an area of effect. --- .../items/weapons/ExplosiveBow.java | 49 +++++++++++++++++-- .../listeners/SlimefunBowListener.java | 2 + .../Objects/handlers/ItemHandler.java | 1 + 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java index 0f6499246..a0c64ad30 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java @@ -1,28 +1,67 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.weapons; +import org.bukkit.Bukkit; +import org.bukkit.Particle; import org.bukkit.Sound; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.handlers.BowShootHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +import java.util.Collection; + public class ExplosiveBow extends SlimefunBow { + private final ItemSetting range = new ItemSetting<>("explosion-range", 3); + public ExplosiveBow(Category category, SlimefunItemStack item, ItemStack[] recipe) { super(category, item, recipe); + addItemSetting(range); } @Override public BowShootHandler onShoot() { return (e, n) -> { - Vector vector = n.getVelocity(); - vector.setY(0.6); - n.setVelocity(vector); - n.getWorld().createExplosion(n.getLocation(), 0F); - n.getWorld().playSound(n.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F); + Collection entites = n.getWorld().getNearbyEntities(n.getLocation(), range.getValue(), range.getValue(), range.getValue(), entity -> entity instanceof LivingEntity); + for (Entity entity : entites) { + if (entity.isValid() && entity instanceof LivingEntity) { + LivingEntity entityL = (LivingEntity) entity; + + double distance = entityL.getLocation().distance(n.getLocation()); + double damage = calculateDamage(distance, e.getDamage()); + + Vector distanceVector = entityL.getLocation().toVector().subtract(n.getLocation().toVector()); + distanceVector.setY(distanceVector.getY() + 0.6D); + Vector entityVelocity = entityL.getVelocity(); + Vector knockback = entityVelocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / Math.round(damage)))); + entityL.setVelocity(knockback); + + entityL.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, entityL.getLocation(), 1); + entityL.getWorld().playSound(entityL.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F); + + if (!entityL.getUniqueId().equals(n.getUniqueId())) { + entityL.damage(damage); + EntityDamageByEntityEvent damageEvent = new EntityDamageByEntityEvent(e.getDamager(), entityL, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); + Bukkit.getPluginManager().callEvent(damageEvent); + } + } + } }; } + private double calculateDamage(double distance, double ogDamage) { + + if (distance == 0D) return ogDamage; + double damage = ogDamage - Math.pow((distance / range.getValue()), 2.5); + if (Math.round(damage) == 0D) damage += 1D; + return Math.min(damage, ogDamage); + } + } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java index b20e8c54f..b2d9130b9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; @@ -69,6 +70,7 @@ public class SlimefunBowListener implements Listener { @EventHandler public void onArrowSuccessfulHit(EntityDamageByEntityEvent e) { if (e.getDamager() instanceof Arrow && e.getEntity() instanceof LivingEntity) { + if (e.getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) return; SlimefunBow bow = projectiles.get(e.getDamager().getUniqueId()); if (bow != null) { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java index 3b685fe40..7b8d80edf 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java @@ -16,6 +16,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; * @see BlockUseHandler * @see EntityKillHandler * @see EntityInteractHandler + * @see BowShootHandler */ @FunctionalInterface public interface ItemHandler { From 558d069a331793cc226901b8230eb2e6a95c853b Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sat, 27 Jun 2020 17:45:39 +0300 Subject: [PATCH 02/36] Did the requested changes + improvements. --- .../items/weapons/ExplosiveBow.java | 49 ++++++++++--------- .../listeners/SlimefunBowListener.java | 3 +- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java index a0c64ad30..d9172bef4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java @@ -19,7 +19,12 @@ import java.util.Collection; public class ExplosiveBow extends SlimefunBow { - private final ItemSetting range = new ItemSetting<>("explosion-range", 3); + private final ItemSetting range = new ItemSetting("explosion-range", 3) { + @Override + public boolean validateInput(Integer input) { + return input > 0; + } + }; public ExplosiveBow(Category category, SlimefunItemStack item, ItemStack[] recipe) { super(category, item, recipe); @@ -29,39 +34,37 @@ public class ExplosiveBow extends SlimefunBow { @Override public BowShootHandler onShoot() { return (e, n) -> { - Collection entites = n.getWorld().getNearbyEntities(n.getLocation(), range.getValue(), range.getValue(), range.getValue(), entity -> entity instanceof LivingEntity); + Collection entites = n.getWorld().getNearbyEntities(n.getLocation(), range.getValue(), range.getValue(), range.getValue(), entity -> entity instanceof LivingEntity && entity.isValid()); for (Entity entity : entites) { - if (entity.isValid() && entity instanceof LivingEntity) { - LivingEntity entityL = (LivingEntity) entity; + LivingEntity entityL = (LivingEntity) entity; - double distance = entityL.getLocation().distance(n.getLocation()); - double damage = calculateDamage(distance, e.getDamage()); + Vector distanceVector = entityL.getLocation().toVector().subtract(n.getLocation().toVector()); + distanceVector.setY(distanceVector.getY() + 0.6D); + Vector entityVelocity = entityL.getVelocity(); - Vector distanceVector = entityL.getLocation().toVector().subtract(n.getLocation().toVector()); - distanceVector.setY(distanceVector.getY() + 0.6D); - Vector entityVelocity = entityL.getVelocity(); - Vector knockback = entityVelocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / Math.round(damage)))); - entityL.setVelocity(knockback); + double distanceSquared = distanceVector.lengthSquared(); + double damage = calculateDamage(distanceSquared, e.getDamage()); - entityL.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, entityL.getLocation(), 1); - entityL.getWorld().playSound(entityL.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F); + Vector knockback = entityVelocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / damage))); + entityL.setVelocity(knockback); - if (!entityL.getUniqueId().equals(n.getUniqueId())) { - entityL.damage(damage); - EntityDamageByEntityEvent damageEvent = new EntityDamageByEntityEvent(e.getDamager(), entityL, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); - Bukkit.getPluginManager().callEvent(damageEvent); - } + entityL.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, entityL.getLocation(), 1); + entityL.getWorld().playSound(entityL.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F); + + if (!entityL.getUniqueId().equals(n.getUniqueId())) { + entityL.damage(damage); + EntityDamageByEntityEvent damageEvent = new EntityDamageByEntityEvent(e.getDamager(), entityL, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); + Bukkit.getPluginManager().callEvent(damageEvent); } } }; } - private double calculateDamage(double distance, double ogDamage) { + private double calculateDamage(double distanceSquared, double originalDamage) { - if (distance == 0D) return ogDamage; - double damage = ogDamage - Math.pow((distance / range.getValue()), 2.5); - if (Math.round(damage) == 0D) damage += 1D; - return Math.min(damage, ogDamage); + if (distanceSquared <= 0.05D) return originalDamage; + double damage = originalDamage * (1 - (distanceSquared / (range.getValue() * range.getValue()))); + return Math.min(Math.max(1, damage), originalDamage); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java index b2d9130b9..2555d5b81 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java @@ -69,8 +69,7 @@ public class SlimefunBowListener implements Listener { @EventHandler public void onArrowSuccessfulHit(EntityDamageByEntityEvent e) { - if (e.getDamager() instanceof Arrow && e.getEntity() instanceof LivingEntity) { - if (e.getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) return; + if (e.getDamager() instanceof Arrow && e.getEntity() instanceof LivingEntity && e.getCause() != EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) { SlimefunBow bow = projectiles.get(e.getDamager().getUniqueId()); if (bow != null) { From f3d21daf6a65703812ada0b082a5a02e36f906f9 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sun, 28 Jun 2020 05:38:49 +0300 Subject: [PATCH 03/36] Did the requested changes. --- .../items/weapons/ExplosiveBow.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java index d9172bef4..a038a0350 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java @@ -22,7 +22,7 @@ public class ExplosiveBow extends SlimefunBow { private final ItemSetting range = new ItemSetting("explosion-range", 3) { @Override public boolean validateInput(Integer input) { - return input > 0; + return input != null && input > 0; } }; @@ -33,12 +33,15 @@ public class ExplosiveBow extends SlimefunBow { @Override public BowShootHandler onShoot() { - return (e, n) -> { - Collection entites = n.getWorld().getNearbyEntities(n.getLocation(), range.getValue(), range.getValue(), range.getValue(), entity -> entity instanceof LivingEntity && entity.isValid()); + return (e, target) -> { + target.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, target.getLocation(), 1); + target.getWorld().playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F); + + Collection entites = target.getWorld().getNearbyEntities(target.getLocation(), range.getValue(), range.getValue(), range.getValue(), entity -> entity instanceof LivingEntity && entity.isValid()); for (Entity entity : entites) { LivingEntity entityL = (LivingEntity) entity; - Vector distanceVector = entityL.getLocation().toVector().subtract(n.getLocation().toVector()); + Vector distanceVector = entityL.getLocation().toVector().subtract(target.getLocation().toVector()); distanceVector.setY(distanceVector.getY() + 0.6D); Vector entityVelocity = entityL.getVelocity(); @@ -48,20 +51,14 @@ public class ExplosiveBow extends SlimefunBow { Vector knockback = entityVelocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / damage))); entityL.setVelocity(knockback); - entityL.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, entityL.getLocation(), 1); - entityL.getWorld().playSound(entityL.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F); - - if (!entityL.getUniqueId().equals(n.getUniqueId())) { + if (!entityL.getUniqueId().equals(target.getUniqueId())) { entityL.damage(damage); - EntityDamageByEntityEvent damageEvent = new EntityDamageByEntityEvent(e.getDamager(), entityL, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); - Bukkit.getPluginManager().callEvent(damageEvent); } } }; } private double calculateDamage(double distanceSquared, double originalDamage) { - if (distanceSquared <= 0.05D) return originalDamage; double damage = originalDamage * (1 - (distanceSquared / (range.getValue() * range.getValue()))); return Math.min(Math.max(1, damage), originalDamage); From d7ba054befffd980a495d262120f12f3c3d9516c Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sun, 28 Jun 2020 05:39:32 +0300 Subject: [PATCH 04/36] Removed unused imports. --- .../slimefun4/implementation/items/weapons/ExplosiveBow.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java index a038a0350..cde396e3c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java @@ -1,12 +1,9 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.weapons; -import org.bukkit.Bukkit; import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; From 911ee2340f5c782f0022b6a37b3ae66e45e630d5 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Sun, 28 Jun 2020 14:22:15 +0300 Subject: [PATCH 05/36] Did a requested change. --- .../implementation/items/weapons/ExplosiveBow.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java index cde396e3c..6c283dcd0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java @@ -1,9 +1,12 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.weapons; +import org.bukkit.Bukkit; import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; @@ -49,7 +52,11 @@ public class ExplosiveBow extends SlimefunBow { entityL.setVelocity(knockback); if (!entityL.getUniqueId().equals(target.getUniqueId())) { - entityL.damage(damage); + EntityDamageByEntityEvent damageEvent = new EntityDamageByEntityEvent(e.getDamager(), entityL, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); + Bukkit.getPluginManager().callEvent(damageEvent); + if (!damageEvent.isCancelled()) { + entityL.damage(damageEvent.getDamage()); + } } } }; From 7f7ed6861eb7f3f28ddd747656c131166fc4ea38 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 29 Jun 2020 03:04:31 +0200 Subject: [PATCH 06/36] Fixes #1959 and other Grappling hook-related issues --- .../items/tools/GrapplingHook.java | 13 +- .../listeners/GrapplingHookEntity.java | 46 +++++ .../listeners/GrapplingHookListener.java | 167 +++++++++++------- 3 files changed, 155 insertions(+), 71 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookEntity.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java index e4d27a4ab..9e2ba83f5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java @@ -55,14 +55,15 @@ public class GrapplingHook extends SimpleSlimefunItem { arrow.setShooter(p); arrow.setVelocity(direction); - Bat b = (Bat) p.getWorld().spawnEntity(p.getLocation(), EntityType.BAT); - b.setCanPickupItems(false); - b.setAI(false); - b.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000)); - b.setLeashHolder(arrow); + Bat bat = (Bat) p.getWorld().spawnEntity(p.getLocation(), EntityType.BAT); + bat.setCanPickupItems(false); + bat.setAI(false); + bat.setSilent(true); + bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000)); + bat.setLeashHolder(arrow); boolean state = item.getType() != Material.SHEARS; - SlimefunPlugin.getGrapplingHookListener().addGrapplingHook(uuid, arrow, b, state, despawnTicks.getValue() * 20L); + SlimefunPlugin.getGrapplingHookListener().addGrapplingHook(p, arrow, bat, state, despawnTicks.getValue()); } }; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookEntity.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookEntity.java new file mode 100644 index 000000000..86661d9ff --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookEntity.java @@ -0,0 +1,46 @@ +package io.github.thebusybiscuit.slimefun4.implementation.listeners; + +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; + +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; + +final class GrapplingHookEntity { + + private final boolean dropItem; + + private final Arrow arrow; + private final Entity leashTarget; + + GrapplingHookEntity(Player p, Arrow arrow, Entity leashTarget, boolean dropItem) { + this.arrow = arrow; + this.leashTarget = leashTarget; + this.dropItem = p.getGameMode() != GameMode.CREATIVE && dropItem; + } + + public Arrow getArrow() { + return arrow; + } + + public void drop(Location l) { + if (dropItem) { + Item item = l.getWorld().dropItem(l, SlimefunItems.GRAPPLING_HOOK.clone()); + item.setPickupDelay(16); + } + } + + public void remove() { + if (arrow.isValid()) { + arrow.remove(); + } + + if (leashTarget.isValid()) { + leashTarget.remove(); + } + } + +} \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java index bf84dce05..49ada3a45 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java @@ -6,32 +6,41 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Arrow; import org.bukkit.entity.Bat; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityPortalEnterEvent; import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.util.Vector; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GrapplingHook; import me.mrCookieSlime.Slimefun.api.Slimefun; +/** + * This {@link Listener} is responsible for the mechanics behind the {@link GrapplingHook}. + * + * @author TheBusyBiscuit + * @author Linox + * @author BlackBeltPanda + * + * @see GrapplingHook + * + */ public class GrapplingHookListener implements Listener { private GrapplingHook grapplingHook; - private final Map grappleState = new HashMap<>(); - private final Set invulnerable = new HashSet<>(); - private final Map temporaryEntities = new HashMap<>(); + private final Map activeHooks = new HashMap<>(); + private final Set invulnerability = new HashSet<>(); public void register(SlimefunPlugin plugin, GrapplingHook grapplingHook) { plugin.getServer().getPluginManager().registerEvents(this, plugin); @@ -39,9 +48,13 @@ public class GrapplingHookListener implements Listener { this.grapplingHook = grapplingHook; } + private boolean isEnabled() { + return grapplingHook != null && !grapplingHook.isDisabled(); + } + @EventHandler public void onArrowHitEntity(EntityDamageByEntityEvent e) { - if (grapplingHook == null || grapplingHook.isDisabled()) { + if (!isEnabled()) { return; } @@ -51,102 +64,126 @@ public class GrapplingHookListener implements Listener { } @EventHandler - public void onArrowHit(ProjectileHitEvent e) { - if (grapplingHook == null || grapplingHook.isDisabled()) { + public void onArrowHitSurface(ProjectileHitEvent e) { + if (!isEnabled()) { return; } Slimefun.runSync(() -> { - if (e.getEntity().isValid() && e.getEntity() instanceof Arrow) { + if (e.getEntity() instanceof Arrow) { handleGrapplingHook((Arrow) e.getEntity()); } - }, 4L); + }, 2L); } @EventHandler - public void onArrowHit(EntityDamageEvent e) { - if (grapplingHook == null || grapplingHook.isDisabled()) { + public void onArrowHitHanging(HangingBreakByEntityEvent e) { + if (!isEnabled()) { return; } - if (e.getEntity() instanceof Player && e.getCause() == DamageCause.FALL && invulnerable.contains(e.getEntity().getUniqueId())) { + // This is called when the arrow shoots off a painting or an item frame + if (e.getRemover() instanceof Arrow) { + handleGrapplingHook((Arrow) e.getRemover()); + } + } + + @EventHandler + public void onLeave(PlayerQuitEvent e) { + if (!isEnabled()) { + return; + } + + UUID uuid = e.getPlayer().getUniqueId(); + activeHooks.remove(uuid); + invulnerability.remove(uuid); + } + + @EventHandler + public void onFallDamage(EntityDamageEvent e) { + if (!isEnabled()) { + return; + } + + if (e.getEntity() instanceof Player && e.getCause() == DamageCause.FALL && invulnerability.remove(e.getEntity().getUniqueId())) { e.setCancelled(true); - invulnerable.remove(e.getEntity().getUniqueId()); + } + } + + @EventHandler + public void onPortalEnter(EntityPortalEnterEvent e) { + if (!isEnabled()) { + return; + } + + if (e.getEntity() instanceof Arrow) { + handleGrapplingHook((Arrow) e.getEntity()); } } private void handleGrapplingHook(Arrow arrow) { - if (arrow != null && arrow.getShooter() instanceof Player && grappleState.containsKey(((Player) arrow.getShooter()).getUniqueId())) { + if (arrow != null && arrow.isValid() && arrow.getShooter() instanceof Player) { Player p = (Player) arrow.getShooter(); + GrapplingHookEntity hook = activeHooks.get(p.getUniqueId()); - if (p.getGameMode() != GameMode.CREATIVE && (boolean) grappleState.get(p.getUniqueId())) { - arrow.getWorld().dropItem(arrow.getLocation(), SlimefunItems.GRAPPLING_HOOK.clone()); - } + if (hook != null) { + Location target = arrow.getLocation(); + hook.drop(target); - Vector velocity = new Vector(0.0, 0.2, 0.0); + Vector velocity = new Vector(0.0, 0.2, 0.0); - if (p.getLocation().distance(arrow.getLocation()) < 3.0) { - if (arrow.getLocation().getY() <= p.getLocation().getY()) { - velocity = arrow.getLocation().toVector().subtract(p.getLocation().toVector()); + if (p.getLocation().distance(target) < 3.0) { + if (target.getY() <= p.getLocation().getY()) { + velocity = target.toVector().subtract(p.getLocation().toVector()); + } } - } - else { - Location l = p.getLocation(); - l.setY(l.getY() + 0.5); - p.teleport(l); + else { + Location l = p.getLocation(); + l.setY(l.getY() + 0.5); + p.teleport(l); - double g = -0.08; - double d = arrow.getLocation().distance(l); - double t = d; - double vX = (1.0 + 0.08 * t) * (arrow.getLocation().getX() - l.getX()) / t; - double vY = (1.0 + 0.04 * t) * (arrow.getLocation().getY() - l.getY()) / t - 0.5D * g * t; - double vZ = (1.0 + 0.08 * t) * (arrow.getLocation().getZ() - l.getZ()) / t; + double g = -0.08; + double d = target.distance(l); + double t = d; + double vX = (1.0 + 0.08 * t) * (target.getX() - l.getX()) / t; + double vY = (1.0 + 0.04 * t) * (target.getY() - l.getY()) / t - 0.5D * g * t; + double vZ = (1.0 + 0.08 * t) * (target.getZ() - l.getZ()) / t; - velocity = p.getVelocity(); - velocity.setX(vX); - velocity.setY(vY); - velocity.setZ(vZ); - } - - p.setVelocity(velocity); - - for (Entity n : temporaryEntities.get(p.getUniqueId())) { - if (n.isValid()) { - n.remove(); + velocity = p.getVelocity(); + velocity.setX(vX); + velocity.setY(vY); + velocity.setZ(vZ); } - } - Slimefun.runSync(() -> { - grappleState.remove(p.getUniqueId()); - temporaryEntities.remove(p.getUniqueId()); - }, 20L); + p.setVelocity(velocity); + + hook.remove(); + Slimefun.runSync(() -> activeHooks.remove(p.getUniqueId()), 20L); + } } } public boolean isGrappling(UUID uuid) { - return grappleState.containsKey(uuid); + return activeHooks.containsKey(uuid); } - public void addGrapplingHook(UUID uuid, Arrow arrow, Bat b, boolean state, long despawnTicks) { - grappleState.put(uuid, state); - invulnerable.add(uuid); - temporaryEntities.put(uuid, new Entity[] { b, arrow }); + public void addGrapplingHook(Player p, Arrow arrow, Bat bat, boolean dropItem, long despawnTicks) { + GrapplingHookEntity hook = new GrapplingHookEntity(p, arrow, bat, dropItem); + UUID uuid = p.getUniqueId(); + + activeHooks.put(uuid, hook); // To fix issue #253 Slimefun.runSync(() -> { - if (grappleState.containsKey(uuid)) { - SlimefunPlugin.getBowListener().getProjectileData().remove(uuid); + GrapplingHookEntity entity = activeHooks.get(uuid); - for (Entity n : temporaryEntities.get(uuid)) { - if (n.isValid()) { - n.remove(); - } - } + if (entity != null) { + SlimefunPlugin.getBowListener().getProjectileData().remove(uuid); + entity.remove(); Slimefun.runSync(() -> { - invulnerable.remove(uuid); - grappleState.remove(uuid); - temporaryEntities.remove(uuid); + activeHooks.remove(uuid); + invulnerability.remove(uuid); }, 20L); } }, despawnTicks); From c5da9a3b4fb1ca2c7b951a211550dc1d089088dd Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 29 Jun 2020 03:26:30 +0200 Subject: [PATCH 07/36] [CI skip] Updated change log --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ce3e5f7c..a21c1da8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,10 @@ * Fixed a rare concurrency issue with world saving * Fixed some contributors showing up twice * Fixed #2062 +* Fixed Grappling hooks disappearing when fired at Item frames or paintaings +* Fixed Grappling hooks not getting removed when the Player leaves +* Fixed Grappling hooks making Bat sounds +* Fixed #1959 ## Release Candidate 13 (16 Jun 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13 From 4f2bb90f1595f84673b6135931a67a1b0920e7e3 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 29 Jun 2020 12:10:45 +0200 Subject: [PATCH 08/36] [CI skip] Slight refactoring --- CHANGELOG.md | 1 + .../items/weapons/ExplosiveBow.java | 49 +++++++++++++------ .../implementation/setup/PostSetup.java | 1 + 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a21c1da8f..623c0b218 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ * (1.16+) Added Nether Gold Ore recipe to the Ore Crusher * (1.16+) Added Shroomlights to the fuel list for the Bio Generator * (1.16+) Added Warped and Crimson Fungus to the fuel list for the Bio Generator +* Added an AoE damage effect to the Explosive Bow #### Changes * Coolant Cells now last twice as long diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java index 6c283dcd0..92bda6202 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java @@ -17,17 +17,31 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import java.util.Collection; +/** + * The {@link ExplosiveBow} is a {@link SlimefunBow} which creates a fake explosion when it hits + * a {@link LivingEntity}. Any nearby {@link LivingEntity LivingEntities} get pushed away and + * take a little bit of damage, similar to an "Area of Effect" damage. + * + * @author TheBusyBiscuit + * @author Linox + * + * @see SlimefunBow + * + */ public class ExplosiveBow extends SlimefunBow { private final ItemSetting range = new ItemSetting("explosion-range", 3) { + @Override public boolean validateInput(Integer input) { - return input != null && input > 0; + return super.validateInput(input) && input > 0; } + }; public ExplosiveBow(Category category, SlimefunItemStack item, ItemStack[] recipe) { super(category, item, recipe); + addItemSetting(range); } @@ -35,27 +49,29 @@ public class ExplosiveBow extends SlimefunBow { public BowShootHandler onShoot() { return (e, target) -> { target.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, target.getLocation(), 1); - target.getWorld().playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F); + target.getWorld().playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1, 1); Collection entites = target.getWorld().getNearbyEntities(target.getLocation(), range.getValue(), range.getValue(), range.getValue(), entity -> entity instanceof LivingEntity && entity.isValid()); - for (Entity entity : entites) { - LivingEntity entityL = (LivingEntity) entity; + for (Entity nearby : entites) { + LivingEntity entity = (LivingEntity) nearby; - Vector distanceVector = entityL.getLocation().toVector().subtract(target.getLocation().toVector()); - distanceVector.setY(distanceVector.getY() + 0.6D); - Vector entityVelocity = entityL.getVelocity(); + Vector distanceVector = entity.getLocation().toVector().subtract(target.getLocation().toVector()); + distanceVector.setY(distanceVector.getY() + 0.6); + + Vector velocity = entity.getVelocity(); double distanceSquared = distanceVector.lengthSquared(); double damage = calculateDamage(distanceSquared, e.getDamage()); - Vector knockback = entityVelocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / damage))); - entityL.setVelocity(knockback); + Vector knockback = velocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / damage))); + entity.setVelocity(knockback); - if (!entityL.getUniqueId().equals(target.getUniqueId())) { - EntityDamageByEntityEvent damageEvent = new EntityDamageByEntityEvent(e.getDamager(), entityL, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); - Bukkit.getPluginManager().callEvent(damageEvent); - if (!damageEvent.isCancelled()) { - entityL.damage(damageEvent.getDamage()); + if (!entity.getUniqueId().equals(target.getUniqueId())) { + EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(e.getDamager(), entity, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); + Bukkit.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + entity.damage(event.getDamage()); } } } @@ -63,7 +79,10 @@ public class ExplosiveBow extends SlimefunBow { } private double calculateDamage(double distanceSquared, double originalDamage) { - if (distanceSquared <= 0.05D) return originalDamage; + if (distanceSquared <= 0.05) { + return originalDamage; + } + double damage = originalDamage * (1 - (distanceSquared / (range.getValue() * range.getValue()))); return Math.min(Math.max(1, damage), originalDamage); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java index b4fffe314..1a541a456 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java @@ -180,6 +180,7 @@ public final class PostSetup { if (input[0] != null && recipe[0] != null) { grinderRecipes.add(new ItemStack[] { input[0], recipe[0] }); } + input = null; } } From fe6363728145f7a15b0e032d3e7dfdbf86627cba Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 29 Jun 2020 13:04:36 +0200 Subject: [PATCH 09/36] Removed unused folder --- .../thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java index 3da4f58f4..40a622ce6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java @@ -426,7 +426,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { private void createDirectories() { String[] storageFolders = { "Players", "blocks", "stored-blocks", "stored-inventories", "stored-chunks", "universal-inventories", "waypoints", "block-backups" }; - String[] pluginFolders = { "scripts", "generators", "error-reports", "cache/github", "world-settings" }; + String[] pluginFolders = { "scripts", "error-reports", "cache/github", "world-settings" }; for (String folder : storageFolders) { File file = new File("data-storage/Slimefun", folder); From 37139405128254d9e2b8fb566d7e94e7bf36e77d Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 29 Jun 2020 15:19:20 +0200 Subject: [PATCH 10/36] Prevent Spigot from breaking everything... --- .../slimefun4/implementation/SlimefunPlugin.java | 12 ++++++++++-- .../listeners/GrapplingHookListener.java | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java index 40a622ce6..ddb6cfa5c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java @@ -270,12 +270,20 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { // Clear the Slimefun Guide History upon Player Leaving new PlayerProfileListener(this); - // Initiating various Stuff and all Items with a slightly delay (0ms after the Server finished loading) + // Initiating various Stuff and all items with a slight delay (0ms after the Server finished loading) Slimefun.runSync(new SlimefunStartupTask(this, () -> { protections = new ProtectionManager(getServer()); textureService.register(registry.getAllSlimefunItems(), true); permissionsService.register(registry.getAllSlimefunItems(), true); - recipeService.refresh(); + + // This try/catch should prevent buggy Spigot builds from blocking item loading + try { + recipeService.refresh(); + } + catch (Exception | LinkageError x) { + getLogger().log(Level.SEVERE, x, () -> "An Exception occured while iterating through the Recipe list on Minecraft Version " + minecraftVersion.getName() + " (Slimefun v" + getVersion() + ")"); + } + }), 0); // Setting up the command /sf and all subcommands diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java index 49ada3a45..f71d7bb7f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/GrapplingHookListener.java @@ -18,6 +18,7 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityPortalEnterEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.util.Vector; @@ -99,6 +100,17 @@ public class GrapplingHookListener implements Listener { invulnerability.remove(uuid); } + @EventHandler + public void onLeave(PlayerKickEvent e) { + if (!isEnabled()) { + return; + } + + UUID uuid = e.getPlayer().getUniqueId(); + activeHooks.remove(uuid); + invulnerability.remove(uuid); + } + @EventHandler public void onFallDamage(EntityDamageEvent e) { if (!isEnabled()) { From 3415a124c76eb65d99254bdb5b9006b202b06e97 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 29 Jun 2020 15:47:51 +0200 Subject: [PATCH 11/36] A bunch of refactoring --- CHANGELOG.md | 1 + .../IncompatibleItemHandlerException.java | 2 +- .../core}/handlers/BlockDispenseHandler.java | 3 +- .../core}/handlers/BlockUseHandler.java | 3 +- .../core}/handlers/BowShootHandler.java | 3 +- .../core}/handlers/EntityInteractHandler.java | 3 +- .../core}/handlers/EntityKillHandler.java | 3 +- .../handlers/ItemConsumptionHandler.java | 3 +- .../core}/handlers/ItemDropHandler.java | 4 +- .../core/handlers/RainbowTickHandler.java} | 10 +- .../slimefun4/core/handlers/package-info.java | 5 + .../implementation/SlimefunPlugin.java | 120 +++++++++--------- .../items/blocks/BlockPlacer.java | 2 +- .../items/blocks/Composter.java | 2 +- .../implementation/items/blocks/Crucible.java | 2 +- .../items/blocks/HologramProjector.java | 2 +- .../items/blocks/RainbowBlock.java | 10 +- .../items/cargo/CargoConnectorNode.java | 2 +- .../items/cargo/CargoManager.java | 2 +- .../electric/generators/SolarGenerator.java | 2 +- .../implementation/items/food/DietCookie.java | 2 +- .../items/food/FortuneCookie.java | 2 +- .../implementation/items/food/MeatJerky.java | 2 +- .../items/food/MonsterJerky.java | 2 +- .../implementation/items/geo/GEOScanner.java | 2 +- .../items/gps/ElevatorPlate.java | 2 +- .../items/gps/GPSControlPanel.java | 2 +- .../items/gps/TeleporterPylon.java | 6 +- .../items/magical/MagicalZombiePills.java | 2 +- .../items/magical/SoulboundRune.java | 2 +- .../items/medical/Medicine.java | 2 +- .../items/weapons/ExplosiveBow.java | 2 +- .../implementation/items/weapons/IcyBow.java | 2 +- .../items/weapons/SlimefunBow.java | 2 +- .../items/weapons/SwordOfBeheading.java | 2 +- .../listeners/DispenserListener.java | 2 +- .../listeners/MobDropListener.java | 2 +- .../PlayerInteractEntityListener.java | 2 +- .../listeners/SlimefunBowListener.java | 2 +- .../SlimefunItemConsumeListener.java | 2 +- .../listeners/SlimefunItemListener.java | 4 +- .../setup/SlimefunItemSetup.java | 52 ++++---- .../Objects/handlers/ItemHandler.java | 5 + .../testing/interfaces/SlimefunItemTest.java | 2 +- .../testing/tests/items/TestItemHandlers.java | 2 +- 45 files changed, 159 insertions(+), 134 deletions(-) rename src/main/java/{me/mrCookieSlime/Slimefun/Objects => io/github/thebusybiscuit/slimefun4/core}/handlers/BlockDispenseHandler.java (92%) rename src/main/java/{me/mrCookieSlime/Slimefun/Objects => io/github/thebusybiscuit/slimefun4/core}/handlers/BlockUseHandler.java (89%) rename src/main/java/{me/mrCookieSlime/Slimefun/Objects => io/github/thebusybiscuit/slimefun4/core}/handlers/BowShootHandler.java (91%) rename src/main/java/{me/mrCookieSlime/Slimefun/Objects => io/github/thebusybiscuit/slimefun4/core}/handlers/EntityInteractHandler.java (91%) rename src/main/java/{me/mrCookieSlime/Slimefun/Objects => io/github/thebusybiscuit/slimefun4/core}/handlers/EntityKillHandler.java (88%) rename src/main/java/{me/mrCookieSlime/Slimefun/Objects => io/github/thebusybiscuit/slimefun4/core}/handlers/ItemConsumptionHandler.java (92%) rename src/main/java/{me/mrCookieSlime/Slimefun/Objects => io/github/thebusybiscuit/slimefun4/core}/handlers/ItemDropHandler.java (79%) rename src/main/java/{me/mrCookieSlime/Slimefun/Objects/handlers/RainbowTicker.java => io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java} (92%) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/package-info.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 623c0b218..741492823 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ * Fixed Grappling hooks not getting removed when the Player leaves * Fixed Grappling hooks making Bat sounds * Fixed #1959 +* Fixed Melon Juice requiring Melons instead of Melon Slices ## Release Candidate 13 (16 Jun 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/IncompatibleItemHandlerException.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/IncompatibleItemHandlerException.java index 0a9de09a0..ff4ccd753 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/IncompatibleItemHandlerException.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/IncompatibleItemHandlerException.java @@ -2,8 +2,8 @@ package io.github.thebusybiscuit.slimefun4.api.exceptions; import org.bukkit.plugin.Plugin; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; /** diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockDispenseHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockDispenseHandler.java similarity index 92% rename from src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockDispenseHandler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockDispenseHandler.java index 315435d90..437608096 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockDispenseHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockDispenseHandler.java @@ -1,4 +1,4 @@ -package me.mrCookieSlime.Slimefun.Objects.handlers; +package io.github.thebusybiscuit.slimefun4.core.handlers; import java.util.Optional; @@ -11,6 +11,7 @@ import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandler import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.BlockPlacer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; /** * This {@link ItemHandler} is triggered when the {@link SlimefunItem} it was assigned to diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockUseHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockUseHandler.java similarity index 89% rename from src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockUseHandler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockUseHandler.java index b72320829..a88f963d0 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockUseHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockUseHandler.java @@ -1,4 +1,4 @@ -package me.mrCookieSlime.Slimefun.Objects.handlers; +package io.github.thebusybiscuit.slimefun4.core.handlers; import java.util.Optional; @@ -6,6 +6,7 @@ import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; @FunctionalInterface public interface BlockUseHandler extends ItemHandler { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BowShootHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BowShootHandler.java similarity index 91% rename from src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BowShootHandler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BowShootHandler.java index 8b990ee64..6cfa61768 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BowShootHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BowShootHandler.java @@ -1,4 +1,4 @@ -package me.mrCookieSlime.Slimefun.Objects.handlers; +package io.github.thebusybiscuit.slimefun4.core.handlers; import java.util.Optional; @@ -9,6 +9,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException; import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SlimefunBow; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; /** * This {@link ItemHandler} is triggered when the {@link SlimefunItem} it was assigned to diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/EntityInteractHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/EntityInteractHandler.java similarity index 91% rename from src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/EntityInteractHandler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/EntityInteractHandler.java index c7fa151a9..5f35f94dd 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/EntityInteractHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/EntityInteractHandler.java @@ -1,4 +1,4 @@ -package me.mrCookieSlime.Slimefun.Objects.handlers; +package io.github.thebusybiscuit.slimefun4.core.handlers; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; /** * This is triggered when a {@link Player} interacts with an {@link Entity}. diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/EntityKillHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/EntityKillHandler.java similarity index 88% rename from src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/EntityKillHandler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/EntityKillHandler.java index 99d2e1513..adaa86513 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/EntityKillHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/EntityKillHandler.java @@ -1,4 +1,4 @@ -package me.mrCookieSlime.Slimefun.Objects.handlers; +package io.github.thebusybiscuit.slimefun4.core.handlers; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; /** * If this {@link ItemHandler} is added to a {@link SlimefunItem} it will listen diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemConsumptionHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/ItemConsumptionHandler.java similarity index 92% rename from src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemConsumptionHandler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/ItemConsumptionHandler.java index e9380f8e8..6599fc4b9 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemConsumptionHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/ItemConsumptionHandler.java @@ -1,4 +1,4 @@ -package me.mrCookieSlime.Slimefun.Objects.handlers; +package io.github.thebusybiscuit.slimefun4.core.handlers; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerItemConsumeEvent; @@ -8,6 +8,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.food.DietCookie; import io.github.thebusybiscuit.slimefun4.implementation.items.food.FortuneCookie; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; /** * This {@link ItemHandler} is triggered when the {@link SlimefunItem} it was assigned to diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemDropHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/ItemDropHandler.java similarity index 79% rename from src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemDropHandler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/ItemDropHandler.java index e9a6435c4..c9e3f753b 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemDropHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/ItemDropHandler.java @@ -1,9 +1,11 @@ -package me.mrCookieSlime.Slimefun.Objects.handlers; +package io.github.thebusybiscuit.slimefun4.core.handlers; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerDropItemEvent; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; + @FunctionalInterface public interface ItemDropHandler extends ItemHandler { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/RainbowTicker.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java similarity index 92% rename from src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/RainbowTicker.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java index 61171ee1b..2461f8c6c 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/RainbowTicker.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java @@ -1,4 +1,4 @@ -package me.mrCookieSlime.Slimefun.Objects.handlers; +package io.github.thebusybiscuit.slimefun4.core.handlers; import java.util.Arrays; @@ -14,6 +14,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; /** * This is a {@link BlockTicker} that is exclusively used for Rainbow blocks. @@ -25,13 +26,13 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; * @see RainbowBlock * */ -public class RainbowTicker extends BlockTicker { +public class RainbowTickHandler extends BlockTicker { private final LoopIterator iterator; private final boolean waterlogged; private Material material; - public RainbowTicker(Material... materials) { + public RainbowTickHandler(Material... materials) { if (materials.length == 0) { throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!"); } @@ -70,7 +71,7 @@ public class RainbowTicker extends BlockTicker { return false; } - public RainbowTicker(MaterialCollection collection) { + public RainbowTickHandler(MaterialCollection collection) { this(collection.getAsArray()); } @@ -84,7 +85,6 @@ public class RainbowTicker extends BlockTicker { if (waterlogged) { BlockData blockData = b.getBlockData(); - b.setType(material, true); if (blockData instanceof Waterlogged && ((Waterlogged) blockData).isWaterlogged()) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/package-info.java new file mode 100644 index 000000000..5e9d82140 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/package-info.java @@ -0,0 +1,5 @@ +/** + * This package contains all variations of {@link me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler} that + * can be assigned to a {@link me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem} + */ +package io.github.thebusybiscuit.slimefun4.core.attributes; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java index ddb6cfa5c..f95ffbb70 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java @@ -154,8 +154,9 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { @Override public void onEnable() { + instance = this; + if (minecraftVersion == MinecraftVersion.UNIT_TEST) { - instance = this; local = new LocalizationService(this, "", null); gpsNetwork = new GPSNetwork(); command.register(); @@ -169,14 +170,13 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { return; } - instance = this; - // Creating all necessary Folders - getLogger().log(Level.INFO, "Loading various systems..."); + getLogger().log(Level.INFO, "Creating directories..."); createDirectories(); registry.load(config); // Set up localization + getLogger().log(Level.INFO, "Loading language files..."); local = new LocalizationService(this, config.getString("options.chat-prefix"), config.getString("options.language")); // Setting up Networks @@ -216,59 +216,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { registry.setResearchingEnabled(getResearchCfg().getBoolean("enable-researching")); PostSetup.setupWiki(); - // All Slimefun Listeners - new SlimefunBootsListener(this); - new SlimefunItemListener(this); - new SlimefunItemConsumeListener(this); - new BlockPhysicsListener(this); - new CargoNodeListener(this); - new MultiBlockListener(this); - new GadgetsListener(this); - new DispenserListener(this); - new BlockListener(this); - new EnhancedFurnaceListener(this); - new ItemPickupListener(this); - new DeathpointListener(this); - new ExplosionsListener(this); - new DebugFishListener(this); - new VanillaMachinesListener(this); - new FireworksListener(this); - new WitherListener(this); - new IronGolemListener(this); - new PlayerInteractEntityListener(this); - - new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem()); - - // Item-specific Listeners - new VampireBladeListener(this, (VampireBlade) SlimefunItems.BLADE_OF_VAMPIRES.getItem()); - new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem()); - new SeismicAxeListener(this, (SeismicAxe) SlimefunItems.SEISMIC_AXE.getItem()); - grapplingHookListener.register(this, (GrapplingHook) SlimefunItems.GRAPPLING_HOOK.getItem()); - ancientAltarListener.register(this, (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem()); - - bowListener.register(this); - - // Toggleable Listeners for performance reasons - if (config.getBoolean("items.talismans")) { - new TalismanListener(this); - } - - if (config.getBoolean("items.soulbound")) { - new SoulboundListener(this); - } - - if (config.getBoolean("items.backpacks")) { - backpackListener.register(this); - } - - // Handle Slimefun Guide being given on Join - new SlimefunGuideListener(this, config.getBoolean("guide.receive-on-first-join")); - - // Load/Unload Worlds in Slimefun - new WorldListener(this); - - // Clear the Slimefun Guide History upon Player Leaving - new PlayerProfileListener(this); + getLogger().log(Level.INFO, "Registering listeners..."); + registerListeners(); // Initiating various Stuff and all items with a slight delay (0ms after the Server finished loading) Slimefun.runSync(new SlimefunStartupTask(this, () -> { @@ -303,6 +252,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { getLogger().log(Level.INFO, "Slimefun has finished loading in {0}", getStartupTime(timestamp)); } else { + instance = null; + getLogger().log(Level.INFO, "#################### - INFO - ####################"); getLogger().log(Level.INFO, " "); getLogger().log(Level.INFO, "Slimefun could not be loaded (yet)."); @@ -453,6 +404,61 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { } } + private void registerListeners() { + new SlimefunBootsListener(this); + new SlimefunItemListener(this); + new SlimefunItemConsumeListener(this); + new BlockPhysicsListener(this); + new CargoNodeListener(this); + new MultiBlockListener(this); + new GadgetsListener(this); + new DispenserListener(this); + new BlockListener(this); + new EnhancedFurnaceListener(this); + new ItemPickupListener(this); + new DeathpointListener(this); + new ExplosionsListener(this); + new DebugFishListener(this); + new VanillaMachinesListener(this); + new FireworksListener(this); + new WitherListener(this); + new IronGolemListener(this); + new PlayerInteractEntityListener(this); + + new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem()); + + // Item-specific Listeners + new VampireBladeListener(this, (VampireBlade) SlimefunItems.BLADE_OF_VAMPIRES.getItem()); + new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem()); + new SeismicAxeListener(this, (SeismicAxe) SlimefunItems.SEISMIC_AXE.getItem()); + grapplingHookListener.register(this, (GrapplingHook) SlimefunItems.GRAPPLING_HOOK.getItem()); + ancientAltarListener.register(this, (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem()); + + bowListener.register(this); + + // Toggleable Listeners for performance reasons + if (config.getBoolean("items.talismans")) { + new TalismanListener(this); + } + + if (config.getBoolean("items.soulbound")) { + new SoulboundListener(this); + } + + if (config.getBoolean("items.backpacks")) { + backpackListener.register(this); + } + + // Handle Slimefun Guide being given on Join + new SlimefunGuideListener(this, config.getBoolean("guide.receive-on-first-join")); + + // Load/Unload Worlds in Slimefun + new WorldListener(this); + + // Clear the Slimefun Guide History upon Player Leaving + new PlayerProfileListener(this); + } + private void loadItems() { try { SlimefunItemSetup.setup(this); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java index 874a31794..6b2f02caa 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java @@ -19,12 +19,12 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockDispenseHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Composter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Composter.java index 6c09d146d..cbb7bd53c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Composter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Composter.java @@ -20,12 +20,12 @@ import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.cscorelib2.scheduling.TaskQueue; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java index 48dfec049..e866be381 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java @@ -17,12 +17,12 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java index 24a68ac93..ff09249af 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram; @@ -21,7 +22,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RainbowBlock.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RainbowBlock.java index c4f87726d..613a72fc4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RainbowBlock.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RainbowBlock.java @@ -2,24 +2,24 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.blocks; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.RainbowTickHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.RainbowTicker; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -public class RainbowBlock extends SimpleSlimefunItem { +public class RainbowBlock extends SimpleSlimefunItem { - private final RainbowTicker ticker; + private final RainbowTickHandler ticker; - public RainbowBlock(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput, RainbowTicker ticker) { + public RainbowBlock(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput, RainbowTickHandler ticker) { super(category, item, recipeType, recipe, recipeOutput); this.ticker = ticker; } @Override - public RainbowTicker getItemHandler() { + public RainbowTickHandler getItemHandler() { return ticker; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java index 42c8d347a..16da4bca6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java @@ -5,11 +5,11 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.core.networks.cargo.CargoNet; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class CargoConnectorNode extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java index 5a318b18b..29ff47e5b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.core.networks.cargo.CargoNet; import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; @@ -15,7 +16,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java index 84b0fa7d0..f66ce9036 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java @@ -7,13 +7,13 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.GeneratorTicker; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/DietCookie.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/DietCookie.java index 683908ccb..5956b14cf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/DietCookie.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/DietCookie.java @@ -5,11 +5,11 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/FortuneCookie.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/FortuneCookie.java index 5797fc6e1..d57ba3b2f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/FortuneCookie.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/FortuneCookie.java @@ -7,13 +7,13 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; import io.github.thebusybiscuit.slimefun4.core.services.LocalizationService; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java index 7da8dad06..1304fea16 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java @@ -3,10 +3,10 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.food; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MonsterJerky.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MonsterJerky.java index 4033da48e..8377f6ff0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MonsterJerky.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MonsterJerky.java @@ -4,10 +4,10 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOScanner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOScanner.java index 0ab93122f..2b0834283 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOScanner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOScanner.java @@ -3,11 +3,11 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.geo; import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class GEOScanner extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java index 7505563e8..b411cc895 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java @@ -20,6 +20,7 @@ import io.github.thebusybiscuit.cscorelib2.chat.json.ClickEvent; import io.github.thebusybiscuit.cscorelib2.chat.json.CustomBookInterface; import io.github.thebusybiscuit.cscorelib2.chat.json.HoverEvent; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; @@ -29,7 +30,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSControlPanel.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSControlPanel.java index 94fc3fb67..57323e3d7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSControlPanel.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSControlPanel.java @@ -2,11 +2,11 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.gps; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class GPSControlPanel extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/TeleporterPylon.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/TeleporterPylon.java index 1d4bba69d..742428e51 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/TeleporterPylon.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/TeleporterPylon.java @@ -3,10 +3,10 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.gps; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.RainbowTickHandler; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.handlers.RainbowTicker; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** @@ -17,12 +17,12 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; * * @see Teleporter * @see RainbowBlock - * @see RainbowTicker + * @see RainbowTickHandler */ public class TeleporterPylon extends RainbowBlock { public TeleporterPylon(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) { - super(category, item, recipeType, recipe, recipeOutput, new RainbowTicker(Material.CYAN_STAINED_GLASS, Material.PURPLE_STAINED_GLASS)); + super(category, item, recipeType, recipe, recipeOutput, new RainbowTickHandler(Material.CYAN_STAINED_GLASS, Material.PURPLE_STAINED_GLASS)); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java index a04470728..1882e63c7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java @@ -8,12 +8,12 @@ import org.bukkit.entity.ZombieVillager; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.core.handlers.EntityInteractHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.EntityInteractHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java index a9eedcd16..487894f40 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java @@ -12,6 +12,7 @@ import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.Soulbound; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemDropHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; @@ -19,7 +20,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemDropHandler; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Medicine.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Medicine.java index 25056dfa4..1fa813917 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Medicine.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Medicine.java @@ -3,10 +3,10 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.medical; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffectType; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class Medicine extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java index 92bda6202..0a4e82b1c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java @@ -11,8 +11,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.handlers.BowShootHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import java.util.Collection; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java index 944903b18..f0bc3e8c6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java @@ -6,8 +6,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.handlers.BowShootHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class IcyBow extends SlimefunBow { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SlimefunBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SlimefunBow.java index 376b8a343..00573ab8d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SlimefunBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SlimefunBow.java @@ -3,10 +3,10 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.weapons; import org.bukkit.entity.Arrow; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BowShootHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java index 51e018ae9..92c2b4222 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java @@ -14,10 +14,10 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.core.handlers.EntityKillHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.EntityKillHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class SwordOfBeheading extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DispenserListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DispenserListener.java index 8cde6ccdb..cdd6cbafb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DispenserListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DispenserListener.java @@ -9,9 +9,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockDispenseEvent; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockDispenseHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MobDropListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MobDropListener.java index 346975b50..0d511e58a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MobDropListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MobDropListener.java @@ -10,10 +10,10 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.EntityKillHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.BasicCircuitBoard; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.EntityKillHandler; import me.mrCookieSlime.Slimefun.api.Slimefun; public class MobDropListener implements Listener { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/PlayerInteractEntityListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/PlayerInteractEntityListener.java index c66177b10..2bdc3baec 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/PlayerInteractEntityListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/PlayerInteractEntityListener.java @@ -8,9 +8,9 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.EntityInteractHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.EntityInteractHandler; import me.mrCookieSlime.Slimefun.api.Slimefun; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java index e6dda81ce..9a69a0038 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunBowListener.java @@ -14,10 +14,10 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; +import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SlimefunBow; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BowShootHandler; import me.mrCookieSlime.Slimefun.api.Slimefun; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemConsumeListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemConsumeListener.java index 937db4a8b..6fc3c8374 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemConsumeListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemConsumeListener.java @@ -10,11 +10,11 @@ import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.food.Juice; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.api.Slimefun; public class SlimefunItemConsumeListener implements Listener { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemListener.java index f440c2a98..563f4f57e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemListener.java @@ -14,12 +14,12 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemDropHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockUseHandler; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemDropHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 49504bda3..d3e3b2e9d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -16,6 +16,7 @@ import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactivity; +import io.github.thebusybiscuit.slimefun4.core.handlers.RainbowTickHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.RadioactiveItem; @@ -178,7 +179,6 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.RainbowTicker; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import org.bukkit.potion.PotionType; @@ -1214,7 +1214,7 @@ public final class SlimefunItemSetup { .register(plugin); new Juice(categories.food, SlimefunItems.MELON_JUICE, RecipeType.JUICER, - new ItemStack[] {new ItemStack(Material.MELON), null, null, null, null, null, null, null, null}) + new ItemStack[] {new ItemStack(Material.MELON_SLICE), null, null, null, null, null, null, null, null}) .register(plugin); new Juice(categories.food, SlimefunItems.PUMPKIN_JUICE, RecipeType.JUICER, @@ -2504,128 +2504,128 @@ public final class SlimefunItemSetup { new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_WOOL, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL)}, - new CustomItem(SlimefunItems.RAINBOW_WOOL, 8), new RainbowTicker(MaterialCollections.getAllWoolColors())) + new CustomItem(SlimefunItems.RAINBOW_WOOL, 8), new RainbowTickHandler(MaterialCollections.getAllWoolColors())) .register(plugin); new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_GLASS, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS)}, - new CustomItem(SlimefunItems.RAINBOW_GLASS, 8), new RainbowTicker(MaterialCollections.getAllStainedGlassColors())) + new CustomItem(SlimefunItems.RAINBOW_GLASS, 8), new RainbowTickHandler(MaterialCollections.getAllStainedGlassColors())) .register(plugin); new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_GLASS_PANE, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE)}, - new CustomItem(SlimefunItems.RAINBOW_GLASS_PANE, 8), new RainbowTicker(MaterialCollections.getAllStainedGlassPaneColors())) + new CustomItem(SlimefunItems.RAINBOW_GLASS_PANE, 8), new RainbowTickHandler(MaterialCollections.getAllStainedGlassPaneColors())) .register(plugin); new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_CLAY, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA)}, - new CustomItem(SlimefunItems.RAINBOW_CLAY, 8), new RainbowTicker(MaterialCollections.getAllTerracottaColors())) + new CustomItem(SlimefunItems.RAINBOW_CLAY, 8), new RainbowTickHandler(MaterialCollections.getAllTerracottaColors())) .register(plugin); new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_CONCRETE, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE)}, - new CustomItem(SlimefunItems.RAINBOW_CONCRETE, 8), new RainbowTicker(MaterialCollections.getAllConcreteColors())) + new CustomItem(SlimefunItems.RAINBOW_CONCRETE, 8), new RainbowTickHandler(MaterialCollections.getAllConcreteColors())) .register(plugin); new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_GLAZED_TERRACOTTA, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA)}, - new CustomItem(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA, 8), new RainbowTicker(MaterialCollections.getAllGlazedTerracottaColors())) + new CustomItem(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA, 8), new RainbowTickHandler(MaterialCollections.getAllGlazedTerracottaColors())) .register(plugin); // Christmas new RainbowBlock(categories.christmas, SlimefunItems.RAINBOW_WOOL_XMAS, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(GREEN_DYE), new ItemStack(Material.WHITE_WOOL), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_WOOL), new ItemStack(GREEN_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_WOOL_XMAS, 2), new RainbowTicker(Material.RED_WOOL, Material.GREEN_WOOL)) + new CustomItem(SlimefunItems.RAINBOW_WOOL_XMAS, 2), new RainbowTickHandler(Material.RED_WOOL, Material.GREEN_WOOL)) .register(plugin); new RainbowBlock(categories.christmas, SlimefunItems.RAINBOW_GLASS_XMAS, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(GREEN_DYE), new ItemStack(Material.WHITE_STAINED_GLASS), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(GREEN_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_GLASS_XMAS, 2), new RainbowTicker(Material.RED_STAINED_GLASS, Material.GREEN_STAINED_GLASS)) + new CustomItem(SlimefunItems.RAINBOW_GLASS_XMAS, 2), new RainbowTickHandler(Material.RED_STAINED_GLASS, Material.GREEN_STAINED_GLASS)) .register(plugin); new RainbowBlock(categories.christmas, SlimefunItems.RAINBOW_GLASS_PANE_XMAS, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(GREEN_DYE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(GREEN_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_GLASS_PANE_XMAS, 2), new RainbowTicker(Material.RED_STAINED_GLASS_PANE, Material.GREEN_STAINED_GLASS_PANE)) + new CustomItem(SlimefunItems.RAINBOW_GLASS_PANE_XMAS, 2), new RainbowTickHandler(Material.RED_STAINED_GLASS_PANE, Material.GREEN_STAINED_GLASS_PANE)) .register(plugin); new RainbowBlock(categories.christmas, SlimefunItems.RAINBOW_CLAY_XMAS, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(GREEN_DYE), new ItemStack(Material.WHITE_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(GREEN_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_CLAY_XMAS, 2), new RainbowTicker(Material.RED_TERRACOTTA, Material.GREEN_TERRACOTTA)) + new CustomItem(SlimefunItems.RAINBOW_CLAY_XMAS, 2), new RainbowTickHandler(Material.RED_TERRACOTTA, Material.GREEN_TERRACOTTA)) .register(plugin); new RainbowBlock(categories.christmas, SlimefunItems.RAINBOW_CONCRETE_XMAS, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(GREEN_DYE), new ItemStack(Material.WHITE_CONCRETE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_CONCRETE), new ItemStack(GREEN_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_CONCRETE_XMAS, 2), new RainbowTicker(Material.RED_CONCRETE, Material.GREEN_CONCRETE)) + new CustomItem(SlimefunItems.RAINBOW_CONCRETE_XMAS, 2), new RainbowTickHandler(Material.RED_CONCRETE, Material.GREEN_CONCRETE)) .register(plugin); new RainbowBlock(categories.christmas, SlimefunItems.RAINBOW_GLAZED_TERRACOTTA_XMAS, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(GREEN_DYE), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(GREEN_DYE), SlimefunItems.CHRISTMAS_COOKIE, new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA_XMAS, 2), new RainbowTicker(Material.RED_GLAZED_TERRACOTTA, Material.GREEN_GLAZED_TERRACOTTA)) + new CustomItem(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA_XMAS, 2), new RainbowTickHandler(Material.RED_GLAZED_TERRACOTTA, Material.GREEN_GLAZED_TERRACOTTA)) .register(plugin); // Valentines Day new RainbowBlock(categories.valentinesDay, SlimefunItems.RAINBOW_WOOL_VALENTINE, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), new ItemStack(Material.POPPY), new ItemStack(Material.PINK_DYE), new ItemStack(Material.WHITE_WOOL), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.PINK_DYE), new ItemStack(Material.POPPY), new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_WOOL_VALENTINE, 2), new RainbowTicker(Material.MAGENTA_WOOL, Material.PINK_WOOL)) + new CustomItem(SlimefunItems.RAINBOW_WOOL_VALENTINE, 2), new RainbowTickHandler(Material.MAGENTA_WOOL, Material.PINK_WOOL)) .register(plugin); new RainbowBlock(categories.valentinesDay, SlimefunItems.RAINBOW_GLASS_VALENTINE, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), new ItemStack(Material.POPPY), new ItemStack(Material.PINK_DYE), new ItemStack(Material.WHITE_STAINED_GLASS), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.PINK_DYE), new ItemStack(Material.POPPY), new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_GLASS_VALENTINE, 2), new RainbowTicker(Material.MAGENTA_STAINED_GLASS, Material.PINK_STAINED_GLASS)) + new CustomItem(SlimefunItems.RAINBOW_GLASS_VALENTINE, 2), new RainbowTickHandler(Material.MAGENTA_STAINED_GLASS, Material.PINK_STAINED_GLASS)) .register(plugin); new RainbowBlock(categories.valentinesDay, SlimefunItems.RAINBOW_GLASS_PANE_VALENTINE, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), new ItemStack(Material.POPPY), new ItemStack(Material.PINK_DYE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.PINK_DYE), new ItemStack(Material.POPPY), new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_GLASS_PANE_VALENTINE, 2), new RainbowTicker(Material.MAGENTA_STAINED_GLASS_PANE, Material.PINK_STAINED_GLASS_PANE)) + new CustomItem(SlimefunItems.RAINBOW_GLASS_PANE_VALENTINE, 2), new RainbowTickHandler(Material.MAGENTA_STAINED_GLASS_PANE, Material.PINK_STAINED_GLASS_PANE)) .register(plugin); new RainbowBlock(categories.valentinesDay, SlimefunItems.RAINBOW_CLAY_VALENTINE, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), new ItemStack(Material.POPPY), new ItemStack(Material.PINK_DYE), new ItemStack(Material.WHITE_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.PINK_DYE), new ItemStack(Material.POPPY), new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_CLAY_VALENTINE, 2), new RainbowTicker(Material.MAGENTA_TERRACOTTA, Material.PINK_TERRACOTTA)) + new CustomItem(SlimefunItems.RAINBOW_CLAY_VALENTINE, 2), new RainbowTickHandler(Material.MAGENTA_TERRACOTTA, Material.PINK_TERRACOTTA)) .register(plugin); new RainbowBlock(categories.valentinesDay, SlimefunItems.RAINBOW_CONCRETE_VALENTINE, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), new ItemStack(Material.POPPY), new ItemStack(Material.PINK_DYE), new ItemStack(Material.WHITE_CONCRETE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.PINK_DYE), new ItemStack(Material.POPPY), new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_CONCRETE_VALENTINE, 2), new RainbowTicker(Material.MAGENTA_CONCRETE, Material.PINK_CONCRETE)) + new CustomItem(SlimefunItems.RAINBOW_CONCRETE_VALENTINE, 2), new RainbowTickHandler(Material.MAGENTA_CONCRETE, Material.PINK_CONCRETE)) .register(plugin); new RainbowBlock(categories.valentinesDay, SlimefunItems.RAINBOW_GLAZED_TERRACOTTA_VALENTINE, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(RED_DYE), new ItemStack(Material.POPPY), new ItemStack(Material.PINK_DYE), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.PINK_DYE), new ItemStack(Material.POPPY), new ItemStack(RED_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA_VALENTINE, 2), new RainbowTicker(Material.MAGENTA_GLAZED_TERRACOTTA, Material.PINK_GLAZED_TERRACOTTA)) + new CustomItem(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA_VALENTINE, 2), new RainbowTickHandler(Material.MAGENTA_GLAZED_TERRACOTTA, Material.PINK_GLAZED_TERRACOTTA)) .register(plugin); // Halloween new RainbowBlock(categories.halloween, SlimefunItems.RAINBOW_WOOL_HALLOWEEN, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.ORANGE_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(BLACK_DYE), new ItemStack(Material.WHITE_WOOL), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_WOOL), new ItemStack(BLACK_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(Material.ORANGE_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_WOOL_HALLOWEEN, 2), new RainbowTicker(Material.ORANGE_WOOL, Material.BLACK_WOOL)) + new CustomItem(SlimefunItems.RAINBOW_WOOL_HALLOWEEN, 2), new RainbowTickHandler(Material.ORANGE_WOOL, Material.BLACK_WOOL)) .register(plugin); new RainbowBlock(categories.halloween, SlimefunItems.RAINBOW_GLASS_HALLOWEEN, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.ORANGE_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(BLACK_DYE), new ItemStack(Material.WHITE_STAINED_GLASS), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(BLACK_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(Material.ORANGE_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_GLASS_HALLOWEEN, 2), new RainbowTicker(Material.ORANGE_STAINED_GLASS, Material.BLACK_STAINED_GLASS)) + new CustomItem(SlimefunItems.RAINBOW_GLASS_HALLOWEEN, 2), new RainbowTickHandler(Material.ORANGE_STAINED_GLASS, Material.BLACK_STAINED_GLASS)) .register(plugin); new RainbowBlock(categories.halloween, SlimefunItems.RAINBOW_GLASS_PANE_HALLOWEEN, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.ORANGE_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(BLACK_DYE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(BLACK_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(Material.ORANGE_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_GLASS_PANE_HALLOWEEN, 2), new RainbowTicker(Material.ORANGE_STAINED_GLASS_PANE, Material.BLACK_STAINED_GLASS_PANE)) + new CustomItem(SlimefunItems.RAINBOW_GLASS_PANE_HALLOWEEN, 2), new RainbowTickHandler(Material.ORANGE_STAINED_GLASS_PANE, Material.BLACK_STAINED_GLASS_PANE)) .register(plugin); new RainbowBlock(categories.halloween, SlimefunItems.RAINBOW_CLAY_HALLOWEEN, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.ORANGE_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(BLACK_DYE), new ItemStack(Material.WHITE_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(BLACK_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(Material.ORANGE_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_CLAY_HALLOWEEN, 2), new RainbowTicker(Material.ORANGE_TERRACOTTA, Material.BLACK_TERRACOTTA)) + new CustomItem(SlimefunItems.RAINBOW_CLAY_HALLOWEEN, 2), new RainbowTickHandler(Material.ORANGE_TERRACOTTA, Material.BLACK_TERRACOTTA)) .register(plugin); new RainbowBlock(categories.halloween, SlimefunItems.RAINBOW_CONCRETE_HALLOWEEN, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.ORANGE_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(BLACK_DYE), new ItemStack(Material.WHITE_CONCRETE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_CONCRETE), new ItemStack(BLACK_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(Material.ORANGE_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_CONCRETE_HALLOWEEN, 2), new RainbowTicker(Material.ORANGE_CONCRETE, Material.BLACK_CONCRETE)) + new CustomItem(SlimefunItems.RAINBOW_CONCRETE_HALLOWEEN, 2), new RainbowTickHandler(Material.ORANGE_CONCRETE, Material.BLACK_CONCRETE)) .register(plugin); new RainbowBlock(categories.halloween, SlimefunItems.RAINBOW_GLAZED_TERRACOTTA_HALLOWEEN, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.ORANGE_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(BLACK_DYE), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(BLACK_DYE), new ItemStack(Material.PUMPKIN), new ItemStack(Material.ORANGE_DYE)}, - new CustomItem(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA_HALLOWEEN, 2), new RainbowTicker(Material.ORANGE_GLAZED_TERRACOTTA, Material.BLACK_GLAZED_TERRACOTTA)) + new CustomItem(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA_HALLOWEEN, 2), new RainbowTickHandler(Material.ORANGE_GLAZED_TERRACOTTA, Material.BLACK_GLAZED_TERRACOTTA)) .register(plugin); new WitherProofBlock(categories.technicalComponents, SlimefunItems.WITHER_PROOF_GLASS, RecipeType.ENHANCED_CRAFTING_TABLE, diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java index 7b8d80edf..cf2d67916 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java @@ -3,6 +3,11 @@ package me.mrCookieSlime.Slimefun.Objects.handlers; import java.util.Optional; import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.EntityInteractHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.EntityKillHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; /** diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/interfaces/SlimefunItemTest.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/interfaces/SlimefunItemTest.java index 32c7b4162..f85522387 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/interfaces/SlimefunItemTest.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/interfaces/SlimefunItemTest.java @@ -7,9 +7,9 @@ import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.inventory.EquipmentSlot; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; @FunctionalInterface diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestItemHandlers.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestItemHandlers.java index 06df60470..e48b863b9 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestItemHandlers.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestItemHandlers.java @@ -14,11 +14,11 @@ import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException; +import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.testing.TestUtilities; import io.github.thebusybiscuit.slimefun4.testing.mocks.MockItemHandler; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BowShootHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; From 6f1a2b82b571a29588092d1cb74231144a7fdb33 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 29 Jun 2020 17:12:54 +0200 Subject: [PATCH 12/36] Added runtime deprecation warnings for Addon Creators --- CHANGELOG.md | 1 + .../core/handlers/BlockBreakHandler.java | 19 ++++++++ .../core}/handlers/BlockPlaceHandler.java | 7 ++- .../core/handlers/ItemUseHandler.java | 37 +++++++++++++++ .../MultiBlockInteractionHandler.java | 45 +++++++++++++++++++ .../core/multiblocks/MultiBlock.java | 2 +- .../core/multiblocks/MultiBlockMachine.java | 2 +- .../items/backpacks/EnderBackpack.java | 2 +- .../items/backpacks/SlimefunBackpack.java | 2 +- .../items/blocks/RepairedSpawner.java | 4 +- .../items/blocks/UnplaceableBlock.java | 2 +- .../items/electric/BasicCircuitBoard.java | 2 +- .../items/electric/gadgets/MultiTool.java | 4 +- .../items/electric/gadgets/Multimeter.java | 2 +- .../implementation/items/food/MagicSugar.java | 2 +- .../items/geo/PortableGEOScanner.java | 2 +- .../items/gps/GPSMarkerTool.java | 2 +- .../items/magical/InfernalBonemeal.java | 2 +- .../items/magical/KnowledgeFlask.java | 2 +- .../items/magical/KnowledgeTome.java | 2 +- .../items/magical/MagicEyeOfEnder.java | 2 +- .../items/magical/StormStaff.java | 2 +- .../items/magical/TelepositionScroll.java | 2 +- .../items/magical/WaterStaff.java | 2 +- .../items/magical/WindStaff.java | 2 +- .../implementation/items/medical/Bandage.java | 2 +- .../implementation/items/medical/Rag.java | 2 +- .../implementation/items/medical/Splint.java | 2 +- .../items/medical/Vitamins.java | 2 +- .../items/seasonal/ChristmasPresent.java | 6 +-- .../items/seasonal/EasterEgg.java | 2 +- .../items/tools/ExplosiveTool.java | 2 +- .../implementation/items/tools/GoldPan.java | 2 +- .../items/tools/GrapplingHook.java | 2 +- .../items/tools/HerculesPickaxe.java | 2 +- .../implementation/items/tools/LumberAxe.java | 4 +- .../items/tools/PickaxeOfContainment.java | 2 +- .../items/tools/PickaxeOfTheSeeker.java | 2 +- .../items/tools/PickaxeOfVeinMining.java | 2 +- .../items/tools/PortableCrafter.java | 2 +- .../items/tools/PortableDustbin.java | 2 +- .../items/tools/SmeltersPickaxe.java | 2 +- .../items/weapons/SeismicAxe.java | 2 +- .../listeners/BlockListener.java | 13 ++---- .../listeners/MultiBlockListener.java | 2 +- .../listeners/SlimefunItemListener.java | 2 +- .../SlimefunItem/SimpleSlimefunItem.java | 2 +- .../Objects/SlimefunItem/SlimefunItem.java | 41 +++++++++++++++++ .../Objects/handlers/BlockBreakHandler.java | 18 +++----- .../Objects/handlers/ItemHandler.java | 1 + .../Objects/handlers/ItemUseHandler.java | 33 ++------------ .../MultiBlockInteractionHandler.java | 41 ++--------------- .../testing/interfaces/SlimefunItemTest.java | 2 +- .../testing/tests/items/TestItemHandlers.java | 2 +- 54 files changed, 211 insertions(+), 141 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockBreakHandler.java rename src/main/java/{me/mrCookieSlime/Slimefun/Objects => io/github/thebusybiscuit/slimefun4/core}/handlers/BlockPlaceHandler.java (56%) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/ItemUseHandler.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/MultiBlockInteractionHandler.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 741492823..49a2830b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ * (1.16+) Added Shroomlights to the fuel list for the Bio Generator * (1.16+) Added Warped and Crimson Fungus to the fuel list for the Bio Generator * Added an AoE damage effect to the Explosive Bow +* Added runtime deprecation warnings for ItemHandlers and Attributes used by Addons #### Changes * Coolant Cells now last twice as long diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockBreakHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockBreakHandler.java new file mode 100644 index 000000000..d9a045fe3 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockBreakHandler.java @@ -0,0 +1,19 @@ +package io.github.thebusybiscuit.slimefun4.core.handlers; + +import java.util.List; + +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; + +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; + +@FunctionalInterface +public interface BlockBreakHandler extends ItemHandler { + + boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List drops); + + @Override + default Class getIdentifier() { + return BlockBreakHandler.class; + } +} diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockPlaceHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockPlaceHandler.java similarity index 56% rename from src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockPlaceHandler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockPlaceHandler.java index 47310a0cb..cd4dccf81 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockPlaceHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/BlockPlaceHandler.java @@ -1,12 +1,15 @@ -package me.mrCookieSlime.Slimefun.Objects.handlers; +package io.github.thebusybiscuit.slimefun4.core.handlers; +import org.bukkit.entity.Player; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; + @FunctionalInterface public interface BlockPlaceHandler extends ItemHandler { - boolean onBlockPlace(BlockPlaceEvent e, ItemStack item); + boolean onBlockPlace(Player p, BlockPlaceEvent e, ItemStack item); @Override default Class getIdentifier() { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/ItemUseHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/ItemUseHandler.java new file mode 100644 index 000000000..ebc661018 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/ItemUseHandler.java @@ -0,0 +1,37 @@ +package io.github.thebusybiscuit.slimefun4.core.handlers; + +import org.bukkit.entity.Player; + +import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; + +/** + * This {@link ItemHandler} is triggered when the {@link SlimefunItem} it was assigned to + * is right-clicked. + * + * @author TheBusyBiscuit + * + * @see ItemHandler + * @see SimpleSlimefunItem + * + */ +@FunctionalInterface +public interface ItemUseHandler extends ItemHandler { + + /** + * This function is triggered when a {@link Player} right clicks with the assigned {@link SlimefunItem} + * in his hand. + * + * @param e + * The {@link PlayerRightClickEvent} that was triggered + */ + void onRightClick(PlayerRightClickEvent e); + + @Override + default Class getIdentifier() { + return ItemUseHandler.class; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/MultiBlockInteractionHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/MultiBlockInteractionHandler.java new file mode 100644 index 000000000..36f2ce0ed --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/MultiBlockInteractionHandler.java @@ -0,0 +1,45 @@ +package io.github.thebusybiscuit.slimefun4.core.handlers; + +import java.util.Optional; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; +import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; + +/** + * This {@link ItemHandler} is called whenever a {@link Player} interacts with + * this {@link MultiBlock}. + * Note that this {@link MultiBlockInteractionHandler} should be assigned to + * a class that inherits from {@link MultiBlockMachine}. + * + * @author TheBusyBiscuit + * + * @see ItemHandler + * @see MultiBlock + * @see MultiBlockMachine + * + */ +@FunctionalInterface +public interface MultiBlockInteractionHandler extends ItemHandler { + + boolean onInteract(Player p, MultiBlock mb, Block b); + + @Override + default Optional validate(SlimefunItem item) { + if (!(item instanceof MultiBlockMachine)) { + return Optional.of(new IncompatibleItemHandlerException("Only classes inheriting 'MultiBlockMachine' can have a MultiBlockInteractionHandler", item, this)); + } + + return Optional.empty(); + } + + @Override + default Class getIdentifier() { + return MultiBlockInteractionHandler.class; + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java index 62083c2e8..af5572702 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java @@ -13,9 +13,9 @@ import org.bukkit.block.BlockFace; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockInteractEvent; +import io.github.thebusybiscuit.slimefun4.core.handlers.MultiBlockInteractionHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.MultiBlockInteractionHandler; /** * A {@link MultiBlock} represents a structure build in a {@link World}. diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlockMachine.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlockMachine.java index 1b7af5b77..a4fd5fb55 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlockMachine.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlockMachine.java @@ -20,11 +20,11 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; +import io.github.thebusybiscuit.slimefun4.core.handlers.MultiBlockInteractionHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.MultiBlockInteractionHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/EnderBackpack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/EnderBackpack.java index ec7454918..288ca6c69 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/EnderBackpack.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/EnderBackpack.java @@ -5,10 +5,10 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class EnderBackpack extends SimpleSlimefunItem implements NotPlaceable { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java index aee23c7f0..359f9fff8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java @@ -5,13 +5,13 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListener; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RepairedSpawner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RepairedSpawner.java index 3af6687a6..d64ef794d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RepairedSpawner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RepairedSpawner.java @@ -8,12 +8,12 @@ import org.bukkit.block.CreatureSpawner; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockPlaceHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class RepairedSpawner extends SimpleSlimefunItem { @@ -24,7 +24,7 @@ public class RepairedSpawner extends SimpleSlimefunItem { @Override public BlockPlaceHandler getItemHandler() { - return (e, item) -> { + return (p, e, item) -> { // We need to explicitly ignore the lore here if (SlimefunUtils.isItemSimilar(item, SlimefunItems.REPAIRED_SPAWNER, false, false)) { Optional entity = getEntityType(item); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/UnplaceableBlock.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/UnplaceableBlock.java index 1d1b02824..688d4571c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/UnplaceableBlock.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/UnplaceableBlock.java @@ -4,10 +4,10 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class UnplaceableBlock extends SimpleSlimefunItem implements NotPlaceable { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/BasicCircuitBoard.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/BasicCircuitBoard.java index 1934f01b5..d7e6e42aa 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/BasicCircuitBoard.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/BasicCircuitBoard.java @@ -5,10 +5,10 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class BasicCircuitBoard extends SimpleSlimefunItem implements NotPlaceable { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java index bc151084c..4f73938a6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java @@ -11,12 +11,12 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class MultiTool extends SlimefunItem implements Rechargeable { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java index 6955c9105..437f1e4d4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java @@ -7,11 +7,11 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MagicSugar.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MagicSugar.java index fb7af2b3e..6e48a99bc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MagicSugar.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MagicSugar.java @@ -9,10 +9,10 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class MagicSugar extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/PortableGEOScanner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/PortableGEOScanner.java index 960114fce..1a30b19e4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/PortableGEOScanner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/PortableGEOScanner.java @@ -5,11 +5,11 @@ import java.util.Optional; import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class PortableGEOScanner extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSMarkerTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSMarkerTool.java index b03c96e5f..9cba1fbe4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSMarkerTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSMarkerTool.java @@ -4,11 +4,11 @@ import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class GPSMarkerTool extends SimpleSlimefunItem implements NotPlaceable { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfernalBonemeal.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfernalBonemeal.java index c2dd7eda7..28b7a88d5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfernalBonemeal.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfernalBonemeal.java @@ -11,10 +11,10 @@ import org.bukkit.event.Event.Result; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class InfernalBonemeal extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeFlask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeFlask.java index b0e45da66..72d6fa168 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeFlask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeFlask.java @@ -5,12 +5,12 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeTome.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeTome.java index 33d05d2db..7a32c1eae 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeTome.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeTome.java @@ -14,12 +14,12 @@ import org.bukkit.inventory.meta.ItemMeta; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class KnowledgeTome extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicEyeOfEnder.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicEyeOfEnder.java index 762ca355f..810d53f31 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicEyeOfEnder.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicEyeOfEnder.java @@ -6,12 +6,12 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class MagicEyeOfEnder extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java index b6fb77951..0d649de9f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java @@ -17,13 +17,13 @@ import org.bukkit.persistence.PersistentDataType; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java index 122e88126..4a7f227e4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java @@ -7,11 +7,11 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WaterStaff.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WaterStaff.java index c460cc3a1..f81147741 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WaterStaff.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WaterStaff.java @@ -3,12 +3,12 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.magical; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WindStaff.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WindStaff.java index b28125bed..ddf53c80f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WindStaff.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WindStaff.java @@ -9,11 +9,11 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class WindStaff extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java index 1113a6098..8b9f68f9d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java @@ -10,10 +10,10 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class Bandage extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Rag.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Rag.java index 31ccd18b2..772faed29 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Rag.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Rag.java @@ -10,10 +10,10 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class Rag extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java index 437248c3d..ec417312c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java @@ -9,10 +9,10 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class Splint extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Vitamins.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Vitamins.java index 85362792a..fc9fd4261 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Vitamins.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Vitamins.java @@ -8,10 +8,10 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class Vitamins extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/ChristmasPresent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/ChristmasPresent.java index b60a2528f..a408deb6e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/ChristmasPresent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/ChristmasPresent.java @@ -7,11 +7,11 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockPlaceHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class ChristmasPresent extends SimpleSlimefunItem implements NotPlaceable { @@ -26,7 +26,7 @@ public class ChristmasPresent extends SimpleSlimefunItem impl @Override public BlockPlaceHandler getItemHandler() { - return (e, item) -> { + return (p, e, item) -> { if (isItem(item)) { e.setCancelled(true); @@ -34,7 +34,7 @@ public class ChristmasPresent extends SimpleSlimefunItem impl ItemUtils.consumeItem(item, false); } - FireworkUtils.launchRandom(e.getPlayer(), 3); + FireworkUtils.launchRandom(p, 3); ItemStack gift = gifts[ThreadLocalRandom.current().nextInt(gifts.length)].clone(); e.getBlockPlaced().getWorld().dropItemNaturally(e.getBlockPlaced().getLocation(), gift); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/EasterEgg.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/EasterEgg.java index 7eb03c61b..5073842d7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/EasterEgg.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/EasterEgg.java @@ -7,12 +7,12 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java index 664e79b46..54ac67e53 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java @@ -19,6 +19,7 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; @@ -26,7 +27,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java index db79ec099..23a8f6136 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java @@ -15,6 +15,7 @@ import io.github.thebusybiscuit.cscorelib2.collections.RandomizedSet; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.ElectricGoldPan; @@ -23,7 +24,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java index 9e2ba83f5..aa78365d4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GrapplingHook.java @@ -13,11 +13,11 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class GrapplingHook extends SimpleSlimefunItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/HerculesPickaxe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/HerculesPickaxe.java index 82eeafce8..7292a16b0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/HerculesPickaxe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/HerculesPickaxe.java @@ -7,11 +7,11 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/LumberAxe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/LumberAxe.java index 98b41e326..5e35de377 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/LumberAxe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/LumberAxe.java @@ -16,12 +16,12 @@ import io.github.thebusybiscuit.cscorelib2.blocks.Vein; import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfContainment.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfContainment.java index 304a3577f..2580a8abe 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfContainment.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfContainment.java @@ -9,6 +9,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.BrokenSpawner; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RepairedSpawner; @@ -16,7 +17,6 @@ import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfTheSeeker.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfTheSeeker.java index 2d7df1f4c..204b5719e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfTheSeeker.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfTheSeeker.java @@ -8,11 +8,11 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class PickaxeOfTheSeeker extends SimpleSlimefunItem implements DamageableItem { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfVeinMining.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfVeinMining.java index b4c6f0816..9862f4dcf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfVeinMining.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PickaxeOfVeinMining.java @@ -15,11 +15,11 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PortableCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PortableCrafter.java index 47cab337c..ce223f020 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PortableCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PortableCrafter.java @@ -5,10 +5,10 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class PortableCrafter extends SimpleSlimefunItem implements NotPlaceable { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PortableDustbin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PortableDustbin.java index 79c735443..cf43a17c9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PortableDustbin.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/PortableDustbin.java @@ -7,10 +7,10 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class PortableDustbin extends SimpleSlimefunItem implements NotPlaceable { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/SmeltersPickaxe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/SmeltersPickaxe.java index e46c05080..5fdc56a50 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/SmeltersPickaxe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/SmeltersPickaxe.java @@ -12,11 +12,11 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SeismicAxe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SeismicAxe.java index 0fecccf40..9305abdac 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SeismicAxe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SeismicAxe.java @@ -21,11 +21,11 @@ import org.bukkit.util.Vector; import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index db3e4cb6a..d7d69e17b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -22,12 +22,12 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockPlaceHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; @@ -74,14 +74,7 @@ public class BlockListener implements Listener { blockHandler.onPlace(e.getPlayer(), e.getBlock(), sfItem); } else { - sfItem.callItemHandler(BlockPlaceHandler.class, handler -> handler.onBlockPlace(e, item)); - } - } - } - else { - for (ItemHandler handler : SlimefunItem.getPublicItemHandlers(BlockPlaceHandler.class)) { - if (((BlockPlaceHandler) handler).onBlockPlace(e, item)) { - break; + sfItem.callItemHandler(BlockPlaceHandler.class, handler -> handler.onBlockPlace(e.getPlayer(), e, item)); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MultiBlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MultiBlockListener.java index f271295ea..c97cac228 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MultiBlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MultiBlockListener.java @@ -15,9 +15,9 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockInteractEvent; +import io.github.thebusybiscuit.slimefun4.core.handlers.MultiBlockInteractionHandler; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import me.mrCookieSlime.Slimefun.Objects.handlers.MultiBlockInteractionHandler; /** * This {@link Listener} is responsible for listening to a {@link PlayerInteractEvent} and diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemListener.java index 563f4f57e..523fa7939 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunItemListener.java @@ -16,12 +16,12 @@ import org.bukkit.inventory.EquipmentSlot; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemDropHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SimpleSlimefunItem.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SimpleSlimefunItem.java index a16a3898f..690b13c58 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SimpleSlimefunItem.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SimpleSlimefunItem.java @@ -2,10 +2,10 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java index 755b679de..6e0a0e8fd 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java @@ -391,6 +391,7 @@ public class SlimefunItem implements Placeable { } state = ItemState.ENABLED; + checkForDeprecations(getClass()); useableInWorkbench = SlimefunPlugin.getItemCfg().getBoolean(id + ".can-be-used-in-workbenches"); hidden = SlimefunPlugin.getItemCfg().getBoolean(id + ".hide-in-guide"); @@ -426,6 +427,12 @@ public class SlimefunItem implements Placeable { if (exception.isPresent()) { throw exception.get(); } + else { + // Make developers or at least Server admins aware that + // an Item is using a deprecated ItemHandler + // checkForDeprecations(handler.getClass()); + // A bit too spammy atm, will enable it again later + } if (!handler.isPrivate()) { Set handlerset = getPublicItemHandlers(handler.getIdentifier()); @@ -434,6 +441,35 @@ public class SlimefunItem implements Placeable { } } + /** + * This method checks recursively for all {@link Class} parents to look for any {@link Deprecated} + * elements. + * + * If a {@link Deprecated} element was found, a warning message will be printed. + * + * @param c + * The {@link Class} from which to start this operation. + */ + private void checkForDeprecations(Class c) { + // We do not wanna throw an Exception here since this could also mean that + // we have reached the end of the Class hierarchy + if (c != null) { + // Check if this Class is deprecated + if (c.isAnnotationPresent(Deprecated.class)) { + warn("The inherited Class \"" + c.getName() + "\" has been deprecated. Check the documentation for more details!"); + } + + for (Class parent : c.getInterfaces()) { + // Check if this Interface is deprecated + if (parent.isAnnotationPresent(Deprecated.class)) { + warn("The implemented Interface \"" + parent.getName() + "\" has been deprecated. Check the documentation for more details!"); + } + } + + checkForDeprecations(c.getSuperclass()); + } + } + /** * This method will set the {@link Research} of this {@link SlimefunItem}. * You don't have to call this method if your {@link SlimefunItem} was linked to your {@link Research} @@ -765,6 +801,11 @@ public class SlimefunItem implements Placeable { public void warn(String message) { String msg = toString() + ": " + message; addon.getLogger().log(Level.WARNING, msg); + + if (addon.getBugTrackerURL() != null) { + // We can prompt the server operator to report it to the addon's bug tracker + addon.getLogger().log(Level.WARNING, "You can report this warning here: {0}", addon.getBugTrackerURL()); + } } /** diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockBreakHandler.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockBreakHandler.java index 72b1d1b7d..2b43d181d 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockBreakHandler.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/BlockBreakHandler.java @@ -1,17 +1,9 @@ package me.mrCookieSlime.Slimefun.Objects.handlers; -import java.util.List; +/** + * @deprecated Moved to {@link io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler} + */ +@Deprecated +public interface BlockBreakHandler extends io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler { -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.inventory.ItemStack; - -@FunctionalInterface -public interface BlockBreakHandler extends ItemHandler { - - boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List drops); - - @Override - default Class getIdentifier() { - return BlockBreakHandler.class; - } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java index cf2d67916..ca6417ae4 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemHandler.java @@ -8,6 +8,7 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.EntityInteractHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.EntityKillHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; /** diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemUseHandler.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemUseHandler.java index 22aaa40d1..13c5653b2 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemUseHandler.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/ItemUseHandler.java @@ -1,36 +1,9 @@ package me.mrCookieSlime.Slimefun.Objects.handlers; -import org.bukkit.entity.Player; - -import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; - /** - * This {@link ItemHandler} is triggered when the {@link SlimefunItem} it was assigned to - * is right-clicked. - * - * @author TheBusyBiscuit - * - * @see ItemHandler - * @see SimpleSlimefunItem - * + * @deprecated Moved to {@link io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler} */ -@FunctionalInterface -public interface ItemUseHandler extends ItemHandler { - - /** - * This function is triggered when a {@link Player} right clicks with the assigned {@link SlimefunItem} - * in his hand. - * - * @param e - * The {@link PlayerRightClickEvent} that was triggered - */ - void onRightClick(PlayerRightClickEvent e); - - @Override - default Class getIdentifier() { - return ItemUseHandler.class; - } +@Deprecated +public interface ItemUseHandler extends io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler { } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java index 7f68b1fb6..226f52ea3 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/MultiBlockInteractionHandler.java @@ -1,44 +1,9 @@ package me.mrCookieSlime.Slimefun.Objects.handlers; -import java.util.Optional; - -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException; -import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; -import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; - /** - * This {@link ItemHandler} is called whenever a {@link Player} interacts with - * this {@link MultiBlock}. - * Note that this {@link MultiBlockInteractionHandler} should be assigned to - * a class that inherits from {@link MultiBlockMachine}. - * - * @author TheBusyBiscuit - * - * @see ItemHandler - * @see MultiBlock - * @see MultiBlockMachine - * + * @deprecated Moved to {@link io.github.thebusybiscuit.slimefun4.core.handlers.MultiBlockInteractionHandler} */ -@FunctionalInterface -public interface MultiBlockInteractionHandler extends ItemHandler { +@Deprecated +public interface MultiBlockInteractionHandler extends io.github.thebusybiscuit.slimefun4.core.handlers.MultiBlockInteractionHandler { - boolean onInteract(Player p, MultiBlock mb, Block b); - - @Override - default Optional validate(SlimefunItem item) { - if (!(item instanceof MultiBlockMachine)) { - return Optional.of(new IncompatibleItemHandlerException("Only classes inheriting 'MultiBlockMachine' can have a MultiBlockInteractionHandler", item, this)); - } - - return Optional.empty(); - } - - @Override - default Class getIdentifier() { - return MultiBlockInteractionHandler.class; - } } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/interfaces/SlimefunItemTest.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/interfaces/SlimefunItemTest.java index f85522387..a17fb3756 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/interfaces/SlimefunItemTest.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/interfaces/SlimefunItemTest.java @@ -8,9 +8,9 @@ import org.bukkit.inventory.EquipmentSlot; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; @FunctionalInterface public interface SlimefunItemTest { diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestItemHandlers.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestItemHandlers.java index e48b863b9..e28d9cb7b 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestItemHandlers.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestItemHandlers.java @@ -15,12 +15,12 @@ import be.seeseemelk.mockbukkit.MockBukkit; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException; import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.testing.TestUtilities; import io.github.thebusybiscuit.slimefun4.testing.mocks.MockItemHandler; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; -import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler; public class TestItemHandlers { From cb7cc4402f44673f44246b292162a29d1610034f Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Tue, 30 Jun 2020 01:33:13 +0200 Subject: [PATCH 13/36] Refactoring --- .../Slimefun/Objects/SlimefunItem/SlimefunItem.java | 12 +++++++++++- .../me/mrCookieSlime/Slimefun/SlimefunPlugin.java | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java index 6e0a0e8fd..492aa39c1 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java @@ -19,6 +19,7 @@ import io.github.thebusybiscuit.cscorelib2.collections.OptionalMap; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; +import io.github.thebusybiscuit.slimefun4.api.SlimefunBranch; import io.github.thebusybiscuit.slimefun4.api.exceptions.IdConflictException; import io.github.thebusybiscuit.slimefun4.api.exceptions.IncompatibleItemHandlerException; import io.github.thebusybiscuit.slimefun4.api.exceptions.MissingDependencyException; @@ -430,7 +431,7 @@ public class SlimefunItem implements Placeable { else { // Make developers or at least Server admins aware that // an Item is using a deprecated ItemHandler - // checkForDeprecations(handler.getClass()); + checkForDeprecations(handler.getClass()); // A bit too spammy atm, will enable it again later } @@ -451,6 +452,14 @@ public class SlimefunItem implements Placeable { * The {@link Class} from which to start this operation. */ private void checkForDeprecations(Class c) { + if (SlimefunPlugin.getUpdater().getBranch() == SlimefunBranch.DEVELOPMENT) { + // This method is currently way too spammy with all the restructuring going on... + // Since DEV builds are anyway under "development", things may be relocated. + // So we fire these only for stable versions, since devs should update then, so + // it's the perfect moment to tell them to act. + return; + } + // We do not wanna throw an Exception here since this could also mean that // we have reached the end of the Class hierarchy if (c != null) { @@ -466,6 +475,7 @@ public class SlimefunItem implements Placeable { } } + // Recursively lookup the super class checkForDeprecations(c.getSuperclass()); } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java index df0719e51..ad05fec1f 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java @@ -35,7 +35,9 @@ import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; * */ @Deprecated -public class SlimefunPlugin { +public final class SlimefunPlugin { + + private SlimefunPlugin() {} public static Config getCfg() { return io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin.getCfg(); From 527ffdd7425f1c9e42eab4390b4073abce964b19 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Tue, 30 Jun 2020 02:12:40 +0200 Subject: [PATCH 14/36] Added Gilded Blackstone recipe to the Ore Crusher --- CHANGELOG.md | 1 + .../slimefun4/implementation/items/multiblocks/OreCrusher.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49a2830b5..ba2a13b29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ * Added Clay -> Clay blocks recipe to the Electric Press * (1.16+) Slimefun guide can now show Smithing Table recipes * (1.16+) Added Nether Gold Ore recipe to the Ore Crusher +* (1.16+) Added Gilded Blackstone recipe to the Ore Crusher * (1.16+) Added Shroomlights to the fuel list for the Bio Generator * (1.16+) Added Warped and Crimson Fungus to the fuel list for the Bio Generator * Added an AoE damage effect to the Explosive Bow diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java index dc528767e..85337c638 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java @@ -48,6 +48,9 @@ public class OreCrusher extends MultiBlockMachine { if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) { displayRecipes.add(new ItemStack(Material.NETHER_GOLD_ORE)); displayRecipes.add(doubleOres.getGoldNuggets()); + + displayRecipes.add(new ItemStack(Material.GILDED_BLACKSTONE)); + displayRecipes.add(doubleOres.getGoldNuggets()); } } From 0aa99df8c2db0830c2fe10cd0ad1dc51c9c6c986 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Tue, 30 Jun 2020 16:44:50 +0200 Subject: [PATCH 15/36] Performance optimization --- .../slimefun4/implementation/tasks/TickerTask.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java index bebfe79d0..01c7a9e04 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java @@ -106,12 +106,14 @@ public class TickerTask implements Runnable { long chunkTimestamp = System.nanoTime(); chunks++; - for (Location l : BlockStorage.getTickingLocations(chunk)) { + Set locations = BlockStorage.getTickingLocations(chunk); + + for (Location l : locations) { if (l.getWorld().isChunkLoaded(l.getBlockX() >> 4, l.getBlockZ() >> 4)) { tick(l, chunk, bugs); } else { - skippedBlocks += BlockStorage.getTickingLocations(chunk).size(); + skippedBlocks += locations.size(); skippedChunks.add(chunk); chunks--; break; From d82b66a842cd03788a1247b945cb60de832bee7d Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Tue, 30 Jun 2020 19:36:55 +0200 Subject: [PATCH 16/36] Added a better profiler --- CHANGELOG.md | 5 + .../commands/subcommands/TimingsCommand.java | 3 +- .../core/networks/cargo/CargoNet.java | 2 +- .../core/networks/energy/EnergyNet.java | 4 +- .../core/services/github/GitHubTask.java | 2 +- .../services/plugins/PlaceholderAPIHook.java | 2 +- .../core/services/profiler/ProfiledBlock.java | 49 +++ .../services/profiler/SlimefunProfiler.java | 317 ++++++++++++++++++ .../core/services/profiler/package-info.java | 9 + .../implementation/SlimefunPlugin.java | 6 + .../items/cargo/CargoManager.java | 2 +- .../listeners/DebugFishListener.java | 46 ++- .../implementation/tasks/TickerTask.java | 235 +++---------- .../slimefun4/utils/NumberUtils.java | 6 +- 14 files changed, 463 insertions(+), 225 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/ProfiledBlock.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/package-info.java diff --git a/CHANGELOG.md b/CHANGELOG.md index ba2a13b29..146e6b4d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ * (1.16+) Added Warped and Crimson Fungus to the fuel list for the Bio Generator * Added an AoE damage effect to the Explosive Bow * Added runtime deprecation warnings for ItemHandlers and Attributes used by Addons +* Added a proper lag profiler #### Changes * Coolant Cells now last twice as long @@ -54,6 +55,7 @@ * Small performance improvements to the Cargo Net * Slimefun no longer supports CraftBukkit * Item Energy is now also stored persistently via NBT +* General performance improvements for ticking blocks #### Fixes * Fixed #2005 @@ -72,6 +74,9 @@ * Fixed Grappling hooks making Bat sounds * Fixed #1959 * Fixed Melon Juice requiring Melons instead of Melon Slices +* Fixed Cargo networks not showing up in /sf timings +* Fixed /sf timings reporting slightly inaccurate timings +* Fixed concurrency-related issues with the profiling ## Release Candidate 13 (16 Jun 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java index 33528c197..2b85e48aa 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java @@ -26,7 +26,8 @@ class TimingsCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { if (sender.hasPermission("slimefun.command.timings") || sender instanceof ConsoleCommandSender) { - SlimefunPlugin.getTickerTask().info(sender); + sender.sendMessage("Please wait a second... The results are coming in!"); + SlimefunPlugin.getProfiler().requestSummary(sender); } else { SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java index 883635780..5d5c11918 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java @@ -166,7 +166,7 @@ public class CargoNet extends ChestTerminalNetwork { destinations.addAll(output16); } - Slimefun.runSync(() -> run(b, destinations, output)); + run(b, destinations, output); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java index 9dc4f273f..0208a04d1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java @@ -211,7 +211,7 @@ public class EnergyNet extends Network { Set exploded = new HashSet<>(); for (Location source : generators) { - long timestamp = System.currentTimeMillis(); + long timestamp = SlimefunPlugin.getProfiler().newEntry(); SlimefunItem item = BlockStorage.check(source); if (item != null) { @@ -247,7 +247,7 @@ public class EnergyNet extends Network { new ErrorReport(t, source, item); } - SlimefunPlugin.getTickerTask().addBlockTimings(source, System.currentTimeMillis() - timestamp); + SlimefunPlugin.getProfiler().closeEntry(source, item, timestamp); } else { // This block seems to be gone now, better remove it to be extra safe diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java index e666f9fae..1f36dcc52 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java @@ -56,7 +56,7 @@ class GitHubTask implements Runnable { } } - if (requests >= MAX_REQUESTS_PER_MINUTE) { + if (requests >= MAX_REQUESTS_PER_MINUTE && SlimefunPlugin.instance != null && SlimefunPlugin.instance.isEnabled()) { // Slow down API requests and wait a minute after more than x requests were made Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance, this::grabTextures, 2 * 60 * 20L); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java index e9dec1405..111ee37ad 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java @@ -85,7 +85,7 @@ class PlaceholderAPIHook extends PlaceholderExpansion { } if (params.equals("timings_lag")) { - return SlimefunPlugin.getTickerTask().getTime() + "ms"; + return SlimefunPlugin.getProfiler().getTime(); } if (params.equals("language")) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/ProfiledBlock.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/ProfiledBlock.java new file mode 100644 index 000000000..70c5c2549 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/ProfiledBlock.java @@ -0,0 +1,49 @@ +package io.github.thebusybiscuit.slimefun4.core.services.profiler; + +import org.bukkit.block.Block; + +import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition; +import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; + +class ProfiledBlock { + + private final BlockPosition position; + private final SlimefunItem item; + + ProfiledBlock(BlockPosition position, SlimefunItem item) { + this.position = position; + this.item = item; + } + + ProfiledBlock(Block b) { + this(new BlockPosition(b), null); + } + + public BlockPosition getPosition() { + return position; + } + + public String getId() { + return item.getID(); + } + + public SlimefunAddon getAddon() { + return item.getAddon(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ProfiledBlock) { + return position.equals(((ProfiledBlock) obj).position); + } + + return false; + } + + @Override + public int hashCode() { + return position.hashCode(); + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java new file mode 100644 index 000000000..5fbe2e270 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java @@ -0,0 +1,317 @@ +package io.github.thebusybiscuit.slimefun4.core.services.profiler; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Queue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; +import java.util.logging.Level; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.block.Block; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition; +import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; +import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask; +import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.api.Slimefun; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; + +/** + * The {@link SlimefunProfiler} works closely to the {@link TickerTask} and is responsible for + * monitoring that task. + * It collects timings data for any ticked {@link Block} and the corresponding {@link SlimefunItem}. + * This allows developers to identify laggy {@link SlimefunItem SlimefunItems} or {@link SlimefunAddon SlimefunAddons}. + * But it also enabled Server Admins to locate lag-inducing areas on the {@link Server}. + * + * @author TheBusyBiscuit + * + * @see TickerTask + * + */ +public class SlimefunProfiler { + + // The threshold at which a Block or Chunk is significant enough to appear in /sf timings + private static final int VISIBILITY_THRESHOLD = 275_000; + + private final ExecutorService executor = Executors.newFixedThreadPool(3); + private final AtomicBoolean running = new AtomicBoolean(false); + private final AtomicInteger queued = new AtomicInteger(0); + + private long totalElapsedTime; + + private final Map timings = new ConcurrentHashMap<>(); + private final Queue requests = new ConcurrentLinkedQueue<>(); + + /** + * This method starts the profiling, data from previous runs will be cleared. + */ + public void start() { + running.set(true); + queued.set(0); + timings.clear(); + } + + /** + * This method starts a new profiler entry. + * + * @return A timestamp, best fed back into {@link #closeEntry(Location, SlimefunItem, long)} + */ + public long newEntry() { + if (!running.get()) { + return 0; + } + + queued.incrementAndGet(); + return System.nanoTime(); + } + + /** + * This method closes a previously started entry. + * Make sure to call {@link #newEntry()} to get the timestamp in advance. + * + * @param l + * The {@link Location} of our {@link Block} + * @param item + * The {@link SlimefunItem} at this {@link Location} + * @param timestamp + * The timestamp marking the start of this entry, you can retrieve it using {@link #newEntry()} + */ + public void closeEntry(Location l, SlimefunItem item, long timestamp) { + if (timestamp == 0) { + return; + } + + long elapsedTime = System.nanoTime() - timestamp; + + executor.execute(() -> { + ProfiledBlock block = new ProfiledBlock(new BlockPosition(l), item); + timings.put(block, elapsedTime); + queued.decrementAndGet(); + }); + } + + /** + * This stops the profiling. + */ + public void stop() { + running.set(false); + + if (SlimefunPlugin.instance == null || !SlimefunPlugin.instance.isEnabled()) { + // Slimefun has been disabled + return; + } + + // Since we got more than one Thread in our pool, blocking this one is completely fine + executor.execute(() -> { + + // Wait for all timing results to come in + while (queued.get() > 0 && !running.get()) { + try { + Thread.sleep(1); + } + catch (InterruptedException e) { + Slimefun.getLogger().log(Level.SEVERE, "A waiting Thread was interrupted", e); + Thread.currentThread().interrupt(); + } + } + + if (running.get()) { + // Looks like the next profiling has already started, abort! + return; + } + + totalElapsedTime = timings.values().stream().mapToLong(Long::longValue).sum(); + + Iterator iterator = requests.iterator(); + + while (iterator.hasNext()) { + sendSummary(iterator.next()); + iterator.remove(); + } + }); + + } + + /** + * This method requests a summary for the given {@link CommandSender}. + * The summary will be sent upon the next available moment in time. + * + * @param sender + * The {@link CommandSender} who shall receive this summary. + */ + public void requestSummary(CommandSender sender) { + requests.add(sender); + } + + private Map getByItem() { + Map map = new HashMap<>(); + + for (Map.Entry entry : timings.entrySet()) { + map.merge(entry.getKey().getId(), entry.getValue(), Long::sum); + } + + return map; + } + + private Map getByChunk() { + Map map = new HashMap<>(); + + for (Map.Entry entry : timings.entrySet()) { + String world = entry.getKey().getPosition().getWorld().getName(); + int x = entry.getKey().getPosition().getChunkX(); + int z = entry.getKey().getPosition().getChunkZ(); + + map.merge(world + " (" + x + ',' + z + ')', entry.getValue(), Long::sum); + } + + return map; + } + + private int getBlocksInChunk(String chunk) { + int blocks = 0; + + for (ProfiledBlock block : timings.keySet()) { + String world = block.getPosition().getWorld().getName(); + int x = block.getPosition().getChunkX(); + int z = block.getPosition().getChunkZ(); + + if (chunk.equals(world + " (" + x + ',' + z + ')')) { + blocks++; + } + } + + return blocks; + } + + private int getBlocks(String id) { + int blocks = 0; + + for (ProfiledBlock block : timings.keySet()) { + if (block.getId().equals(id)) { + blocks++; + } + } + + return blocks; + } + + private void sendSummary(CommandSender sender) { + Map chunks = getByChunk(); + Map machines = getByItem(); + + sender.sendMessage(ChatColors.color("&2== &aSlimefun Lag Profiler &2==")); + sender.sendMessage(ChatColors.color("&6Running: &e&l" + String.valueOf(!SlimefunPlugin.getTickerTask().isHalted()).toUpperCase(Locale.ROOT))); + sender.sendMessage(""); + sender.sendMessage(ChatColors.color("&6Impact: &e" + NumberUtils.getAsMillis(totalElapsedTime))); + sender.sendMessage(ChatColors.color("&6Ticked Chunks: &e" + chunks.size())); + sender.sendMessage(ChatColors.color("&6Ticked Blocks: &e" + timings.size())); + sender.sendMessage(""); + sender.sendMessage(ChatColors.color("&6Ticking Machines:")); + + summarizeTimings(sender, entry -> { + int count = getBlocks(entry.getKey()); + String time = NumberUtils.getAsMillis(entry.getValue()); + String average = NumberUtils.getAsMillis(entry.getValue() / count); + + return entry.getKey() + " - " + count + "x (" + time + ", " + average + " avg/block)"; + }, machines.entrySet().stream()); + + sender.sendMessage(""); + sender.sendMessage(ChatColors.color("&6Ticking Chunks:")); + + summarizeTimings(sender, entry -> { + int count = getBlocksInChunk(entry.getKey()); + String time = NumberUtils.getAsMillis(entry.getValue()); + + return entry.getKey() + " - " + count + "x (" + time + ")"; + }, chunks.entrySet().stream()); + } + + private void summarizeTimings(CommandSender sender, Function, String> formatter, Stream> stream) { + List> results = stream.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()); + + if (sender instanceof Player) { + TextComponent component = new TextComponent(" Hover for more details..."); + component.setColor(net.md_5.bungee.api.ChatColor.GRAY); + component.setItalic(true); + StringBuilder builder = new StringBuilder(); + int hidden = 0; + + for (Map.Entry entry : results) { + if (entry.getValue() > VISIBILITY_THRESHOLD) { + builder.append("\n&e").append(formatter.apply(entry)); + } + else { + hidden++; + } + } + + builder.append("\n\n&c+ &6").append(hidden).append(" more"); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColors.color(builder.toString())))); + sender.spigot().sendMessage(component); + } + else { + int hidden = 0; + + for (Map.Entry entry : results) { + if (entry.getValue() > VISIBILITY_THRESHOLD) { + sender.sendMessage(" " + ChatColor.stripColor(formatter.apply(entry))); + } + else { + hidden++; + } + } + + sender.sendMessage("+ " + hidden + " more"); + } + } + + public String getTime() { + return NumberUtils.getAsMillis(totalElapsedTime); + } + + public String getTime(Block b) { + Validate.notNull("Cannot get timings for a null Block"); + + long time = timings.getOrDefault(new ProfiledBlock(b), 0L); + return NumberUtils.getAsMillis(time); + } + + public String getTime(Chunk chunk) { + Validate.notNull("Cannot get timings for a null Chunk"); + + long time = getByChunk().getOrDefault(chunk.getWorld().getName() + " (" + chunk.getX() + ',' + chunk.getZ() + ')', 0L); + return NumberUtils.getAsMillis(time); + } + + public String getTime(SlimefunItem item) { + Validate.notNull("Cannot get timings for a null SlimefunItem"); + + long time = getByItem().getOrDefault(item.getID(), 0L); + return NumberUtils.getAsMillis(time); + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/package-info.java new file mode 100644 index 000000000..62b32be85 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/package-info.java @@ -0,0 +1,9 @@ +/** + * This package holds classes related to the + * {@link io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler}. + * The {@link io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler} is used to determine + * {@link org.bukkit.block.Block Blocks}, {@link org.bukkit.Chunk Chunks} or + * {@link me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem SlimefunItems} that cause lag or performance + * drops. + */ +package io.github.thebusybiscuit.slimefun4.core.services.profiler; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java index f95ffbb70..16f7905ee 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java @@ -43,6 +43,7 @@ import io.github.thebusybiscuit.slimefun4.core.services.UpdaterService; import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService; import io.github.thebusybiscuit.slimefun4.core.services.metrics.MetricsService; import io.github.thebusybiscuit.slimefun4.core.services.plugins.ThirdPartyPluginService; +import io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler; import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.BasicCircuitBoard; @@ -126,6 +127,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { private final PerWorldSettingsService worldSettingsService = new PerWorldSettingsService(this); private final ThirdPartyPluginService thirdPartySupportService = new ThirdPartyPluginService(this); private final MinecraftRecipeService recipeService = new MinecraftRecipeService(this); + private final SlimefunProfiler profiler = new SlimefunProfiler(); private LocalizationService local; private GPSNetwork gpsNetwork; @@ -612,6 +614,10 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { return instance.command; } + public static SlimefunProfiler getProfiler() { + return instance.profiler; + } + /** * This returns the currently installed version of Minecraft. * diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java index 29ff47e5b..66b8bc768 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java @@ -41,7 +41,7 @@ public class CargoManager extends SlimefunItem { @Override public boolean isSynchronized() { - return false; + return true; } }, new BlockUseHandler() { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java index 2345d307e..d2ff3e424 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java @@ -1,6 +1,5 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Skull; @@ -15,12 +14,11 @@ import org.bukkit.inventory.EquipmentSlot; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.cscorelib2.skull.SkullBlock; +import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNet; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; -import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.BlockStorage; @@ -28,14 +26,14 @@ import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; public class DebugFishListener implements Listener { - private final String enabledTooltip; - private final String disabledTooltip; + private final String greenCheckmark; + private final String redCross; public DebugFishListener(SlimefunPlugin plugin) { plugin.getServer().getPluginManager().registerEvents(this, plugin); - enabledTooltip = "&2\u2714"; - disabledTooltip = "&4\u2718"; + greenCheckmark = "&2\u2714"; + redCross = "&4\u2718"; } @EventHandler @@ -81,7 +79,7 @@ public class DebugFishListener implements Listener { p.sendMessage(ChatColors.color("&dPlugin: " + "&e" + item.getAddon().getName())); if (b.getState() instanceof Skull) { - p.sendMessage(ChatColors.color("&dSkull: " + enabledTooltip)); + p.sendMessage(ChatColors.color("&dSkull: " + greenCheckmark)); // Check if the skull is a wall skull, and if so use Directional instead of Rotatable. if (b.getType() == Material.PLAYER_WALL_HEAD) { @@ -93,40 +91,40 @@ public class DebugFishListener implements Listener { } if (BlockStorage.getStorage(b.getWorld()).hasInventory(b.getLocation())) { - p.sendMessage(ChatColors.color("&dInventory: " + enabledTooltip)); + p.sendMessage(ChatColors.color("&dInventory: " + greenCheckmark)); } else { - p.sendMessage(ChatColors.color("&dInventory: " + disabledTooltip)); + p.sendMessage(ChatColors.color("&dInventory: " + redCross)); } - TickerTask ticker = SlimefunPlugin.getTickerTask(); - if (item.isTicking()) { - p.sendMessage(ChatColors.color("&dTicker: " + enabledTooltip)); - p.sendMessage(ChatColors.color(" &dAsync: &e" + (BlockStorage.check(b).getBlockTicker().isSynchronized() ? disabledTooltip : enabledTooltip))); - p.sendMessage(ChatColors.color(" &dTimings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b)))); - p.sendMessage(ChatColors.color(" &dTotal Timings: &e" + NumberUtils.getAsMillis(ticker.getTimings(BlockStorage.checkID(b))))); - p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b.getChunk())))); + p.sendMessage(ChatColors.color("&dTicker: " + greenCheckmark)); + p.sendMessage(ChatColors.color(" &dAsync: &e" + (item.getBlockTicker().isSynchronized() ? redCross : greenCheckmark))); + p.sendMessage(ChatColors.color(" &dTimings: &e" + SlimefunPlugin.getProfiler().getTime(b))); + p.sendMessage(ChatColors.color(" &dTotal Timings: &e" + SlimefunPlugin.getProfiler().getTime(item))); + p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + SlimefunPlugin.getProfiler().getTime(b.getChunk()))); } else if (item.getEnergyTicker() != null) { p.sendMessage(ChatColors.color("&dTicking: " + "&3Indirect")); - p.sendMessage(ChatColors.color(" &dTimings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b)))); - p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b.getChunk())))); + p.sendMessage(ChatColors.color(" &dTimings: &e" + SlimefunPlugin.getProfiler().getTime(b))); + p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + SlimefunPlugin.getProfiler().getTime(b.getChunk()))); } else { - p.sendMessage(ChatColors.color("&dTicker: " + disabledTooltip)); - p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&dTicking: " + disabledTooltip)); + p.sendMessage(ChatColors.color("&dTicker: " + redCross)); + p.sendMessage(ChatColors.color("&dTicking: " + redCross)); } if (ChargableBlock.isChargable(b)) { - p.sendMessage(ChatColors.color("&dChargeable: " + enabledTooltip)); + p.sendMessage(ChatColors.color("&dChargeable: " + greenCheckmark)); p.sendMessage(ChatColors.color(" &dEnergy: &e" + ChargableBlock.getCharge(b) + " / " + ChargableBlock.getMaxCharge(b))); } else { - p.sendMessage(ChatColors.color("&dChargeable: " + disabledTooltip)); + p.sendMessage(ChatColors.color("&dChargeable: " + redCross)); } - p.sendMessage(ChatColors.color(" &dEnergyNet Type: &e" + EnergyNet.getComponent(b.getLocation()))); + if (item instanceof EnergyNetComponent) { + p.sendMessage(ChatColors.color(" &dEnergyNet Type: &e" + EnergyNet.getComponent(b.getLocation()))); + } p.sendMessage(ChatColors.color("&6" + BlockStorage.getBlockInfoAsJson(b))); p.sendMessage(" "); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java index 01c7a9e04..518845fbb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java @@ -1,70 +1,38 @@ package io.github.thebusybiscuit.slimefun4.implementation.tasks; -import java.util.AbstractMap; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.List; -import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.function.Function; import java.util.logging.Level; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.slimefun4.api.ErrorReport; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; +import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; public class TickerTask implements Runnable { - private static final int VISIBILITY_THRESHOLD = 225_000; - private final Set tickers = new HashSet<>(); // These are "Queues" of blocks that need to be removed or moved - private final ConcurrentMap movingQueue = new ConcurrentHashMap<>(); - private final ConcurrentMap deletionQueue = new ConcurrentHashMap<>(); - - private final ConcurrentMap buggedBlocks = new ConcurrentHashMap<>(); - - private final ConcurrentMap blockTimings = new ConcurrentHashMap<>(); - private final ConcurrentMap machineCount = new ConcurrentHashMap<>(); - private final ConcurrentMap machineTimings = new ConcurrentHashMap<>(); - - private final ConcurrentMap chunkTimings = new ConcurrentHashMap<>(); - private final ConcurrentMap chunkItemCount = new ConcurrentHashMap<>(); - private final Set skippedChunks = new HashSet<>(); + private final Map movingQueue = new ConcurrentHashMap<>(); + private final Map deletionQueue = new ConcurrentHashMap<>(); + private final Map buggedBlocks = new ConcurrentHashMap<>(); private boolean halted = false; - - private int skippedBlocks = 0; - private int chunks = 0; - private int blocks = 0; - private long time = 0; - private boolean running = false; public void abortTick() { @@ -78,18 +46,7 @@ public class TickerTask implements Runnable { } running = true; - long timestamp = System.nanoTime(); - - skippedBlocks = 0; - chunks = 0; - blocks = 0; - chunkItemCount.clear(); - machineCount.clear(); - time = 0; - chunkTimings.clear(); - skippedChunks.clear(); - machineTimings.clear(); - blockTimings.clear(); + SlimefunPlugin.getProfiler().start(); Map bugs = new HashMap<>(buggedBlocks); buggedBlocks.clear(); @@ -103,24 +60,23 @@ public class TickerTask implements Runnable { if (!halted) { for (String chunk : BlockStorage.getTickingChunks()) { - long chunkTimestamp = System.nanoTime(); - chunks++; + try { + Set locations = BlockStorage.getTickingLocations(chunk); + String[] components = PatternUtils.SEMICOLON.split(chunk); - Set locations = BlockStorage.getTickingLocations(chunk); + World world = Bukkit.getWorld(components[0]); + int x = Integer.parseInt(components[components.length - 2]); + int z = Integer.parseInt(components[components.length - 1]); - for (Location l : locations) { - if (l.getWorld().isChunkLoaded(l.getBlockX() >> 4, l.getBlockZ() >> 4)) { - tick(l, chunk, bugs); - } - else { - skippedBlocks += locations.size(); - skippedChunks.add(chunk); - chunks--; - break; + if (world != null && world.isChunkLoaded(x, z)) { + for (Location l : locations) { + tick(l, bugs); + } } } - - chunkTimings.put(chunk, System.nanoTime() - chunkTimestamp); + catch (ArrayIndexOutOfBoundsException | NumberFormatException x) { + Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Exception has occured while trying to parse Chunk: " + chunk); + } } } @@ -136,49 +92,27 @@ public class TickerTask implements Runnable { iterator.remove(); } - time = System.nanoTime() - timestamp; running = false; + SlimefunPlugin.getProfiler().stop(); } - private void tick(Location l, String tickedChunk, Map bugs) { - Block b = l.getBlock(); - SlimefunItem item = BlockStorage.check(l); + private void tick(Location l, Map bugs) { + Config data = BlockStorage.getLocationInfo(l); + SlimefunItem item = SlimefunItem.getByID(data.getString("id")); if (item != null && item.getBlockTicker() != null) { - blocks++; - try { + long timestamp = SlimefunPlugin.getProfiler().newEntry(); + Block b = l.getBlock(); item.getBlockTicker().update(); if (item.getBlockTicker().isSynchronized()) { - Slimefun.runSync(() -> { - try { - long timestamp = System.nanoTime(); - item.getBlockTicker().tick(b, item, BlockStorage.getLocationInfo(l)); - - long machinetime = NumberUtils.getLong(machineTimings.get(item.getID()), 0); - int chunk = NumberUtils.getInt(chunkItemCount.get(tickedChunk), 0); - int machine = NumberUtils.getInt(machineCount.get(item.getID()), 0); - - machineTimings.put(item.getID(), machinetime + (System.nanoTime() - timestamp)); - chunkItemCount.put(tickedChunk, chunk + 1); - machineCount.put(item.getID(), machine + 1); - blockTimings.put(l, System.nanoTime() - timestamp); - } - catch (Exception | LinkageError x) { - int errors = bugs.getOrDefault(l, 0); - reportErrors(l, item, x, errors); - } - }); + // We are ignoring the timestamp from above because synchronized actions + // are always ran with a 50ms delay (1 game tick) + Slimefun.runSync(() -> tickBlock(bugs, l, b, item, data, System.nanoTime())); } else { - long timestamp = System.nanoTime(); - item.getBlockTicker().tick(b, item, BlockStorage.getLocationInfo(l)); - - machineTimings.merge(item.getID(), (System.nanoTime() - timestamp), Long::sum); - chunkItemCount.merge(tickedChunk, 1, Integer::sum); - machineCount.merge(item.getID(), 1, Integer::sum); - blockTimings.put(l, System.nanoTime() - timestamp); + tickBlock(bugs, l, b, item, data, timestamp); } tickers.add(item.getBlockTicker()); @@ -188,8 +122,18 @@ public class TickerTask implements Runnable { reportErrors(l, item, x, errors); } } - else { - skippedBlocks++; + } + + private void tickBlock(Map bugs, Location l, Block b, SlimefunItem item, Config data, long timestamp) { + try { + item.getBlockTicker().tick(b, item, data); + } + catch (Exception | LinkageError x) { + int errors = bugs.getOrDefault(l, 0); + reportErrors(l, item, x, errors); + } + finally { + SlimefunPlugin.getProfiler().closeEntry(l, item, timestamp); } } @@ -215,101 +159,6 @@ public class TickerTask implements Runnable { } } - public String getTime() { - return NumberUtils.getAsMillis(time); - } - - public void info(CommandSender sender) { - sender.sendMessage(ChatColors.color("&2== &aSlimefun Diagnostic Tool &2==")); - sender.sendMessage(ChatColors.color("&6Halted: &e&l" + String.valueOf(halted).toUpperCase(Locale.ROOT))); - sender.sendMessage(""); - sender.sendMessage(ChatColors.color("&6Impact: &e" + NumberUtils.getAsMillis(time))); - sender.sendMessage(ChatColors.color("&6Ticked Chunks: &e" + chunks)); - sender.sendMessage(ChatColors.color("&6Ticked Machines: &e" + blocks)); - sender.sendMessage(ChatColors.color("&6Skipped Machines: &e" + skippedBlocks)); - sender.sendMessage(""); - sender.sendMessage(ChatColors.color("&6Ticking Machines:")); - - summarizeTimings(sender, entry -> { - int count = machineCount.get(entry.getKey()); - String timings = NumberUtils.getAsMillis(entry.getValue()); - String average = NumberUtils.getAsMillis(entry.getValue() / count); - - return entry.getKey() + " - " + count + "x (" + timings + ", " + average + " avg/machine)"; - }, machineCount.keySet().stream().map(key -> new AbstractMap.SimpleEntry<>(key, machineTimings.getOrDefault(key, 0L)))); - - sender.sendMessage(""); - sender.sendMessage(ChatColors.color("&6Ticking Chunks:")); - - summarizeTimings(sender, entry -> { - int count = chunkItemCount.getOrDefault(entry.getKey(), 0); - String timings = NumberUtils.getAsMillis(entry.getValue()); - - return formatChunk(entry.getKey()) + " - " + count + "x (" + timings + ")"; - }, chunkTimings.entrySet().stream().filter(entry -> !skippedChunks.contains(entry.getKey()))); - } - - private void summarizeTimings(CommandSender sender, Function, String> formatter, Stream> stream) { - List> timings = stream.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()); - - if (sender instanceof Player) { - TextComponent component = new TextComponent(" Hover for more Info"); - component.setColor(net.md_5.bungee.api.ChatColor.GRAY); - component.setItalic(true); - StringBuilder builder = new StringBuilder(); - int hidden = 0; - - for (Map.Entry entry : timings) { - if (entry.getValue() > VISIBILITY_THRESHOLD) { - builder.append("\n&c").append(formatter.apply(entry)); - } - else { - hidden++; - } - } - - builder.append("\n\n&c+ &4").append(hidden).append(" Hidden"); - component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColors.color(builder.toString())))); - sender.spigot().sendMessage(component); - } - else { - int hidden = 0; - - for (Map.Entry entry : timings) { - if (entry.getValue() > VISIBILITY_THRESHOLD) { - sender.sendMessage(" " + ChatColor.stripColor(formatter.apply(entry))); - } - else { - hidden++; - } - } - - sender.sendMessage("+ " + hidden + " Hidden"); - } - } - - private String formatChunk(String chunk) { - String[] components = PatternUtils.SEMICOLON.split(chunk); - return components[0] + " [" + components[2] + ',' + components[3] + ']'; - } - - public long getTimings(Block b) { - return blockTimings.getOrDefault(b.getLocation(), 0L); - } - - public long getTimings(String item) { - return machineTimings.getOrDefault(item, 0L); - } - - public long getTimings(Chunk c) { - String id = c.getWorld().getName() + ';' + c.getX() + ';' + c.getZ(); - return chunkTimings.getOrDefault(id, 0L); - } - - public void addBlockTimings(Location l, long time) { - blockTimings.put(l, time); - } - public boolean isHalted() { return halted; } @@ -320,7 +169,7 @@ public class TickerTask implements Runnable { @Override public String toString() { - return "TickerTask {\n" + " HALTED = " + halted + "\n" + " tickers = " + tickers + "\n" + " move = " + movingQueue + "\n" + " delete = " + deletionQueue + "\n" + " chunks = " + chunkItemCount + "\n" + " machines = " + machineCount + "\n" + " machinetime = " + machineTimings + "\n" + " chunktime = " + chunkTimings + "\n" + " skipped = " + skippedChunks + "\n" + "}"; + return "TickerTask {\n" + " HALTED = " + halted + "\n" + " tickers = " + tickers + "\n" + " move = " + movingQueue + "\n" + " delete = " + deletionQueue + "}"; } public void queueMove(Location from, Location to) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java index 1c5a37cb3..2619f02ec 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java @@ -69,6 +69,10 @@ public final class NumberUtils { } public static String getAsMillis(long nanoseconds) { + if (nanoseconds == 0) { + return "0ms"; + } + String number = DECIMAL_FORMAT.format(nanoseconds / 1000000.0); String[] parts = PatternUtils.NUMBER_SEPERATOR.split(number); @@ -76,7 +80,7 @@ public final class NumberUtils { return parts[0]; } else { - return parts[0] + ',' + ChatColor.GRAY + parts[1] + "ms"; + return parts[0] + ',' + parts[1] + "ms"; } } From a4197fe5dde16d257098ee9fff8af8b7deefa235 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Tue, 30 Jun 2020 21:31:55 +0200 Subject: [PATCH 17/36] A couple of performance and memory optimizations --- .../items/electric/reactors/Reactor.java | 2 +- .../abstractItems/AGenerator.java | 2 +- .../Slimefun/api/BlockStorage.java | 19 ++++++++--- .../Slimefun/api/EmptyBlockData.java | 29 ++++++++++++++++ .../Slimefun/api/energy/ChargableBlock.java | 33 +++++++++---------- 5 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 src/main/java/me/mrCookieSlime/Slimefun/api/EmptyBlockData.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java index ec0760c28..d04bf339a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java @@ -278,7 +278,7 @@ public abstract class Reactor extends AbstractEnergyProvider { if (timeleft > 0) { int produced = getEnergyProduction(); - int space = ChargableBlock.getMaxCharge(l) - charge; + int space = getCapacity() - charge; if (space >= produced || !ReactorMode.GENERATOR.toString().equals(BlockStorage.getLocationInfo(l, MODE))) { progress.put(l, timeleft - 1); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java index 7add05178..ad84a1ac9 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java @@ -153,7 +153,7 @@ public abstract class AGenerator extends AbstractEnergyProvider { ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(l).getTicks(), getProgressBar()); if (chargeable) { - if (ChargableBlock.getMaxCharge(l) - charge >= getEnergyProduction()) { + if (getCapacity() - charge >= getEnergyProduction()) { ChargableBlock.addCharge(l, getEnergyProduction()); progress.put(l, timeleft - 1); return (double) (charge + getEnergyProduction()); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java index c5413bdbc..8f1929daa 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java @@ -47,6 +47,8 @@ public class BlockStorage { private static final String PATH_CHUNKS = "data-storage/Slimefun/stored-chunks/"; private static final String PATH_INVENTORIES = "data-storage/Slimefun/stored-inventories/"; + private static final EmptyBlockData emptyBlockData = new EmptyBlockData(); + private final World world; private final Map storage = new ConcurrentHashMap<>(); private final Map inventories = new ConcurrentHashMap<>(); @@ -362,7 +364,10 @@ public class BlockStorage { public static void store(Block block, ItemStack item) { SlimefunItem sfitem = SlimefunItem.getByItem(item); - if (sfitem != null) addBlockInfo(block, "id", sfitem.getID(), true); + + if (sfitem != null) { + addBlockInfo(block, "id", sfitem.getID(), true); + } } public static void store(Block block, String item) { @@ -393,7 +398,7 @@ public class BlockStorage { public static Config getLocationInfo(Location l) { BlockStorage storage = getStorage(l.getWorld()); Config cfg = storage.storage.get(l); - return cfg == null ? new BlockInfoConfig() : cfg; + return cfg == null ? emptyBlockData : cfg; } private static Map parseJSON(String json) { @@ -514,7 +519,11 @@ public class BlockStorage { public static void setBlockInfo(Location l, String json, boolean updateTicker) { Config blockInfo = json == null ? new BlockInfoConfig() : parseBlockInfo(l, json); - if (blockInfo == null) return; + + if (blockInfo == null) { + return; + } + setBlockInfo(l, blockInfo, updateTicker); } @@ -803,7 +812,7 @@ public class BlockStorage { public static Config getChunkInfo(World world, int x, int z) { try { if (!isWorldRegistered(world.getName())) { - return new BlockInfoConfig(); + return emptyBlockData; } String key = serializeChunk(world, x, z); @@ -818,7 +827,7 @@ public class BlockStorage { } catch (Exception e) { Slimefun.getLogger().log(Level.SEVERE, e, () -> "Failed to parse ChunkInfo for Slimefun " + SlimefunPlugin.getVersion()); - return new BlockInfoConfig(); + return emptyBlockData; } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/EmptyBlockData.java b/src/main/java/me/mrCookieSlime/Slimefun/api/EmptyBlockData.java new file mode 100644 index 000000000..c1cae795b --- /dev/null +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/EmptyBlockData.java @@ -0,0 +1,29 @@ +package me.mrCookieSlime.Slimefun.api; + +/** + * This package-private class is supposed to be used as a singleton fallback in places where a + * {@link NullPointerException} should be avoided, like {@link BlockStorage#getLocationInfo(org.bukkit.Location)}. + * + * This object is a read-only variant of {@link BlockInfoConfig} and only serves the purpose of + * performance and memory optimization. + * + * @author TheBusyBiscuit + * + */ +class EmptyBlockData extends BlockInfoConfig { + + EmptyBlockData() { + super(null); + } + + @Override + protected void store(String path, Object value) { + throw new UnsupportedOperationException("Cannot store values (" + path + ':' + value + " on a read-only data object!"); + } + + @Override + public String getString(String path) { + return null; + } + +} diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java b/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java index f3022cedc..ac49e096a 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java @@ -24,7 +24,8 @@ public final class ChargableBlock { return false; } - return SlimefunPlugin.getRegistry().getEnergyCapacities().containsKey(BlockStorage.checkID(l)); + String id = BlockStorage.checkID(l); + return SlimefunPlugin.getRegistry().getEnergyCapacities().containsKey(id); } public static int getCharge(Block b) { @@ -53,7 +54,10 @@ public final class ChargableBlock { } else { int capacity = getMaxCharge(l); - if (charge > capacity) charge = capacity; + + if (charge > capacity) { + charge = capacity; + } } if (charge != getCharge(l)) { @@ -76,8 +80,9 @@ public final class ChargableBlock { } public static int addCharge(Location l, int charge) { + int capacity = getMaxCharge(l); int energy = getCharge(l); - int space = getMaxCharge(l) - energy; + int space = capacity - energy; int rest = charge; if (space > 0 && charge > 0) { @@ -87,7 +92,7 @@ public final class ChargableBlock { } else { rest = charge - space; - setCharge(l, getMaxCharge(l)); + setCharge(l, capacity); } if (SlimefunPlugin.getRegistry().getEnergyCapacitors().contains(BlockStorage.checkID(l))) { @@ -112,13 +117,13 @@ public final class ChargableBlock { int capacity = getMaxCharge(b); if (b.getType() == Material.PLAYER_HEAD || b.getType() == Material.PLAYER_WALL_HEAD) { - if (charge < (int) (capacity * 0.25D)) { + if (charge < (int) (capacity * 0.25)) { SkullBlock.setFromHash(b, HeadTexture.CAPACITOR_25.getTexture()); } - else if (charge < (int) (capacity * 0.5D)) { + else if (charge < (int) (capacity * 0.5)) { SkullBlock.setFromHash(b, HeadTexture.CAPACITOR_50.getTexture()); } - else if (charge < (int) (capacity * 0.75D)) { + else if (charge < (int) (capacity * 0.75)) { SkullBlock.setFromHash(b, HeadTexture.CAPACITOR_75.getTexture()); } else { @@ -134,22 +139,14 @@ public final class ChargableBlock { public static int getMaxCharge(Location l) { Config cfg = BlockStorage.getLocationInfo(l); + String id = cfg.getString("id"); - if (!cfg.contains("id")) { + if (id == null) { BlockStorage.clearBlockInfo(l); return 0; } - String str = cfg.getString("energy-capacity"); - - if (str != null) { - return Integer.parseInt(str); - } - else { - int capacity = SlimefunPlugin.getRegistry().getEnergyCapacities().get(cfg.getString("id")); - BlockStorage.addBlockInfo(l, "energy-capacity", String.valueOf(capacity), false); - return capacity; - } + return SlimefunPlugin.getRegistry().getEnergyCapacities().getOrDefault(id, 0); } } From 9100dfe6f3c7cc7e11c54971854bdfcd8310ea24 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Tue, 30 Jun 2020 23:38:21 +0300 Subject: [PATCH 18/36] Minor refactoring and more documentation. --- .../items/tools/ExplosivePickaxe.java | 1 + .../items/tools/ExplosiveShovel.java | 9 ++------- .../items/tools/ExplosiveTool.java | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosivePickaxe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosivePickaxe.java index 27a01f047..3ccd13f4a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosivePickaxe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosivePickaxe.java @@ -13,6 +13,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; * @author TheBusyBiscuit * * @see ExplosiveShovel + * @see ExplosiveTool * */ public class ExplosivePickaxe extends ExplosiveTool { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java index a0ca6b56e..3d65cbceb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java @@ -22,6 +22,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; * @author Linox * * @see ExplosivePickaxe + * @see ExplosiveTool * */ public class ExplosiveShovel extends ExplosiveTool { @@ -36,14 +37,8 @@ public class ExplosiveShovel extends ExplosiveTool { SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); + b.breakNaturally(item); - for (ItemStack drop : b.getDrops(getItem())) { - if (drop != null) { - b.getWorld().dropItemNaturally(b.getLocation(), drop); - } - } - - b.setType(Material.AIR); damageItem(p, item); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java index 54ac67e53..5586d3d11 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java @@ -53,23 +53,25 @@ class ExplosiveTool extends SimpleSlimefunItem implements Not @Override public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List drops) { if (isItem(item)) { - if (Slimefun.hasUnlocked(e.getPlayer(), ExplosiveTool.this, true)) { - e.getBlock().getWorld().createExplosion(e.getBlock().getLocation(), 0.0F); - e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.2F, 1F); + Player p = e.getPlayer(); + if (Slimefun.hasUnlocked(p, ExplosiveTool.this, true)) { + Block b = e.getBlock(); - List blocks = findBlocks(e.getBlock()); + b.getWorld().createExplosion(b.getLocation(), 0.0F); + b.getWorld().playSound(b.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.2F, 1F); + List blocks = findBlocks(b); if (callExplosionEvent.getValue().booleanValue()) { - BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(e.getBlock(), blocks, 0); + BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(b, blocks, 0); Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent); if (!blockExplodeEvent.isCancelled()) { - blockExplodeEvent.blockList().forEach(b -> breakBlock(e.getPlayer(), item, b, fortune, drops)); + blockExplodeEvent.blockList().forEach(block -> breakBlock(p, item, block, fortune, drops)); } } else { - for (Block b : blocks) { - breakBlock(e.getPlayer(), item, b, fortune, drops); + for (Block block : blocks) { + breakBlock(p, item, block, fortune, drops); } } } From 7bf31d600e4bc5866212fea14da472444d5cab27 Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Wed, 1 Jul 2020 10:31:06 +0300 Subject: [PATCH 19/36] Did the requested change. --- .../slimefun4/implementation/items/tools/ExplosiveTool.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java index 5586d3d11..770bcfe17 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java @@ -66,7 +66,9 @@ class ExplosiveTool extends SimpleSlimefunItem implements Not Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent); if (!blockExplodeEvent.isCancelled()) { - blockExplodeEvent.blockList().forEach(block -> breakBlock(p, item, block, fortune, drops)); + for (Block block : blockExplodeEvent.blockList()) { + breakBlock(p, item, block, fortune, drops); + } } } else { From 0e9c1a6ccfdbb06133bfad93f8ea87ef9f0116ac Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Wed, 1 Jul 2020 10:33:25 +0300 Subject: [PATCH 20/36] Removed a redundant import. --- .../slimefun4/implementation/items/tools/ExplosiveShovel.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java index 3d65cbceb..8b83819a5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java @@ -3,7 +3,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools; import java.util.List; import org.bukkit.Effect; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; From 1016b5fc76d30bf0733f7fb09c0ba6925825dce8 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Wed, 1 Jul 2020 18:20:34 +0200 Subject: [PATCH 21/36] Added better summaries, ratings + more performance improvements --- CHANGELOG.md | 2 +- .../core/networks/cargo/CargoNet.java | 93 ++++++----- .../services/profiler/PerformanceRating.java | 46 +++++ .../services/profiler/PerformanceSummary.java | 157 ++++++++++++++++++ .../services/profiler/SlimefunProfiler.java | 110 +++--------- .../items/blocks/EnhancedFurnace.java | 11 +- .../items/cargo/CargoManager.java | 2 +- .../implementation/tasks/TickerTask.java | 48 +++--- .../slimefun4/utils/ChestMenuUtils.java | 19 +-- .../slimefun4/utils/NumberUtils.java | 6 +- 10 files changed, 319 insertions(+), 175 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 146e6b4d7..8008e0d2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,10 +52,10 @@ * Crafting Tin cans now produces 8 items instead of 4 * Multi Tool lore now says "Crouch" instead of "Hold Shift" * items which cannot be distributed by a Cargo Net will be dropped on the ground now instead of getting deleted -* Small performance improvements to the Cargo Net * Slimefun no longer supports CraftBukkit * Item Energy is now also stored persistently via NBT * General performance improvements for ticking blocks +* Performance improvements to the Cargo Net #### Fixes * Fixed #2005 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java index 5d5c11918..c98c6e9f7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java @@ -19,6 +19,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.network.Network; import io.github.thebusybiscuit.slimefun4.api.network.NetworkComponent; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; @@ -156,28 +157,59 @@ public class CargoNet extends ChestTerminalNetwork { } else { SimpleHologram.update(b, "&7Status: &a&lONLINE"); - Map> output = mapOutputNodes(); - // Chest Terminal Stuff - Set destinations = new HashSet<>(); - List output16 = output.get(16); - - if (output16 != null) { - destinations.addAll(output16); + // Skip ticking if the threshold is not reached. The delay is not same as minecraft tick, + // but it's based on 'custom-ticker-delay' config. + if (tickDelayThreshold < TICK_DELAY) { + tickDelayThreshold++; + return; } - run(b, destinations, output); + // Reset the internal threshold, so we can start skipping again + tickDelayThreshold = 0; + + // Chest Terminal Stuff + Set chestTerminalInputs = new HashSet<>(); + Set chestTerminalOutputs = new HashSet<>(); + + Map inputs = mapInputNodes(chestTerminalInputs); + Map> outputs = mapOutputNodes(chestTerminalOutputs); + + SlimefunPlugin.getProfiler().newEntry(); + Slimefun.runSync(() -> run(b, inputs, outputs, chestTerminalInputs, chestTerminalOutputs)); } } - private Map> mapOutputNodes() { + private Map mapInputNodes(Set chestTerminalNodes) { + Map inputs = new HashMap<>(); + + for (Location node : inputNodes) { + int frequency = getFrequency(node); + + if (frequency == 16) { + chestTerminalNodes.add(node); + } + else if (frequency >= 0 && frequency < 16) { + inputs.put(node, frequency); + } + } + + return inputs; + } + + private Map> mapOutputNodes(Set chestTerminalOutputs) { Map> output = new HashMap<>(); List list = new LinkedList<>(); int lastFrequency = -1; - for (Location outputNode : outputNodes) { - int frequency = getFrequency(outputNode); + for (Location node : outputNodes) { + int frequency = getFrequency(node); + + if (frequency == 16) { + chestTerminalOutputs.add(node); + continue; + } if (frequency != lastFrequency && lastFrequency != -1) { output.merge(lastFrequency, list, (prev, next) -> { @@ -188,7 +220,7 @@ public class CargoNet extends ChestTerminalNetwork { list = new LinkedList<>(); } - list.add(outputNode); + list.add(node); lastFrequency = frequency; } @@ -202,38 +234,16 @@ public class CargoNet extends ChestTerminalNetwork { return output; } - private void run(Block b, Set destinations, Map> output) { + private void run(Block b, Map inputs, Map> outputs, Set chestTerminalInputs, Set chestTerminalOutputs) { + long timestamp = System.nanoTime(); + if (BlockStorage.getLocationInfo(b.getLocation(), "visualizer") == null) { display(); } - // Skip ticking if the threshold is not reached. The delay is not same as minecraft tick, - // but it's based on 'custom-ticker-delay' config. - if (tickDelayThreshold < TICK_DELAY) { - tickDelayThreshold++; - return; - } - - // Reset the internal threshold, so we can start skipping again - tickDelayThreshold = 0; - - Map inputs = new HashMap<>(); - Set providers = new HashSet<>(); - - for (Location node : inputNodes) { - int frequency = getFrequency(node); - - if (frequency == 16) { - providers.add(node); - } - else if (frequency >= 0 && frequency < 16) { - inputs.put(node, frequency); - } - } - // Chest Terminal Code if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) { - handleItemRequests(providers, destinations); + handleItemRequests(chestTerminalInputs, chestTerminalOutputs); } // All operations happen here: Everything gets iterated from the Input Nodes. @@ -243,14 +253,17 @@ public class CargoNet extends ChestTerminalNetwork { Optional attachedBlock = getAttachedBlock(input.getBlock()); if (attachedBlock.isPresent()) { - routeItems(input, attachedBlock.get(), entry.getValue(), output); + routeItems(input, attachedBlock.get(), entry.getValue(), outputs); } } // Chest Terminal Code if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) { - updateTerminals(providers); + updateTerminals(chestTerminalInputs); } + + // Submit a timings report + SlimefunPlugin.getProfiler().closeEntry(regulator, SlimefunItems.CARGO_MANAGER.getItem(), timestamp); } private void routeItems(Location inputNode, Block inputTarget, int frequency, Map> outputNodes) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java new file mode 100644 index 000000000..0ebfbc0fe --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java @@ -0,0 +1,46 @@ +package io.github.thebusybiscuit.slimefun4.core.services.profiler; + +import java.util.function.Predicate; + +import org.bukkit.ChatColor; + +/** + * This enum is used to quantify Slimefun's performance impact. This way we can assign a + * "grade" to each timings report and also use this for metrics collection. + * + * @author TheBusyBiscuit + * + * @see SlimefunProfiler + * + */ +public enum PerformanceRating implements Predicate { + + // Thresholds might change in the future! + + UNKNOWN(ChatColor.WHITE, -1), + + GOOD(ChatColor.DARK_GREEN, 10), + FINE(ChatColor.DARK_GREEN, 20), + OKAY(ChatColor.GREEN, 30), + MODERATE(ChatColor.YELLOW, 55), + SEVERE(ChatColor.RED, 85), + HURTFUL(ChatColor.DARK_RED, Float.MAX_VALUE); + + private final ChatColor color; + private final float threshold; + + PerformanceRating(ChatColor color, float threshold) { + this.color = color; + this.threshold = threshold; + } + + @Override + public boolean test(Float value) { + return value <= threshold; + } + + public ChatColor getColor() { + return color; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java new file mode 100644 index 000000000..b87d04973 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java @@ -0,0 +1,157 @@ +package io.github.thebusybiscuit.slimefun4.core.services.profiler; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; +import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; +import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; + +class PerformanceSummary { + + // The threshold at which a Block or Chunk is significant enough to appear in /sf timings + private static final int VISIBILITY_THRESHOLD = 275_000; + + // A minecraft server tick is 50ms and Slimefun ticks are stretched across + // two ticks (sync and async blocks), so we use 100ms as a reference here + static final int MAX_TICK_DURATION = 100; + + private final SlimefunProfiler profiler; + private final PerformanceRating rating; + private final long totalElapsedTime; + private final int totalTickedBlocks; + + private final Map chunks; + private final Map items; + + PerformanceSummary(SlimefunProfiler profiler, long totalElapsedTime, int totalTickedBlocks) { + this.profiler = profiler; + this.rating = profiler.getPerformance(); + this.totalElapsedTime = totalElapsedTime; + this.totalTickedBlocks = totalTickedBlocks; + + chunks = profiler.getByChunk(); + items = profiler.getByItem(); + } + + public void send(CommandSender sender) { + sender.sendMessage(""); + sender.sendMessage(ChatColor.GREEN + "===== Slimefun Lag Profiler ====="); + sender.sendMessage(ChatColors.color("&6Total: &e" + NumberUtils.getAsMillis(totalElapsedTime))); + sender.sendMessage(ChatColors.color("&6Performance: " + getPerformanceRating())); + sender.sendMessage(ChatColors.color("&6Active Chunks: &e" + chunks.size())); + sender.sendMessage(ChatColors.color("&6Active Blocks: &e" + totalTickedBlocks)); + sender.sendMessage(""); + + summarizeTimings("Chunks", sender, entry -> { + int count = profiler.getBlocksOfId(entry.getKey()); + String time = NumberUtils.getAsMillis(entry.getValue()); + + if (count > 1) { + String average = NumberUtils.getAsMillis(entry.getValue() / count); + + return entry.getKey() + " - " + count + "x (" + time + ", " + average + " avg/block)"; + } + else { + return entry.getKey() + " - " + count + "x (" + time + ')'; + } + }, items.entrySet().stream()); + + sender.sendMessage(""); + + summarizeTimings("Blocks", sender, entry -> { + int count = profiler.getBlocksInChunk(entry.getKey()); + String time = NumberUtils.getAsMillis(entry.getValue()); + + return entry.getKey() + " - " + count + "x (" + time + ")"; + }, chunks.entrySet().stream()); + } + + private void summarizeTimings(String prefix, CommandSender sender, Function, String> formatter, Stream> stream) { + List> results = stream.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()); + + if (sender instanceof Player) { + TextComponent component = new TextComponent(prefix); + component.setColor(ChatColor.GOLD); + + TextComponent hoverComponent = new TextComponent("\n Hover for more details..."); + hoverComponent.setColor(ChatColor.GRAY); + hoverComponent.setItalic(true); + StringBuilder builder = new StringBuilder(); + int hidden = 0; + + for (Map.Entry entry : results) { + if (entry.getValue() > VISIBILITY_THRESHOLD) { + builder.append("\n&e").append(formatter.apply(entry)); + } + else { + hidden++; + } + } + + builder.append("\n\n&c+ &6").append(hidden).append(" more"); + hoverComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColors.color(builder.toString())))); + + component.addExtra(hoverComponent); + sender.spigot().sendMessage(component); + } + else { + int hidden = 0; + + sender.sendMessage(ChatColor.GOLD + prefix); + + for (Map.Entry entry : results) { + if (entry.getValue() > VISIBILITY_THRESHOLD) { + sender.sendMessage(" " + ChatColor.stripColor(formatter.apply(entry))); + } + else { + hidden++; + } + } + + sender.sendMessage("+ " + hidden + " more"); + } + } + + private String getPerformanceRating() { + StringBuilder builder = new StringBuilder(); + + float percentage = Math.round(((((totalElapsedTime / 1000000.0) * 100.0F) / MAX_TICK_DURATION) * 100.0F) / 100.0F); + builder.append(NumberUtils.getColorFromPercentage(100 - Math.min(percentage, 100))); + + int rest = 20; + for (int i = (int) Math.min(percentage, 100); i >= 5; i = i - 5) { + builder.append(':'); + rest--; + } + + builder.append(ChatColor.DARK_GRAY); + + for (int i = 0; i < rest; i++) { + builder.append(':'); + } + + builder.append(" - "); + + builder.append(rating.getColor() + ChatUtils.humanize(rating.name())); + + builder.append(ChatColor.GRAY); + builder.append(" ("); + builder.append(NumberUtils.roundDecimalNumber(percentage)); + builder.append("%)"); + + return builder.toString(); + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java index 5fbe2e270..614885e65 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java @@ -1,12 +1,8 @@ package io.github.thebusybiscuit.slimefun4.core.services.profiler; -import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; -import java.util.List; -import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.Queue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -14,30 +10,22 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Function; import java.util.logging.Level; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.block.Block; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition; -import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.Slimefun; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; /** * The {@link SlimefunProfiler} works closely to the {@link TickerTask} and is responsible for @@ -53,9 +41,6 @@ import net.md_5.bungee.api.chat.TextComponent; */ public class SlimefunProfiler { - // The threshold at which a Block or Chunk is significant enough to appear in /sf timings - private static final int VISIBILITY_THRESHOLD = 275_000; - private final ExecutorService executor = Executors.newFixedThreadPool(3); private final AtomicBoolean running = new AtomicBoolean(false); private final AtomicInteger queued = new AtomicInteger(0); @@ -145,11 +130,14 @@ public class SlimefunProfiler { totalElapsedTime = timings.values().stream().mapToLong(Long::longValue).sum(); - Iterator iterator = requests.iterator(); + if (!requests.isEmpty()) { + PerformanceSummary summary = new PerformanceSummary(this, totalElapsedTime, timings.size()); + Iterator iterator = requests.iterator(); - while (iterator.hasNext()) { - sendSummary(iterator.next()); - iterator.remove(); + while (iterator.hasNext()) { + summary.send(iterator.next()); + iterator.remove(); + } } }); @@ -166,7 +154,7 @@ public class SlimefunProfiler { requests.add(sender); } - private Map getByItem() { + protected Map getByItem() { Map map = new HashMap<>(); for (Map.Entry entry : timings.entrySet()) { @@ -176,7 +164,7 @@ public class SlimefunProfiler { return map; } - private Map getByChunk() { + protected Map getByChunk() { Map map = new HashMap<>(); for (Map.Entry entry : timings.entrySet()) { @@ -190,7 +178,7 @@ public class SlimefunProfiler { return map; } - private int getBlocksInChunk(String chunk) { + protected int getBlocksInChunk(String chunk) { int blocks = 0; for (ProfiledBlock block : timings.keySet()) { @@ -206,7 +194,7 @@ public class SlimefunProfiler { return blocks; } - private int getBlocks(String id) { + protected int getBlocksOfId(String id) { int blocks = 0; for (ProfiledBlock block : timings.keySet()) { @@ -218,75 +206,21 @@ public class SlimefunProfiler { return blocks; } - private void sendSummary(CommandSender sender) { - Map chunks = getByChunk(); - Map machines = getByItem(); + /** + * This method returns the current {@link PerformanceRating}. + * + * @return The current performance grade + */ + public PerformanceRating getPerformance() { + float percentage = Math.round(((((totalElapsedTime / 1000000.0) * 100.0F) / PerformanceSummary.MAX_TICK_DURATION) * 100.0F) / 100.0F); - sender.sendMessage(ChatColors.color("&2== &aSlimefun Lag Profiler &2==")); - sender.sendMessage(ChatColors.color("&6Running: &e&l" + String.valueOf(!SlimefunPlugin.getTickerTask().isHalted()).toUpperCase(Locale.ROOT))); - sender.sendMessage(""); - sender.sendMessage(ChatColors.color("&6Impact: &e" + NumberUtils.getAsMillis(totalElapsedTime))); - sender.sendMessage(ChatColors.color("&6Ticked Chunks: &e" + chunks.size())); - sender.sendMessage(ChatColors.color("&6Ticked Blocks: &e" + timings.size())); - sender.sendMessage(""); - sender.sendMessage(ChatColors.color("&6Ticking Machines:")); - - summarizeTimings(sender, entry -> { - int count = getBlocks(entry.getKey()); - String time = NumberUtils.getAsMillis(entry.getValue()); - String average = NumberUtils.getAsMillis(entry.getValue() / count); - - return entry.getKey() + " - " + count + "x (" + time + ", " + average + " avg/block)"; - }, machines.entrySet().stream()); - - sender.sendMessage(""); - sender.sendMessage(ChatColors.color("&6Ticking Chunks:")); - - summarizeTimings(sender, entry -> { - int count = getBlocksInChunk(entry.getKey()); - String time = NumberUtils.getAsMillis(entry.getValue()); - - return entry.getKey() + " - " + count + "x (" + time + ")"; - }, chunks.entrySet().stream()); - } - - private void summarizeTimings(CommandSender sender, Function, String> formatter, Stream> stream) { - List> results = stream.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()); - - if (sender instanceof Player) { - TextComponent component = new TextComponent(" Hover for more details..."); - component.setColor(net.md_5.bungee.api.ChatColor.GRAY); - component.setItalic(true); - StringBuilder builder = new StringBuilder(); - int hidden = 0; - - for (Map.Entry entry : results) { - if (entry.getValue() > VISIBILITY_THRESHOLD) { - builder.append("\n&e").append(formatter.apply(entry)); - } - else { - hidden++; - } + for (PerformanceRating rating : PerformanceRating.values()) { + if (rating.test(percentage)) { + return rating; } - - builder.append("\n\n&c+ &6").append(hidden).append(" more"); - component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColors.color(builder.toString())))); - sender.spigot().sendMessage(component); } - else { - int hidden = 0; - for (Map.Entry entry : results) { - if (entry.getValue() > VISIBILITY_THRESHOLD) { - sender.sendMessage(" " + ChatColor.stripColor(formatter.apply(entry))); - } - else { - hidden++; - } - } - - sender.sendMessage("+ " + hidden + " more"); - } + return PerformanceRating.UNKNOWN; } public String getTime() { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java index 3f7432f69..24012fc56 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java @@ -30,14 +30,14 @@ public class EnhancedFurnace extends SimpleSlimefunItem { private final int speed; private final int efficiency; - private final int fortune; + private final int fortuneLevel; public EnhancedFurnace(Category category, int speed, int efficiency, int fortune, SlimefunItemStack item, ItemStack[] recipe) { super(category, item, RecipeType.ENHANCED_CRAFTING_TABLE, recipe); this.speed = speed - 1; this.efficiency = efficiency - 1; - this.fortune = fortune - 1; + this.fortuneLevel = fortune - 1; } public int getSpeed() { @@ -49,11 +49,8 @@ public class EnhancedFurnace extends SimpleSlimefunItem { } public int getOutput() { - int bonus = this.fortune; - bonus = ThreadLocalRandom.current().nextInt(bonus + 2) - 1; - if (bonus <= 0) bonus = 0; - bonus++; - return bonus; + int bonus = ThreadLocalRandom.current().nextInt(fortuneLevel + 2); + return 1 + bonus; } @Override diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java index 66b8bc768..29ff47e5b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java @@ -41,7 +41,7 @@ public class CargoManager extends SlimefunItem { @Override public boolean isSynchronized() { - return true; + return false; } }, new BlockUseHandler() { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java index 518845fbb..e13d9c236 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java @@ -1,6 +1,5 @@ package io.github.thebusybiscuit.slimefun4.implementation.tasks; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; @@ -14,6 +13,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition; import io.github.thebusybiscuit.slimefun4.api.ErrorReport; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; @@ -30,7 +30,7 @@ public class TickerTask implements Runnable { // These are "Queues" of blocks that need to be removed or moved private final Map movingQueue = new ConcurrentHashMap<>(); private final Map deletionQueue = new ConcurrentHashMap<>(); - private final Map buggedBlocks = new ConcurrentHashMap<>(); + private final Map bugs = new ConcurrentHashMap<>(); private boolean halted = false; private boolean running = false; @@ -48,14 +48,11 @@ public class TickerTask implements Runnable { running = true; SlimefunPlugin.getProfiler().start(); - Map bugs = new HashMap<>(buggedBlocks); - buggedBlocks.clear(); - - Map removals = new HashMap<>(deletionQueue); - - for (Map.Entry entry : removals.entrySet()) { + Iterator> removals = deletionQueue.entrySet().iterator(); + while (removals.hasNext()) { + Map.Entry entry = removals.next(); BlockStorage._integrated_removeBlockInfo(entry.getKey(), entry.getValue()); - deletionQueue.remove(entry.getKey()); + removals.remove(); } if (!halted) { @@ -70,7 +67,7 @@ public class TickerTask implements Runnable { if (world != null && world.isChunkLoaded(x, z)) { for (Location l : locations) { - tick(l, bugs); + tick(l); } } } @@ -80,12 +77,13 @@ public class TickerTask implements Runnable { } } - for (Map.Entry entry : movingQueue.entrySet()) { + Iterator> moves = movingQueue.entrySet().iterator(); + while (moves.hasNext()) { + Map.Entry entry = moves.next(); BlockStorage._integrated_moveLocationInfo(entry.getKey(), entry.getValue()); + moves.remove(); } - movingQueue.clear(); - Iterator iterator = tickers.iterator(); while (iterator.hasNext()) { iterator.next().startNewTick(); @@ -96,7 +94,7 @@ public class TickerTask implements Runnable { SlimefunPlugin.getProfiler().stop(); } - private void tick(Location l, Map bugs) { + private void tick(Location l) { Config data = BlockStorage.getLocationInfo(l); SlimefunItem item = SlimefunItem.getByID(data.getString("id")); @@ -109,53 +107,53 @@ public class TickerTask implements Runnable { if (item.getBlockTicker().isSynchronized()) { // We are ignoring the timestamp from above because synchronized actions // are always ran with a 50ms delay (1 game tick) - Slimefun.runSync(() -> tickBlock(bugs, l, b, item, data, System.nanoTime())); + Slimefun.runSync(() -> tickBlock(l, b, item, data, System.nanoTime())); } else { - tickBlock(bugs, l, b, item, data, timestamp); + tickBlock(l, b, item, data, timestamp); } tickers.add(item.getBlockTicker()); } catch (Exception x) { - int errors = bugs.getOrDefault(l, 0); - reportErrors(l, item, x, errors); + reportErrors(l, item, x); } } } - private void tickBlock(Map bugs, Location l, Block b, SlimefunItem item, Config data, long timestamp) { + private void tickBlock(Location l, Block b, SlimefunItem item, Config data, long timestamp) { try { item.getBlockTicker().tick(b, item, data); } catch (Exception | LinkageError x) { - int errors = bugs.getOrDefault(l, 0); - reportErrors(l, item, x, errors); + reportErrors(l, item, x); } finally { SlimefunPlugin.getProfiler().closeEntry(l, item, timestamp); } } - private void reportErrors(Location l, SlimefunItem item, Throwable x, int errors) { - errors++; + private void reportErrors(Location l, SlimefunItem item, Throwable x) { + BlockPosition position = new BlockPosition(l); + int errors = bugs.getOrDefault(position, 0) + 1; if (errors == 1) { // Generate a new Error-Report new ErrorReport(x, l, item); - buggedBlocks.put(l, errors); + bugs.put(position, errors); } else if (errors == 4) { Slimefun.getLogger().log(Level.SEVERE, "X: {0} Y: {1} Z: {2} ({3})", new Object[] { l.getBlockX(), l.getBlockY(), l.getBlockZ(), item.getID() }); Slimefun.getLogger().log(Level.SEVERE, "has thrown 4 error messages in the last 4 Ticks, the Block has been terminated."); Slimefun.getLogger().log(Level.SEVERE, "Check your /plugins/Slimefun/error-reports/ folder for details."); Slimefun.getLogger().log(Level.SEVERE, " "); + bugs.remove(position); BlockStorage._integrated_removeBlockInfo(l, true); Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> l.getBlock().setType(Material.AIR)); } else { - buggedBlocks.put(l, errors); + bugs.put(position, errors); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java index 0c861495f..bebdaf7ab 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java @@ -116,30 +116,25 @@ public final class ChestMenuUtils { } public static String getProgressBar(int time, int total) { - StringBuilder progress = new StringBuilder(); + StringBuilder builder = new StringBuilder(); float percentage = Math.round(((((total - time) * 100.0F) / total) * 100.0F) / 100.0F); - if (percentage < 16.0F) progress.append("&4"); - else if (percentage < 32.0F) progress.append("&c"); - else if (percentage < 48.0F) progress.append("&6"); - else if (percentage < 64.0F) progress.append("&e"); - else if (percentage < 80.0F) progress.append("&2"); - else progress.append("&a"); + builder.append(NumberUtils.getColorFromPercentage(percentage)); int rest = 20; for (int i = (int) percentage; i >= 5; i = i - 5) { - progress.append(':'); + builder.append(':'); rest--; } - progress.append("&7"); + builder.append("&7"); for (int i = 0; i < rest; i++) { - progress.append(':'); + builder.append(':'); } - progress.append(" - ").append(percentage).append('%'); - return ChatColors.color(progress.toString()); + builder.append(" - ").append(percentage).append('%'); + return ChatColors.color(builder.toString()); } private static short getDurability(ItemStack item, int timeLeft, int max) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java index 2619f02ec..15e9f15fc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java @@ -73,7 +73,7 @@ public final class NumberUtils { return "0ms"; } - String number = DECIMAL_FORMAT.format(nanoseconds / 1000000.0); + String number = roundDecimalNumber(nanoseconds / 1000000.0); String[] parts = PatternUtils.NUMBER_SEPERATOR.split(number); if (parts.length == 1) { @@ -84,6 +84,10 @@ public final class NumberUtils { } } + public static String roundDecimalNumber(double number) { + return DECIMAL_FORMAT.format(number); + } + public static long getLong(Long value, long defaultValue) { return value == null ? defaultValue : value; } From ef7624dde9a214b88c81d977b6593ece126decb3 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Wed, 1 Jul 2020 20:39:01 +0200 Subject: [PATCH 22/36] Performance improvement for ChestTerminal --- .../core/networks/cargo/ChestTerminalNetwork.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java index 3722ada69..17d3a5b16 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java @@ -269,6 +269,7 @@ abstract class ChestTerminalNetwork extends Network { ItemStackAndInteger item = items.get(index); ItemStack stack = item.getItem().clone(); + stack.setAmount(1); ItemMeta im = stack.getItemMeta(); List lore = new ArrayList<>(); lore.add(""); @@ -366,7 +367,7 @@ abstract class ChestTerminalNetwork extends Network { } if (add) { - items.add(new ItemStackAndInteger(new CustomItem(is, 1), is.getAmount() + stored)); + items.add(new ItemStackAndInteger(is, is.getAmount() + stored)); } } } @@ -378,19 +379,19 @@ abstract class ChestTerminalNetwork extends Network { } } - private void filter(ItemStack is, List items, Location l) { - if (is != null && CargoUtils.matchesFilter(l.getBlock(), is)) { + private void filter(ItemStack stack, List items, Location node) { + if (stack != null && CargoUtils.matchesFilter(node.getBlock(), stack)) { boolean add = true; for (ItemStackAndInteger item : items) { - if (SlimefunUtils.isItemSimilar(is, item.getItem(), true)) { + if (SlimefunUtils.isItemSimilar(stack, item.getItem(), true)) { add = false; - item.add(is.getAmount()); + item.add(stack.getAmount()); } } if (add) { - items.add(new ItemStackAndInteger(new CustomItem(is, 1), is.getAmount())); + items.add(new ItemStackAndInteger(stack, stack.getAmount())); } } } From 697b1733591d9ba6681aa8a09ec7c77dc421c886 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 2 Jul 2020 11:26:38 +0200 Subject: [PATCH 23/36] Refactoring --- .../services/profiler/PerformanceRating.java | 5 ++++ .../services/profiler/PerformanceSummary.java | 30 +++++++++++-------- .../services/profiler/SlimefunProfiler.java | 16 +++++++--- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java index 0ebfbc0fe..1b88383f4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java @@ -36,6 +36,11 @@ public enum PerformanceRating implements Predicate { @Override public boolean test(Float value) { + if (value == null) { + // null will only test true for UNKNOWN + return threshold < 0; + } + return value <= threshold; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java index b87d04973..4e8b72650 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java @@ -31,6 +31,7 @@ class PerformanceSummary { private final PerformanceRating rating; private final long totalElapsedTime; private final int totalTickedBlocks; + private final float percentage; private final Map chunks; private final Map items; @@ -38,6 +39,7 @@ class PerformanceSummary { PerformanceSummary(SlimefunProfiler profiler, long totalElapsedTime, int totalTickedBlocks) { this.profiler = profiler; this.rating = profiler.getPerformance(); + this.percentage = profiler.getPercentageOfTick(); this.totalElapsedTime = totalElapsedTime; this.totalTickedBlocks = totalTickedBlocks; @@ -48,13 +50,13 @@ class PerformanceSummary { public void send(CommandSender sender) { sender.sendMessage(""); sender.sendMessage(ChatColor.GREEN + "===== Slimefun Lag Profiler ====="); - sender.sendMessage(ChatColors.color("&6Total: &e" + NumberUtils.getAsMillis(totalElapsedTime))); - sender.sendMessage(ChatColors.color("&6Performance: " + getPerformanceRating())); - sender.sendMessage(ChatColors.color("&6Active Chunks: &e" + chunks.size())); - sender.sendMessage(ChatColors.color("&6Active Blocks: &e" + totalTickedBlocks)); + sender.sendMessage(ChatColor.GOLD + "Total: " + ChatColor.YELLOW + NumberUtils.getAsMillis(totalElapsedTime)); + sender.sendMessage(ChatColor.GOLD + "Performance: " + getPerformanceRating()); + sender.sendMessage(ChatColor.GOLD + "Active Chunks: " + ChatColor.YELLOW + chunks.size()); + sender.sendMessage(ChatColor.GOLD + "Active Blocks: " + ChatColor.YELLOW + totalTickedBlocks); sender.sendMessage(""); - summarizeTimings("Chunks", sender, entry -> { + summarizeTimings("Blocks", sender, entry -> { int count = profiler.getBlocksOfId(entry.getKey()); String time = NumberUtils.getAsMillis(entry.getValue()); @@ -70,7 +72,7 @@ class PerformanceSummary { sender.sendMessage(""); - summarizeTimings("Blocks", sender, entry -> { + summarizeTimings("Chunks", sender, entry -> { int count = profiler.getBlocksInChunk(entry.getKey()); String time = NumberUtils.getAsMillis(entry.getValue()); @@ -93,7 +95,7 @@ class PerformanceSummary { for (Map.Entry entry : results) { if (entry.getValue() > VISIBILITY_THRESHOLD) { - builder.append("\n&e").append(formatter.apply(entry)); + builder.append("\n").append(ChatColor.YELLOW).append(formatter.apply(entry)); } else { hidden++; @@ -108,26 +110,28 @@ class PerformanceSummary { } else { int hidden = 0; - - sender.sendMessage(ChatColor.GOLD + prefix); + StringBuilder builder = new StringBuilder(); + builder.append(ChatColor.GOLD + prefix); for (Map.Entry entry : results) { if (entry.getValue() > VISIBILITY_THRESHOLD) { - sender.sendMessage(" " + ChatColor.stripColor(formatter.apply(entry))); + builder.append(" "); + builder.append(ChatColor.stripColor(formatter.apply(entry))); } else { hidden++; } } - sender.sendMessage("+ " + hidden + " more"); + builder.append("\n+ "); + builder.append(hidden); + builder.append(" more..."); + sender.sendMessage(builder.toString()); } } private String getPerformanceRating() { StringBuilder builder = new StringBuilder(); - - float percentage = Math.round(((((totalElapsedTime / 1000000.0) * 100.0F) / MAX_TICK_DURATION) * 100.0F) / 100.0F); builder.append(NumberUtils.getColorFromPercentage(100 - Math.min(percentage, 100))); int rest = 20; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java index 614885e65..084e7a99f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java @@ -28,11 +28,11 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.Slimefun; /** - * The {@link SlimefunProfiler} works closely to the {@link TickerTask} and is responsible for - * monitoring that task. + * The {@link SlimefunProfiler} works closely to the {@link TickerTask} and is + * responsible for monitoring that task. * It collects timings data for any ticked {@link Block} and the corresponding {@link SlimefunItem}. * This allows developers to identify laggy {@link SlimefunItem SlimefunItems} or {@link SlimefunAddon SlimefunAddons}. - * But it also enabled Server Admins to locate lag-inducing areas on the {@link Server}. + * But it also enables Server Admins to locate lag-inducing areas on the {@link Server}. * * @author TheBusyBiscuit * @@ -151,6 +151,8 @@ public class SlimefunProfiler { * The {@link CommandSender} who shall receive this summary. */ public void requestSummary(CommandSender sender) { + Validate.notNull(sender, "Cannot request a summary for null"); + requests.add(sender); } @@ -206,13 +208,19 @@ public class SlimefunProfiler { return blocks; } + protected float getPercentageOfTick() { + float millis = totalElapsedTime / 1000000.0F; + float fraction = (millis * 100.0F) / PerformanceSummary.MAX_TICK_DURATION; + return Math.round((fraction * 100.0F) / 100.0F); + } + /** * This method returns the current {@link PerformanceRating}. * * @return The current performance grade */ public PerformanceRating getPerformance() { - float percentage = Math.round(((((totalElapsedTime / 1000000.0) * 100.0F) / PerformanceSummary.MAX_TICK_DURATION) * 100.0F) / 100.0F); + float percentage = getPercentageOfTick(); for (PerformanceRating rating : PerformanceRating.values()) { if (rating.test(percentage)) { From 548e3586ae6ba58b5194a1b1e167eb23f7018a38 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 2 Jul 2020 11:50:07 +0200 Subject: [PATCH 24/36] Fixes #2066 --- CHANGELOG.md | 1 + .../slimefun4/core/attributes/RechargeableHelper.java | 8 +++++--- .../thebusybiscuit/slimefun4/utils/LoreBuilder.java | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba2a13b29..bde7a3959 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ * Fixed Grappling hooks making Bat sounds * Fixed #1959 * Fixed Melon Juice requiring Melons instead of Melon Slices +* Fixed #2066 ## Release Candidate 13 (16 Jun 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java index 26c1c370e..29f6c8180 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import org.bukkit.NamespacedKey; import org.bukkit.inventory.meta.ItemMeta; @@ -26,7 +27,8 @@ import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; final class RechargeableHelper { private static final NamespacedKey CHARGE_KEY = new NamespacedKey(SlimefunPlugin.instance, "item_charge"); - private static final String LORE_PREFIX = ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7"); + private static final String LORE_PREFIX = ChatColors.color("&8\u21E8 &e\u26A1 &7"); + private static final Pattern REGEX = Pattern.compile(ChatColors.color("(&c&o)?" + LORE_PREFIX) + "[0-9\\.]+ \\/ [0-9\\.]+ J"); private RechargeableHelper() {} @@ -42,7 +44,7 @@ final class RechargeableHelper { for (int i = 0; i < lore.size(); i++) { String line = lore.get(i); - if (line.startsWith(LORE_PREFIX)) { + if (REGEX.matcher(line).matches()) { lore.set(i, LORE_PREFIX + value + " / " + capacity + " J"); meta.setLore(lore); return; @@ -66,7 +68,7 @@ final class RechargeableHelper { // If no persistent data exists, we will just fall back to the lore if (meta.hasLore()) { for (String line : meta.getLore()) { - if (line.startsWith(LORE_PREFIX) && line.contains(" / ") && line.endsWith(" J")) { + if (REGEX.matcher(line).matches()) { return Float.parseFloat(PatternUtils.SLASH_SEPARATOR.split(line)[0].replace(LORE_PREFIX, "")); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/LoreBuilder.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/LoreBuilder.java index 4ef841c4c..49d3ff06d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/LoreBuilder.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/LoreBuilder.java @@ -39,7 +39,7 @@ public final class LoreBuilder { } public static String powerCharged(int charge, int capacity) { - return "&c&o&8\u21E8 &e\u26A1 &7" + charge + " / " + capacity + " J"; + return "&8\u21E8 &e\u26A1 &7" + charge + " / " + capacity + " J"; } public static String material(String material) { From b978a8def3b1baf5690b3174df31b18a8143d177 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 2 Jul 2020 11:57:11 +0200 Subject: [PATCH 25/36] Another small fix --- .../slimefun4/testing/tests/items/TestRechargeableItems.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestRechargeableItems.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestRechargeableItems.java index cc417f06d..f4fde025c 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestRechargeableItems.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/TestRechargeableItems.java @@ -61,7 +61,7 @@ public class TestRechargeableItems { rechargeable.setItemCharge(item, 10); Assertions.assertEquals(10, rechargeable.getItemCharge(item)); - String lore = ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7") + "10.0 / 10.0 J"; + String lore = ChatColors.color("&8\u21E8 &e\u26A1 &7") + "10.0 / 10.0 J"; Assertions.assertEquals(lore, item.getItemMeta().getLore().get(1)); } @@ -100,7 +100,7 @@ public class TestRechargeableItems { Assertions.assertTrue(rechargeable.addItemCharge(item, 10)); Assertions.assertEquals(10, rechargeable.getItemCharge(item)); - String lore = ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7") + "10.0 / 10.0 J"; + String lore = ChatColors.color("&8\u21E8 &e\u26A1 &7") + "10.0 / 10.0 J"; Assertions.assertEquals(lore, item.getItemMeta().getLore().get(0)); } From 144483178d8d839a5bf8a8f519eaff74c311bf58 Mon Sep 17 00:00:00 2001 From: Scott Gomez Andoy Date: Thu, 2 Jul 2020 11:27:01 +0000 Subject: [PATCH 26/36] Translate categories_tl.yml via GitLocalize --- src/main/resources/languages/categories_tl.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/languages/categories_tl.yml b/src/main/resources/languages/categories_tl.yml index 8503ddf9d..4b114b10e 100644 --- a/src/main/resources/languages/categories_tl.yml +++ b/src/main/resources/languages/categories_tl.yml @@ -23,4 +23,4 @@ slimefun: easter: Mahal na Araw (Abril) birthday: Ang Kaarawan ni TheBusyBiscuit (26th Oktubre) halloween: Undas (31st Oktubre) - androids: Mga Androids na Maipoprograma + androids: Mga Programmable Androids From 424cf12b644e4f1eec63c51d54bdeed7f240fa0b Mon Sep 17 00:00:00 2001 From: Scott Gomez Andoy Date: Thu, 2 Jul 2020 11:27:02 +0000 Subject: [PATCH 27/36] Translate messages_tl.yml via GitLocalize --- src/main/resources/languages/messages_tl.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/languages/messages_tl.yml b/src/main/resources/languages/messages_tl.yml index 8568fc2f3..644547da4 100644 --- a/src/main/resources/languages/messages_tl.yml +++ b/src/main/resources/languages/messages_tl.yml @@ -4,12 +4,12 @@ commands: cheat: Pinapayagan kang dayain ang mga Aytem sa Slimefun. give: Nagbibigay ito ng mga Aytem sa Slimefun. guide: Bibigyan ka nito ng Simefun Guide. - timings: Lag-Info patungkol sa iyong server. + timings: Lag-info patungkol sa iyong server. teleporter: Tingnan ang mga Waypoints ng mga Players. - versions: Ipapakita nito ang mga na-install na Addon sa Slimefun. + versions: Ipapakita nito ang mga na-install na mga Addon sa Slimefun. search: Hahanapin sa Guide ang binigyan na katawagan. - open_guide: Bubuksan nito ang Slimefun's Guide na wala ang libro. - stats: Ipapakita ang hindi karamihan na Estatistika ng Player. + open_guide: Bubuksan nito ang Slimefun's guide na wala ang libro. + stats: Ipapakita ang hindi karamihan na estatistika ng Player. research: description: Iaunlock/Irereset ang mga Researches para sa Player. reset: "&cNareset mo ang Knowledge para kay %player%." From 172a2c47fb4ddc6fff3f5cdab6cef1d82afd7d86 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 2 Jul 2020 18:04:26 +0200 Subject: [PATCH 28/36] Added a directional cache to Cargo Nodes, should improve performance --- .../slimefun4/api/network/Network.java | 67 ++++++++++--------- .../slimefun4/core/handlers/package-info.java | 2 +- .../core/networks/cargo/CargoNet.java | 18 +++-- .../networks/cargo/ChestTerminalNetwork.java | 15 ++++- 4 files changed, 62 insertions(+), 40 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java index c4c21e496..6980314ea 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java @@ -8,6 +8,7 @@ import java.util.Set; import org.apache.commons.lang.Validate; import org.bukkit.Color; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.Particle.DustOptions; @@ -26,6 +27,34 @@ import me.mrCookieSlime.Slimefun.api.Slimefun; */ public abstract class Network { + private final NetworkManager manager; + protected Location regulator; + private Queue nodeQueue = new ArrayDeque<>(); + + protected final Set connectedLocations = new HashSet<>(); + protected final Set regulatorNodes = new HashSet<>(); + protected final Set connectorNodes = new HashSet<>(); + protected final Set terminusNodes = new HashSet<>(); + + /** + * This constructs a new {@link Network} at the given {@link Location}. + * + * @param manager + * The {@link NetworkManager} instance + * @param regulator + * The {@link Location} marking the regulator of this {@link Network}. + */ + protected Network(NetworkManager manager, Location regulator) { + Validate.notNull(manager, "A NetworkManager must be provided"); + Validate.notNull(regulator, "No regulator was specified"); + + this.manager = manager; + this.regulator = regulator; + + connectedLocations.add(regulator); + nodeQueue.add(regulator.clone()); + } + /** * This method returns the range of the {@link Network}. * The range determines how far the {@link Network} will search for @@ -60,34 +89,6 @@ public abstract class Network { */ public abstract void onClassificationChange(Location l, NetworkComponent from, NetworkComponent to); - protected Location regulator; - private Queue nodeQueue = new ArrayDeque<>(); - - private final NetworkManager manager; - protected final Set connectedLocations = new HashSet<>(); - protected final Set regulatorNodes = new HashSet<>(); - protected final Set connectorNodes = new HashSet<>(); - protected final Set terminusNodes = new HashSet<>(); - - /** - * This constructs a new {@link Network} at the given {@link Location}. - * - * @param manager - * The {@link NetworkManager} instance - * @param regulator - * The {@link Location} marking the regulator of this {@link Network}. - */ - protected Network(NetworkManager manager, Location regulator) { - Validate.notNull(manager, "A NetworkManager must be provided"); - Validate.notNull(regulator, "No regulator was specified"); - - this.manager = manager; - this.regulator = regulator; - - connectedLocations.add(regulator); - nodeQueue.add(regulator.clone()); - } - /** * This returns the size of this {@link Network}. It is equivalent to the amount * of {@link Location Locations} connected to this {@link Network}. @@ -208,14 +209,18 @@ public abstract class Network { /** * This method runs the network visualizer which displays a {@link Particle} on - * every {@link Location} that this {@link Network} can connect to. + * every {@link Location} that this {@link Network} is connected to. */ public void display() { Slimefun.runSync(() -> { - DustOptions options = new DustOptions(Color.BLUE, 2F); + DustOptions options = new DustOptions(Color.BLUE, 3F); for (Location l : connectedLocations) { - l.getWorld().spawnParticle(Particle.REDSTONE, l.getX() + 0.5, l.getY() + 0.5, l.getZ() + 0.5, 1, 0, 0, 0, 1, options); + Material type = l.getBlock().getType(); + + if (type == Material.PLAYER_HEAD || type == Material.PLAYER_WALL_HEAD) { + l.getWorld().spawnParticle(Particle.REDSTONE, l.getX() + 0.5, l.getY() + 0.5, l.getZ() + 0.5, 1, 0, 0, 0, 1, options); + } } }); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/package-info.java index 5e9d82140..2dc20269a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/package-info.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/package-info.java @@ -2,4 +2,4 @@ * This package contains all variations of {@link me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler} that * can be assigned to a {@link me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem} */ -package io.github.thebusybiscuit.slimefun4.core.attributes; \ No newline at end of file +package io.github.thebusybiscuit.slimefun4.core.handlers; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java index c98c6e9f7..4dd87917a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java @@ -112,6 +112,8 @@ public class CargoNet extends ChestTerminalNetwork { @Override public void onClassificationChange(Location l, NetworkComponent from, NetworkComponent to) { + connectorCache.remove(l); + if (from == NetworkComponent.TERMINUS) { inputNodes.remove(l); outputNodes.remove(l); @@ -121,7 +123,8 @@ public class CargoNet extends ChestTerminalNetwork { } if (to == NetworkComponent.TERMINUS) { - switch (BlockStorage.checkID(l)) { + String id = BlockStorage.checkID(l); + switch (id) { case "CARGO_NODE_INPUT": inputNodes.add(l); break; @@ -175,8 +178,12 @@ public class CargoNet extends ChestTerminalNetwork { Map inputs = mapInputNodes(chestTerminalInputs); Map> outputs = mapOutputNodes(chestTerminalOutputs); + if (BlockStorage.getLocationInfo(b.getLocation(), "visualizer") == null) { + display(); + } + SlimefunPlugin.getProfiler().newEntry(); - Slimefun.runSync(() -> run(b, inputs, outputs, chestTerminalInputs, chestTerminalOutputs)); + Slimefun.runSync(() -> run(inputs, outputs, chestTerminalInputs, chestTerminalOutputs)); } } @@ -234,13 +241,9 @@ public class CargoNet extends ChestTerminalNetwork { return output; } - private void run(Block b, Map inputs, Map> outputs, Set chestTerminalInputs, Set chestTerminalOutputs) { + private void run(Map inputs, Map> outputs, Set chestTerminalInputs, Set chestTerminalOutputs) { long timestamp = System.nanoTime(); - if (BlockStorage.getLocationInfo(b.getLocation(), "visualizer") == null) { - display(); - } - // Chest Terminal Code if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) { handleItemRequests(chestTerminalInputs, chestTerminalOutputs); @@ -268,6 +271,7 @@ public class CargoNet extends ChestTerminalNetwork { private void routeItems(Location inputNode, Block inputTarget, int frequency, Map> outputNodes) { ItemStackAndInteger slot = CargoUtils.withdraw(inputNode.getBlock(), inputTarget); + if (slot == null) { return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java index 17d3a5b16..744a06b6a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java @@ -3,10 +3,12 @@ package io.github.thebusybiscuit.slimefun4.core.networks.cargo; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Queue; import java.util.Set; @@ -57,13 +59,24 @@ abstract class ChestTerminalNetwork extends Network { // This represents a Queue of requests to handle private final Queue itemRequests = new LinkedList<>(); + // This is a cache for the BlockFace a node is facing, so we don't need to request the + // BlockData each time we visit a node + protected Map connectorCache = new HashMap<>(); + protected ChestTerminalNetwork(Location regulator) { super(SlimefunPlugin.getNetworkManager(), regulator); } - protected static Optional getAttachedBlock(Block block) { + protected Optional getAttachedBlock(Block block) { if (block.getType() == Material.PLAYER_WALL_HEAD) { + BlockFace cached = connectorCache.get(block.getLocation()); + + if (cached != null) { + return Optional.of(block.getRelative(cached)); + } + BlockFace face = ((Directional) block.getBlockData()).getFacing().getOppositeFace(); + connectorCache.put(block.getLocation(), face); return Optional.of(block.getRelative(face)); } From 4ddea8f7ae14405286cb2ccb0072326f01203e2e Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 2 Jul 2020 20:41:40 +0200 Subject: [PATCH 29/36] Small performance improvement --- CHANGELOG.md | 1 + .../core/networks/energy/EnergyNet.java | 92 ++++++++++--------- .../Slimefun/api/energy/ChargableBlock.java | 70 +++++++------- 3 files changed, 87 insertions(+), 76 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dfe57933..164d35c09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ * Item Energy is now also stored persistently via NBT * General performance improvements for ticking blocks * Performance improvements to the Cargo Net +* Some performance improvements to the Energy Net #### Fixes * Fixed #2005 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java index 0208a04d1..5646b698d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java @@ -141,68 +141,71 @@ public class EnergyNet extends Network { double supply = DoubleHandler.fixDouble(tickAllGenerators() + tickAllCapacitors()); double demand = 0; - int available = (int) supply; + int availableEnergy = (int) supply; - for (Location destination : consumers) { - int capacity = ChargableBlock.getMaxCharge(destination); - int charge = ChargableBlock.getCharge(destination); + for (Location machine : consumers) { + int capacity = ChargableBlock.getMaxCharge(machine); + int charge = ChargableBlock.getCharge(machine); if (charge < capacity) { - int rest = capacity - charge; - demand += rest; + int availableSpace = capacity - charge; + demand += availableSpace; - if (available > 0) { - if (available > rest) { - ChargableBlock.setUnsafeCharge(destination, capacity, false); - available = available - rest; + if (availableEnergy > 0) { + if (availableEnergy > availableSpace) { + ChargableBlock.setUnsafeCharge(machine, capacity, false); + availableEnergy -= availableSpace; } else { - ChargableBlock.setUnsafeCharge(destination, charge + available, false); - available = 0; + ChargableBlock.setUnsafeCharge(machine, charge + availableEnergy, false); + availableEnergy = 0; } } } } - for (Location battery : storage) { - if (available > 0) { - int capacity = ChargableBlock.getMaxCharge(battery); + storeExcessEnergy(availableEnergy); + updateHologram(b, supply, demand); + } + } + private void storeExcessEnergy(int available) { + for (Location capacitor : storage) { + if (available > 0) { + int capacity = ChargableBlock.getMaxCharge(capacitor); + + if (available > capacity) { + ChargableBlock.setUnsafeCharge(capacitor, capacity, true); + available -= capacity; + } + else { + ChargableBlock.setUnsafeCharge(capacitor, available, true); + available = 0; + } + } + else { + ChargableBlock.setUnsafeCharge(capacitor, 0, true); + } + } + + for (Location generator : generators) { + int capacity = ChargableBlock.getMaxCharge(generator); + + if (capacity > 0) { + if (available > 0) { if (available > capacity) { - ChargableBlock.setUnsafeCharge(battery, capacity, true); + ChargableBlock.setUnsafeCharge(generator, capacity, false); available = available - capacity; } else { - ChargableBlock.setUnsafeCharge(battery, available, true); + ChargableBlock.setUnsafeCharge(generator, available, false); available = 0; } } else { - ChargableBlock.setUnsafeCharge(battery, 0, true); + ChargableBlock.setUnsafeCharge(generator, 0, false); } } - - for (Location source : generators) { - if (ChargableBlock.isChargable(source)) { - if (available > 0) { - int capacity = ChargableBlock.getMaxCharge(source); - - if (available > capacity) { - ChargableBlock.setUnsafeCharge(source, capacity, false); - available = available - capacity; - } - else { - ChargableBlock.setUnsafeCharge(source, available, false); - available = 0; - } - } - else { - ChargableBlock.setUnsafeCharge(source, 0, false); - } - } - } - - updateHologram(b, supply, demand); } } @@ -212,11 +215,10 @@ public class EnergyNet extends Network { for (Location source : generators) { long timestamp = SlimefunPlugin.getProfiler().newEntry(); - SlimefunItem item = BlockStorage.check(source); + Config config = BlockStorage.getLocationInfo(source); + SlimefunItem item = SlimefunItem.getByID(config.getString("id")); if (item != null) { - Config config = BlockStorage.getLocationInfo(source); - try { GeneratorTicker generator = item.getEnergyTicker(); @@ -263,8 +265,8 @@ public class EnergyNet extends Network { private double tickAllCapacitors() { double supply = 0; - for (Location battery : storage) { - supply += ChargableBlock.getCharge(battery); + for (Location capacitor : storage) { + supply += ChargableBlock.getCharge(capacitor); } return supply; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java b/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java index ac49e096a..8dd461328 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/energy/ChargableBlock.java @@ -7,12 +7,13 @@ import org.bukkit.block.Block; import io.github.thebusybiscuit.cscorelib2.skull.SkullBlock; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; -import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; public final class ChargableBlock { + private static final String KEY = "energy-charge"; + private ChargableBlock() {} public static boolean isChargable(Block b) { @@ -20,11 +21,12 @@ public final class ChargableBlock { } public static boolean isChargable(Location l) { - if (!BlockStorage.hasBlockInfo(l)) { + String id = BlockStorage.checkID(l); + + if (id == null) { return false; } - String id = BlockStorage.checkID(l); return SlimefunPlugin.getRegistry().getEnergyCapacities().containsKey(id); } @@ -33,13 +35,13 @@ public final class ChargableBlock { } public static int getCharge(Location l) { - String charge = BlockStorage.getLocationInfo(l, "energy-charge"); + String charge = BlockStorage.getLocationInfo(l, KEY); if (charge != null) { return Integer.parseInt(charge); } else { - BlockStorage.addBlockInfo(l, "energy-charge", "0", false); + BlockStorage.addBlockInfo(l, KEY, "0", false); return 0; } } @@ -60,17 +62,15 @@ public final class ChargableBlock { } } - if (charge != getCharge(l)) { - BlockStorage.addBlockInfo(l, "energy-charge", String.valueOf(charge), false); - } + BlockStorage.addBlockInfo(l, KEY, String.valueOf(charge), false); } public static void setUnsafeCharge(Location l, int charge, boolean updateTexture) { if (charge != getCharge(l)) { - BlockStorage.addBlockInfo(l, "energy-charge", String.valueOf(charge), false); + BlockStorage.addBlockInfo(l, KEY, String.valueOf(charge), false); if (updateTexture) { - updateCapacitor(l); + updateCapacitor(l, charge, getMaxCharge(l)); } } } @@ -79,42 +79,51 @@ public final class ChargableBlock { return addCharge(b.getLocation(), charge); } - public static int addCharge(Location l, int charge) { - int capacity = getMaxCharge(l); - int energy = getCharge(l); - int space = capacity - energy; - int rest = charge; + public static int addCharge(Location l, int addedCharge) { + String id = BlockStorage.checkID(l); - if (space > 0 && charge > 0) { - if (space > charge) { - setCharge(l, energy + charge); + if (id == null) { + BlockStorage.clearBlockInfo(l); + return 0; + } + + int capacity = SlimefunPlugin.getRegistry().getEnergyCapacities().getOrDefault(id, 0); + + int charge = getCharge(l); + int availableSpace = capacity - charge; + int rest = addedCharge; + + if (availableSpace > 0 && addedCharge > 0) { + if (availableSpace > addedCharge) { + charge += addedCharge; + setCharge(l, charge); rest = 0; } else { - rest = charge - space; - setCharge(l, capacity); + rest = addedCharge - availableSpace; + charge = capacity; + setCharge(l, charge); } - if (SlimefunPlugin.getRegistry().getEnergyCapacitors().contains(BlockStorage.checkID(l))) { - updateCapacitor(l); + if (SlimefunPlugin.getRegistry().getEnergyCapacitors().contains(id)) { + updateCapacitor(l, charge, capacity); } } - else if (charge < 0 && energy >= -charge) { - setCharge(l, energy + charge); + else if (addedCharge < 0 && charge >= -addedCharge) { + charge += addedCharge; + setCharge(l, charge); - if (SlimefunPlugin.getRegistry().getEnergyCapacitors().contains(BlockStorage.checkID(l))) { - updateCapacitor(l); + if (SlimefunPlugin.getRegistry().getEnergyCapacitors().contains(id)) { + updateCapacitor(l, charge, capacity); } } return rest; } - private static void updateCapacitor(Location l) { + private static void updateCapacitor(Location l, int charge, int capacity) { Slimefun.runSync(() -> { Block b = l.getBlock(); - int charge = getCharge(b); - int capacity = getMaxCharge(b); if (b.getType() == Material.PLAYER_HEAD || b.getType() == Material.PLAYER_WALL_HEAD) { if (charge < (int) (capacity * 0.25)) { @@ -138,8 +147,7 @@ public final class ChargableBlock { } public static int getMaxCharge(Location l) { - Config cfg = BlockStorage.getLocationInfo(l); - String id = cfg.getString("id"); + String id = BlockStorage.checkID(l); if (id == null) { BlockStorage.clearBlockInfo(l); From bbcf1da3e203988854be66f71c9e3284dbfda45a Mon Sep 17 00:00:00 2001 From: LinoxGH Date: Thu, 2 Jul 2020 20:47:59 +0000 Subject: [PATCH 30/36] Translate recipes_tr.yml via GitLocalize --- src/main/resources/languages/recipes_tr.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/languages/recipes_tr.yml b/src/main/resources/languages/recipes_tr.yml index 6872a71ed..40161e2f5 100644 --- a/src/main/resources/languages/recipes_tr.yml +++ b/src/main/resources/languages/recipes_tr.yml @@ -156,3 +156,8 @@ minecraft: lore: - İstediğiniz eşyayı üretmek için - Taş Kesici kullanın. + smithing: + name: Demirci Masası Üretimi + lore: + - Bu eşyayı Demirci Masası kullanarak + - gösterildiği gibi üretin From 06b14836dd2cb6485a51e30b537ae187f0f17f96 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 3 Jul 2020 14:47:51 +0200 Subject: [PATCH 31/36] Added plugins summary to /sf timings --- .../core/networks/energy/EnergyNet.java | 15 +++++-- .../services/profiler/PerformanceSummary.java | 41 +++++++++++-------- .../services/profiler/SlimefunProfiler.java | 30 +++++++++++++- 3 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java index 5646b698d..b73fd8cf2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java @@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.core.networks.energy; import java.util.HashSet; import java.util.Optional; import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.LongConsumer; import org.bukkit.Location; import org.bukkit.Material; @@ -13,6 +15,7 @@ import io.github.thebusybiscuit.slimefun4.api.ErrorReport; import io.github.thebusybiscuit.slimefun4.api.network.Network; import io.github.thebusybiscuit.slimefun4.api.network.NetworkComponent; import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor; import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram; @@ -127,6 +130,8 @@ public class EnergyNet extends Network { } public void tick(Block b) { + AtomicLong timestamp = new AtomicLong(SlimefunPlugin.getProfiler().newEntry()); + if (!regulator.equals(b.getLocation())) { SimpleHologram.update(b, "&4Multiple Energy Regulators connected"); return; @@ -138,7 +143,7 @@ public class EnergyNet extends Network { SimpleHologram.update(b, "&4No Energy Network found"); } else { - double supply = DoubleHandler.fixDouble(tickAllGenerators() + tickAllCapacitors()); + double supply = DoubleHandler.fixDouble(tickAllGenerators(timestamp::getAndAdd) + tickAllCapacitors()); double demand = 0; int availableEnergy = (int) supply; @@ -167,6 +172,9 @@ public class EnergyNet extends Network { storeExcessEnergy(availableEnergy); updateHologram(b, supply, demand); } + + // We have subtracted the timings from Generators, so they do not show up twice. + SlimefunPlugin.getProfiler().closeEntry(b.getLocation(), SlimefunItems.ENERGY_REGULATOR.getItem(), timestamp.get()); } private void storeExcessEnergy(int available) { @@ -209,7 +217,7 @@ public class EnergyNet extends Network { } } - private double tickAllGenerators() { + private double tickAllGenerators(LongConsumer timeCallback) { double supply = 0; Set exploded = new HashSet<>(); @@ -249,7 +257,8 @@ public class EnergyNet extends Network { new ErrorReport(t, source, item); } - SlimefunPlugin.getProfiler().closeEntry(source, item, timestamp); + long time = SlimefunPlugin.getProfiler().closeEntry(source, item, timestamp); + timeCallback.accept(time); } else { // This block seems to be gone now, better remove it to be extra safe diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java index 4e8b72650..788b4a9f4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java @@ -21,7 +21,7 @@ import net.md_5.bungee.api.chat.TextComponent; class PerformanceSummary { // The threshold at which a Block or Chunk is significant enough to appear in /sf timings - private static final int VISIBILITY_THRESHOLD = 275_000; + private static final int VISIBILITY_THRESHOLD = 280_000; // A minecraft server tick is 50ms and Slimefun ticks are stretched across // two ticks (sync and async blocks), so we use 100ms as a reference here @@ -34,6 +34,7 @@ class PerformanceSummary { private final float percentage; private final Map chunks; + private final Map plugins; private final Map items; PerformanceSummary(SlimefunProfiler profiler, long totalElapsedTime, int totalTickedBlocks) { @@ -44,6 +45,7 @@ class PerformanceSummary { this.totalTickedBlocks = totalTickedBlocks; chunks = profiler.getByChunk(); + plugins = profiler.getByPlugin(); items = profiler.getByItem(); } @@ -52,44 +54,47 @@ class PerformanceSummary { sender.sendMessage(ChatColor.GREEN + "===== Slimefun Lag Profiler ====="); sender.sendMessage(ChatColor.GOLD + "Total: " + ChatColor.YELLOW + NumberUtils.getAsMillis(totalElapsedTime)); sender.sendMessage(ChatColor.GOLD + "Performance: " + getPerformanceRating()); - sender.sendMessage(ChatColor.GOLD + "Active Chunks: " + ChatColor.YELLOW + chunks.size()); - sender.sendMessage(ChatColor.GOLD + "Active Blocks: " + ChatColor.YELLOW + totalTickedBlocks); sender.sendMessage(""); - summarizeTimings("Blocks", sender, entry -> { + summarizeTimings(totalTickedBlocks + " Blocks", sender, items, entry -> { int count = profiler.getBlocksOfId(entry.getKey()); String time = NumberUtils.getAsMillis(entry.getValue()); if (count > 1) { String average = NumberUtils.getAsMillis(entry.getValue() / count); - return entry.getKey() + " - " + count + "x (" + time + ", " + average + " avg/block)"; + return entry.getKey() + " - " + count + "x (" + time + " | avg: " + average + ')'; } else { return entry.getKey() + " - " + count + "x (" + time + ')'; } - }, items.entrySet().stream()); + }); - sender.sendMessage(""); - - summarizeTimings("Chunks", sender, entry -> { + summarizeTimings(chunks.size() + " Chunks", sender, chunks, entry -> { int count = profiler.getBlocksInChunk(entry.getKey()); String time = NumberUtils.getAsMillis(entry.getValue()); - return entry.getKey() + " - " + count + "x (" + time + ")"; - }, chunks.entrySet().stream()); + return entry.getKey() + " - " + count + "x Blocks (" + time + ")"; + }); + + summarizeTimings(plugins.size() + " Plugins", sender, plugins, entry -> { + int count = profiler.getBlocksFromPlugin(entry.getKey()); + String time = NumberUtils.getAsMillis(entry.getValue()); + + return entry.getKey() + " - " + count + "x Blocks (" + time + ")"; + }); } - private void summarizeTimings(String prefix, CommandSender sender, Function, String> formatter, Stream> stream) { + private void summarizeTimings(String prefix, CommandSender sender, Map map, Function, String> formatter) { + Stream> stream = map.entrySet().stream(); List> results = stream.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()); if (sender instanceof Player) { TextComponent component = new TextComponent(prefix); - component.setColor(ChatColor.GOLD); + component.setColor(ChatColor.YELLOW); - TextComponent hoverComponent = new TextComponent("\n Hover for more details..."); + TextComponent hoverComponent = new TextComponent(" (Hover for details)"); hoverComponent.setColor(ChatColor.GRAY); - hoverComponent.setItalic(true); StringBuilder builder = new StringBuilder(); int hidden = 0; @@ -111,11 +116,13 @@ class PerformanceSummary { else { int hidden = 0; StringBuilder builder = new StringBuilder(); - builder.append(ChatColor.GOLD + prefix); + builder.append(ChatColor.GOLD); + builder.append(prefix); + builder.append(ChatColor.YELLOW); for (Map.Entry entry : results) { if (entry.getValue() > VISIBILITY_THRESHOLD) { - builder.append(" "); + builder.append("\n "); builder.append(ChatColor.stripColor(formatter.apply(entry))); } else { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java index 084e7a99f..7bfa9c733 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java @@ -83,10 +83,12 @@ public class SlimefunProfiler { * The {@link SlimefunItem} at this {@link Location} * @param timestamp * The timestamp marking the start of this entry, you can retrieve it using {@link #newEntry()} + * + * @return The total timings of this entry */ - public void closeEntry(Location l, SlimefunItem item, long timestamp) { + public long closeEntry(Location l, SlimefunItem item, long timestamp) { if (timestamp == 0) { - return; + return 0; } long elapsedTime = System.nanoTime() - timestamp; @@ -96,6 +98,8 @@ public class SlimefunProfiler { timings.put(block, elapsedTime); queued.decrementAndGet(); }); + + return elapsedTime; } /** @@ -166,6 +170,16 @@ public class SlimefunProfiler { return map; } + protected Map getByPlugin() { + Map map = new HashMap<>(); + + for (Map.Entry entry : timings.entrySet()) { + map.merge(entry.getKey().getAddon().getName(), entry.getValue(), Long::sum); + } + + return map; + } + protected Map getByChunk() { Map map = new HashMap<>(); @@ -208,6 +222,18 @@ public class SlimefunProfiler { return blocks; } + protected int getBlocksFromPlugin(String id) { + int blocks = 0; + + for (ProfiledBlock block : timings.keySet()) { + if (block.getAddon().getName().equals(id)) { + blocks++; + } + } + + return blocks; + } + protected float getPercentageOfTick() { float millis = totalElapsedTime / 1000000.0F; float fraction = (millis * 100.0F) / PerformanceSummary.MAX_TICK_DURATION; From 768e4f10216c6fc19fbfe2d42a2e971abcbabc97 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 3 Jul 2020 17:43:10 +0200 Subject: [PATCH 32/36] Massive performance improvements to Rainbow Glass Panes --- CHANGELOG.md | 12 +++-- .../core/handlers/RainbowTickHandler.java | 46 ++++++++++++------- .../slimefun4/utils/ChatUtils.java | 2 +- .../slimefun4/utils/PatternUtils.java | 1 + 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 164d35c09..dc1826bed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,22 +41,23 @@ * Added an AoE damage effect to the Explosive Bow * Added runtime deprecation warnings for ItemHandlers and Attributes used by Addons * Added a proper lag profiler +* Added per-plugin lag info to /sf timings #### Changes * Coolant Cells now last twice as long * Ticking blocks will now catch more errors caused by addons -* Massive performance improvements to GPS/GEO machines, especially Oil Pump and GEO Miner * Changed the texture for the Nuclear Reactor * Changed the texture for the Nether Star Reactor -* Performance improvements to Rainbow Blocks * Crafting Tin cans now produces 8 items instead of 4 * Multi Tool lore now says "Crouch" instead of "Hold Shift" -* items which cannot be distributed by a Cargo Net will be dropped on the ground now instead of getting deleted +* Items which cannot be distributed by a Cargo Net will be dropped on the ground now instead of getting deleted * Slimefun no longer supports CraftBukkit * Item Energy is now also stored persistently via NBT -* General performance improvements for ticking blocks +* Performance improvements to GPS/GEO machines, especially Oil Pump and GEO Miner +* Performance improvements for ticking blocks * Performance improvements to the Cargo Net -* Some performance improvements to the Energy Net +* performance improvements to the Energy Net +* Performance improvements to Rainbow Blocks #### Fixes * Fixed #2005 @@ -79,6 +80,7 @@ * Fixed /sf timings reporting slightly inaccurate timings * Fixed concurrency-related issues with the profiling * Fixed #2066 +* Fixed Rainbow Glass Panes not properly connecting to blocks ## Release Candidate 13 (16 Jun 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java index 2461f8c6c..70fa1ce35 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java @@ -2,10 +2,12 @@ package io.github.thebusybiscuit.slimefun4.core.handlers; import java.util.Arrays; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Waterlogged; +import org.bukkit.block.data.type.GlassPane; import io.github.thebusybiscuit.cscorelib2.collections.LoopIterator; import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollection; @@ -29,31 +31,33 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; public class RainbowTickHandler extends BlockTicker { private final LoopIterator iterator; - private final boolean waterlogged; + private final boolean glassPanes; private Material material; public RainbowTickHandler(Material... materials) { + Validate.noNullElements(materials, "A RainbowTicker cannot have a Material that is null!"); + if (materials.length == 0) { throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!"); } - waterlogged = containsWaterlogged(materials); + glassPanes = containsGlassPanes(materials); iterator = new LoopIterator<>(Arrays.asList(materials)); material = iterator.next(); } /** * This method checks whether a given {@link Material} array contains any {@link Material} - * that would result in a {@link Waterlogged} {@link BlockData}. + * that would result in a {@link GlassPane} {@link BlockData}. * This is done to save performance, so we don't have to validate {@link BlockData} at * runtime. * * @param materials * The {@link Material} Array to check * - * @return Whether the array contained any {@link Waterlogged} materials + * @return Whether the array contained any {@link GlassPane} materials */ - private boolean containsWaterlogged(Material[] materials) { + private boolean containsGlassPanes(Material[] materials) { if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) { // BlockData is not available to us during Unit Tests :/ return false; @@ -62,8 +66,8 @@ public class RainbowTickHandler extends BlockTicker { for (Material type : materials) { // This BlockData is purely virtual and only created on startup, it should have // no impact on performance, in fact it should save performance as it preloads - // the data but also saves heavy calls for non-waterlogged Materials - if (type.createBlockData() instanceof Waterlogged) { + // the data but also saves heavy calls for other Materials + if (type.createBlockData() instanceof GlassPane) { return true; } } @@ -83,19 +87,29 @@ public class RainbowTickHandler extends BlockTicker { return; } - if (waterlogged) { + if (glassPanes) { BlockData blockData = b.getBlockData(); - b.setType(material, true); - if (blockData instanceof Waterlogged && ((Waterlogged) blockData).isWaterlogged()) { - Waterlogged block = (Waterlogged) b.getBlockData(); - block.setWaterlogged(true); + if (blockData instanceof GlassPane) { + BlockData block = material.createBlockData(bd -> { + if (bd instanceof GlassPane) { + GlassPane previousData = (GlassPane) blockData; + GlassPane nextData = (GlassPane) bd; + + nextData.setWaterlogged(previousData.isWaterlogged()); + + for (BlockFace face : previousData.getAllowedFaces()) { + nextData.setFace(face, previousData.hasFace(face)); + } + } + }); + b.setBlockData(block); + return; } } - else { - b.setType(material, false); - } + + b.setType(material, false); } @Override diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java index d6bac1e3c..f1c5725bf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java @@ -66,7 +66,7 @@ public final class ChatUtils { */ public static String humanize(String string) { StringBuilder builder = new StringBuilder(); - String[] segments = string.toLowerCase(Locale.ROOT).split("_"); + String[] segments = PatternUtils.UNDERSCORE.split(string.toLowerCase(Locale.ROOT)); builder.append(Character.toUpperCase(segments[0].charAt(0))).append(segments[0].substring(1)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/PatternUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/PatternUtils.java index c79bae32e..cf61255d9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/PatternUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/PatternUtils.java @@ -21,6 +21,7 @@ public final class PatternUtils { public static final Pattern COMMA = Pattern.compile(","); public static final Pattern SLASH_SEPARATOR = Pattern.compile(" / "); public static final Pattern DASH = Pattern.compile("-"); + public static final Pattern UNDERSCORE = Pattern.compile("_"); public static final Pattern ASCII = Pattern.compile("[A-Za-z \"_]+"); public static final Pattern ALPHANUMERIC = Pattern.compile("[A-Fa-f0-9]+"); public static final Pattern NUMERIC = Pattern.compile("[0-9]+"); From 5a19b186330c22156c4b49091db5ee3217f28495 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sat, 4 Jul 2020 19:04:29 +0200 Subject: [PATCH 33/36] Thunderstorms now count as night for Solar Generators (+ other stuff) --- CHANGELOG.md | 5 ++ .../slimefun4/core/SlimefunRegistry.java | 4 +- .../core/networks/cargo/CargoNet.java | 5 ++ .../networks/cargo/ChestTerminalNetwork.java | 16 +++++ .../services/profiler/PerformanceSummary.java | 25 ++++--- .../services/profiler/SlimefunProfiler.java | 28 ++++++++ .../items/androids/Instruction.java | 4 +- .../items/androids/ProgrammableAndroid.java | 69 ++++++++----------- .../implementation/items/androids/Script.java | 28 ++++++++ .../electric/generators/SolarGenerator.java | 22 +++++- .../items/electric/machines/AutoAnvil.java | 10 +-- .../items/electric/machines/AutoBrewer.java | 15 ++-- .../electric/machines/AutoDisenchanter.java | 13 ++-- .../items/electric/machines/AutoDrier.java | 10 +-- .../electric/machines/AutoEnchanter.java | 15 ++-- .../electric/machines/ElectricDustWasher.java | 16 ++--- .../electric/machines/ElectricGoldPan.java | 17 ++--- .../machines/ElectricIngotPulverizer.java | 7 +- .../machines/HeatedPressureChamber.java | 15 ++-- .../listeners/BlockPhysicsListener.java | 1 + .../listeners/CargoNodeListener.java | 23 +++++-- .../listeners/DebugFishListener.java | 20 +++--- .../slimefun4/utils/ChestMenuUtils.java | 8 +++ .../slimefun4/utils/NumberUtils.java | 4 +- .../Objects/SlimefunItem/SlimefunItem.java | 4 +- .../abstractItems/AGenerator.java | 14 +++- .../Slimefun/api/BlockStorage.java | 58 +++++++++++----- .../listeners/TestCargoNodeListener.java | 4 ++ 28 files changed, 298 insertions(+), 162 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc1826bed..9b0b2f270 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,10 @@ * Performance improvements to the Cargo Net * performance improvements to the Energy Net * Performance improvements to Rainbow Blocks +* Performance improvements to Androids +* performance improvements to Generators and Electric Machines +* Cargo timings will now be attributed to the corresponding node and not the Cargo manager +* Thunderstorms now count as night time for Solar Generators #### Fixes * Fixed #2005 @@ -81,6 +85,7 @@ * Fixed concurrency-related issues with the profiling * Fixed #2066 * Fixed Rainbow Glass Panes not properly connecting to blocks +* Fixed Androids turning in the wrong direction ## Release Candidate 13 (16 Jun 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java index 62aebdfae..3093112fb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java @@ -18,6 +18,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.collections.KeyMap; import io.github.thebusybiscuit.cscorelib2.config.Config; +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.attributes.WitherProof; @@ -25,6 +26,7 @@ import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import io.github.thebusybiscuit.slimefun4.core.researching.Research; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide; import io.github.thebusybiscuit.slimefun4.implementation.guide.CheatSheetSlimefunGuide; import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide; @@ -99,7 +101,7 @@ public class SlimefunRegistry { researchRanks.addAll(cfg.getStringList("research-ranks")); - backwardsCompatibility = cfg.getBoolean("options.backwards-compatibility"); + backwardsCompatibility = cfg.getBoolean("options.backwards-compatibility") || SlimefunPlugin.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_14); freeCreativeResearches = cfg.getBoolean("researches.free-in-creative-mode"); researchFireworks = cfg.getBoolean("researches.enable-fireworks"); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java index 4dd87917a..334e913f7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java @@ -183,6 +183,7 @@ public class CargoNet extends ChestTerminalNetwork { } SlimefunPlugin.getProfiler().newEntry(); + SlimefunPlugin.getProfiler().scheduleEntries(inputNodes.size()); Slimefun.runSync(() -> run(inputs, outputs, chestTerminalInputs, chestTerminalOutputs)); } } @@ -252,12 +253,16 @@ public class CargoNet extends ChestTerminalNetwork { // All operations happen here: Everything gets iterated from the Input Nodes. // (Apart from ChestTerminal Buses) for (Map.Entry entry : inputs.entrySet()) { + long nodeTimestamp = System.nanoTime(); Location input = entry.getKey(); Optional attachedBlock = getAttachedBlock(input.getBlock()); if (attachedBlock.isPresent()) { routeItems(input, attachedBlock.get(), entry.getValue(), outputs); } + + // This will prevent this timings from showing up for the Cargo Manager + timestamp += SlimefunPlugin.getProfiler().closeEntry(entry.getKey(), SlimefunItems.CARGO_INPUT_NODE.getItem(), nodeTimestamp); } // Chest Terminal Code diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java index 744a06b6a..7ccfa5606 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java @@ -32,6 +32,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu; @@ -183,7 +184,10 @@ abstract class ChestTerminalNetwork extends Network { } private void collectImportRequests() { + SlimefunItem item = SlimefunItem.getByID("CT_IMPORT_BUS"); + for (Location bus : imports) { + long timestamp = SlimefunPlugin.getProfiler().newEntry(); BlockMenu menu = BlockStorage.getInventory(bus); if (menu.getItemInSlot(17) == null) { @@ -201,11 +205,16 @@ abstract class ChestTerminalNetwork extends Network { if (menu.getItemInSlot(17) != null) { itemRequests.add(new ItemRequest(bus, 17, menu.getItemInSlot(17), ItemTransportFlow.INSERT)); } + + SlimefunPlugin.getProfiler().closeEntry(bus, item, timestamp); } } private void collectExportRequests() { + SlimefunItem item = SlimefunItem.getByID("CT_EXPORT_BUS"); + for (Location bus : exports) { + long timestamp = SlimefunPlugin.getProfiler().newEntry(); BlockMenu menu = BlockStorage.getInventory(bus); if (menu.getItemInSlot(17) != null) { @@ -236,17 +245,24 @@ abstract class ChestTerminalNetwork extends Network { itemRequests.add(new ItemRequest(bus, 17, items.get(index), ItemTransportFlow.WITHDRAW)); } } + + SlimefunPlugin.getProfiler().closeEntry(bus, item, timestamp); } } private void collectTerminalRequests() { + SlimefunItem item = SlimefunItem.getByID("CHEST_TERMINAL"); + for (Location terminal : terminals) { + long timestamp = SlimefunPlugin.getProfiler().newEntry(); BlockMenu menu = BlockStorage.getInventory(terminal); ItemStack sendingItem = menu.getItemInSlot(TERMINAL_OUT_SLOT); if (sendingItem != null) { itemRequests.add(new ItemRequest(terminal, TERMINAL_OUT_SLOT, sendingItem, ItemTransportFlow.INSERT)); } + + SlimefunPlugin.getProfiler().closeEntry(terminal, item, timestamp); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java index 788b4a9f4..37c24bd57 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java @@ -22,6 +22,8 @@ class PerformanceSummary { // The threshold at which a Block or Chunk is significant enough to appear in /sf timings private static final int VISIBILITY_THRESHOLD = 280_000; + private static final int MIN_ITEMS = 3; + private static final int MAX_ITEMS = 10; // A minecraft server tick is 50ms and Slimefun ticks are stretched across // two ticks (sync and async blocks), so we use 100ms as a reference here @@ -56,7 +58,7 @@ class PerformanceSummary { sender.sendMessage(ChatColor.GOLD + "Performance: " + getPerformanceRating()); sender.sendMessage(""); - summarizeTimings(totalTickedBlocks + " Blocks", sender, items, entry -> { + summarizeTimings(totalTickedBlocks, "block", sender, items, entry -> { int count = profiler.getBlocksOfId(entry.getKey()); String time = NumberUtils.getAsMillis(entry.getValue()); @@ -70,24 +72,25 @@ class PerformanceSummary { } }); - summarizeTimings(chunks.size() + " Chunks", sender, chunks, entry -> { + summarizeTimings(chunks.size(), "chunk", sender, chunks, entry -> { int count = profiler.getBlocksInChunk(entry.getKey()); String time = NumberUtils.getAsMillis(entry.getValue()); - return entry.getKey() + " - " + count + "x Blocks (" + time + ")"; + return entry.getKey() + " - " + count + " block" + (count != 1 ? 's' : "") + " (" + time + ")"; }); - summarizeTimings(plugins.size() + " Plugins", sender, plugins, entry -> { + summarizeTimings(plugins.size(), "plugin", sender, plugins, entry -> { int count = profiler.getBlocksFromPlugin(entry.getKey()); String time = NumberUtils.getAsMillis(entry.getValue()); - return entry.getKey() + " - " + count + "x Blocks (" + time + ")"; + return entry.getKey() + " - " + count + " block" + (count != 1 ? 's' : "") + " (" + time + ")"; }); } - private void summarizeTimings(String prefix, CommandSender sender, Map map, Function, String> formatter) { + private void summarizeTimings(int count, String name, CommandSender sender, Map map, Function, String> formatter) { Stream> stream = map.entrySet().stream(); List> results = stream.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList()); + String prefix = count + " " + name + (count != 1 ? 's' : ""); if (sender instanceof Player) { TextComponent component = new TextComponent(prefix); @@ -96,11 +99,14 @@ class PerformanceSummary { TextComponent hoverComponent = new TextComponent(" (Hover for details)"); hoverComponent.setColor(ChatColor.GRAY); StringBuilder builder = new StringBuilder(); + + int displayed = 0; int hidden = 0; for (Map.Entry entry : results) { - if (entry.getValue() > VISIBILITY_THRESHOLD) { + if (displayed < MAX_ITEMS && (displayed < MIN_ITEMS || entry.getValue() > VISIBILITY_THRESHOLD)) { builder.append("\n").append(ChatColor.YELLOW).append(formatter.apply(entry)); + displayed++; } else { hidden++; @@ -114,16 +120,19 @@ class PerformanceSummary { sender.spigot().sendMessage(component); } else { + int displayed = 0; int hidden = 0; + StringBuilder builder = new StringBuilder(); builder.append(ChatColor.GOLD); builder.append(prefix); builder.append(ChatColor.YELLOW); for (Map.Entry entry : results) { - if (entry.getValue() > VISIBILITY_THRESHOLD) { + if (displayed < MAX_ITEMS && (displayed < MIN_ITEMS || entry.getValue() > VISIBILITY_THRESHOLD)) { builder.append("\n "); builder.append(ChatColor.stripColor(formatter.apply(entry))); + displayed++; } else { hidden++; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java index 7bfa9c733..8c73f0444 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java @@ -73,6 +73,18 @@ public class SlimefunProfiler { return System.nanoTime(); } + /** + * This method schedules a given amount of entries for the future. + * Be careful to {@link #closeEntry(Location, SlimefunItem, long)} all of them again! + * No {@link PerformanceSummary} will be sent until all entires were closed. + * + * @param amount + * The amount of entries that should be scheduled. + */ + public void scheduleEntries(int amount) { + queued.getAndAdd(amount); + } + /** * This method closes a previously started entry. * Make sure to call {@link #newEntry()} to get the timestamp in advance. @@ -87,6 +99,9 @@ public class SlimefunProfiler { * @return The total timings of this entry */ public long closeEntry(Location l, SlimefunItem item, long timestamp) { + Validate.notNull(l, "Location must not be null!"); + Validate.notNull(item, "You need to specify a SlimefunItem!"); + if (timestamp == 0) { return 0; } @@ -261,6 +276,19 @@ public class SlimefunProfiler { return NumberUtils.getAsMillis(totalElapsedTime); } + /** + * This method checks whether the {@link SlimefunProfiler} has collected timings on + * the given {@link Block} + * + * @param b The {@link Block} + * + * @return Whether timings of this {@link Block} have been collected + */ + public boolean hasTimings(Block b) { + Validate.notNull("Cannot get timings for a null Block"); + return timings.containsKey(new ProfiledBlock(b)); + } + public String getTime(Block b) { Validate.notNull("Cannot get timings for a null Block"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java index 8cb11286c..a2c70889b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java @@ -41,12 +41,12 @@ enum Instruction { // Directions TURN_LEFT(AndroidType.NONE, HeadTexture.SCRIPT_LEFT, (android, b, inv, face) -> { int mod = -1; - android.rotate(b, mod); + android.rotate(b, face, mod); }), TURN_RIGHT(AndroidType.NONE, HeadTexture.SCRIPT_RIGHT, (android, b, inv, face) -> { int mod = 1; - android.rotate(b, mod); + android.rotate(b, face, mod); }), // Action - Pickaxe diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java index d963bf588..a43094b52 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java @@ -2,7 +2,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.androids; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.function.Predicate; @@ -16,6 +15,7 @@ import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Dispenser; +import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Rotatable; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -49,6 +49,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.api.BlockStorage; +import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; @@ -198,8 +199,8 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent @Override public void tick(Block b, SlimefunItem item, Config data) { - if (b != null) { - ProgrammableAndroid.this.tick(b); + if (b != null && data != null) { + ProgrammableAndroid.this.tick(b, data); } } @@ -387,23 +388,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent } else { Script script = scripts.get(target); - List lore = new LinkedList<>(); - lore.add("&7by &r" + script.getAuthor()); - lore.add(""); - lore.add("&7Downloads: &r" + script.getDownloads()); - lore.add("&7Rating: " + getScriptRatingPercentage(script)); - lore.add("&a" + script.getUpvotes() + " \u263A &7| &4\u2639 " + script.getDownvotes()); - lore.add(""); - lore.add("&eLeft Click &rto download this Script"); - lore.add("&4(This will override your current Script)"); - - if (script.canRate(p)) { - lore.add("&eShift + Left Click &rto leave a positive Rating"); - lore.add("&eShift + Right Click &rto leave a negative Rating"); - } - - ItemStack item = new CustomItem(getItem(), "&b" + script.getName(), lore.toArray(new String[0])); - menu.addItem(index, item, (player, slot, stack, action) -> { + menu.addItem(index, script.getAsItemStack(this, p), (player, slot, stack, action) -> { if (action.isShiftClicked()) { if (script.isAuthor(player)) { SlimefunPlugin.getLocalization().sendMessage(player, "android.scripts.rating.own", true); @@ -509,11 +494,6 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent return list; } - protected String getScriptRatingPercentage(Script script) { - float percentage = script.getRating(); - return NumberUtils.getColorFromPercentage(percentage) + String.valueOf(percentage) + ChatColor.RESET + "% "; - } - protected void editInstruction(Player p, Block b, String[] script, int index) { ChestMenu menu = new ChestMenu(ChatColor.DARK_AQUA + SlimefunPlugin.getLocalization().getMessage(p, "android.scripts.editor")); ChestMenuUtils.drawBackground(menu, 0, 1, 2, 3, 4, 5, 6, 7, 8); @@ -627,23 +607,26 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent public abstract int getTier(); - protected void tick(Block b) { + protected void tick(Block b, Config data) { if (b.getType() != Material.PLAYER_HEAD) { // The Android was destroyed or moved. return; } - if ("false".equals(BlockStorage.getLocationInfo(b.getLocation(), "paused"))) { + if ("false".equals(data.getString("paused"))) { BlockMenu menu = BlockStorage.getInventory(b); - float fuel = Float.parseFloat(BlockStorage.getLocationInfo(b.getLocation(), "fuel")); + String fuelData = data.getString("fuel"); + float fuel = fuelData == null ? 0 : Float.parseFloat(fuelData); if (fuel < 0.001) { consumeFuel(b, menu); } else { - String[] script = PatternUtils.DASH.split(BlockStorage.getLocationInfo(b.getLocation(), "script")); + String code = data.getString("script"); + String[] script = PatternUtils.DASH.split(code == null ? DEFAULT_SCRIPT : code); - int index = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "index")) + 1; + String indexData = data.getString("index"); + int index = (indexData == null ? 0 : Integer.parseInt(indexData)) + 1; if (index >= script.length) { index = 0; } @@ -653,7 +636,8 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent Instruction instruction = Instruction.valueOf(script[index]); if (getAndroidType().isType(instruction.getRequiredType())) { - BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation")); + String rotationData = data.getString("rotation"); + BlockFace face = rotationData == null ? BlockFace.NORTH : BlockFace.valueOf(rotationData); switch (instruction) { case START: @@ -679,8 +663,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent } } - protected void rotate(Block b, int mod) { - BlockFace current = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation")); + protected void rotate(Block b, BlockFace current, int mod) { int index = POSSIBLE_ROTATIONS.indexOf(current) + mod; if (index == POSSIBLE_ROTATIONS.size()) { @@ -693,7 +676,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent BlockFace rotation = POSSIBLE_ROTATIONS.get(index); Rotatable rotatatable = (Rotatable) b.getBlockData(); - rotatatable.setRotation(rotation); + rotatatable.setRotation(rotation.getOppositeFace()); b.setBlockData(rotatatable); BlockStorage.addBlockInfo(b, "rotation", rotation.name()); } @@ -739,7 +722,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent dispenser.setItem(slot, null); return true; } - else if (SlimefunUtils.isItemSimilar(newFuel, currentFuel, true)) { + else if (SlimefunUtils.isItemSimilar(newFuel, currentFuel, true, false)) { int rest = newFuel.getType().getMaxStackSize() - currentFuel.getAmount(); if (rest > 0) { @@ -766,7 +749,8 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent menu.pushItem(new ItemStack(Material.BUCKET), getOutputSlots()); } - BlockStorage.addBlockInfo(b, "fuel", String.valueOf((int) (fuel.getTicks() * this.getFuelEfficiency()))); + int fuelLevel = (int) (fuel.getTicks() * getFuelEfficiency()); + BlockStorage.addBlockInfo(b, "fuel", String.valueOf(fuelLevel)); break; } } @@ -809,12 +793,15 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent protected void move(Block b, BlockFace face, Block block) { if (block.getY() > 0 && block.getY() < block.getWorld().getMaxHeight() && (block.getType() == Material.AIR || block.getType() == Material.CAVE_AIR)) { - block.setType(Material.PLAYER_HEAD); - Rotatable blockData = (Rotatable) block.getBlockData(); - blockData.setRotation(face.getOppositeFace()); - block.setBlockData(blockData); + BlockData blockData = Material.PLAYER_HEAD.createBlockData(data -> { + if (data instanceof Rotatable) { + Rotatable rotatable = ((Rotatable) data); + rotatable.setRotation(face.getOppositeFace()); + } + }); - SkullBlock.setFromBase64(block, texture); + block.setBlockData(blockData); + Slimefun.runSync(() -> SkullBlock.setFromBase64(block, texture)); b.setType(Material.AIR); BlockStorage.moveBlockInfo(b.getLocation(), block.getLocation()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java index f075fcd86..783cff824 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java @@ -11,11 +11,15 @@ import java.util.logging.Level; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.config.Config; +import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; +import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import me.mrCookieSlime.Slimefun.api.Slimefun; public final class Script { @@ -105,6 +109,30 @@ public final class Script { return !upvoters.contains(p.getUniqueId().toString()) && !downvoters.contains(p.getUniqueId().toString()); } + ItemStack getAsItemStack(ProgrammableAndroid android, Player p) { + List lore = new LinkedList<>(); + lore.add("&7by &r" + getAuthor()); + lore.add(""); + lore.add("&7Downloads: &r" + getDownloads()); + lore.add("&7Rating: " + getScriptRatingPercentage()); + lore.add("&a" + getUpvotes() + " \u263A &7| &4\u2639 " + getDownvotes()); + lore.add(""); + lore.add("&eLeft Click &rto download this Script"); + lore.add("&4(This will override your current Script)"); + + if (canRate(p)) { + lore.add("&eShift + Left Click &rto leave a positive Rating"); + lore.add("&eShift + Right Click &rto leave a negative Rating"); + } + + return new CustomItem(android.getItem(), "&b" + getName(), lore.toArray(new String[0])); + } + + private String getScriptRatingPercentage() { + float percentage = getRating(); + return NumberUtils.getColorFromPercentage(percentage) + String.valueOf(percentage) + ChatColor.RESET + "% "; + } + /** * This method returns the amount of upvotes this {@link Script} has received. * diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java index f66ce9036..aea9f3d5e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java @@ -68,11 +68,18 @@ public abstract class SolarGenerator extends SimpleSlimefunItem return 0; } + boolean isDaytime = isDaytime(world); + + // Performance optimization for daytime-only solar generators + if (!isDaytime && getNightEnergy() == 0) { + return 0; + } + if (!world.isChunkLoaded(l.getBlockX() >> 4, l.getBlockZ() >> 4) || l.getBlock().getLightFromSky() != 15) { return 0; } - if (world.getTime() < 12300 || world.getTime() > 23850) { + if (isDaytime) { return getDayEnergy(); } @@ -86,6 +93,19 @@ public abstract class SolarGenerator extends SimpleSlimefunItem }; } + /** + * This method returns whether a given {@link World} has daytime. + * It will also return false if a thunderstorm is active in this world. + * + * @param world + * The {@link World} to check + * + * @return Whether the given {@link World} has daytime and no active thunderstorm + */ + private boolean isDaytime(World world) { + return !world.hasStorm() && !world.isThundering() && (world.getTime() < 12300 || world.getTime() > 23850); + } + @Override public void preRegister() { super.preRegister(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoAnvil.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoAnvil.java index 14e2a570e..831583010 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoAnvil.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoAnvil.java @@ -57,12 +57,12 @@ public abstract class AutoAnvil extends AContainer { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.isChargable(b)) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return; - ChargableBlock.addCharge(b, -getEnergyConsumption()); - progress.put(b, timeleft - 1); + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; } - else progress.put(b, timeleft - 1); + + ChargableBlock.addCharge(b, -getEnergyConsumption()); + progress.put(b, timeleft - 1); } else { menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java index c25218602..85cb3d60e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java @@ -68,17 +68,12 @@ public abstract class AutoBrewer extends AContainer { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.isChargable(b)) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { - return; - } + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; + } - ChargableBlock.addCharge(b, -getEnergyConsumption()); - progress.put(b, timeleft - 1); - } - else { - progress.put(b, timeleft - 1); - } + ChargableBlock.addCharge(b, -getEnergyConsumption()); + progress.put(b, timeleft - 1); } else { menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java index 92621dafb..ff9b03605 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java @@ -78,15 +78,12 @@ public class AutoDisenchanter extends AContainer { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.isChargable(b)) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { - return; - } - - ChargableBlock.addCharge(b, -getEnergyConsumption()); - progress.put(b, timeleft - 1); + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; } - else progress.put(b, timeleft - 1); + + ChargableBlock.addCharge(b, -getEnergyConsumption()); + progress.put(b, timeleft - 1); } else { menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java index ffdcb4c6c..c25892873 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java @@ -104,12 +104,12 @@ public class AutoDrier extends AContainer implements RecipeDisplayItem { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.isChargable(b)) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return; - ChargableBlock.addCharge(b, -getEnergyConsumption()); - progress.put(b, timeleft - 1); + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; } - else progress.put(b, timeleft - 1); + + ChargableBlock.addCharge(b, -getEnergyConsumption()); + progress.put(b, timeleft - 1); } else { menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java index c0db898c7..afcb3f41f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java @@ -67,17 +67,12 @@ public class AutoEnchanter extends AContainer { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.isChargable(b)) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { - return; - } + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; + } - ChargableBlock.addCharge(b, -getEnergyConsumption()); - progress.put(b, timeleft - 1); - } - else { - progress.put(b, timeleft - 1); - } + ChargableBlock.addCharge(b, -getEnergyConsumption()); + progress.put(b, timeleft - 1); } else { menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricDustWasher.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricDustWasher.java index 011d8fef8..4f037164e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricDustWasher.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricDustWasher.java @@ -59,18 +59,14 @@ public abstract class ElectricDustWasher extends AContainer { if (timeleft > 0 && getSpeed() < 10) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.isChargable(b)) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { - return; - } - ChargableBlock.addCharge(b, -getEnergyConsumption()); - progress.put(b, timeleft - 1); - } - else { - progress.put(b, timeleft - 1); + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; } + + ChargableBlock.addCharge(b, -getEnergyConsumption()); + progress.put(b, timeleft - 1); } - else if (ChargableBlock.isChargable(b)) { + else { if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java index 1564d400e..f8e75b2e4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricGoldPan.java @@ -63,19 +63,14 @@ public abstract class ElectricGoldPan extends AContainer implements RecipeDispla if (timeleft > 0 && getSpeed() < 10) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.isChargable(b)) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { - return; - } + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; + } - ChargableBlock.addCharge(b, -getEnergyConsumption()); - progress.put(b, timeleft - 1); - } - else { - progress.put(b, timeleft - 1); - } + ChargableBlock.addCharge(b, -getEnergyConsumption()); + progress.put(b, timeleft - 1); } - else if (ChargableBlock.isChargable(b)) { + else { if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java index 14993cfac..3fb9aec88 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java @@ -53,10 +53,9 @@ public class ElectricIngotPulverizer extends AContainer implements RecipeDisplay @Override protected void registerDefaultRecipes() { - // this is an extra recipe on top of PostSetup.loadSmelteryRecipes() for converting Vanilla Gold Ingot to Slimefun gold dust - registerRecipe(3, - new ItemStack(Material.GOLD_INGOT), - SlimefunItems.GOLD_DUST); + // this is an extra recipe on top of PostSetup.loadSmelteryRecipes() for converting + // Vanilla Gold Ingot to Slimefun gold dust + registerRecipe(3, new ItemStack(Material.GOLD_INGOT), SlimefunItems.GOLD_DUST); } @Override diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/HeatedPressureChamber.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/HeatedPressureChamber.java index 2fbea6f3b..e13a6b319 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/HeatedPressureChamber.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/HeatedPressureChamber.java @@ -148,17 +148,12 @@ public abstract class HeatedPressureChamber extends AContainer { if (timeleft > 0) { ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.isChargable(b)) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { - return; - } + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; + } - ChargableBlock.addCharge(b, -getEnergyConsumption()); - progress.put(b, timeleft - 1); - } - else { - progress.put(b, timeleft - 1); - } + ChargableBlock.addCharge(b, -getEnergyConsumption()); + progress.put(b, timeleft - 1); } else { menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockPhysicsListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockPhysicsListener.java index 0b69c00a6..51a0018ec 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockPhysicsListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockPhysicsListener.java @@ -89,6 +89,7 @@ public class BlockPhysicsListener implements Listener { public void onBucketUse(PlayerBucketEmptyEvent e) { // Fix for placing water on player heads Location l = e.getBlockClicked().getRelative(e.getBlockFace()).getLocation(); + if (BlockStorage.hasBlockInfo(l)) { e.setCancelled(true); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CargoNodeListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CargoNodeListener.java index 57e19ff1c..ae00e218a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CargoNodeListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/CargoNodeListener.java @@ -9,6 +9,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; /** * This {@link Listener} is solely responsible for preventing Cargo Nodes from being placed @@ -25,15 +26,29 @@ public class CargoNodeListener implements Listener { @EventHandler(ignoreCancelled = true) public void onCargoNodePlace(BlockPlaceEvent e) { - if (e.getBlock().getY() != e.getBlockAgainst().getY() && isCargoNode(new ItemStackWrapper(e.getItemInHand()))) { + if (e.getBlock().getY() != e.getBlockAgainst().getY() && isCargoNode(e.getItemInHand())) { SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "machines.CARGO_NODES.must-be-placed", true); e.setCancelled(true); } } private boolean isCargoNode(ItemStack item) { - return SlimefunUtils.isItemSimilar(item, SlimefunItems.CARGO_INPUT_NODE, false) - || SlimefunUtils.isItemSimilar(item, SlimefunItems.CARGO_OUTPUT_NODE, false) - || SlimefunUtils.isItemSimilar(item, SlimefunItems.CARGO_OUTPUT_NODE_2, false); + if (SlimefunPlugin.getRegistry().isBackwardsCompatible()) { + ItemStackWrapper wrapper = new ItemStackWrapper(item); + + return SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.CARGO_INPUT_NODE, false) + || SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.CARGO_OUTPUT_NODE, false) + || SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.CARGO_OUTPUT_NODE_2, false); + } + + SlimefunItem sfItem = SlimefunItem.getByItem(item); + + if (sfItem == null) { + return false; + } + + return sfItem.getID().equals(SlimefunItems.CARGO_INPUT_NODE.getItemId()) + || sfItem.getID().equals(SlimefunItems.CARGO_OUTPUT_NODE.getItemId()) + || sfItem.getID().equals(SlimefunItems.CARGO_OUTPUT_NODE_2.getItemId()); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java index d2ff3e424..1a3a886e9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/DebugFishListener.java @@ -98,21 +98,21 @@ public class DebugFishListener implements Listener { } if (item.isTicking()) { - p.sendMessage(ChatColors.color("&dTicker: " + greenCheckmark)); + p.sendMessage(ChatColors.color("&dTicking: " + greenCheckmark)); p.sendMessage(ChatColors.color(" &dAsync: &e" + (item.getBlockTicker().isSynchronized() ? redCross : greenCheckmark))); + } + else if (item.getEnergyTicker() != null) { + p.sendMessage(ChatColors.color("&dTicking: &3Indirect")); + } + else { + p.sendMessage(ChatColors.color("&dTicking: " + redCross)); + } + + if (SlimefunPlugin.getProfiler().hasTimings(b)) { p.sendMessage(ChatColors.color(" &dTimings: &e" + SlimefunPlugin.getProfiler().getTime(b))); p.sendMessage(ChatColors.color(" &dTotal Timings: &e" + SlimefunPlugin.getProfiler().getTime(item))); p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + SlimefunPlugin.getProfiler().getTime(b.getChunk()))); } - else if (item.getEnergyTicker() != null) { - p.sendMessage(ChatColors.color("&dTicking: " + "&3Indirect")); - p.sendMessage(ChatColors.color(" &dTimings: &e" + SlimefunPlugin.getProfiler().getTime(b))); - p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + SlimefunPlugin.getProfiler().getTime(b.getChunk()))); - } - else { - p.sendMessage(ChatColors.color("&dTicker: " + redCross)); - p.sendMessage(ChatColors.color("&dTicking: " + redCross)); - } if (ChargableBlock.isChargable(b)) { p.sendMessage(ChatColors.color("&dChargeable: " + greenCheckmark)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java index bebdaf7ab..22fb6b61b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java @@ -6,6 +6,7 @@ import java.util.List; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; @@ -100,6 +101,13 @@ public final class ChestMenuUtils { } public static void updateProgressbar(ChestMenu menu, int slot, int timeLeft, int time, ItemStack indicator) { + Inventory inv = menu.toInventory(); + + // We don't need to update the progress bar if noone is watching :o + if (inv == null || inv.getViewers().isEmpty()) { + return; + } + ItemStack item = indicator.clone(); ItemMeta im = item.getItemMeta(); im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java index 15e9f15fc..dbf6a0c74 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java @@ -77,10 +77,10 @@ public final class NumberUtils { String[] parts = PatternUtils.NUMBER_SEPERATOR.split(number); if (parts.length == 1) { - return parts[0]; + return parts[0] + "ms"; } else { - return parts[0] + ',' + parts[1] + "ms"; + return parts[0] + '.' + parts[1] + "ms"; } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java index 492aa39c1..32f22f887 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java @@ -589,7 +589,7 @@ public class SlimefunItem implements Placeable { } // Backwards compatibility - if (SlimefunPlugin.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_14) || SlimefunPlugin.getRegistry().isBackwardsCompatible()) { + if (SlimefunPlugin.getRegistry().isBackwardsCompatible()) { boolean loreInsensitive = this instanceof Rechargeable || this instanceof SlimefunBackpack || id.equals("BROKEN_SPAWNER") || id.equals("REINFORCED_SPAWNER"); return SlimefunUtils.isItemSimilar(item, this.item, !loreInsensitive); } @@ -863,7 +863,7 @@ public class SlimefunItem implements Placeable { } // Backwards compatibility - if (SlimefunPlugin.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_14) || SlimefunPlugin.getRegistry().isBackwardsCompatible()) { + if (SlimefunPlugin.getRegistry().isBackwardsCompatible()) { // This wrapper improves the heavy ItemStack#getItemMeta() call by caching it. ItemStackWrapper wrapper = new ItemStackWrapper(item); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java index ad84a1ac9..89ff25612 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java @@ -17,6 +17,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.AbstractEnergyProvider; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenuClickHandler; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction; @@ -143,7 +144,7 @@ public abstract class AGenerator extends AbstractEnergyProvider { @Override public double generateEnergy(Location l, SlimefunItem sf, Config data) { BlockMenu inv = BlockStorage.getInventory(l); - boolean chargeable = ChargableBlock.isChargable(l); + boolean chargeable = getCapacity() > 0; int charge = chargeable ? ChargableBlock.getCharge(l) : 0; if (isProcessing(l)) { @@ -169,7 +170,7 @@ public abstract class AGenerator extends AbstractEnergyProvider { else { ItemStack fuel = processing.get(l).getInput(); - if (SlimefunUtils.isItemSimilar(fuel, new ItemStack(Material.LAVA_BUCKET), true) || SlimefunUtils.isItemSimilar(fuel, SlimefunItems.FUEL_BUCKET, true) || SlimefunUtils.isItemSimilar(fuel, SlimefunItems.OIL_BUCKET, true)) { + if (isBucket(fuel)) { inv.pushItem(new ItemStack(Material.BUCKET), getOutputSlots()); } @@ -204,6 +205,15 @@ public abstract class AGenerator extends AbstractEnergyProvider { }; } + private boolean isBucket(ItemStack item) { + if (item == null) { + return false; + } + + ItemStackWrapper wrapper = new ItemStackWrapper(item); + return SlimefunUtils.isItemSimilar(wrapper, new ItemStack(Material.LAVA_BUCKET), true) || SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.FUEL_BUCKET, true) || SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.OIL_BUCKET, true); + } + private MachineFuel findRecipe(BlockMenu menu, Map found) { for (MachineFuel fuel : fuelTypes) { for (int slot : getInputSlots()) { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java index 8f1929daa..70ebe6b12 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java @@ -386,17 +386,29 @@ public class BlockStorage { * @since 4.0 */ public static ItemStack retrieve(Block block) { - if (!hasBlockInfo(block)) return null; + if (!hasBlockInfo(block)) { + return null; + } else { - final SlimefunItem item = SlimefunItem.getByID(getLocationInfo(block.getLocation(), "id")); + SlimefunItem item = SlimefunItem.getByID(getLocationInfo(block.getLocation(), "id")); clearBlockInfo(block); - if (item == null) return null; - else return item.getItem(); + + if (item == null) { + return null; + } + else { + return item.getItem(); + } } } public static Config getLocationInfo(Location l) { BlockStorage storage = getStorage(l.getWorld()); + + if (storage == null) { + return emptyBlockData; + } + Config cfg = storage.storage.get(l); return cfg == null ? emptyBlockData : cfg; } @@ -480,7 +492,14 @@ public class BlockStorage { public static boolean hasBlockInfo(Location l) { BlockStorage storage = getStorage(l.getWorld()); - return storage != null && storage.storage.containsKey(l) && getLocationInfo(l, "id") != null; + + if (storage != null) { + Config cfg = storage.storage.get(l); + return cfg != null && cfg.getString("id") != null; + } + else { + return false; + } } public static void setBlockInfo(Block block, Config cfg, boolean updateTicker) { @@ -489,12 +508,13 @@ public class BlockStorage { public static void setBlockInfo(Location l, Config cfg, boolean updateTicker) { BlockStorage storage = getStorage(l.getWorld()); + if (storage == null) { Slimefun.getLogger().warning("Could not set Block info for non-registered World '" + l.getWorld().getName() + "'. Is some plugin trying to store data in a fake world?"); return; } - storage.storage.put(l, cfg); + storage.storage.put(l, cfg); String id = cfg.getString("id"); if (BlockMenuPreset.isInventory(id)) { @@ -505,8 +525,13 @@ public class BlockStorage { } else if (!storage.hasInventory(l)) { File file = new File(PATH_INVENTORIES + serializeLocation(l) + ".sfi"); - if (file.exists()) storage.inventories.put(l, new BlockMenu(BlockMenuPreset.getPreset(id), l, new io.github.thebusybiscuit.cscorelib2.config.Config(file))); - else storage.loadInventory(l, BlockMenuPreset.getPreset(id)); + + if (file.exists()) { + storage.inventories.put(l, new BlockMenu(BlockMenuPreset.getPreset(id), l, new io.github.thebusybiscuit.cscorelib2.config.Config(file))); + } + else { + storage.loadInventory(l, BlockMenuPreset.getPreset(id)); + } } } @@ -590,8 +615,8 @@ public class BlockStorage { } BlockStorage storage = getStorage(from.getWorld()); - - setBlockInfo(to, getLocationInfo(from), true); + Config previousData = getLocationInfo(from); + setBlockInfo(to, previousData, true); if (storage.inventories.containsKey(from)) { BlockMenu menu = storage.inventories.get(from); @@ -600,7 +625,7 @@ public class BlockStorage { menu.move(to); } - refreshCache(storage, from, getLocationInfo(from).getString("id"), null, true); + refreshCache(storage, from, previousData.getString("id"), null, true); storage.storage.remove(from); String chunkString = locationToChunkString(from); @@ -636,11 +661,9 @@ public class BlockStorage { String chunkString = locationToChunkString(l); if (value != null) { - Set locations = SlimefunPlugin.getRegistry().getActiveTickers().get(chunkString); - if (locations == null) locations = new HashSet<>(); - + Set locations = SlimefunPlugin.getRegistry().getActiveTickers().computeIfAbsent(chunkString, c -> new HashSet<>()); locations.add(l); - SlimefunPlugin.getRegistry().getActiveTickers().put(chunkString, locations); + SlimefunPlugin.getRegistry().getActiveChunks().add(chunkString); } } @@ -797,7 +820,10 @@ public class BlockStorage { public static BlockMenu getInventory(Location l) { BlockStorage storage = getStorage(l.getWorld()); - if (storage == null) return null; + + if (storage == null) { + return null; + } BlockMenu menu = storage.inventories.get(l); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestCargoNodeListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestCargoNodeListener.java index f878de7aa..bdf2e6d9b 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestCargoNodeListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestCargoNodeListener.java @@ -55,6 +55,7 @@ public class TestCargoNodeListener { @ParameterizedTest @SlimefunItemsSource(items = { "CARGO_INPUT_NODE", "CARGO_OUTPUT_NODE", "CARGO_OUTPUT_NODE_2" }) public void testInvalidPlacement(ItemStack item) { + SlimefunPlugin.getRegistry().setBackwardsCompatible(true); Player player = server.addPlayer(); Location l = new Location(player.getWorld(), 190, 50, 400); Block b = l.getBlock(); @@ -63,10 +64,12 @@ public class TestCargoNodeListener { BlockPlaceEvent event = new BlockPlaceEvent(b, new BlockStateMock(), against, item, player, true, EquipmentSlot.HAND); listener.onCargoNodePlace(event); Assertions.assertTrue(event.isCancelled()); + SlimefunPlugin.getRegistry().setBackwardsCompatible(false); } @Test public void testNonCargoNode() { + SlimefunPlugin.getRegistry().setBackwardsCompatible(true); Player player = server.addPlayer(); Location l = new Location(player.getWorld(), 190, 50, 400); Block b = l.getBlock(); @@ -77,6 +80,7 @@ public class TestCargoNodeListener { BlockPlaceEvent event = new BlockPlaceEvent(b, new BlockStateMock(), against, item, player, true, EquipmentSlot.HAND); listener.onCargoNodePlace(event); Assertions.assertFalse(event.isCancelled()); + SlimefunPlugin.getRegistry().setBackwardsCompatible(false); } } From 7d901744fd98ae9a12a85e58c1db6d11d00ae7b5 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sat, 4 Jul 2020 19:15:13 +0200 Subject: [PATCH 34/36] Small improvement --- .../slimefun4/core/networks/cargo/CargoNet.java | 3 +-- .../slimefun4/core/services/profiler/SlimefunProfiler.java | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java index 334e913f7..2919bcb08 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java @@ -182,8 +182,7 @@ public class CargoNet extends ChestTerminalNetwork { display(); } - SlimefunPlugin.getProfiler().newEntry(); - SlimefunPlugin.getProfiler().scheduleEntries(inputNodes.size()); + SlimefunPlugin.getProfiler().scheduleEntries(1 + inputNodes.size()); Slimefun.runSync(() -> run(inputs, outputs, chestTerminalInputs, chestTerminalOutputs)); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java index 8c73f0444..2f22a1f1a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java @@ -82,7 +82,9 @@ public class SlimefunProfiler { * The amount of entries that should be scheduled. */ public void scheduleEntries(int amount) { - queued.getAndAdd(amount); + if (running.get()) { + queued.getAndAdd(amount); + } } /** @@ -280,7 +282,8 @@ public class SlimefunProfiler { * This method checks whether the {@link SlimefunProfiler} has collected timings on * the given {@link Block} * - * @param b The {@link Block} + * @param b + * The {@link Block} * * @return Whether timings of this {@link Block} have been collected */ From 4edc557547817e7181fa8b0f65112721685cfb5a Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 5 Jul 2020 11:46:20 +0200 Subject: [PATCH 35/36] Fixed an issue where moving Androids got stuck --- CHANGELOG.md | 1 + .../core/networks/cargo/CargoUtils.java | 1 + .../services/profiler/PerformanceSummary.java | 50 +++++++++++++------ .../items/androids/AdvancedFarmerAndroid.java | 5 +- .../items/androids/FisherAndroid.java | 5 +- .../items/androids/ProgrammableAndroid.java | 50 +++++++++++-------- .../items/androids/WoodcutterAndroid.java | 14 ++++-- .../items/cargo/ReactorAccessPort.java | 5 +- .../electric/generators/SolarGenerator.java | 2 +- .../items/electric/reactors/Reactor.java | 2 +- .../abstractItems/AContainer.java | 7 ++- .../abstractItems/AGenerator.java | 4 +- .../Slimefun/api/BlockStorage.java | 7 ++- .../api/inventory/DirtyChestMenu.java | 11 ++++ 14 files changed, 108 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b0b2f270..1ec3e8674 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ * performance improvements to Generators and Electric Machines * Cargo timings will now be attributed to the corresponding node and not the Cargo manager * Thunderstorms now count as night time for Solar Generators +* Fixed an issue with moving androids getting stuck #### Fixes * Fixed #2005 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java index d45567123..8d1be290e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java @@ -365,6 +365,7 @@ final class CargoUtils { try { BlockMenu menu = BlockStorage.getInventory(block.getLocation()); + if (menu == null) { return false; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java index 37c24bd57..5262a1745 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java @@ -93,9 +93,20 @@ class PerformanceSummary { String prefix = count + " " + name + (count != 1 ? 's' : ""); if (sender instanceof Player) { - TextComponent component = new TextComponent(prefix); - component.setColor(ChatColor.YELLOW); + TextComponent component = summarizeAsTextComponent(count, prefix, results, formatter); + sender.spigot().sendMessage(component); + } + else { + String text = summarizeAsString(count, prefix, results, formatter); + sender.sendMessage(text); + } + } + private TextComponent summarizeAsTextComponent(int count, String prefix, List> results, Function, String> formatter) { + TextComponent component = new TextComponent(prefix); + component.setColor(ChatColor.YELLOW); + + if (count > 0) { TextComponent hoverComponent = new TextComponent(" (Hover for details)"); hoverComponent.setColor(ChatColor.GRAY); StringBuilder builder = new StringBuilder(); @@ -113,19 +124,27 @@ class PerformanceSummary { } } - builder.append("\n\n&c+ &6").append(hidden).append(" more"); + if (hidden > 0) { + builder.append("\n\n&c+ &6").append(hidden).append(" more"); + } + hoverComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColors.color(builder.toString())))); component.addExtra(hoverComponent); - sender.spigot().sendMessage(component); } - else { - int displayed = 0; - int hidden = 0; - StringBuilder builder = new StringBuilder(); - builder.append(ChatColor.GOLD); - builder.append(prefix); + return component; + } + + private String summarizeAsString(int count, String prefix, List> results, Function, String> formatter) { + int displayed = 0; + int hidden = 0; + + StringBuilder builder = new StringBuilder(); + builder.append(ChatColor.GOLD); + builder.append(prefix); + + if (count > 0) { builder.append(ChatColor.YELLOW); for (Map.Entry entry : results) { @@ -139,11 +158,14 @@ class PerformanceSummary { } } - builder.append("\n+ "); - builder.append(hidden); - builder.append(" more..."); - sender.sendMessage(builder.toString()); + if (hidden > 0) { + builder.append("\n+ "); + builder.append(hidden); + builder.append(" more..."); + } } + + return builder.toString(); } private String getPerformanceRating() { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/AdvancedFarmerAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/AdvancedFarmerAndroid.java index d3cf5d9ce..716d21473 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/AdvancedFarmerAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/AdvancedFarmerAndroid.java @@ -44,10 +44,7 @@ public abstract class AdvancedFarmerAndroid extends FarmerAndroid { if (result.isPresent()) { ItemStack drop = result.get(); menu.pushItem(drop, getOutputSlots()); - - if (menu.fits(drop, getOutputSlots())) { - block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType()); - } + block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType()); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FisherAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FisherAndroid.java index e5e98b92c..5bc7adf33 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FisherAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FisherAndroid.java @@ -62,10 +62,7 @@ public abstract class FisherAndroid extends ProgrammableAndroid { if (ThreadLocalRandom.current().nextInt(100) < 10 * getTier()) { ItemStack drop = fishingLoot.getRandom(); - - if (menu.fits(drop, getOutputSlots())) { - menu.pushItem(drop, getOutputSlots()); - } + menu.pushItem(drop, getOutputSlots()); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java index a43094b52..874b13505 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java @@ -627,38 +627,44 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent String indexData = data.getString("index"); int index = (indexData == null ? 0 : Integer.parseInt(indexData)) + 1; + if (index >= script.length) { index = 0; } - boolean refresh = true; BlockStorage.addBlockInfo(b, "fuel", String.valueOf(fuel - 1)); Instruction instruction = Instruction.valueOf(script[index]); + executeInstruction(instruction, b, menu, data, index); + } + } + } - if (getAndroidType().isType(instruction.getRequiredType())) { - String rotationData = data.getString("rotation"); - BlockFace face = rotationData == null ? BlockFace.NORTH : BlockFace.valueOf(rotationData); + private void executeInstruction(Instruction instruction, Block b, BlockMenu inv, Config data, int index) { + if (getAndroidType().isType(instruction.getRequiredType())) { + String rotationData = data.getString("rotation"); + BlockFace face = rotationData == null ? BlockFace.NORTH : BlockFace.valueOf(rotationData); - switch (instruction) { - case START: - case WAIT: - // Just "waiting" here which means we do nothing - break; - case REPEAT: - BlockStorage.addBlockInfo(b, "index", String.valueOf(0)); - break; - case CHOP_TREE: - refresh = chopTree(b, menu, face); - break; - default: - instruction.execute(this, b, menu, face); - break; - } - } - - if (refresh) { + switch (instruction) { + case START: + case WAIT: + // We are "waiting" here, so we only move a step forward + BlockStorage.addBlockInfo(b, "index", String.valueOf(index)); + break; + case REPEAT: + // "repeat" just means, we reset our index + BlockStorage.addBlockInfo(b, "index", String.valueOf(0)); + break; + case CHOP_TREE: + // We only move to the next step if we finished chopping wood + if (chopTree(b, inv, face)) { BlockStorage.addBlockInfo(b, "index", String.valueOf(index)); } + break; + default: + // We set the index here in advance to fix moving android issues + BlockStorage.addBlockInfo(b, "index", String.valueOf(index)); + instruction.execute(this, b, inv, face); + break; } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/WoodcutterAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/WoodcutterAndroid.java index 735e8bade..60c85e59e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/WoodcutterAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/WoodcutterAndroid.java @@ -7,12 +7,13 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.blocks.Vein; -import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.cscorelib2.materials.MaterialConverter; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; @@ -24,6 +25,8 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; public abstract class WoodcutterAndroid extends ProgrammableAndroid { + private static final int MAX_REACH = 160; + public WoodcutterAndroid(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); } @@ -35,14 +38,17 @@ public abstract class WoodcutterAndroid extends ProgrammableAndroid { @Override protected boolean chopTree(Block b, BlockMenu menu, BlockFace face) { - if (MaterialCollections.getAllLogs().contains(b.getRelative(face).getType())) { - List list = Vein.find(b.getRelative(face), 180, block -> MaterialCollections.getAllLogs().contains(block.getType())); + Block target = b.getRelative(face); + + if (Tag.LOGS.isTagged(target.getType())) { + List list = Vein.find(target, MAX_REACH, block -> Tag.LOGS.isTagged(block.getType())); if (!list.isEmpty()) { Block log = list.get(list.size() - 1); log.getWorld().playEffect(log.getLocation(), Effect.STEP_SOUND, log.getType()); - if (SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), log.getLocation(), ProtectableAction.BREAK_BLOCK)) { + OfflinePlayer owner = Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))); + if (SlimefunPlugin.getProtectionManager().hasPermission(owner, log.getLocation(), ProtectableAction.BREAK_BLOCK)) { breakLog(log, b, menu, face); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java index 3546efb22..4f31246ec 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java @@ -160,7 +160,10 @@ public class ReactorAccessPort extends SlimefunItem { Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ()); SlimefunItem item = BlockStorage.check(reactorL.getBlock()); - if (item instanceof Reactor) return BlockStorage.getInventory(reactorL); + + if (item instanceof Reactor) { + return BlockStorage.getInventory(reactorL); + } return null; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java index aea9f3d5e..f7042c789 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java @@ -71,7 +71,7 @@ public abstract class SolarGenerator extends SimpleSlimefunItem boolean isDaytime = isDaytime(world); // Performance optimization for daytime-only solar generators - if (!isDaytime && getNightEnergy() == 0) { + if (!isDaytime && getNightEnergy() < 0.1) { return 0; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java index d04bf339a..582fd78e5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java @@ -347,7 +347,7 @@ public abstract class Reactor extends AbstractEnergyProvider { } private void createByproduct(Location l, BlockMenu inv, BlockMenu accessPort) { - inv.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + inv.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); if (processing.get(l).getOutput() != null) { inv.pushItem(processing.get(l).getOutput(), getOutputSlots()); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java index 2ce4d01c8..3a0cd7fd5 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java @@ -244,8 +244,11 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock, if (timeleft > 0) { ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(b).getTicks(), getProgressBar()); - if (ChargableBlock.isChargable(b)) { - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return; + if (getCapacity() > 0) { + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; + } + ChargableBlock.addCharge(b, -getEnergyConsumption()); progress.put(b, timeleft - 1); } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java index 89ff25612..e745b3ecb 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java @@ -116,7 +116,7 @@ public abstract class AGenerator extends AbstractEnergyProvider { }); } - preset.addItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler()); + preset.addItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler()); } @Override @@ -174,7 +174,7 @@ public abstract class AGenerator extends AbstractEnergyProvider { inv.pushItem(new ItemStack(Material.BUCKET), getOutputSlots()); } - inv.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + inv.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); progress.remove(l); processing.remove(l); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java index 70ebe6b12..c8900f942 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java @@ -481,7 +481,12 @@ public class BlockStorage { } public static void addBlockInfo(Location l, String key, String value, boolean updateTicker) { - Config cfg = hasBlockInfo(l) ? getLocationInfo(l) : new BlockInfoConfig(); + Config cfg = getLocationInfo(l); + + if (cfg == emptyBlockData) { + cfg = new BlockInfoConfig(); + } + cfg.setValue(key, value); setBlockInfo(l, cfg, updateTicker); } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/DirtyChestMenu.java b/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/DirtyChestMenu.java index 6703fa951..f89bef612 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/DirtyChestMenu.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/DirtyChestMenu.java @@ -6,6 +6,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; @@ -26,6 +27,16 @@ public class DirtyChestMenu extends ChestMenu { this.preset = preset; } + /** + * This method checks whether this {@link DirtyChestMenu} is currently viewed by a {@link Player}. + * + * @return Whether anyone is currently viewing this {@link Inventory} + */ + public boolean hasViewer() { + Inventory inv = toInventory(); + return inv != null && !inv.getViewers().isEmpty(); + } + public void markDirty() { changes++; } From 88dfdfa560ddf47e3c08fcb637ce4acec6c8390e Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 5 Jul 2020 12:04:40 +0200 Subject: [PATCH 36/36] Small improvement to Cargo performance --- .../core/networks/cargo/CargoNet.java | 29 +++++++++---------- .../core/networks/cargo/CargoUtils.java | 5 +++- .../networks/cargo/ChestTerminalNetwork.java | 3 +- .../services/profiler/PerformanceRating.java | 3 +- .../mrCookieSlime/Slimefun/api/Slimefun.java | 8 +++++ 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java index 2919bcb08..d38d1a675 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java @@ -8,13 +8,12 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import org.bukkit.Location; import org.bukkit.block.Block; -import org.bukkit.block.BlockState; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.network.Network; @@ -274,7 +273,8 @@ public class CargoNet extends ChestTerminalNetwork { } private void routeItems(Location inputNode, Block inputTarget, int frequency, Map> outputNodes) { - ItemStackAndInteger slot = CargoUtils.withdraw(inputNode.getBlock(), inputTarget); + AtomicReference inventory = new AtomicReference<>(); + ItemStackAndInteger slot = CargoUtils.withdraw(inputNode.getBlock(), inputTarget, inventory); if (slot == null) { return; @@ -289,9 +289,11 @@ public class CargoNet extends ChestTerminalNetwork { } if (stack != null) { - DirtyChestMenu menu = CargoUtils.getChestMenu(inputTarget); + Object inputInventory = inventory.get(); + + if (inputInventory instanceof DirtyChestMenu) { + DirtyChestMenu menu = (DirtyChestMenu) inputInventory; - if (menu != null) { if (menu.getItemInSlot(previousSlot) == null) { menu.replaceExistingItem(previousSlot, stack); } @@ -299,18 +301,15 @@ public class CargoNet extends ChestTerminalNetwork { inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack); } } - else if (CargoUtils.hasInventory(inputTarget)) { - BlockState state = inputTarget.getState(); - if (state instanceof InventoryHolder) { - Inventory inv = ((InventoryHolder) state).getInventory(); + if (inputInventory instanceof Inventory) { + Inventory inv = (Inventory) inputInventory; - if (inv.getItem(previousSlot) == null) { - inv.setItem(previousSlot, stack); - } - else { - inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack); - } + if (inv.getItem(previousSlot) == null) { + inv.setItem(previousSlot, stack); + } + else { + inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java index 8d1be290e..0d4426c94 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java @@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.core.networks.cargo; import java.util.LinkedList; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import org.bukkit.Material; @@ -153,7 +154,7 @@ final class CargoUtils { return null; } - static ItemStackAndInteger withdraw(Block node, Block target) { + static ItemStackAndInteger withdraw(Block node, Block target, AtomicReference inventory) { DirtyChestMenu menu = getChestMenu(target); if (menu != null) { @@ -162,6 +163,7 @@ final class CargoUtils { if (matchesFilter(node, is)) { menu.replaceExistingItem(slot, null); + inventory.set(menu); return new ItemStackAndInteger(is, slot); } } @@ -189,6 +191,7 @@ final class CargoUtils { if (matchesFilter(node, is)) { inv.setItem(slot, null); + inventory.set(inv); return new ItemStackAndInteger(is, slot); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java index 7ccfa5606..2edafc0e7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java @@ -12,6 +12,7 @@ import java.util.Map; import java.util.Optional; import java.util.Queue; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import org.bukkit.Location; import org.bukkit.Material; @@ -194,7 +195,7 @@ abstract class ChestTerminalNetwork extends Network { Optional target = getAttachedBlock(bus.getBlock()); if (target.isPresent()) { - ItemStackAndInteger stack = CargoUtils.withdraw(bus.getBlock(), target.get()); + ItemStackAndInteger stack = CargoUtils.withdraw(bus.getBlock(), target.get(), new AtomicReference<>()); if (stack != null) { menu.replaceExistingItem(17, stack.getItem()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java index 1b88383f4..2e549ef20 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java @@ -24,7 +24,8 @@ public enum PerformanceRating implements Predicate { OKAY(ChatColor.GREEN, 30), MODERATE(ChatColor.YELLOW, 55), SEVERE(ChatColor.RED, 85), - HURTFUL(ChatColor.DARK_RED, Float.MAX_VALUE); + HURTFUL(ChatColor.DARK_RED, 500), + BAD(ChatColor.DARK_RED, Float.MAX_VALUE); private final ChatColor color; private final float threshold; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java b/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java index 9a8f979a6..97b5c1b65 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java @@ -231,6 +231,10 @@ public final class Slimefun { return null; } + if (SlimefunPlugin.instance == null || !SlimefunPlugin.instance.isEnabled()) { + return null; + } + return Bukkit.getScheduler().runTask(SlimefunPlugin.instance, r); } @@ -240,6 +244,10 @@ public final class Slimefun { return null; } + if (SlimefunPlugin.instance == null || !SlimefunPlugin.instance.isEnabled()) { + return null; + } + return Bukkit.getScheduler().runTaskLater(SlimefunPlugin.instance, r, delay); } } \ No newline at end of file