Skip to content

Commit

Permalink
First cleanup pass
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus committed Jan 17, 2025
1 parent 247b9c3 commit 15966d8
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 200 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ repositories {
}

dependencies {
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.600'
implementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.1'
implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.19.4-R0.1-SNAPSHOT'
implementation (group: 'com.github.SkriptLang', name: 'Skript', version: '2.10.0') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ch.njol.skript.util.EnumUtils;
import io.github.apickledwalrus.skriptgui.gui.GUI;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

public class SkriptClasses {

Expand All @@ -20,7 +20,7 @@ public SkriptClasses() {
.description("Represents a skript-gui GUI")
.examples("See the GUI creation section.")
.since("1.0")
.parser(new Parser<GUI>() {
.parser(new Parser<>() {
@Override
public boolean canParse(ParseContext ctx) {
return false;
Expand All @@ -29,7 +29,7 @@ public boolean canParse(ParseContext ctx) {
@Override
public String toString(GUI gui, int flags) {
return gui.getInventory().getType().getDefaultTitle().toLowerCase()
+ " gui named " + gui.getName()
+ " gui named " + gui.getName()
+ " with " + gui.getInventory().getSize() / 9 + " rows"
+ " and shape " + gui.getRawShape();
}
Expand All @@ -49,18 +49,12 @@ public String toVariableNameString(GUI gui) {
.description("Represents the slot type in an Inventory Click Event.")
.examples(slotTypes.getAllNames())
.since("1.0.0")
.parser(new Parser<SlotType>() {
.parser(new Parser<>() {
@Override
@Nullable
public SlotType parse(String expr, ParseContext context) {
public @Nullable SlotType parse(String expr, ParseContext context) {
return slotTypes.parse(expr);
}

@Override
public boolean canParse(ParseContext ctx) {
return true;
}

@Override
public String toString(SlotType type, int flags) {
return slotTypes.toString(type, flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

public class SkriptGUI extends JavaPlugin {

@SuppressWarnings("NotNullFieldNotInitialized")
private static SkriptGUI instance;
@SuppressWarnings("NotNullFieldNotInitialized")
private static GUIManager manager;

@Override
Expand Down Expand Up @@ -51,7 +49,7 @@ public void onEnable() {
new SkriptClasses(); // Register ClassInfos
new SkriptConverters(); // Register Converters
} catch (IOException e) {
getLogger().severe("An error occured while trying to load the addon's elements. The addon will be disabled.");
getLogger().severe("An error occurred while trying to load the addon's elements. The addon will be disabled.");
getLogger().severe("Printing StackTrace:");
e.printStackTrace();
getServer().getPluginManager().disablePlugin(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,37 @@
package io.github.apickledwalrus.skriptgui.elements.conditions;

import ch.njol.skript.conditions.base.PropertyCondition;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;

import io.github.apickledwalrus.skriptgui.SkriptGUI;
import org.eclipse.jdt.annotation.Nullable;

@Name("Has GUI")
@Description("Checks whether the given player(s) has/have a GUI open.")
@Description("Checks whether a player has a GUI open.")
@Examples({
"command /guiviewers: # Returns a list of all players with a GUI open.",
"command /guiviewers: # Prints a list of all players with a GUI open.",
"\tset {_viewers::*} to all players where [input has a gui]",
"\tsend \"GUI Viewers: %{_viewers::*}%\" to player"
})
@Since("1.0.0")
public class CondHasGUI extends Condition {
public class CondHasGUI extends PropertyCondition<Player> {

static {
Skript.registerCondition(CondHasGUI.class,
"%players% (has|have) a gui [open]",
"%players% (doesn't|does not|do not|don't) have a gui [open]"
);
}

@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<Player> players;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean kleenean, ParseResult parseResult) {
players = (Expression<Player>) exprs[0];
setNegated(matchedPattern == 1);
return true;
register(CondHasGUI.class, PropertyType.HAVE, "a gui [open]", "players");
}

@Override
public boolean check(Event e) {
return players.check(e, p -> SkriptGUI.getGUIManager().hasGUI(p), isNegated());
public boolean check(Player player) {
return SkriptGUI.getGUIManager().hasGUI(player);
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return players.toString(e, debug) + (!isNegated() ? " has/have " : " do not/don't have ") + " a gui open";
protected String getPropertyName() {
return "a gui open";
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SectionSkriptEvent;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import io.github.apickledwalrus.skriptgui.SkriptGUI;
import io.github.apickledwalrus.skriptgui.elements.sections.SecGUIOpenClose;
import io.github.apickledwalrus.skriptgui.gui.GUI;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

@Name("Cancel GUI Close")
@Description({
"Cancels or uncancels the closing of a GUI.",
" This effect can be used within a GUI close section.",
" A 1 tick delay is applied by this effect after the code has run."
"This effect can be used within a GUI close section.",
"A 1 tick delay is applied by this effect after the code has run."
})
@Examples({
"create a gui with virtual chest inventory with 3 rows named \"My GUI\":",
Expand All @@ -33,33 +32,33 @@ public class EffCancelGUIClose extends Effect {

static {
Skript.registerEffect(EffCancelGUIClose.class,
"(cancel|uncancel) [the] gui clos(e|ing)"
"(:cancel|uncancel) [the] gui clos(e|ing)"
);
}

private boolean cancel;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
SkriptEvent skriptEvent = getParser().getCurrentSkriptEvent();
if (!(skriptEvent instanceof SectionSkriptEvent) || !((SectionSkriptEvent) skriptEvent).isSection(SecGUIOpenClose.class)) {
if (!(getParser().getCurrentStructure() instanceof SectionSkriptEvent sectionEvent)
|| !(sectionEvent.isSection(SecGUIOpenClose.class))) {
Skript.error("Cancelling or uncancelling the closing of a GUI can only be done within a GUI close section.");
return false;
}
cancel = parseResult.mark == 0;
cancel = parseResult.hasTag("cancel");
return true;
}

@Override
protected void execute(Event e) {
GUI gui = SkriptGUI.getGUIManager().getGUI(e);
protected void execute(Event event) {
GUI gui = SkriptGUI.getGUIManager().getGUI(event);
if (gui != null) {
gui.setCloseCancelled(cancel);
}
}

@Override
public String toString(@Nullable Event e, boolean debug) {
public String toString(@Nullable Event event, boolean debug) {
return (cancel ? "cancel" : "uncancel") + " the gui closing";
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.github.apickledwalrus.skriptgui.SkriptGUI;
import io.github.apickledwalrus.skriptgui.gui.GUI;
import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

@Name("GUI of Player")
@Description("The GUI that the player currently has open.")
Expand All @@ -24,8 +24,7 @@ public class ExprGUI extends SimplePropertyExpression<Player, GUI> {
}

@Override
@Nullable
public GUI convert(Player player) {
public @Nullable GUI convert(Player player) {
return SkriptGUI.getGUIManager().getGUI(player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import io.github.apickledwalrus.skriptgui.SkriptGUI;
import io.github.apickledwalrus.skriptgui.gui.GUI;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

@Name("Global GUI Identifiers")
@Description("A list of the identifiers of all registered global GUIs.")
Expand All @@ -31,7 +32,7 @@ public class ExprGUIIdentifiers extends SimpleExpression<String> {

static {
Skript.registerExpression(ExprGUIIdentifiers.class, String.class, ExpressionType.SIMPLE,
"[(all [[of] the]|the)] (global|registered) gui id(s|entifiers)"
"[all [[of] the]|the] (global|registered) gui id(s|entifiers)"
);
}

Expand All @@ -41,14 +42,15 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
}

@Override
protected String[] get(Event e) {
List<String> identifiers = new ArrayList<>();
for (GUI gui : SkriptGUI.getGUIManager().getTrackedGUIs()) {
if (gui.getID() != null) {
identifiers.add(gui.getID());
}
}
return identifiers.toArray(new String[0]);
protected String[] get(Event event) {
return stream(event).toArray(String[]::new);
}

@Override
public Stream<? extends @NotNull String> stream(Event event) {
return SkriptGUI.getGUIManager().getTrackedGUIs().stream()
.map(GUI::getID)
.filter(Objects::nonNull);
}

@Override
Expand All @@ -62,8 +64,8 @@ public Class<? extends String> getReturnType() {
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return "all of the registered gui identifiers";
public String toString(@Nullable Event event, boolean debug) {
return "the registered gui identifiers";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

@Name("GUI Values")
@Description("Different utility values for a GUI. Some are available in vanilla Skript. Not all values are available for the GUI close section.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package io.github.apickledwalrus.skriptgui.elements.expressions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
Expand All @@ -9,12 +13,20 @@
import io.github.apickledwalrus.skriptgui.SkriptGUI;
import io.github.apickledwalrus.skriptgui.gui.GUI;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import org.jetbrains.annotations.Nullable;

@Name("GUIs")
@Description("An expression to obtain all of the global/tracked GUIs.")
@Examples({
"open a random gui out of all guis to all players"
})
@Since("1.3")
public class ExprGUIs extends SimpleExpression<GUI> {

static {
Skript.registerExpression(ExprGUIs.class, GUI.class, ExpressionType.SIMPLE, "all guis");
Skript.registerExpression(ExprGUIs.class, GUI.class, ExpressionType.SIMPLE,
"[all [[of] the]|the] guis"
);
}

@Override
Expand All @@ -23,9 +35,8 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
}

@Override
@Nullable
protected GUI[] get(Event e) {
return SkriptGUI.getGUIManager().getTrackedGUIs().toArray(new GUI[0]);
protected GUI[] get(Event event) {
return SkriptGUI.getGUIManager().getTrackedGUIs().toArray(GUI[]::new);
}

@Override
Expand All @@ -39,8 +50,8 @@ public Class<? extends GUI> getReturnType() {
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return "all guis";
public String toString(@Nullable Event event, boolean debug) {
return "the guis";
}

}
Loading

0 comments on commit 15966d8

Please sign in to comment.