Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeaconEvents + Expressions #7079

Open
wants to merge 34 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
30667ef
Starter Commit
TheAbsolutionism Sep 14, 2024
f70523c
Requested Changes
TheAbsolutionism Sep 15, 2024
8d4bd83
Doc Fix
TheAbsolutionism Sep 15, 2024
d717601
cleanup
TheAbsolutionism Sep 15, 2024
8547c55
Remove Beacon Values
TheAbsolutionism Sep 15, 2024
8781610
Changes
TheAbsolutionism Sep 16, 2024
4fa3dd6
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Sep 19, 2024
9e76bd4
Requested Changes
TheAbsolutionism Sep 20, 2024
7b467d4
Revert Test
TheAbsolutionism Sep 20, 2024
7f35180
Fix JUnit
TheAbsolutionism Sep 20, 2024
c2e7df1
Requested Changes
TheAbsolutionism Sep 21, 2024
4741ff7
Requested Changes
TheAbsolutionism Sep 21, 2024
2cca8b9
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Sep 21, 2024
fcb90c0
:)
TheAbsolutionism Sep 21, 2024
c69e9cb
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Sep 22, 2024
21ef704
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Sep 22, 2024
f6ab79d
Requested Changes
TheAbsolutionism Sep 22, 2024
fb46302
Merge branch 'dev/beacon-events' of https://github.com/TheAbsolutioni…
TheAbsolutionism Sep 22, 2024
48be9ac
More Changes
TheAbsolutionism Sep 22, 2024
5f1e438
Requested Changes
TheAbsolutionism Sep 24, 2024
c9fa0bd
Change
TheAbsolutionism Sep 24, 2024
ef4f467
Requested Changes
TheAbsolutionism Sep 29, 2024
69193ba
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Oct 1, 2024
212ac88
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Oct 2, 2024
4ce0465
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Oct 6, 2024
61fd200
Merge remote-tracking branch 'upstream/dev/feature' into dev/beacon-e…
TheAbsolutionism Oct 13, 2024
041a45f
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Oct 15, 2024
39d31b8
Merge remote-tracking branch 'upstream/dev/feature' into dev/beacon-e…
TheAbsolutionism Oct 27, 2024
b56b63e
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Nov 11, 2024
cdf9f7c
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Nov 16, 2024
27d9291
Miniscule Changes
TheAbsolutionism Nov 23, 2024
e318eef
Merge branch 'dev/feature' into dev/beacon-events
TheAbsolutionism Nov 23, 2024
9fbbe65
Merge remote-tracking branch 'upstream/dev/feature' into dev/beacon-e…
TheAbsolutionism Dec 15, 2024
eaa75e9
Merge remote-tracking branch 'upstream/dev/feature' into dev/beacon-e…
TheAbsolutionism Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 53 additions & 145 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,180 +18,64 @@
*/
package ch.njol.skript.classes.data;

