Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package org.skriptlang.skript.bukkit.fishing;

import ch.njol.skript.Skript;
import ch.njol.skript.classes.EnumClassInfo;
import ch.njol.skript.registrations.Classes;
import org.bukkit.event.player.PlayerFishEvent;

import java.io.IOException;

public class FishingModule {

public static void load() throws IOException {
// Register the Fishing State enum as a Skript type
Classes.registerClass(new EnumClassInfo<>(PlayerFishEvent.State.class, "fishingstate", "fishing states")
.user("fishing ?states?")
.name("Fishing State")
.description("Represents the different states of a fishing event.")
.since("INSERT VERSION")
);
Comment thread
APickledWalrus marked this conversation as resolved.

Skript.getAddonInstance().loadClasses("org.skriptlang.skript.bukkit.fishing", "elements");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ch.njol.skript.registrations.EventValues;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.entity.FishHook;
import org.bukkit.event.player.PlayerFishEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -17,15 +18,15 @@
public class EvtFish extends SkriptEvent {

private enum State {

FISHING(PlayerFishEvent.State.FISHING, "[fishing] (line|rod) cast", "fishing line cast"),
CAUGHT_FISH(PlayerFishEvent.State.CAUGHT_FISH, "fish (caught|catch)", "fish caught"),
CAUGHT_ENTITY(PlayerFishEvent.State.CAUGHT_ENTITY, "entity (hook[ed]|caught|catch)", "entity hooked"),
IN_GROUND(PlayerFishEvent.State.IN_GROUND, "(bobber|hook) (in|hit) ground", "bobber hit ground"),
FISH_ESCAPE(PlayerFishEvent.State.FAILED_ATTEMPT, "fish (escape|get away)", "fish escape"),
REEL_IN(PlayerFishEvent.State.REEL_IN, "[fishing] (rod|line) reel in", "fishing rod reel in"),
BITE(PlayerFishEvent.State.BITE, "fish bit(e|ing)", "fish bite"),
LURED(getOptional("LURED"), "(fish approach[ing]|(bobber|hook) lure[d])", "fish approaching");
LURED(getOptional("LURED"), "(fish approach[ing]|(bobber|hook) lure[d])", "fish approaching"),
STATE_CHANGE(null, "fishing state change[d]", "fishing state changed");

private final @Nullable PlayerFishEvent.State state;
private final String pattern;
Expand All @@ -49,7 +50,7 @@ private static PlayerFishEvent.State getOptional(String name) {
static {
List<String> patterns = new ArrayList<>();
for (State state : State.values()) {
if (state.state == null)
if (state.state == null && state != State.STATE_CHANGE)
continue;

patterns.add(state.pattern);
Expand All @@ -60,18 +61,30 @@ private static PlayerFishEvent.State getOptional(String name) {
"Called when a player triggers a fishing event.",
"An entity hooked event is triggered when an entity gets caught by a fishing rod.",
"A fish escape event is called when the player fails to click on time, and the fish escapes.",
"A fish approaching event is when the bobber is waiting to be hooked, and a fish is approaching."
"A fish approaching event is when the bobber is waiting to be hooked, and a fish is approaching.",
"A fishing state change event is triggered whenever the fishing state changes."
)
.examples(
"on fishing line cast:",
"\tsend \"You caught a fish!\" to player",
"on fishing state of caught entity:",
"\tpush event-entity vector from entity to player"
"on entity caught:",
"\tpush event-entity vector from entity to player",
"on fishing state change:",
"\tif event-fishing state is fish caught:",
"\t\tbroadcast \"A fish has been caught!\""

)
.requiredPlugins("Paper (bobber lured)")
.since("2.10");
.since("2.10, INSERT VERSION (state change)");

EventValues.registerEventValue(PlayerFishEvent.class, Entity.class, PlayerFishEvent::getCaught);

// Register event value for event-fishing state
EventValues.registerEventValue(PlayerFishEvent.class, PlayerFishEvent.State.class, PlayerFishEvent::getState);

Comment thread
TheMug06 marked this conversation as resolved.
// Register event value for fishing hook
EventValues.registerEventValue(PlayerFishEvent.class, FishHook.class, PlayerFishEvent::getHook);

}

private State state;
Expand All @@ -86,13 +99,12 @@ public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResu
public boolean check(Event event) {
if (!(event instanceof PlayerFishEvent fishEvent))
return false;

return state.state == fishEvent.getState();
return state == State.STATE_CHANGE || state.state == fishEvent.getState();
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return state.toString;
}

}
13 changes: 13 additions & 0 deletions src/main/resources/lang/default.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,17 @@ input keys:
sneak: sneak key, sneaking key
sprint: sprint key, sprinting key

# -- Fishing States --
fishing states:
fishing: fishing line cast, rod cast, fishing rod cast, fishing
caught_fish: fish caught, caught fish
caught_entity: entity caught, caught entity
in_ground: bobber in ground, in ground
failed_attempt: fish escape, fish escaped, failed attempt
reel_in: reel in
bite: bite, fish bite
lured: lured, fish lured

# -- Equipment Slots --
equipment slots:
head: helmet slot, head slot, helmet
Expand Down Expand Up @@ -2669,8 +2680,10 @@ types:
bannerpatterntype: banner pattern type¦s @a
bannerpattern: banner pattern¦s @a
vehicle: vehicle¦s @a
fishingstate: fishing state¦s @a
equipmentslot: equipment slot¦s @an


# Skript
weathertype: weather type¦s @a
entitytype: entity type¦s @an
Expand Down