mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
[CI skip] Refactoring
This commit is contained in:
parent
55269d587c
commit
ffc0fe41f0
@ -57,14 +57,14 @@ public class BackpackListener implements Listener {
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent e) {
|
||||
ItemStack item = SlimefunPlugin.getUtilities().backpack.get(e.getWhoClicked().getUniqueId());
|
||||
|
||||
if (item != null) {
|
||||
if (e.getClick() == ClickType.NUMBER_KEY) {
|
||||
ItemStack hotbarItem = e.getWhoClicked().getInventory().getItem(e.getHotbarButton());
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(hotbarItem);
|
||||
if ((hotbarItem != null && hotbarItem.getType().toString().contains("SHULKER_BOX")) ||
|
||||
sfItem instanceof SlimefunBackpack)
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
if ((hotbarItem != null && hotbarItem.getType().toString().contains("SHULKER_BOX")) || SlimefunItem.getByItem(hotbarItem) instanceof SlimefunBackpack) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
else if (e.getCurrentItem() != null && e.getCurrentItem().getType() != Material.AIR) {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(e.getCurrentItem());
|
||||
|
@ -18,37 +18,40 @@ import me.mrCookieSlime.Slimefun.api.PlayerProfile;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BackpackInventory;
|
||||
|
||||
public class CoolerListener implements Listener {
|
||||
|
||||
|
||||
public CoolerListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onStarve(FoodLevelChangeEvent e) {
|
||||
if (e.getFoodLevel() < ((Player) e.getEntity()).getFoodLevel()) {
|
||||
Player p = (Player) e.getEntity();
|
||||
|
||||
for (ItemStack item : p.getInventory().getContents()) {
|
||||
if (SlimefunManager.isItemSimilar(item, SlimefunItems.COOLER, false)) {
|
||||
BackpackInventory backpack = PlayerProfile.getBackpack(item);
|
||||
|
||||
if (backpack != null) {
|
||||
Inventory inv = backpack.getInventory();
|
||||
int slot = -1;
|
||||
|
||||
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
ItemStack stack = inv.getItem(i);
|
||||
|
||||
if (stack != null && stack.getType() == Material.POTION && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) {
|
||||
slot = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (slot >= 0) {
|
||||
PotionMeta im = (PotionMeta) inv.getItem(slot).getItemMeta();
|
||||
|
||||
|
||||
for (PotionEffect effect : im.getCustomEffects()) {
|
||||
p.addPotionEffect(effect);
|
||||
}
|
||||
|
||||
|
||||
p.setSaturation(6F);
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_DRINK, 1F, 1F);
|
||||
inv.setItem(slot, null);
|
||||
|
@ -12,11 +12,11 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
public class WaypointListener implements Listener {
|
||||
public class DeathpointListener implements Listener {
|
||||
|
||||
private final SimpleDateFormat format = new SimpleDateFormat("(MMM d, yyyy @ hh:mm)");
|
||||
|
||||
public WaypointListener(SlimefunPlugin plugin) {
|
||||
public DeathpointListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@ -24,8 +24,9 @@ public class WaypointListener implements Listener {
|
||||
public void onDamage(EntityDeathEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
Player p = (Player) e.getEntity();
|
||||
|
||||
if (p.getInventory().containsAtLeast(SlimefunItems.GPS_EMERGENCY_TRANSMITTER, 1)) {
|
||||
Slimefun.getGPSNetwork().addWaypoint(p, "&4Deathpoint &7" + format.format(new Date()), p.getLocation().getBlock().getLocation());
|
||||
Slimefun.getGPSNetwork().addWaypoint(p, SlimefunPlugin.getLocal().getMessage(p, "gps.deathpoint").replace("%date%", format.format(new Date())), p.getLocation().getBlock().getLocation());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.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.api.BlockStorage;
|
||||
|
||||
public class ExplosionsListener implements Listener {
|
||||
|
||||
public ExplosionsListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityExplode(EntityExplodeEvent e) {
|
||||
Iterator<Block> blocks = e.blockList().iterator();
|
||||
|
||||
while (blocks.hasNext()) {
|
||||
Block block = blocks.next();
|
||||
String id = BlockStorage.checkID(block);
|
||||
if (id != null) {
|
||||
blocks.remove();
|
||||
|
||||
if (!id.equalsIgnoreCase("HARDENED_GLASS") && !id.equalsIgnoreCase("WITHER_PROOF_OBSIDIAN") && !id.equalsIgnoreCase("WITHER_PROOF_GLASS") && !id.equalsIgnoreCase("FORCEFIELD_PROJECTOR") && !id.equalsIgnoreCase("FORCEFIELD_RELAY")) {
|
||||
boolean success = true;
|
||||
SlimefunItem sfItem = SlimefunItem.getByID(id);
|
||||
|
||||
SlimefunBlockHandler blockHandler = SlimefunPlugin.getUtilities().blockHandlers.get(sfItem.getID());
|
||||
|
||||
if (blockHandler != null) {
|
||||
success = blockHandler.onBreak(null, block, sfItem, UnregisterReason.EXPLODE);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
BlockStorage.clearBlockInfo(block);
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -40,8 +40,7 @@ public class SlimefunBootsListener implements Listener {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
|
||||
cancelledEvents.put("ENDER_BOOTS", e ->
|
||||
e instanceof EntityDamageByEntityEvent
|
||||
&& ((EntityDamageByEntityEvent) e).getDamager() instanceof EnderPearl
|
||||
e instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent) e).getDamager() instanceof EnderPearl
|
||||
);
|
||||
|
||||
cancelledEvents.put("BOOTS_OF_THE_STOMPER", e -> {
|
||||
|
@ -41,11 +41,11 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class TalismanListener implements Listener {
|
||||
|
||||
|
||||
public TalismanListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onDamageGet(EntityDamageEvent e) {
|
||||
if (!e.isCancelled()) {
|
||||
@ -53,7 +53,7 @@ public class TalismanListener implements Listener {
|
||||
((Player) ((EntityDamageByEntityEvent) e).getDamager()).playSound(((EntityDamageByEntityEvent) e).getDamager().getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.7F, 0.7F);
|
||||
((Player) ((EntityDamageByEntityEvent) e).getDamager()).addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 1));
|
||||
}
|
||||
|
||||
|
||||
if (e.getEntity() instanceof Player) {
|
||||
if (e.getCause() == DamageCause.LAVA) Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_LAVA);
|
||||
if (e.getCause() == DamageCause.DROWNING) Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_WATER);
|
||||
@ -70,15 +70,15 @@ public class TalismanListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final int[] armorSlots = {39, 38, 37, 36};
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onItemBreak(PlayerItemBreakEvent e) {
|
||||
if (Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_ANVIL)) {
|
||||
PlayerInventory inv = e.getPlayer().getInventory();
|
||||
int slot = inv.getHeldItemSlot();
|
||||
|
||||
|
||||
// Did the tool in our hand broke or was it an Armorpiece?
|
||||
if (!inv.getItem(inv.getHeldItemSlot()).equals(e.getBrokenItem())) {
|
||||
for (int s : armorSlots) {
|
||||
@ -88,32 +88,32 @@ public class TalismanListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ItemStack item = e.getBrokenItem().clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
|
||||
if (meta instanceof Damageable) {
|
||||
((Damageable) meta).setDamage(0);
|
||||
}
|
||||
|
||||
|
||||
item.setItemMeta(meta);
|
||||
|
||||
|
||||
int itemSlot = slot;
|
||||
Slimefun.runSync(() -> inv.setItem(itemSlot, item), 1L);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onSprint(PlayerToggleSprintEvent e) {
|
||||
if (e.isSprinting()) {
|
||||
Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_TRAVELLER);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onEnchant(EnchantItemEvent e) {
|
||||
Random random = ThreadLocalRandom.current();
|
||||
|
||||
|
||||
if (Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_MAGICIAN)) {
|
||||
List<String> enchantments = new ArrayList<>();
|
||||
for (Enchantment en : Enchantment.values()) {
|
||||
@ -126,13 +126,15 @@ public class TalismanListener implements Listener {
|
||||
String enchant = enchantments.get(random.nextInt(enchantments.size()));
|
||||
e.getEnchantsToAdd().put(Enchantment.getByKey(NamespacedKey.minecraft(enchant.split("-")[0])), Integer.parseInt(enchant.split("-")[1]));
|
||||
}
|
||||
|
||||
|
||||
if (!e.getEnchantsToAdd().containsKey(Enchantment.SILK_TOUCH) && Enchantment.LOOT_BONUS_BLOCKS.canEnchantItem(e.getItem()) && Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_WIZARD)) {
|
||||
if (e.getEnchantsToAdd().containsKey(Enchantment.LOOT_BONUS_BLOCKS)) e.getEnchantsToAdd().remove(Enchantment.LOOT_BONUS_BLOCKS);
|
||||
Set<Enchantment> enchantments = e.getEnchantsToAdd().keySet();
|
||||
|
||||
for (Enchantment en : enchantments) {
|
||||
if (random.nextInt(100) < 40) e.getEnchantsToAdd().put(en, random.nextInt(3) + 1);
|
||||
}
|
||||
|
||||
e.getItem().addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, random.nextInt(3) + 3);
|
||||
}
|
||||
}
|
||||
@ -148,7 +150,7 @@ public class TalismanListener implements Listener {
|
||||
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
|
||||
int fortune = 1;
|
||||
Random random = ThreadLocalRandom.current();
|
||||
|
||||
|
||||
if (item.getType() != Material.AIR && item.getAmount() > 0) {
|
||||
if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
|
||||
fortune = random.nextInt(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
|
||||
@ -160,7 +162,7 @@ public class TalismanListener implements Listener {
|
||||
if (drops.isEmpty()) {
|
||||
drops = e.getBlock().getDrops();
|
||||
}
|
||||
|
||||
|
||||
for (ItemStack drop : new ArrayList<>(drops)) {
|
||||
if (!drop.getType().isBlock()) {
|
||||
drops.add(new CustomItem(drop, fortune * 2));
|
||||
|
@ -1,14 +1,5 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.GPS.Elevator;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.Teleporter;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -16,34 +7,36 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.GPS.Elevator;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.Teleporter;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
|
||||
public class TeleporterListener implements Listener {
|
||||
|
||||
|
||||
private final BlockFace[] faces = {BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST};
|
||||
|
||||
|
||||
public TeleporterListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true)
|
||||
public void onStarve(PlayerInteractEvent e) {
|
||||
if (e.getAction() != Action.PHYSICAL || e.getClickedBlock() == null) return;
|
||||
|
||||
|
||||
String id = BlockStorage.checkID(e.getClickedBlock());
|
||||
if (id == null) return;
|
||||
|
||||
|
||||
if (id.equals("GPS_ACTIVATION_DEVICE_SHARED") || (id.equals("GPS_ACTIVATION_DEVICE_PERSONAL") && BlockStorage.getLocationInfo(e.getClickedBlock().getLocation(), "owner").equals(e.getPlayer().getUniqueId().toString()))) {
|
||||
SlimefunItem teleporter = BlockStorage.check(e.getClickedBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
|
||||
if (teleporter instanceof Teleporter) {
|
||||
for (BlockFace face : faces) {
|
||||
if (!BlockStorage.check(e.getClickedBlock().getRelative(BlockFace.DOWN).getRelative(face), "GPS_TELEPORTER_PYLON")) return;
|
||||
}
|
||||
|
||||
try {
|
||||
((Teleporter) teleporter).onInteract(e.getPlayer(), e.getClickedBlock().getRelative(BlockFace.DOWN));
|
||||
} catch (Exception x) {
|
||||
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while interacting with a Teleporter", x);
|
||||
}
|
||||
|
||||
((Teleporter) teleporter).onInteract(e.getPlayer(), e.getClickedBlock().getRelative(BlockFace.DOWN));
|
||||
}
|
||||
}
|
||||
else if (id.equals("ELEVATOR_PLATE")) {
|
||||
|
@ -33,7 +33,9 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListe
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BlockListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.CoolerListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.DamageListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.DeathpointListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.EnhancedFurnaceListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.ExplosionsListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.GearListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.GrapplingHookListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.ItemPickupListener;
|
||||
@ -46,7 +48,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.SlimefunGuide
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SoulboundListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.TalismanListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.TeleporterListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.WaypointListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.WorldListener;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
|
||||
import me.mrCookieSlime.Slimefun.GEO.OreGenSystem;
|
||||
@ -224,7 +225,8 @@ public final class SlimefunPlugin extends JavaPlugin {
|
||||
new AndroidKillingListener(this);
|
||||
new NetworkListener(this);
|
||||
new ItemPickupListener(this);
|
||||
new WaypointListener(this);
|
||||
new DeathpointListener(this);
|
||||
new ExplosionsListener(this);
|
||||
|
||||
// Toggleable Listeners for performance
|
||||
if (config.getBoolean("items.talismans")) new TalismanListener(this);
|
||||
|
@ -66,9 +66,9 @@ import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.utils.Utilities;
|
||||
|
||||
public class ItemListener implements Listener {
|
||||
|
||||
|
||||
private final Utilities utilities;
|
||||
|
||||
|
||||
public ItemListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
utilities = SlimefunPlugin.getUtilities();
|
||||
@ -80,7 +80,7 @@ public class ItemListener implements Listener {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onGrindstone(InventoryClickEvent e) {
|
||||
if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.GRINDSTONE) {
|
||||
@ -112,19 +112,19 @@ public class ItemListener implements Listener {
|
||||
if (e.getAction() != Action.LEFT_CLICK_AIR && e.getAction() != Action.LEFT_CLICK_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ItemStack item = e.getItem();
|
||||
if (item != null && !Slimefun.isEnabled(e.getPlayer(), item, true)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void debug(PlayerInteractEvent e) {
|
||||
if (e.getAction() == Action.PHYSICAL || e.getHand() != EquipmentSlot.HAND) return;
|
||||
|
||||
|
||||
Player p = e.getPlayer();
|
||||
|
||||
|
||||
if (SlimefunManager.isItemSimilar(e.getItem(), SlimefunItems.DEBUG_FISH, true)) {
|
||||
e.setCancelled(true);
|
||||
if (p.isOp()) {
|
||||
@ -191,7 +191,7 @@ public class ItemListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onBucketUse(PlayerBucketEmptyEvent e) {
|
||||
// Fix for placing water on player heads
|
||||
@ -227,13 +227,13 @@ public class ItemListener implements Listener {
|
||||
}
|
||||
else {
|
||||
SlimefunItem slimefunItem = SlimefunItem.getByItem(item);
|
||||
|
||||
|
||||
if (slimefunItem != null) {
|
||||
if (Slimefun.hasUnlocked(p, slimefunItem, true)) {
|
||||
slimefunItem.callItemHandler(ItemInteractionHandler.class, handler ->
|
||||
handler.onRightClick(e, p, item)
|
||||
);
|
||||
|
||||
handler.onRightClick(e, p, item)
|
||||
);
|
||||
|
||||
// Open the Backpack (also includes Coolers)
|
||||
if (slimefunItem instanceof SlimefunBackpack) {
|
||||
e.setCancelled(true);
|
||||
@ -241,14 +241,14 @@ public class ItemListener implements Listener {
|
||||
}
|
||||
else if (slimefunItem instanceof MultiTool) {
|
||||
e.setCancelled(true);
|
||||
|
||||
|
||||
List<Integer> modes = ((MultiTool) slimefunItem).getModes();
|
||||
int index = utilities.mode.getOrDefault(p.getUniqueId(), 0);
|
||||
|
||||
if (!p.isSneaking()) {
|
||||
float charge = ItemEnergy.getStoredEnergy(item);
|
||||
float cost = 0.3F;
|
||||
|
||||
|
||||
if (charge >= cost) {
|
||||
p.getEquipment().setItemInMainHand(ItemEnergy.chargeItem(item, -cost));
|
||||
Bukkit.getPluginManager().callEvent(new ItemUseEvent(e.getParentEvent(), SlimefunItem.getByID((String) Slimefun.getItemValue(slimefunItem.getID(), "mode." + modes.get(index) + ".item")).getItem().clone(), e.getClickedBlock()));
|
||||
@ -257,7 +257,7 @@ public class ItemListener implements Listener {
|
||||
else {
|
||||
index++;
|
||||
if (index == modes.size()) index = 0;
|
||||
|
||||
|
||||
SlimefunItem selectedItem = SlimefunItem.getByID((String) Slimefun.getItemValue(slimefunItem.getID(), "mode." + modes.get(index) + ".item"));
|
||||
String itemName = selectedItem != null ? selectedItem.getItemName(): "Unknown";
|
||||
SlimefunPlugin.getLocal().sendMessage(p, "messages.mode-change", true, msg -> msg.replace("%device%", "Multi Tool").replace("%mode%", ChatColor.stripColor(itemName)));
|
||||
@ -276,15 +276,17 @@ public class ItemListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (e.getClickedBlock() != null && BlockStorage.hasBlockInfo(e.getClickedBlock())) {
|
||||
String id = BlockStorage.checkID(e.getClickedBlock());
|
||||
|
||||
if (BlockMenuPreset.isInventory(id) && !canPlaceCargoNodes(p, item, e.getClickedBlock().getRelative(e.getParentEvent().getBlockFace())) && (!p.isSneaking() || item == null || item.getType() == Material.AIR)) {
|
||||
e.setCancelled(true);
|
||||
|
||||
if (BlockStorage.hasUniversalInventory(id)) {
|
||||
UniversalBlockMenu menu = BlockStorage.getUniversalInventory(id);
|
||||
|
||||
if (menu.canOpen(e.getClickedBlock(), p)) {
|
||||
menu.open(p);
|
||||
}
|
||||
@ -294,6 +296,7 @@ public class ItemListener implements Listener {
|
||||
}
|
||||
else if (BlockStorage.getStorage(e.getClickedBlock().getWorld()).hasInventory(e.getClickedBlock().getLocation())) {
|
||||
BlockMenu menu = BlockStorage.getInventory(e.getClickedBlock().getLocation());
|
||||
|
||||
if (menu.canOpen(e.getClickedBlock(), p)) {
|
||||
menu.open(p);
|
||||
}
|
||||
@ -323,7 +326,7 @@ public class ItemListener implements Listener {
|
||||
Player p = e.getPlayer();
|
||||
ItemStack item = e.getItem();
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
|
||||
if (sfItem != null) {
|
||||
if (Slimefun.hasUnlocked(p, sfItem, true)) {
|
||||
if (sfItem instanceof Juice) {
|
||||
@ -379,6 +382,7 @@ public class ItemListener implements Listener {
|
||||
public void onCraft(CraftItemEvent e) {
|
||||
for (ItemStack item : e.getInventory().getContents()) {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
if (sfItem != null && !sfItem.isUseableInWorkbench()) {
|
||||
e.setCancelled(true);
|
||||
SlimefunPlugin.getLocal().sendMessage((Player) e.getWhoClicked(), "workbench.not-enhanced", true);
|
||||
@ -386,11 +390,12 @@ public class ItemListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPrepareCraft(PrepareItemCraftEvent e) {
|
||||
for (ItemStack item : e.getInventory().getContents()) {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
if (sfItem != null && !sfItem.isUseableInWorkbench()) {
|
||||
e.getInventory().setResult(null);
|
||||
break;
|
||||
@ -408,29 +413,30 @@ public class ItemListener implements Listener {
|
||||
}
|
||||
else if (e.getEntity() instanceof Wither) {
|
||||
String id = BlockStorage.checkID(e.getBlock());
|
||||
|
||||
if (id != null && id.startsWith("WITHER_PROOF_")) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onIronGolemHeal(PlayerInteractEntityEvent e) {
|
||||
if (e.getRightClicked() instanceof IronGolem) {
|
||||
PlayerInventory inv = e.getPlayer().getInventory();
|
||||
ItemStack item = null;
|
||||
|
||||
|
||||
if (e.getHand() == EquipmentSlot.HAND) {
|
||||
item = inv.getItemInMainHand();
|
||||
}
|
||||
else if (e.getHand() == EquipmentSlot.OFF_HAND) {
|
||||
item = inv.getItemInOffHand();
|
||||
}
|
||||
|
||||
|
||||
if (item != null && item.getType() == Material.IRON_INGOT && SlimefunItem.getByItem(item) != null) {
|
||||
e.setCancelled(true);
|
||||
SlimefunPlugin.getLocal().sendMessage(e.getPlayer(), "messages.no-iron-golem-heal");
|
||||
|
||||
|
||||
// This is just there to update the Inventory...
|
||||
// Somehow cancelling it isn't enough.
|
||||
if (e.getHand() == EquipmentSlot.HAND) {
|
||||
@ -448,9 +454,9 @@ public class ItemListener implements Listener {
|
||||
if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.ANVIL) {
|
||||
ItemStack slot0 = e.getInventory().getContents()[0];
|
||||
ItemStack slot1 = e.getInventory().getContents()[1];
|
||||
|
||||
|
||||
if (SlimefunManager.isItemSimilar(slot0, SlimefunItems.ELYTRA, true)) return;
|
||||
|
||||
|
||||
if (SlimefunItem.getByItem(slot0) != null && !SlimefunItem.isDisabled(slot0) ||
|
||||
SlimefunItem.getByItem(slot1) != null && !SlimefunItem.isDisabled(slot1) ||
|
||||
|
||||
@ -460,8 +466,8 @@ public class ItemListener implements Listener {
|
||||
SlimefunManager.isItemSimilar(slot1, SlimefunGuide.getItem(SlimefunGuideLayout.BOOK), true) ||
|
||||
SlimefunManager.isItemSimilar(slot1, SlimefunGuide.getItem(SlimefunGuideLayout.CHEST), true)) {
|
||||
|
||||
e.setCancelled(true);
|
||||
SlimefunPlugin.getLocal().sendMessage((Player) e.getWhoClicked(), "anvil.not-working", true);
|
||||
e.setCancelled(true);
|
||||
SlimefunPlugin.getLocal().sendMessage((Player) e.getWhoClicked(), "anvil.not-working", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -469,6 +475,7 @@ public class ItemListener implements Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPreBrew(InventoryClickEvent e) {
|
||||
Inventory inventory = e.getInventory();
|
||||
|
||||
if (inventory instanceof BrewerInventory && inventory.getHolder() instanceof BrewingStand && e.getRawSlot() < inventory.getSize()) {
|
||||
e.setCancelled(SlimefunItem.getByItem(e.getCursor()) != null);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package me.mrCookieSlime.Slimefun.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
@ -22,7 +21,6 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
@ -289,32 +287,4 @@ public class ToolListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityExplode(EntityExplodeEvent e) {
|
||||
Iterator<Block> blocks = e.blockList().iterator();
|
||||
|
||||
while (blocks.hasNext()) {
|
||||
Block block = blocks.next();
|
||||
String id = BlockStorage.checkID(block);
|
||||
if (id != null) {
|
||||
blocks.remove();
|
||||
if (!id.equalsIgnoreCase("HARDENED_GLASS") && !id.equalsIgnoreCase("WITHER_PROOF_OBSIDIAN") && !id.equalsIgnoreCase("WITHER_PROOF_GLASS") && !id.equalsIgnoreCase("FORCEFIELD_PROJECTOR") && !id.equalsIgnoreCase("FORCEFIELD_RELAY")) {
|
||||
boolean success = true;
|
||||
SlimefunItem sfItem = SlimefunItem.getByID(id);
|
||||
|
||||
SlimefunBlockHandler blockHandler = utilities.blockHandlers.get(sfItem.getID());
|
||||
if (blockHandler != null) {
|
||||
success = blockHandler.onBreak(null, block, sfItem, UnregisterReason.EXPLODE);
|
||||
}
|
||||
if (success) {
|
||||
BlockStorage.clearBlockInfo(block);
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -139,6 +139,7 @@ workbench:
|
||||
not-enhanced: '&4You cannot use Slimefun Items in a normal workbench'
|
||||
|
||||
gps:
|
||||
deathpoint: '&4Deathpoint &7%date%'
|
||||
waypoint:
|
||||
new: '&ePlease type in a name for your new waypoint in the chat. &7(Color Codes supported!)'
|
||||
added: '&aSuccessfully added a new waypoint'
|
||||
|
Loading…
Reference in New Issue
Block a user