Skip to content

Commit 5b6ed52

Browse files
Rework Potions (#4183)
1 parent b5bfb9a commit 5b6ed52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3392
-1373
lines changed

src/main/java/ch/njol/skript/Skript.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
import org.skriptlang.skript.bukkit.itemcomponents.ItemComponentModule;
103103
import org.skriptlang.skript.bukkit.log.runtime.BukkitRuntimeErrorConsumer;
104104
import org.skriptlang.skript.bukkit.loottables.LootTableModule;
105+
import org.skriptlang.skript.bukkit.potion.PotionModule;
105106
import org.skriptlang.skript.bukkit.registration.BukkitSyntaxInfos;
106107
import org.skriptlang.skript.bukkit.tags.TagModule;
107108
import org.skriptlang.skript.common.CommonModule;
@@ -600,12 +601,12 @@ public void onEnable() {
600601
FurnaceModule.load();
601602
LootTableModule.load();
602603
skript.loadModules(
603-
new DamageSourceModule(),
604-
new EntityModule(),
605-
new ItemComponentModule(),
606-
new BrewingModule(),
607-
new CommonModule()
608-
);
604+
new CommonModule(),
605+
new BrewingModule(),
606+
new EntityModule(),
607+
new DamageSourceModule(),
608+
new ItemComponentModule(),
609+
new PotionModule());
609610
} catch (final Exception e) {
610611
exception(e, "Could not load required .class files: " + e.getLocalizedMessage());
611612
setEnabled(false);

src/main/java/ch/njol/skript/bukkitutil/BukkitUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ public static boolean registryExists(String registry) {
4343
* <p>Paper/Bukkit have 2 different names for the same registry.</p>
4444
*
4545
* @return PotionEffectType Registry
46+
* @deprecated Use {@link Registry#MOB_EFFECT} or {@link Registry#EFFECT} depending on your version.
4647
*/
4748
@SuppressWarnings("NullableProblems")
49+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
4850
public static @Nullable Registry<PotionEffectType> getPotionEffectTypeRegistry() {
4951
if (registryExists("MOB_EFFECT")) { // Paper (1.21.4)
5052
return Registry.MOB_EFFECT;

src/main/java/ch/njol/skript/classes/data/BukkitClasses.java

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import ch.njol.skript.lang.util.SimpleLiteral;
1313
import ch.njol.skript.registrations.Classes;
1414
import ch.njol.skript.util.BlockUtils;
15-
import ch.njol.skript.util.PotionEffectUtils;
1615
import ch.njol.yggdrasil.Fields;
1716
import io.papermc.paper.world.MoonPhase;
1817
import org.bukkit.*;
@@ -29,7 +28,6 @@
2928
import org.bukkit.entity.*;
3029
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
3130
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
32-
import org.bukkit.event.entity.EntityPotionEffectEvent;
3331
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
3432
import org.bukkit.event.entity.EntityTransformEvent.TransformReason;
3533
import org.bukkit.event.entity.EntityUnleashEvent;
@@ -47,8 +45,6 @@
4745
import org.bukkit.inventory.InventoryHolder;
4846
import org.bukkit.inventory.ItemFlag;
4947
import org.bukkit.metadata.Metadatable;
50-
import org.bukkit.potion.PotionEffect;
51-
import org.bukkit.potion.PotionEffectType;
5248
import org.bukkit.util.CachedServerIcon;
5349
import org.bukkit.util.Vector;
5450
import org.jetbrains.annotations.Nullable;
@@ -542,86 +538,6 @@ public String toVariableNameString(InventoryHolder holder) {
542538
.since("1.4.4")
543539
.after("damagecause"));
544540

545-
Classes.registerClass(new ClassInfo<>(PotionEffect.class, "potioneffect")
546-
.user("potion ?effects?")
547-
.name("Potion Effect")
548-
.description("A potion effect, including the potion effect type, tier and duration.")
549-
.usage("speed of tier 1 for 10 seconds")
550-
.since("2.5.2")
551-
.parser(new Parser<PotionEffect>() {
552-
553-
@Override
554-
public boolean canParse(ParseContext context) {
555-
return false;
556-
}
557-
558-
@Override
559-
public String toString(PotionEffect potionEffect, int flags) {
560-
return PotionEffectUtils.toString(potionEffect);
561-
}
562-
563-
@Override
564-
public String toVariableNameString(PotionEffect o) {
565-
return "potion_effect:" + o.getType().getName();
566-
}
567-
568-
})
569-
.serializer(new Serializer<PotionEffect>() {
570-
@Override
571-
public Fields serialize(PotionEffect o) {
572-
Fields fields = new Fields();
573-
fields.putObject("type", o.getType().getName());
574-
fields.putPrimitive("amplifier", o.getAmplifier());
575-
fields.putPrimitive("duration", o.getDuration());
576-
fields.putPrimitive("particles", o.hasParticles());
577-
fields.putPrimitive("ambient", o.isAmbient());
578-
return fields;
579-
}
580-
581-
@Override
582-
public void deserialize(PotionEffect o, Fields f) {
583-
assert false;
584-
}
585-
586-
@Override
587-
protected PotionEffect deserialize(Fields fields) throws StreamCorruptedException {
588-
String typeName = fields.getObject("type", String.class);
589-
assert typeName != null;
590-
PotionEffectType type = PotionEffectType.getByName(typeName);
591-
if (type == null)
592-
throw new StreamCorruptedException("Invalid PotionEffectType " + typeName);
593-
int amplifier = fields.getPrimitive("amplifier", int.class);
594-
int duration = fields.getPrimitive("duration", int.class);
595-
boolean particles = fields.getPrimitive("particles", boolean.class);
596-
boolean ambient = fields.getPrimitive("ambient", boolean.class);
597-
return new PotionEffect(type, duration, amplifier, ambient, particles);
598-
}
599-
600-
@Override
601-
public boolean mustSyncDeserialization() {
602-
return false;
603-
}
604-
605-
@Override
606-
protected boolean canBeInstantiated() {
607-
return false;
608-
}
609-
}));
610-
611-
Registry<PotionEffectType> petRegistry = BukkitUtils.getPotionEffectTypeRegistry();
612-
if (petRegistry != null) {
613-
Classes.registerClass(new RegistryClassInfo<>(PotionEffectType.class, petRegistry, "potioneffecttype", "potion effect types", false)
614-
.user("potion ?effect ?types?")
615-
.name("Potion Effect Type")
616-
.description("A potion effect type, e.g. 'strength' or 'swiftness'.")
617-
.examples("apply swiftness 5 to the player",
618-
"apply potion of speed 2 to the player for 60 seconds",
619-
"remove invisibility from the victim")
620-
.since(""));
621-
} else {
622-
Classes.registerClass(PotionEffectUtils.getLegacyClassInfo());
623-
}
624-
625541
// REMIND make my own damage cause class (that e.g. stores the attacker entity, the projectile, or the attacking block)
626542
Classes.registerClass(new EnumClassInfo<>(DamageCause.class, "damagecause", "damage causes", new ExprDamageCause())
627543
.user("damage ?causes?")
@@ -1000,12 +916,6 @@ public String toVariableNameString(EnchantmentOffer eo) {
1000916
.description("Represents flags that may be applied to hide certain attributes of an item.")
1001917
.since("2.10"));
1002918

1003-
Classes.registerClass(new EnumClassInfo<>(EntityPotionEffectEvent.Cause.class, "entitypotioncause", "entity potion causes")
1004-
.user("(entity )?potion ?effect ?cause")
1005-
.name("Entity Potion Cause")
1006-
.description("Represents the cause of the action of a potion effect on an entity, e.g. arrow, command")
1007-
.since("2.10"));
1008-
1009919
Classes.registerClass(new EnumClassInfo<>(ChangeReason.class, "experiencecooldownchangereason", "experience cooldown change reasons")
1010920
.user("(experience|[e]xp) cooldown change (reason|cause)s?")
1011921
.name("Experience Cooldown Change Reason")

src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import org.bukkit.event.weather.WeatherEvent;
5858
import org.bukkit.event.world.*;
5959
import org.bukkit.inventory.*;
60-
import org.bukkit.potion.PotionEffect;
6160
import org.bukkit.potion.PotionEffectType;
6261
import org.bukkit.potion.PotionType;
6362
import org.jetbrains.annotations.Nullable;
@@ -193,12 +192,6 @@ public final class BukkitEventValues {
193192
return damageEvent == null ? null : damageEvent.getCause();
194193
});
195194

196-
// Entity Potion Effect
197-
EventValues.registerEventValue(EntityPotionEffectEvent.class, PotionEffect.class, EntityPotionEffectEvent::getOldEffect, TIME_PAST);
198-
EventValues.registerEventValue(EntityPotionEffectEvent.class, PotionEffect.class, EntityPotionEffectEvent::getNewEffect);
199-
EventValues.registerEventValue(EntityPotionEffectEvent.class, PotionEffectType.class, EntityPotionEffectEvent::getModifiedType);
200-
EventValues.registerEventValue(EntityPotionEffectEvent.class, EntityPotionEffectEvent.Cause.class, EntityPotionEffectEvent::getCause);
201-
202195
// ProjectileHitEvent
203196
// ProjectileHitEvent#getHitBlock was added in 1.11
204197
if (Skript.methodExists(ProjectileHitEvent.class, "getHitBlock"))

src/main/java/ch/njol/skript/classes/data/DefaultComparators.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.bukkit.event.inventory.InventoryType;
3131
import org.bukkit.inventory.Inventory;
3232
import org.bukkit.inventory.ItemStack;
33-
import org.bukkit.potion.PotionEffectType;
3433
import org.skriptlang.skript.lang.comparator.Comparator;
3534
import org.skriptlang.skript.lang.comparator.Comparators;
3635
import org.skriptlang.skript.lang.comparator.Relation;
@@ -276,8 +275,6 @@ public Relation compare(EntityData e, ItemType i) {
276275

277276
if (e instanceof Item)
278277
return Relation.get(i.isOfType(((Item) e).getItemStack()));
279-
// if (e instanceof ThrownPotion)
280-
// return Relation.get(i.isOfType(Material.POTION.getId(), PotionEffectUtils.guessData((ThrownPotion) e)));
281278
// if (Skript.classExists("org.bukkit.entity.WitherSkull") && e instanceof WitherSkull)
282279
// return Relation.get(i.isOfType(Material.SKULL_ITEM.getId(), (short) 1));
283280
if (e instanceof BoatData)
@@ -637,9 +634,6 @@ public boolean supportsOrdering() {
637634
}
638635
});
639636

640-
// Potion Effect Type
641-
Comparators.registerComparator(PotionEffectType.class, PotionEffectType.class, (one, two) -> Relation.get(one.equals(two)));
642-
643637
// Color - Color
644638
Comparators.registerComparator(Color.class, Color.class, (one, two) -> Relation.get(one.asBukkitColor().equals(two.asBukkitColor())));
645639
Comparators.registerComparator(Color.class, org.bukkit.Color.class, (one, two) -> Relation.get(one.asBukkitColor().equals(two)));

src/main/java/ch/njol/skript/conditions/CondHasPotion.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/main/java/ch/njol/skript/effects/EffPoison.java

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)