Compare commits
No commits in common. "d94bbb741786d609dcb253b8fe7946e6c01e3b29" and "639d06b01db4b2c1e78d08c2f0aad3822d9c5421" have entirely different histories.
d94bbb7417
...
639d06b01d
@ -1,27 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.forbiddenItems;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.core.appliance.ApplianceListener;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|
||||||
|
|
||||||
class ForbiddenEntityListener extends ApplianceListener<ForbiddenItems> {
|
|
||||||
@EventHandler
|
|
||||||
public void onEntitySpawn(EntitySpawnEvent event) {
|
|
||||||
if(!this.getAppliance().forbiddenEntities.isForbidden(event.getEntity())) return;
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onEntityInteraction(PlayerInteractEntityEvent event) {
|
|
||||||
if(!this.getAppliance().forbiddenEntities.isForbidden(event.getRightClicked())) return;
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
event.getPlayer().sendActionBar(
|
|
||||||
Component.text()
|
|
||||||
.append(Component.text(event.getRightClicked().getName()))
|
|
||||||
.append(Component.text(" ist eine verbotene Entität!"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.forbiddenItems;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class ForbiddenGroup<TType> {
|
|
||||||
private final Set<Function<TType, Boolean>> forbiddenT;
|
|
||||||
|
|
||||||
public ForbiddenGroup(Set<Function<TType, Boolean>> forbiddenT) {
|
|
||||||
this.forbiddenT = forbiddenT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isForbidden(TType value) {
|
|
||||||
return this.forbiddenT.stream()
|
|
||||||
.anyMatch(test -> test.apply(value));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.forbiddenItems;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.core.appliance.Appliance;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Villager;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ForbiddenItems extends Appliance {
|
|
||||||
public ForbiddenGroup<Material> forbiddenMaterials = new ForbiddenGroup<>(Set.of(
|
|
||||||
(material) -> material.name().startsWith("NETHERITE"),
|
|
||||||
(material) -> material.equals(Material.TOTEM_OF_UNDYING),
|
|
||||||
(material) -> material.equals(Material.END_CRYSTAL),
|
|
||||||
(material) -> material.equals(Material.MACE),
|
|
||||||
(material) -> material.equals(Material.ENCHANTED_GOLDEN_APPLE)
|
|
||||||
));
|
|
||||||
|
|
||||||
public ForbiddenGroup<Entity> forbiddenEntities = new ForbiddenGroup<>(Set.of(
|
|
||||||
(entity) -> {
|
|
||||||
if(!(entity instanceof Villager villager)) return false;
|
|
||||||
return List.of(
|
|
||||||
Villager.Profession.LIBRARIAN,
|
|
||||||
Villager.Profession.ARMORER
|
|
||||||
).contains(villager.getProfession());
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
public ForbiddenGroup<PotionEffect> forbiddenPotions = new ForbiddenGroup<>(Set.of(
|
|
||||||
(potion) -> !potion.getType().equals(PotionEffectType.INSTANT_HEALTH) && potion.getAmplifier() >= 1 // Amplifier starts at 0
|
|
||||||
));
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull List<Listener> listeners() {
|
|
||||||
return List.of(
|
|
||||||
new ForbiddenMaterialListener(),
|
|
||||||
new ForbiddenEntityListener(),
|
|
||||||
new ForbiddenPotionsListener()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.forbiddenItems;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.core.appliance.ApplianceListener;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
class ForbiddenMaterialListener extends ApplianceListener<ForbiddenItems> {
|
|
||||||
@EventHandler
|
|
||||||
public void onPickup(EntityPickupItemEvent event) {
|
|
||||||
this.testAndCancel(event, event.getItem().getItemStack().getType(), event.getEntity());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInventoryInteraction(InventoryClickEvent event) {
|
|
||||||
if(event.getCurrentItem() == null) return;
|
|
||||||
if(List.of(ClickType.DROP, ClickType.CONTROL_DROP).contains(event.getClick())) return;
|
|
||||||
this.testAndCancel(event, event.getCurrentItem().getType(), event.getWhoClicked());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testAndCancel(Cancellable event, Material material, Entity entity) {
|
|
||||||
if(!this.getAppliance().forbiddenMaterials.isForbidden(material)) return;
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
if(entity instanceof Player p) {
|
|
||||||
Component itemName = material.getItemTranslationKey() != null
|
|
||||||
? Component.translatable(material.getItemTranslationKey())
|
|
||||||
: Component.text(material.name());
|
|
||||||
|
|
||||||
p.sendActionBar(
|
|
||||||
Component.text()
|
|
||||||
.append(itemName)
|
|
||||||
.append(Component.text(" ist ein verbotener Gegenstand!"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.forbiddenItems;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.core.appliance.ApplianceListener;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.entity.LingeringPotionSplashEvent;
|
|
||||||
import org.bukkit.event.entity.PotionSplashEvent;
|
|
||||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
class ForbiddenPotionsListener extends ApplianceListener<ForbiddenItems> {
|
|
||||||
@EventHandler
|
|
||||||
public void onPotionSplash(PotionSplashEvent event) {
|
|
||||||
Collection<PotionEffect> effects = event.getPotion().getEffects();
|
|
||||||
|
|
||||||
this.testAndCancel(event, effects, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPotionConsume(PlayerItemConsumeEvent event) {
|
|
||||||
if(!(event.getItem().getItemMeta() instanceof PotionMeta meta)) return;
|
|
||||||
if(meta.getBasePotionType() == null) return;
|
|
||||||
Collection<PotionEffect> effects = meta.getBasePotionType().getPotionEffects();
|
|
||||||
|
|
||||||
this.testAndCancel(event, effects, event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onLingeringPotionSplash(LingeringPotionSplashEvent event) {
|
|
||||||
if(event.getAreaEffectCloud().getBasePotionType() == null) return;
|
|
||||||
Collection<PotionEffect> effects = event.getAreaEffectCloud().getBasePotionType().getPotionEffects();
|
|
||||||
|
|
||||||
this.testAndCancel(event, effects, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testAndCancel(Cancellable event, Collection<PotionEffect> effects, @Nullable Player player) {
|
|
||||||
if(effects.stream().noneMatch(potionEffect -> this.getAppliance().forbiddenPotions.isForbidden(potionEffect))) return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
if(player == null) return;
|
|
||||||
|
|
||||||
player.sendActionBar(
|
|
||||||
Component.text()
|
|
||||||
.append(Component.text("Das ist ein verbotener Trank!"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user