import java.time.Duration;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.Aliases;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.InventoryUtils;
import ch.njol.skript.command.CommandEvent;
import ch.njol.skript.events.bukkit.ScriptEvent;
import ch.njol.skript.events.bukkit.SkriptStartEvent;
import ch.njol.skript.events.bukkit.SkriptStopEvent;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.BlockStateBlock;
import ch.njol.skript.util.BlockUtils;
import ch.njol.skript.util.DelayedChangeBlock;
import ch.njol.skript.util.Direction;
import ch.njol.skript.util.EnchantmentType;
import ch.njol.skript.util.Getter;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.*;
import ch.njol.skript.util.slot.InventorySlot;
import ch.njol.skript.util.slot.Slot;
import com.destroystokyo.paper.event.block.AnvilDamagedEvent;
import com.destroystokyo.paper.event.block.BeaconEffectEvent;
import com.destroystokyo.paper.event.entity.EndermanAttackPlayerEvent;
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
import io.papermc.paper.event.entity.EntityMoveEvent;
import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
import io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent;
import io.papermc.paper.event.player.PlayerTradeEvent;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.FireworkEffect;
import org.bukkit.GameMode;
import org.bukkit.Keyed;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import io.papermc.paper.event.player.*;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.AbstractVillager;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFertilizeEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.block.BellRingEvent;
import org.bukkit.event.block.BellResonateEvent;
import org.bukkit.entity.*;
import org.bukkit.event.block.*;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityDropItemEvent;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.entity.EntityTransformEvent;
import org.bukkit.event.entity.EntityTransformEvent.TransformReason;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.FireworkExplodeEvent;
import org.bukkit.event.entity.HorseJumpEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.entity.ItemMergeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.DragType;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemBreakEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerItemMendEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupArrowEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerExpCooldownChangeEvent;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerExpCooldownChangeEvent.ChangeReason;
import org.bukkit.event.player.PlayerQuitEvent.QuitReason;
import org.bukkit.event.player.PlayerRiptideEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.event.vehicle.*;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.event.weather.WeatherEvent;
import org.bukkit.event.world.ChunkEvent;
import org.bukkit.event.world.LootGenerateEvent;
import org.bukkit.event.world.PortalCreateEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.event.world.WorldEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.Recipe;
import org.bukkit.event.world.*;
import org.bukkit.inventory.*;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author Peter Güttinger
*/
Expand Down Expand Up @@ -1896,19 +1780,18 @@ public TransformReason get(EntityTransformEvent event) {
// BellRingEvent - these are BlockEvents and not EntityEvents, so they have declared methods for getEntity()
if (Skript.classExists("org.bukkit.event.block.BellRingEvent")) {
EventValues.registerEventValue(BellRingEvent.class, Entity.class, new Getter<Entity, BellRingEvent>() {
@Override
@Nullable
public Entity get(BellRingEvent event) {
return event.getEntity();
}
}, EventValues.TIME_NOW);
@Override
public @Nullable Entity get(BellRingEvent event) {
return event.getEntity();
}
}, EventValues.TIME_NOW);

EventValues.registerEventValue(BellRingEvent.class, Direction.class, new Getter<Direction, BellRingEvent>() {
@Override
public Direction get(BellRingEvent event) {
return new Direction(event.getDirection(), 1);
}
}, EventValues.TIME_NOW);
@Override
public Direction get(BellRingEvent event) {
return new Direction(event.getDirection(), 1);
}
}, EventValues.TIME_NOW);
} else if (Skript.classExists("io.papermc.paper.event.block.BellRingEvent")) {
EventValues.registerEventValue(
io.papermc.paper.event.block.BellRingEvent.class, Entity.class,
Expand All @@ -1930,7 +1813,7 @@ public Entity[] get(BellResonateEvent event) {
}
}, EventValues.TIME_NOW);
}

// InventoryMoveItemEvent
EventValues.registerEventValue(InventoryMoveItemEvent.class, Inventory.class, new Getter<Inventory, InventoryMoveItemEvent>() {
@Override
Expand Down Expand Up @@ -2018,5 +1901,30 @@ public Timespan get(PlayerExpCooldownChangeEvent event) {
}
}, EventValues.TIME_PAST);


// BeaconEffectEvent
if (Skript.classExists("com.destroystokyo.paper.event.block.BeaconEffectEvent")) {
EventValues.registerEventValue(BeaconEffectEvent.class, PotionEffectType.class, new Getter<PotionEffectType, BeaconEffectEvent>() {
@Override
public PotionEffectType get(BeaconEffectEvent event) {
return event.getEffect().getType();
}
}, EventValues.TIME_NOW, "Use 'applied effect' in beacon effect events.", BeaconEffectEvent.class);
EventValues.registerEventValue(BeaconEffectEvent.class, Player.class, new Getter<Player, BeaconEffectEvent>() {
@Override
public Player get(BeaconEffectEvent event) {
return event.getPlayer();
}
}, EventValues.TIME_NOW);
}
// PlayerChangeBeaconEffectEvent
if (Skript.classExists("io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent")) {
EventValues.registerEventValue(PlayerChangeBeaconEffectEvent.class, Block.class, new Getter<Block, PlayerChangeBeaconEffectEvent>() {
@Override
public Block get(PlayerChangeBeaconEffectEvent event) {
return event.getBeacon();
}
}, EventValues.TIME_NOW);
}
}
}
69 changes: 69 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtBeaconEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package ch.njol.skript.events;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import com.destroystokyo.paper.event.block.BeaconEffectEvent;
import org.bukkit.event.Event;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.Nullable;

