From 2f8b2824a9703c587546822653370e484402d8c1 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 3 Nov 2024 18:23:08 +0100 Subject: [PATCH 1/4] init commit --- .../ch/njol/skript/command/ScriptCommand.java | 35 +++++++------------ .../java/ch/njol/skript/events/EvtClick.java | 1 - .../events/bukkit/PreScriptLoadEvent.java | 11 +++--- src/main/java/ch/njol/skript/util/Slot.java | 28 --------------- .../ch/njol/util/CaseInsensitiveString.java | 7 ++-- src/main/java/ch/njol/util/Predicate.java | 4 +-- src/main/java/ch/njol/util/Validate.java | 3 +- .../java/ch/njol/util/coll/BidiHashMap.java | 3 +- src/main/java/ch/njol/util/coll/BidiMap.java | 3 +- .../java/ch/njol/util/coll/CyclicList.java | 5 ++- .../ch/njol/util/coll/ReversedListView.java | 3 +- 11 files changed, 31 insertions(+), 72 deletions(-) delete mode 100644 src/main/java/ch/njol/skript/util/Slot.java diff --git a/src/main/java/ch/njol/skript/command/ScriptCommand.java b/src/main/java/ch/njol/skript/command/ScriptCommand.java index eca22e78a68..ade6142f04f 100644 --- a/src/main/java/ch/njol/skript/command/ScriptCommand.java +++ b/src/main/java/ch/njol/skript/command/ScriptCommand.java @@ -43,40 +43,22 @@ import ch.njol.skript.util.chat.MessageComponent; import ch.njol.skript.variables.Variables; import ch.njol.util.StringUtils; -import ch.njol.util.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.PluginCommand; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.command.TabExecutor; +import org.bukkit.command.*; import org.bukkit.entity.Player; import org.bukkit.event.Event; -import org.bukkit.help.GenericCommandHelpTopic; -import org.bukkit.help.HelpMap; -import org.bukkit.help.HelpTopic; -import org.bukkit.help.HelpTopicComparator; -import org.bukkit.help.IndexHelpTopic; +import org.bukkit.help.*; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.script.Script; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; /** * This class is used for user-defined commands. @@ -165,7 +147,14 @@ public ScriptCommand( @Nullable VariableString cooldownMessage, String cooldownBypass, @Nullable VariableString cooldownStorage, int executableBy, SectionNode node ) { - Validate.notNull(name, pattern, arguments, description, usage, aliases, node); + Preconditions.checkNotNull(name, "name cannot be null"); + Preconditions.checkNotNull(pattern, "pattern cannot be null"); + Preconditions.checkNotNull(arguments, "arguments cannot be null"); + Preconditions.checkNotNull(description, "description cannot be null"); + Preconditions.checkNotNull(usage, "usage cannot be null"); + Preconditions.checkNotNull(aliases, "aliases cannot be null"); + Preconditions.checkNotNull(node, "node cannot be null"); + this.name = name; label = "" + name.toLowerCase(Locale.ENGLISH); this.permission = permission; diff --git a/src/main/java/ch/njol/skript/events/EvtClick.java b/src/main/java/ch/njol/skript/events/EvtClick.java index ed455173889..798f87c7800 100644 --- a/src/main/java/ch/njol/skript/events/EvtClick.java +++ b/src/main/java/ch/njol/skript/events/EvtClick.java @@ -1,6 +1,5 @@ package ch.njol.skript.events; -import ch.njol.util.Predicate; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.entity.ArmorStand; diff --git a/src/main/java/ch/njol/skript/events/bukkit/PreScriptLoadEvent.java b/src/main/java/ch/njol/skript/events/bukkit/PreScriptLoadEvent.java index 4301566bc98..6fccc3e721c 100644 --- a/src/main/java/ch/njol/skript/events/bukkit/PreScriptLoadEvent.java +++ b/src/main/java/ch/njol/skript/events/bukkit/PreScriptLoadEvent.java @@ -18,15 +18,14 @@ */ package ch.njol.skript.events.bukkit; -import java.util.List; - +import ch.njol.skript.ScriptLoader; +import ch.njol.skript.config.Config; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import ch.njol.skript.config.Config; -import ch.njol.util.Validate; -import ch.njol.skript.ScriptLoader; +import java.util.List; /** * This event has no guarantee of being on the main thread. @@ -40,7 +39,7 @@ public class PreScriptLoadEvent extends Event { public PreScriptLoadEvent(List scripts) { super(!Bukkit.isPrimaryThread()); - Validate.notNull(scripts); + Preconditions.checkNotNull(scripts, "scripts cannot be null"); this.scripts = scripts; } diff --git a/src/main/java/ch/njol/skript/util/Slot.java b/src/main/java/ch/njol/skript/util/Slot.java deleted file mode 100644 index ff1094bb303..00000000000 --- a/src/main/java/ch/njol/skript/util/Slot.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * This file is part of Skript. - * - * Skript is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Skript is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Skript. If not, see . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ -package ch.njol.skript.util; - -/** - * Preserved for addon compatibility for a limited amount of time. - * Please, do use {@link ch.njol.skript.util.slot.Slot} instead! - * @deprecated Slot stuff got its own package. - */ -@Deprecated -public abstract class Slot extends ch.njol.skript.util.slot.Slot { -} diff --git a/src/main/java/ch/njol/util/CaseInsensitiveString.java b/src/main/java/ch/njol/util/CaseInsensitiveString.java index 1f77cd834a9..0a76614e5a3 100644 --- a/src/main/java/ch/njol/util/CaseInsensitiveString.java +++ b/src/main/java/ch/njol/util/CaseInsensitiveString.java @@ -23,13 +23,10 @@ import javax.annotation.Nullable; - - /** - * A string which is compared ignoring it's case. - * - * @author Peter Güttinger + * @deprecated Unused in Skript. Use {@link String#equalsIgnoreCase(String)} instead. */ +@Deprecated(forRemoval = true) public class CaseInsensitiveString implements Serializable, Comparable, CharSequence { private static final long serialVersionUID = 1205018864604639962L; diff --git a/src/main/java/ch/njol/util/Predicate.java b/src/main/java/ch/njol/util/Predicate.java index f16b12968d2..7f0dd787372 100644 --- a/src/main/java/ch/njol/util/Predicate.java +++ b/src/main/java/ch/njol/util/Predicate.java @@ -21,9 +21,9 @@ import javax.annotation.Nullable; /** - * @author Peter G�ttinger - * + * @deprecated Unused in Skript. Use {@link java.util.function.Predicate} instead. */ +@Deprecated(forRemoval = true) public abstract interface Predicate { public abstract boolean test(@Nullable T paramT); } diff --git a/src/main/java/ch/njol/util/Validate.java b/src/main/java/ch/njol/util/Validate.java index e47c320fb06..8810ed93641 100644 --- a/src/main/java/ch/njol/util/Validate.java +++ b/src/main/java/ch/njol/util/Validate.java @@ -23,8 +23,9 @@ import org.jetbrains.annotations.Nullable; /** - * @author Peter Güttinger + * @deprecated Unused in Skript. Use {@link com.google.common.base.Preconditions} instead */ +@Deprecated(forRemoval = true) public abstract class Validate { public static void notNull(final Object... objects) { diff --git a/src/main/java/ch/njol/util/coll/BidiHashMap.java b/src/main/java/ch/njol/util/coll/BidiHashMap.java index 47003277110..76992a8b51f 100644 --- a/src/main/java/ch/njol/util/coll/BidiHashMap.java +++ b/src/main/java/ch/njol/util/coll/BidiHashMap.java @@ -26,8 +26,9 @@ import org.jetbrains.annotations.Nullable; /** - * @author Peter Güttinger + * @deprecated Unused in Skript. Use {@link java.util.LinkedHashMap} instead. */ +@Deprecated(forRemoval = true) public class BidiHashMap extends HashMap implements BidiMap { private static final long serialVersionUID = -9011678701069901061L; diff --git a/src/main/java/ch/njol/util/coll/BidiMap.java b/src/main/java/ch/njol/util/coll/BidiMap.java index b4afe6632d4..cac8567bc55 100644 --- a/src/main/java/ch/njol/util/coll/BidiMap.java +++ b/src/main/java/ch/njol/util/coll/BidiMap.java @@ -22,8 +22,9 @@ import java.util.Set; /** - * @author Peter Güttinger + * @deprecated Unused in Skript. Use {@link java.util.LinkedHashMap} instead. */ +@Deprecated(forRemoval = true) public interface BidiMap extends Map { public BidiMap getReverseView(); diff --git a/src/main/java/ch/njol/util/coll/CyclicList.java b/src/main/java/ch/njol/util/coll/CyclicList.java index a57bffed71e..a08c9e31d47 100644 --- a/src/main/java/ch/njol/util/coll/CyclicList.java +++ b/src/main/java/ch/njol/util/coll/CyclicList.java @@ -27,10 +27,9 @@ import ch.njol.util.Math2; /** - * A list with fixed size that overrides the oldest elements when new elements are added and no more space is available. - * - * @author Peter Güttinger + * @deprecated Unused in Skript. */ +@Deprecated(forRemoval = true) public final class CyclicList extends AbstractList { private final Object[] items; diff --git a/src/main/java/ch/njol/util/coll/ReversedListView.java b/src/main/java/ch/njol/util/coll/ReversedListView.java index 632dc55924e..1b574ffdbb9 100644 --- a/src/main/java/ch/njol/util/coll/ReversedListView.java +++ b/src/main/java/ch/njol/util/coll/ReversedListView.java @@ -29,8 +29,9 @@ import ch.njol.util.coll.iterator.ReversedListIterator; /** - * @author Peter Güttinger + * @deprecated Unused in Skript. */ +@Deprecated(forRemoval = true) public class ReversedListView implements List { private final List list; From bef2c6ac8c84412348383a562a5169d5028e8feb Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 3 Nov 2024 18:23:14 +0100 Subject: [PATCH 2/4] deprecate setter --- src/main/java/ch/njol/skript/config/Option.java | 8 ++++---- .../skript/config/validate/EntryValidator.java | 12 ++++++------ .../config/validate/EnumEntryValidator.java | 17 ++++++++--------- .../config/validate/ParsedEntryValidator.java | 9 +++++---- .../config/validate/SectionValidator.java | 14 +++++++------- src/main/java/ch/njol/util/Setter.java | 3 ++- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/main/java/ch/njol/skript/config/Option.java b/src/main/java/ch/njol/skript/config/Option.java index e1f3e441573..8f5770fd5ce 100644 --- a/src/main/java/ch/njol/skript/config/Option.java +++ b/src/main/java/ch/njol/skript/config/Option.java @@ -5,11 +5,11 @@ import ch.njol.skript.classes.Parser; import ch.njol.skript.lang.ParseContext; import ch.njol.skript.registrations.Classes; -import ch.njol.util.Setter; import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.converter.Converter; import java.util.Locale; +import java.util.function.Consumer; /** * @author Peter Güttinger @@ -26,7 +26,7 @@ public class Option { private T parsedValue; @Nullable - private Setter setter; + private Consumer setter; public Option(final String key, final T defaultValue) { this.key = "" + key.toLowerCase(Locale.ENGLISH); @@ -68,7 +68,7 @@ public Option(final String key, final T defaultValue, final Converter setter(final Setter setter) { + public final Option setter(Consumer setter) { this.setter = setter; return this; } @@ -94,7 +94,7 @@ public final void set(final Config config, final String path) { protected void onValueChange() { if (setter != null) - setter.set(parsedValue); + setter.accept(parsedValue); } public final T value() { diff --git a/src/main/java/ch/njol/skript/config/validate/EntryValidator.java b/src/main/java/ch/njol/skript/config/validate/EntryValidator.java index 16efab55581..b0e7bfaf942 100644 --- a/src/main/java/ch/njol/skript/config/validate/EntryValidator.java +++ b/src/main/java/ch/njol/skript/config/validate/EntryValidator.java @@ -18,13 +18,13 @@ */ package ch.njol.skript.config.validate; -import org.jetbrains.annotations.Nullable; - import ch.njol.skript.Skript; import ch.njol.skript.config.EntryNode; import ch.njol.skript.config.Node; import ch.njol.skript.log.SkriptLogger; -import ch.njol.util.Setter; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Consumer; /** * @author Peter Güttinger @@ -32,13 +32,13 @@ public class EntryValidator implements NodeValidator { @Nullable - private final Setter setter; + private final Consumer setter; public EntryValidator() { setter = null; } - public EntryValidator(final Setter setter) { + public EntryValidator(final Consumer setter) { this.setter = setter; } @@ -49,7 +49,7 @@ public boolean validate(final Node node) { return false; } if (setter != null) - setter.set(((EntryNode) node).getValue()); + setter.accept(((EntryNode) node).getValue()); return true; } diff --git a/src/main/java/ch/njol/skript/config/validate/EnumEntryValidator.java b/src/main/java/ch/njol/skript/config/validate/EnumEntryValidator.java index 274c08be6ea..3352f72383c 100644 --- a/src/main/java/ch/njol/skript/config/validate/EnumEntryValidator.java +++ b/src/main/java/ch/njol/skript/config/validate/EnumEntryValidator.java @@ -18,14 +18,13 @@ */ package ch.njol.skript.config.validate; -import java.util.Locale; - -import org.jetbrains.annotations.Nullable; - import ch.njol.skript.Skript; import ch.njol.skript.config.EntryNode; import ch.njol.skript.config.Node; -import ch.njol.util.Setter; +import org.jetbrains.annotations.Nullable; + +import java.util.Locale; +import java.util.function.Consumer; /** * @author Peter Güttinger @@ -33,11 +32,11 @@ public class EnumEntryValidator> extends EntryValidator { private final Class enumType; - private final Setter setter; + private final Consumer setter; @Nullable private String allowedValues = null; - public EnumEntryValidator(final Class enumType, final Setter setter) { + public EnumEntryValidator(final Class enumType, final Consumer setter) { assert enumType != null; this.enumType = enumType; this.setter = setter; @@ -52,7 +51,7 @@ public EnumEntryValidator(final Class enumType, final Setter setter) { } } - public EnumEntryValidator(final Class enumType, final Setter setter, final String allowedValues) { + public EnumEntryValidator(final Class enumType, final Consumer setter, final String allowedValues) { assert enumType != null; this.enumType = enumType; this.setter = setter; @@ -68,7 +67,7 @@ public boolean validate(final Node node) { final E e = Enum.valueOf(enumType, n.getValue().toUpperCase(Locale.ENGLISH).replace(' ', '_')); assert e != null; // if (setter != null) - setter.set(e); + setter.accept(e); } catch (final IllegalArgumentException e) { Skript.error("'" + n.getValue() + "' is not a valid value for '" + n.getKey() + "'" + (allowedValues == null ? "" : ". Allowed values are: " + allowedValues)); return false; diff --git a/src/main/java/ch/njol/skript/config/validate/ParsedEntryValidator.java b/src/main/java/ch/njol/skript/config/validate/ParsedEntryValidator.java index d949279741a..99d8086912d 100644 --- a/src/main/java/ch/njol/skript/config/validate/ParsedEntryValidator.java +++ b/src/main/java/ch/njol/skript/config/validate/ParsedEntryValidator.java @@ -22,7 +22,8 @@ import ch.njol.skript.config.EntryNode; import ch.njol.skript.config.Node; import ch.njol.skript.lang.ParseContext; -import ch.njol.util.Setter; + +import java.util.function.Consumer; /** * @author Peter Güttinger @@ -30,9 +31,9 @@ public class ParsedEntryValidator extends EntryValidator { private final Parser parser; - private final Setter setter; + private final Consumer setter; - public ParsedEntryValidator(final Parser parser, final Setter setter) { + public ParsedEntryValidator(final Parser parser, final Consumer setter) { assert parser != null; assert setter != null; this.parser = parser; @@ -46,7 +47,7 @@ public boolean validate(final Node node) { final T t = parser.parse(((EntryNode) node).getValue(), ParseContext.CONFIG); if (t == null) return false; - setter.set(t); + setter.accept(t); return true; } diff --git a/src/main/java/ch/njol/skript/config/validate/SectionValidator.java b/src/main/java/ch/njol/skript/config/validate/SectionValidator.java index 322c53e5bba..3257cd9b79f 100644 --- a/src/main/java/ch/njol/skript/config/validate/SectionValidator.java +++ b/src/main/java/ch/njol/skript/config/validate/SectionValidator.java @@ -18,17 +18,17 @@ */ package ch.njol.skript.config.validate; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map.Entry; - import ch.njol.skript.Skript; import ch.njol.skript.classes.Parser; import ch.njol.skript.config.EntryNode; import ch.njol.skript.config.Node; import ch.njol.skript.config.SectionNode; import ch.njol.skript.log.SkriptLogger; -import ch.njol.util.Setter; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Map.Entry; +import java.util.function.Consumer; /** * @author Peter Güttinger @@ -63,12 +63,12 @@ public SectionValidator addEntry(final String name, final boolean optional) { return this; } - public SectionValidator addEntry(final String name, final Setter setter, final boolean optional) { + public SectionValidator addEntry(final String name, final Consumer setter, final boolean optional) { addNode(name, new EntryValidator(setter), optional); return this; } - public SectionValidator addEntry(final String name, final Parser parser, final Setter setter, final boolean optional) { + public SectionValidator addEntry(final String name, final Parser parser, final Consumer setter, final boolean optional) { addNode(name, new ParsedEntryValidator<>(parser, setter), optional); return this; } diff --git a/src/main/java/ch/njol/util/Setter.java b/src/main/java/ch/njol/util/Setter.java index 6d03d4d6d14..0304662eccb 100644 --- a/src/main/java/ch/njol/util/Setter.java +++ b/src/main/java/ch/njol/util/Setter.java @@ -19,8 +19,9 @@ package ch.njol.util; /** - * @author Peter Güttinger + * @deprecated Unused in Skript. Use {@link java.util.function.Consumer} instead. */ +@Deprecated(forRemoval = true) public interface Setter { public void set(T t); From c1c23dbd9ff0955eeb255b0805b8bb386ffdcc57 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 3 Nov 2024 19:24:28 +0100 Subject: [PATCH 3/4] update doc --- src/main/java/ch/njol/util/coll/BidiHashMap.java | 2 +- src/main/java/ch/njol/util/coll/BidiMap.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/util/coll/BidiHashMap.java b/src/main/java/ch/njol/util/coll/BidiHashMap.java index 76992a8b51f..60e9b4ea489 100644 --- a/src/main/java/ch/njol/util/coll/BidiHashMap.java +++ b/src/main/java/ch/njol/util/coll/BidiHashMap.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; /** - * @deprecated Unused in Skript. Use {@link java.util.LinkedHashMap} instead. + * @deprecated Unused in Skript. Use {@link com.google.common.collect.BiMap} instead. */ @Deprecated(forRemoval = true) public class BidiHashMap extends HashMap implements BidiMap { diff --git a/src/main/java/ch/njol/util/coll/BidiMap.java b/src/main/java/ch/njol/util/coll/BidiMap.java index cac8567bc55..57f9965b775 100644 --- a/src/main/java/ch/njol/util/coll/BidiMap.java +++ b/src/main/java/ch/njol/util/coll/BidiMap.java @@ -22,7 +22,7 @@ import java.util.Set; /** - * @deprecated Unused in Skript. Use {@link java.util.LinkedHashMap} instead. + * @deprecated Unused in Skript. Use {@link com.google.common.collect.BiMap} instead. */ @Deprecated(forRemoval = true) public interface BidiMap extends Map { From 88288f7e917e93b0f2650fbe5abc39772a0811e4 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Tue, 5 Nov 2024 12:30:39 +0100 Subject: [PATCH 4/4] remove soundutils --- .../java/ch/njol/skript/util/SoundUtils.java | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 src/main/java/ch/njol/skript/util/SoundUtils.java diff --git a/src/main/java/ch/njol/skript/util/SoundUtils.java b/src/main/java/ch/njol/skript/util/SoundUtils.java deleted file mode 100644 index bbf18e2ea1c..00000000000 --- a/src/main/java/ch/njol/skript/util/SoundUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * This file is part of Skript. - * - * Skript is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Skript is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Skript. If not, see . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ -package ch.njol.skript.util; - -import org.bukkit.Sound; -import org.jetbrains.annotations.Nullable; - -/** - * @author Peter Güttinger - */ -public abstract class SoundUtils { - private SoundUtils() {} - - static { - assert false; - } - - private final static EnumUtils util = new EnumUtils<>(Sound.class, "sounds"); - - @Nullable - public static Sound parse(final String s) { - return util.parse(s); - } - - public static String toString(final Sound s, final int flags) { - return util.toString(s, flags); - } - - public static String getAllNames() { - return util.getAllNames(); - } - -}