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

Cleans some utils #7191

Closed
wants to merge 6 commits into from
Closed
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
35 changes: 12 additions & 23 deletions src/main/java/ch/njol/skript/command/ScriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/ch/njol/skript/config/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +26,7 @@ public class Option<T> {
private T parsedValue;

@Nullable
private Setter<? super T> setter;
private Consumer<? super T> setter;

public Option(final String key, final T defaultValue) {
this.key = "" + key.toLowerCase(Locale.ENGLISH);
Expand Down Expand Up @@ -68,7 +68,7 @@ public Option(final String key, final T defaultValue, final Converter<String, ?
this.parser = parser;
}

public final Option<T> setter(final Setter<? super T> setter) {
public final Option<T> setter(Consumer<? super T> setter) {
this.setter = setter;
return this;
}
Expand All @@ -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() {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/ch/njol/skript/config/validate/EntryValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@
*/
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
*/
public class EntryValidator implements NodeValidator {

@Nullable
private final Setter<String> setter;
private final Consumer<String> setter;

public EntryValidator() {
setter = null;
}

public EntryValidator(final Setter<String> setter) {
public EntryValidator(final Consumer<String> setter) {
this.setter = setter;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,25 @@
*/
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
*/
public class EnumEntryValidator<E extends Enum<E>> extends EntryValidator {

private final Class<E> enumType;
private final Setter<E> setter;
private final Consumer<E> setter;
@Nullable
private String allowedValues = null;

public EnumEntryValidator(final Class<E> enumType, final Setter<E> setter) {
public EnumEntryValidator(final Class<E> enumType, final Consumer<E> setter) {
assert enumType != null;
this.enumType = enumType;
this.setter = setter;
Expand All @@ -52,7 +51,7 @@ public EnumEntryValidator(final Class<E> enumType, final Setter<E> setter) {
}
}

public EnumEntryValidator(final Class<E> enumType, final Setter<E> setter, final String allowedValues) {
public EnumEntryValidator(final Class<E> enumType, final Consumer<E> setter, final String allowedValues) {
assert enumType != null;
this.enumType = enumType;
this.setter = setter;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
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
*/
public class ParsedEntryValidator<T> extends EntryValidator {

private final Parser<? extends T> parser;
private final Setter<T> setter;
private final Consumer<T> setter;

public ParsedEntryValidator(final Parser<? extends T> parser, final Setter<T> setter) {
public ParsedEntryValidator(final Parser<? extends T> parser, final Consumer<T> setter) {
assert parser != null;
assert setter != null;
this.parser = parser;
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,12 +63,12 @@ public SectionValidator addEntry(final String name, final boolean optional) {
return this;
}

public SectionValidator addEntry(final String name, final Setter<String> setter, final boolean optional) {
public SectionValidator addEntry(final String name, final Consumer<String> setter, final boolean optional) {
addNode(name, new EntryValidator(setter), optional);
return this;
}

public <T> SectionValidator addEntry(final String name, final Parser<? extends T> parser, final Setter<T> setter, final boolean optional) {
public <T> SectionValidator addEntry(final String name, final Parser<? extends T> parser, final Consumer<T> setter, final boolean optional) {
addNode(name, new ParsedEntryValidator<>(parser, setter), optional);
return this;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/ch/njol/skript/events/EvtClick.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -40,7 +39,7 @@ public class PreScriptLoadEvent extends Event {

public PreScriptLoadEvent(List<Config> scripts) {
super(!Bukkit.isPrimaryThread());
Validate.notNull(scripts);
Preconditions.checkNotNull(scripts, "scripts cannot be null");
this.scripts = scripts;
}

Expand Down
28 changes: 0 additions & 28 deletions src/main/java/ch/njol/skript/util/Slot.java

This file was deleted.

7 changes: 2 additions & 5 deletions src/main/java/ch/njol/util/CaseInsensitiveString.java
Original file line number Diff line number Diff line change
Expand Up @@ -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>, CharSequence {

private static final long serialVersionUID = 1205018864604639962L;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/util/Predicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
public abstract boolean test(@Nullable T paramT);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/njol/util/Setter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {

public void set(T t);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/njol/util/Validate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/njol/util/coll/BidiHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import org.jetbrains.annotations.Nullable;

/**
* @author Peter Güttinger
* @deprecated Unused in Skript. Use {@link com.google.common.collect.BiMap} instead.
*/
@Deprecated(forRemoval = true)
public class BidiHashMap<T1, T2> extends HashMap<T1, T2> implements BidiMap<T1, T2> {

private static final long serialVersionUID = -9011678701069901061L;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/njol/util/coll/BidiMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import java.util.Set;

/**
* @author Peter Güttinger
* @deprecated Unused in Skript. Use {@link com.google.common.collect.BiMap} instead.
*/
@Deprecated(forRemoval = true)
public interface BidiMap<T1, T2> extends Map<T1, T2> {

public BidiMap<T2, T1> getReverseView();
Expand Down
Loading