mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Added Bee Protection to Hazmat Suit.
This commit is contained in:
parent
b138b50d96
commit
cd4a36c519
@ -0,0 +1,59 @@
|
|||||||
|
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Bee;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||||
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
|
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The listener for Hazmat Suit's {@link Bee} sting protection.
|
||||||
|
* Only applied if the whole set is worn.
|
||||||
|
*
|
||||||
|
* @author Linox
|
||||||
|
*
|
||||||
|
* @see Bee
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class HazmatSuitListener implements Listener {
|
||||||
|
|
||||||
|
public HazmatSuitListener(SlimefunPlugin plugin) {
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDamage(EntityDamageByEntityEvent e) {
|
||||||
|
if (!SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_15)) return;
|
||||||
|
|
||||||
|
if (e.getDamager() instanceof Bee) {
|
||||||
|
if (e.getEntity() instanceof Player) {
|
||||||
|
Player p = (Player) e.getEntity();
|
||||||
|
|
||||||
|
int hazmatCount = 0;
|
||||||
|
for (ItemStack armor : p.getInventory().getArmorContents()) {
|
||||||
|
SlimefunItem sfItem = SlimefunItem.getByItem(armor);
|
||||||
|
if (sfItem == null) return;
|
||||||
|
|
||||||
|
String id = sfItem.getID();
|
||||||
|
if (id.equals("SCUBA_HELMET")) hazmatCount++;
|
||||||
|
if (id.equals("HAZMAT_CHESTPLATE")) hazmatCount++;
|
||||||
|
if (id.equals("HAZMAT_LEGGINGS")) hazmatCount++;
|
||||||
|
if (id.equals("RUBBER_BOOTS")) hazmatCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hazmatCount == 4) {
|
||||||
|
e.setDamage(0D);
|
||||||
|
for (ItemStack armor : p.getInventory().getArmorContents()) {
|
||||||
|
ItemUtils.damageItem(armor, 1, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ import java.util.Set;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.HazmatSuitListener;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -237,6 +238,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
|||||||
new WitherListener(this);
|
new WitherListener(this);
|
||||||
new IronGolemListener(this);
|
new IronGolemListener(this);
|
||||||
new PlayerInteractEntityListener(this);
|
new PlayerInteractEntityListener(this);
|
||||||
|
new HazmatSuitListener(this);
|
||||||
|
|
||||||
new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem());
|
new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user