Skip to content

Commit

Permalink
implement spigot 1.21 api & fix experimental items, minecraft name ma…
Browse files Browse the repository at this point in the history
…ppings
  • Loading branch information
EinfachBeez committed Jul 7, 2024
1 parent 12e803c commit 9db77ec
Show file tree
Hide file tree
Showing 48 changed files with 289 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.codingarea.challenges.plugin.challenges.custom.settings.action.impl;

import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper;
import net.codingarea.challenges.plugin.challenges.custom.settings.action.EntityTargetAction;
import net.codingarea.challenges.plugin.challenges.type.helper.SubSettingsHelper;
import net.codingarea.challenges.plugin.utils.item.DefaultItem;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
Expand All @@ -24,7 +24,8 @@ public HealEntityAction(String name) {
String prefix = DefaultItem.getItemPrefix();
for (int i = 1; i < 21; i++) {
builder.addSetting(
String.valueOf(i), new ItemBuilder(MaterialWrapper.RED_DYE, prefix + "§7" + (i / 2f) + " §c❤").setAmount(i).build());
String.valueOf(i), new ItemBuilder(
MinecraftNameWrapper.RED_DYE, prefix + "§7" + (i / 2f) + " §c❤").setAmount(i).build());
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.codingarea.challenges.plugin.challenges.custom.settings.action.impl;

import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper;
import net.codingarea.challenges.plugin.challenges.custom.settings.action.PlayerTargetAction;
import net.codingarea.challenges.plugin.challenges.implementation.setting.MaxHealthSetting;
import net.codingarea.challenges.plugin.challenges.type.abstraction.AbstractChallenge;
import net.codingarea.challenges.plugin.challenges.type.helper.ChallengeHelper;
import net.codingarea.challenges.plugin.challenges.type.helper.SubSettingsHelper;
import net.codingarea.challenges.plugin.content.Message;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper;
import org.bukkit.Material;
import org.bukkit.entity.Player;

Expand All @@ -23,7 +23,7 @@ public ModifyMaxHealthAction(String name) {
super(name, SubSettingsHelper.createEntityTargetSettingsBuilder(false, true)
.createValueChild().fill(builder -> {
builder.addModifierSetting("health_offset",
new ItemBuilder(MaterialWrapper.RED_DYE,
new ItemBuilder(MinecraftNameWrapper.RED_DYE,
Message.forName("item-custom-action-max_health-offset")),
0, -20, 20,
integer -> "", integer -> "HP §8(§e" + (integer / 2f) + " §c❤§8)");
Expand All @@ -32,7 +32,7 @@ public ModifyMaxHealthAction(String name) {

@Override
public Material getMaterial() {
return MaterialWrapper.RED_DYE;
return MinecraftNameWrapper.RED_DYE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.codingarea.challenges.plugin.utils.bukkit.misc.BukkitStringUtils;
import net.codingarea.challenges.plugin.utils.item.DefaultItem;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -19,7 +20,7 @@ public class ConsumeItemTrigger extends ChallengeTrigger {

public ConsumeItemTrigger(String name) {
super(name, SubSettingsBuilder.createChooseMultipleItem(SubSettingsHelper.ITEM).fill(builder -> {
for (Material material : Material.values()) {
for (Material material : ExperimentalUtils.getMaterials()) {
if (material.isEdible()) {
builder.addSetting(material.name(), new ItemBuilder(material, DefaultItem.getItemPrefix() + BukkitStringUtils.getItemName(material).toPlainText()).build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.codingarea.challenges.plugin.challenges.custom.settings.trigger.ChallengeTrigger;
import net.codingarea.challenges.plugin.challenges.type.helper.SubSettingsHelper;
import net.codingarea.challenges.plugin.utils.misc.BlockUtils;
import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -37,7 +38,7 @@ public void onMove(PlayerMoveEvent event) {

Material type = blockBelow.getType();

List<Material> materials = new LinkedList<>(Arrays.asList(Material.values()));
List<Material> materials = new LinkedList<>(Arrays.asList(ExperimentalUtils.getMaterials()));
materials.remove(type);
materials.removeIf(material -> !material.isBlock() || !material.isItem());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package net.codingarea.challenges.plugin.challenges.implementation.challenge;

import net.codingarea.challenges.plugin.utils.item.ItemUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nonnull;
import net.anweisen.utilities.bukkit.utils.misc.BukkitReflectionUtils;
import net.codingarea.challenges.plugin.Challenges;
import net.codingarea.challenges.plugin.challenges.type.abstraction.RandomizerSetting;
Expand All @@ -9,13 +12,10 @@
import net.codingarea.challenges.plugin.management.blocks.BlockDropManager.DropPriority;
import net.codingarea.challenges.plugin.management.menu.MenuType;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.item.ItemUtils;
import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils;
import org.bukkit.Material;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* @author anweisen | https://github.com/anweisen
* @since 2.0
Expand All @@ -36,11 +36,11 @@ public ItemBuilder createDisplayItem() {
protected void reloadRandomization() {
BlockDropManager manager = Challenges.getInstance().getBlockDropManager();

List<Material> blocks = new ArrayList<>(Arrays.asList(Material.values()));
List<Material> blocks = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials()));
blocks.removeIf(material -> !ItemUtils.isObtainableInSurvival(material) || !material.isBlock() || BukkitReflectionUtils.isAir(material));
random.shuffle(blocks);

List<Material> drops = new ArrayList<>(Arrays.asList(Material.values()));
List<Material> drops = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials()));
drops.removeIf(material -> !material.isItem() || !ItemUtils.isObtainableInSurvival(material));
random.shuffle(drops);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.codingarea.challenges.plugin.content.Message;
import net.codingarea.challenges.plugin.management.menu.MenuType;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -35,11 +36,11 @@ public ItemBuilder createDisplayItem() {
@Override
protected void reloadRandomization() {

List<Material> from = new ArrayList<>(Arrays.asList(Material.values()));
List<Material> from = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials()));
from.removeIf(material -> !material.isItem() || !ItemUtils.isObtainableInSurvival(material));
random.shuffle(from);

List<Material> to = new ArrayList<>(Arrays.asList(Material.values()));
List<Material> to = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials()));
to.removeIf(material -> !material.isItem() || !ItemUtils.isObtainableInSurvival(material));
random.shuffle(to);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.codingarea.challenges.plugin.challenges.implementation.challenge;

import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper;
import net.anweisen.utilities.common.annotations.Since;
import net.anweisen.utilities.common.config.Document;
import net.codingarea.challenges.plugin.Challenges;
Expand All @@ -12,6 +11,7 @@
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.BlockUtils;
import net.codingarea.challenges.plugin.utils.misc.InventoryUtils;
import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -84,7 +84,7 @@ protected void onDisable() {
@NotNull
@Override
public ItemBuilder createDisplayItem() {
return new ItemBuilder(MaterialWrapper.SIGN, Message.forName("item-five-hundred-blocks-challenges"));
return new ItemBuilder(MinecraftNameWrapper.SIGN, Message.forName("item-five-hundred-blocks-challenges"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.codingarea.challenges.plugin.management.server.scoreboard.ChallengeBossBar.BossBarInstance;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.BlockUtils;
import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils;
import net.codingarea.challenges.plugin.utils.misc.NameHelper;
import org.bukkit.Material;
import org.bukkit.boss.BarColor;
Expand Down Expand Up @@ -95,7 +96,7 @@ protected void broadcastSuccessMessage() {

@Override
protected void chooseForcing() {
Material[] materials = Arrays.stream(Material.values())
Material[] materials = Arrays.stream(ExperimentalUtils.getMaterials())
.filter(Material::isBlock)
.filter(ItemUtils::isObtainableInSurvival)
.filter(material -> !BlockUtils.isTooHardToGet(material))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.codingarea.challenges.plugin.spigot.events.PlayerPickupItemEvent;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.BlockUtils;
import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils;
import net.codingarea.challenges.plugin.utils.misc.NameHelper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand Down Expand Up @@ -93,7 +94,7 @@ protected void broadcastSuccessMessage(@Nonnull Player player) {

@Override
protected void chooseForcing() {
List<Material> items = new ArrayList<>(Arrays.asList(Material.values()));
List<Material> items = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials()));
items.removeIf(material -> !ItemUtils.isObtainableInSurvival(material));
items.removeIf(material -> !material.isItem());
items.removeIf(BlockUtils::isTooHardToGet);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package net.codingarea.challenges.plugin.challenges.implementation.challenge;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.anweisen.utilities.common.annotations.Since;
import net.codingarea.challenges.plugin.challenges.type.abstraction.SettingModifier;
import net.codingarea.challenges.plugin.challenges.type.helper.ChallengeHelper;
import net.codingarea.challenges.plugin.content.Message;
import net.codingarea.challenges.plugin.management.menu.MenuType;
import net.codingarea.challenges.plugin.management.menu.generator.categorised.SettingCategory;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
Expand All @@ -15,10 +18,6 @@
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* @author KxmischesDomi | https://github.com/kxmischesdomi
Expand Down Expand Up @@ -63,19 +62,19 @@ public void onMove(@Nonnull PlayerMoveEvent event) {
if (event.getTo() == null) return;
if (event.getTo().getY() == event.getFrom().getY() && event.getTo().getX() == event.getFrom().getX() && event.getTo().getZ() == event.getFrom().getZ())
return;
PotionEffect effect = event.getPlayer().getPotionEffect(PotionEffectType.SLOW);
PotionEffect effect = event.getPlayer().getPotionEffect(MinecraftNameWrapper.SLOWNESS);
if (effect == null || effect.getAmplifier() != 255) return;
event.setCancelled(true);
}

public void setFreeze(LivingEntity entity, double damage) {
int time = (int) (damage * getValue() * 20 / 2);
PotionEffect effect = entity.getPotionEffect(PotionEffectType.SLOW);
entity.removePotionEffect(PotionEffectType.SLOW);
PotionEffect effect = entity.getPotionEffect(MinecraftNameWrapper.SLOWNESS);
entity.removePotionEffect(MinecraftNameWrapper.SLOWNESS);

if (effect != null && effect.getAmplifier() == 255) time += effect.getDuration();

entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, time, 255));
entity.addPotionEffect(new PotionEffect(MinecraftNameWrapper.SLOWNESS, time, 255));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.codingarea.challenges.plugin.management.menu.generator.categorised.SettingCategory;
import net.codingarea.challenges.plugin.management.scheduler.task.ScheduledTask;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
Expand Down Expand Up @@ -58,7 +59,7 @@ private void updateSickness(@Nonnull Player player) {

List<Entity> entities = getNearbyTargets(player, 2);
if (entities.isEmpty()) {
player.removePotionEffect(PotionEffectType.CONFUSION);
player.removePotionEffect(MinecraftNameWrapper.NAUSEA);
return;
}

Expand All @@ -67,7 +68,7 @@ private void updateSickness(@Nonnull Player player) {
if (player.getLocation().distance(currentEntity.getLocation()) <= 1.5) value = 2;
}

player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, Integer.MAX_VALUE, 15));
player.addPotionEffect(new PotionEffect(MinecraftNameWrapper.NAUSEA, Integer.MAX_VALUE, 15));
if (value == 1) {
if (!player.hasPotionEffect(PotionEffectType.WITHER)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 5 * 20, 2));
Expand All @@ -80,7 +81,7 @@ private void updateSickness(@Nonnull Player player) {
}

private void removeEffects(@Nonnull Player player) {
player.removePotionEffect(PotionEffectType.CONFUSION);
player.removePotionEffect(MinecraftNameWrapper.NAUSEA);
player.removePotionEffect(PotionEffectType.POISON);
player.removePotionEffect(PotionEffectType.WITHER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.codingarea.challenges.plugin.utils.bukkit.jumpgeneration.RandomJumpGenerator;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.BlockUtils;
import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper;
import net.codingarea.challenges.plugin.utils.misc.NameHelper;
import net.codingarea.challenges.plugin.utils.misc.ParticleUtils;
import org.bukkit.*;
Expand Down Expand Up @@ -207,7 +208,8 @@ public void loadGameState(@Nonnull Document document) {
@ScheduledTask(ticks = 20, timerPolicy = TimerPolicy.ALWAYS, worldPolicy = ExtraWorldPolicy.USED)
public void spawnParticles() {
if (targetBlock == null) return;
ParticleUtils.spawnParticleCircle(targetBlock.getLocation().add(0.5, 1.05, 0.5), Particle.SPELL_INSTANT, 13, 0.35);
ParticleUtils.spawnParticleCircle(targetBlock.getLocation().add(0.5, 1.05, 0.5),
MinecraftNameWrapper.INSTANT_EFFECT, 13, 0.35);
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.codingarea.challenges.plugin.management.blocks.BlockDropManager.DropPriority;
import net.codingarea.challenges.plugin.management.menu.MenuType;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils;
import org.bukkit.Material;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected void onDisable() {
}

protected void reloadChances() {
Arrays.stream(Material.values()).filter(Material::isBlock).forEach(block -> {
Arrays.stream(ExperimentalUtils.getMaterials()).filter(Material::isBlock).forEach(block -> {
Challenges.getInstance().getBlockDropManager().setDropChance(block, DropPriority.CHANCE, () -> random.nextInt(10) < getValue());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.codingarea.challenges.plugin.management.menu.generator.categorised.SettingCategory;
import net.codingarea.challenges.plugin.utils.bukkit.command.PlayerCommand;
import net.codingarea.challenges.plugin.utils.item.ItemBuilder;
import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils;
import net.codingarea.challenges.plugin.utils.misc.InventoryUtils;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
Expand Down Expand Up @@ -77,7 +78,7 @@ public ItemBuilder createDisplayItem() {

@Override
protected void onEnable() {
materials = Arrays.stream(Material.values())
materials = Arrays.stream(ExperimentalUtils.getMaterials())
.filter(Material::isItem)
.filter(ItemUtils::isObtainableInSurvival)
.collect(Collectors.toList());
Expand Down
Loading

0 comments on commit 9db77ec

Please sign in to comment.