@Name("Beacon Effect")
@Description("Called when a player gets an effect from a beacon.")
@Examples({
"on beacon effect:",
"\tbroadcast applied effect",
"\tbroadcast event-player",
"\tbroadcast event-block",
"on primary beacon effect apply of haste:",
"on application of secondary beacon effect:",
"on beacon effect of speed:"
})
@RequiredPlugins("Paper")
@Since("INSERT VERSION")
public class EvtBeaconEffect extends SkriptEvent {

static {
if (Skript.classExists("com.destroystokyo.paper.event.block.BeaconEffectEvent"))
Skript.registerEvent("Beacon Effect", EvtBeaconEffect.class, BeaconEffectEvent.class,
"[:primary|:secondary] beacon effect [of %-potioneffecttypes%]",
"application of [:primary|:secondary] beacon effect [of %-potioneffecttypes%]",
"[:primary|:secondary] beacon effect apply [of %-potioneffecttypes%]");

}

private @Nullable Literal<PotionEffectType> potionTypes;
private @Nullable Boolean primaryCheck;

@Override
@SuppressWarnings("unchecked")
public boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {
potionTypes = (Literal<PotionEffectType>) exprs[0];
if (parseResult.hasTag("primary")) {
primaryCheck = true;
} else if (parseResult.hasTag("secondary")) {
primaryCheck = false;
}
return true;
}

@Override
public boolean check(Event event) {
if (!(event instanceof BeaconEffectEvent effectEvent))
return false;
if (primaryCheck != null && effectEvent.isPrimary() != primaryCheck)
return false;
if (potionTypes != null)
return potionTypes.check(event, type -> effectEvent.getEffect().getType() == type);
return true;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return (primaryCheck == null ? "" : primaryCheck ? "primary " : "secondary ") +
"beacon effect" + (potionTypes == null ? "" : " of " + potionTypes.toString(event, debug));
}

}
58 changes: 58 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtBeaconToggle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ch.njol.skript.events;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import io.papermc.paper.event.block.BeaconActivatedEvent;
import io.papermc.paper.event.block.BeaconDeactivatedEvent;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Beacon Toggle")
@Description("Called when a beacon is activated or deactivated.")
@Examples({
"on beacon toggle:",
"on beacon activate:",
"on beacon deactivate:"
})
@RequiredPlugins("Paper")
@Since("INSERT VERSION")
public class EvtBeaconToggle extends SkriptEvent {

static {
if (Skript.classExists("io.papermc.paper.event.block.BeaconActivatedEvent"))
Skript.registerEvent("Beacon Toggle", EvtBeaconToggle.class, new Class[] {BeaconActivatedEvent.class, BeaconDeactivatedEvent.class},
"beacon toggle",
"beacon activat(e|ion)",
"beacon deactivat(e|ion)");
}

private boolean isActivate, isToggle;

@Override
public boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {
isToggle = matchedPattern == 0;
isActivate = matchedPattern == 1;
return true;
}

@Override
public boolean check(Event event) {
if (!isToggle) {
if (event instanceof BeaconActivatedEvent) {
return isActivate;
} else if (event instanceof BeaconDeactivatedEvent) {
return !isActivate;
}
}
return true;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "beacon " + (isToggle ? "toggle" : isActivate ? "activate" : "deactivate");
}

}
Loading