taboolib 5.05
+ update Time.java + update ArrayUtil.java + update MenuBuilder.java + update ClickEvent.java + update Servers.java + fix @TConfig
This commit is contained in:
parent
b217572056
commit
4629a6fdb0
@ -5,7 +5,7 @@ plugins {
|
|||||||
id 'com.github.johnrengelman.shadow' version '4.0.4'
|
id 'com.github.johnrengelman.shadow' version '4.0.4'
|
||||||
}
|
}
|
||||||
group = 'me.skymc'
|
group = 'me.skymc'
|
||||||
version = '5.04'
|
version = '5.05'
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 1.8
|
targetCompatibility = 1.8
|
||||||
|
198
src/main/scala/io/izzel/taboolib/cronus/util/Time.java
Normal file
198
src/main/scala/io/izzel/taboolib/cronus/util/Time.java
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
package io.izzel.taboolib.cronus.util;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import io.izzel.taboolib.cronus.CronusUtils;
|
||||||
|
import org.bukkit.util.NumberConversions;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 坏黑
|
||||||
|
* @Since 2019-05-28 17:28
|
||||||
|
*/
|
||||||
|
public class Time {
|
||||||
|
|
||||||
|
private static Map<String, Time> cacheMap = Maps.newHashMap();
|
||||||
|
private TimeType type;
|
||||||
|
private int day;
|
||||||
|
private int hour;
|
||||||
|
private int minute;
|
||||||
|
private long time;
|
||||||
|
private Map<Long, Calendar> cacheEnd = Maps.newHashMap();
|
||||||
|
private Calendar end;
|
||||||
|
private String origin;
|
||||||
|
|
||||||
|
public Time(String libTime) {
|
||||||
|
this(CronusUtils.toMillis(libTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Time(long time) {
|
||||||
|
this.type = TimeType.TIME;
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Time(int hour, int minute) {
|
||||||
|
this.type = TimeType.DAY;
|
||||||
|
this.hour = hour;
|
||||||
|
this.minute = minute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Time(TimeType type, int day, int hour, int minute) {
|
||||||
|
this.type = type;
|
||||||
|
this.day = day;
|
||||||
|
this.hour = hour;
|
||||||
|
this.minute = minute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Time origin(String origin) {
|
||||||
|
this.origin = origin;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Time in(long start) {
|
||||||
|
if (this.cacheEnd.containsKey(start)) {
|
||||||
|
this.end = this.cacheEnd.get(start);
|
||||||
|
} else {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
Calendar startCal = (Calendar) calendar.clone();
|
||||||
|
startCal.setTimeInMillis(start);
|
||||||
|
this.end = (Calendar) calendar.clone();
|
||||||
|
this.cacheEnd.put(start, this.end);
|
||||||
|
this.end.set(Calendar.SECOND, 0);
|
||||||
|
this.end.set(Calendar.MILLISECOND, 0);
|
||||||
|
if (this.type != TimeType.TIME) {
|
||||||
|
switch (this.type) {
|
||||||
|
case DAY:
|
||||||
|
this.end.set(Calendar.HOUR_OF_DAY, hour);
|
||||||
|
this.end.set(Calendar.MINUTE, minute);
|
||||||
|
if (startCal.after(this.end)) {
|
||||||
|
this.end.add(Calendar.DATE, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WEEK:
|
||||||
|
this.end.set(Calendar.DAY_OF_WEEK, day + 1);
|
||||||
|
this.end.set(Calendar.HOUR_OF_DAY, hour);
|
||||||
|
this.end.set(Calendar.MINUTE, minute);
|
||||||
|
if (startCal.after(this.end)) {
|
||||||
|
this.end.add(Calendar.DATE, 7);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MONTH:
|
||||||
|
this.end.set(Calendar.DAY_OF_MONTH, day);
|
||||||
|
this.end.set(Calendar.HOUR_OF_DAY, hour);
|
||||||
|
this.end.set(Calendar.MINUTE, minute);
|
||||||
|
if (startCal.after(this.end)) {
|
||||||
|
this.end.add(Calendar.MONTH, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTimeout(long start) {
|
||||||
|
return type == TimeType.TIME ? start + time < System.currentTimeMillis() : isTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTimeout() {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
switch (type) {
|
||||||
|
case DAY: {
|
||||||
|
return calendar.after(this.end);
|
||||||
|
}
|
||||||
|
case WEEK: {
|
||||||
|
return calendar.after(this.end);
|
||||||
|
}
|
||||||
|
case MONTH: {
|
||||||
|
return calendar.after(this.end);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEquals() {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
switch (type) {
|
||||||
|
case DAY: {
|
||||||
|
return calendar.get(Calendar.HOUR_OF_DAY) == hour && calendar.get(Calendar.MINUTE) == minute;
|
||||||
|
}
|
||||||
|
case WEEK: {
|
||||||
|
return calendar.get(Calendar.DAY_OF_WEEK) == day && calendar.get(Calendar.HOUR_OF_DAY) == hour && calendar.get(Calendar.MINUTE) == minute;
|
||||||
|
}
|
||||||
|
case MONTH: {
|
||||||
|
return calendar.get(Calendar.DAY_OF_MONTH) == day && calendar.get(Calendar.HOUR_OF_DAY) == hour && calendar.get(Calendar.MINUTE) == minute;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Time parse(String in) {
|
||||||
|
return cacheMap.computeIfAbsent(in, n -> parse0(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Time parse0(String in) {
|
||||||
|
if (in == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
in = in.toLowerCase();
|
||||||
|
if (in.equalsIgnoreCase("never") || in.equals("-1")) {
|
||||||
|
return null;
|
||||||
|
} else if (in.startsWith("day:")) {
|
||||||
|
String[] v = in.substring("day:".length()).split(":");
|
||||||
|
return new Time(NumberConversions.toInt(v[0]), NumberConversions.toInt(v.length > 1 ? v[1] : 0)).origin(in);
|
||||||
|
} else if (in.startsWith("week:")) {
|
||||||
|
String[] v = in.substring("week:".length()).split(":");
|
||||||
|
return new Time(TimeType.WEEK, NumberConversions.toInt(v[0]), NumberConversions.toInt(v.length > 1 ? v[1] : 0), NumberConversions.toInt(v.length > 2 ? v[2] : 0)).origin(in);
|
||||||
|
} else if (in.startsWith("month:")) {
|
||||||
|
String[] v = in.substring("month:".length()).split(":");
|
||||||
|
return new Time(TimeType.MONTH, NumberConversions.toInt(v[0]), NumberConversions.toInt(v.length > 1 ? v[1] : 0), NumberConversions.toInt(v.length > 1 ? v[2] : 0)).origin(in);
|
||||||
|
} else {
|
||||||
|
return new Time(in).origin(in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Time parseNoTime(String in) {
|
||||||
|
if (in == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
in = in.toLowerCase();
|
||||||
|
if (in.startsWith("week:")) {
|
||||||
|
String[] v = in.substring("week:".length()).split(":");
|
||||||
|
return new Time(TimeType.WEEK, NumberConversions.toInt(v[0]), NumberConversions.toInt(v.length > 1 ? v[1] : 0), NumberConversions.toInt(v.length > 2 ? v[2] : 0)).origin(in);
|
||||||
|
} else if (in.startsWith("month:")) {
|
||||||
|
String[] v = in.substring("month:".length()).split(":");
|
||||||
|
return new Time(TimeType.MONTH, NumberConversions.toInt(v[0]), NumberConversions.toInt(v.length > 1 ? v[1] : 0), NumberConversions.toInt(v.length > 1 ? v[2] : 0)).origin(in);
|
||||||
|
} else {
|
||||||
|
String[] v = in.split(":");
|
||||||
|
return new Time(NumberConversions.toInt(v[0]), NumberConversions.toInt(v.length > 1 ? v[1] : 0)).origin(in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDay() {
|
||||||
|
return day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHour() {
|
||||||
|
return hour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinute() {
|
||||||
|
return minute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrigin() {
|
||||||
|
return origin;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package io.izzel.taboolib.cronus.util;
|
||||||
|
|
||||||
|
public enum TimeType {
|
||||||
|
|
||||||
|
TIME, DAY, WEEK, MONTH
|
||||||
|
}
|
@ -31,7 +31,7 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
|
|||||||
|
|
||||||
private PluginCommand registerCommand;
|
private PluginCommand registerCommand;
|
||||||
private List<Class<?>> linkClasses = new CopyOnWriteArrayList<>();
|
private List<Class<?>> linkClasses = new CopyOnWriteArrayList<>();
|
||||||
private List<io.izzel.taboolib.module.command.base.BaseSubCommand> subCommands = new CopyOnWriteArrayList<>();
|
private List<BaseSubCommand> subCommands = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
public static BaseMainCommand createCommandExecutor(String command, BaseMainCommand baseMainCommand) {
|
public static BaseMainCommand createCommandExecutor(String command, BaseMainCommand baseMainCommand) {
|
||||||
Preconditions.checkArgument(Bukkit.getPluginCommand(command) != null, "PluginCommand \"" + command + "\" not found");
|
Preconditions.checkArgument(Bukkit.getPluginCommand(command) != null, "PluginCommand \"" + command + "\" not found");
|
||||||
@ -147,7 +147,7 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
|
|||||||
TLocale.sendTo(sender, "COMMANDS.INTERNAL.TYPE-ERROR", args[0], TLocale.asString("COMMANDS.INTERNAL.TYPE-" + subCommand.getType()));
|
TLocale.sendTo(sender, "COMMANDS.INTERNAL.TYPE-ERROR", args[0], TLocale.asString("COMMANDS.INTERNAL.TYPE-" + subCommand.getType()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String[] subCommandArgs = ArrayUtil.removeFirst(args);
|
String[] subCommandArgs = removeFirst(args);
|
||||||
if (subCommand.isParameterConform(subCommandArgs)) {
|
if (subCommand.isParameterConform(subCommandArgs)) {
|
||||||
subCommand.onCommand(sender, command, label, subCommand.ignoredLabel() ? subCommandArgs : args);
|
subCommand.onCommand(sender, command, label, subCommand.ignoredLabel() ? subCommandArgs : args);
|
||||||
} else {
|
} else {
|
||||||
@ -230,4 +230,13 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
|
|||||||
private boolean hasPermission(CommandSender sender, BaseSubCommand baseSubCommand) {
|
private boolean hasPermission(CommandSender sender, BaseSubCommand baseSubCommand) {
|
||||||
return baseSubCommand == null || baseSubCommand.getPermission() == null || sender.hasPermission(baseSubCommand.getPermission());
|
return baseSubCommand == null || baseSubCommand.getPermission() == null || sender.hasPermission(baseSubCommand.getPermission());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String[] removeFirst(String[] args) {
|
||||||
|
if (args.length <= 1) {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
List<String> list = ArrayUtil.asList(args);
|
||||||
|
list.remove(0);
|
||||||
|
return list.toArray(new String[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,7 @@ public class TInjectLoader implements TabooLibLoader.Loader {
|
|||||||
injectTypes.put(TConfig.class, (plugin, field, args, pluginClass, instance) -> {
|
injectTypes.put(TConfig.class, (plugin, field, args, pluginClass, instance) -> {
|
||||||
try {
|
try {
|
||||||
TConfig config = TConfig.create(plugin, args.value().length == 0 ? "config.yml" : args.value()[0]);
|
TConfig config = TConfig.create(plugin, args.value().length == 0 ? "config.yml" : args.value()[0]);
|
||||||
|
field.set(instance, config);
|
||||||
if (!args.reload().isEmpty()) {
|
if (!args.reload().isEmpty()) {
|
||||||
try {
|
try {
|
||||||
Method declaredMethod = pluginClass.getDeclaredMethod(args.reload());
|
Method declaredMethod = pluginClass.getDeclaredMethod(args.reload());
|
||||||
@ -73,7 +74,6 @@ public class TInjectLoader implements TabooLibLoader.Loader {
|
|||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
field.set(instance, config);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package io.izzel.taboolib.util;
|
package io.izzel.taboolib.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -12,19 +15,48 @@ import java.util.stream.IntStream;
|
|||||||
*/
|
*/
|
||||||
public class ArrayUtil {
|
public class ArrayUtil {
|
||||||
|
|
||||||
public static <T> int indexOf(T[] array, T obj) {
|
|
||||||
return array == null || array.length == 0 ? -1 : IntStream.range(0, array.length).filter(i -> array[i] != null && array[i].equals(obj)).findFirst().orElse(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> boolean contains(T[] array, T obj) {
|
public static <T> boolean contains(T[] array, T obj) {
|
||||||
return indexOf(array, obj) != -1;
|
return indexOf(array, obj) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> int indexOf(T[] array, T obj) {
|
||||||
|
return array == null || array.length == 0 ? -1 : IntStream.range(0, array.length).filter(i -> array[i] != null && array[i].equals(obj)).findFirst().orElse(-1);
|
||||||
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <T> T[] asArray(T... args) {
|
public static <T> T[] asArray(T... args) {
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> T[] toArray(List<T> list) {
|
||||||
|
T[] a = (T[]) Array.newInstance(list.getClass().getComponentType(), list.size());
|
||||||
|
Arrays.setAll(a, list::get);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public static <T> List<T> asList(T... args) {
|
||||||
|
List<T> list = Lists.newArrayList();
|
||||||
|
Collections.addAll(list, args);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T skipEmpty(T obj) {
|
||||||
|
return skipEmpty(obj, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T[] skipEmpty(T[] obj) {
|
||||||
|
return skipEmpty(obj, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T skipEmpty(T obj, T def) {
|
||||||
|
return Strings.isEmpty(String.valueOf(obj)) ? def : obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T[] skipEmpty(T[] obj, T[] def) {
|
||||||
|
return obj.length == 0 ? def : skipEmpty(obj[0]) == null ? def : obj;
|
||||||
|
}
|
||||||
|
|
||||||
public static String arrayJoin(String[] args, int start) {
|
public static String arrayJoin(String[] args, int start) {
|
||||||
return IntStream.range(start, args.length).mapToObj(i -> args[i] + " ").collect(Collectors.joining()).trim();
|
return IntStream.range(start, args.length).mapToObj(i -> args[i] + " ").collect(Collectors.joining()).trim();
|
||||||
}
|
}
|
||||||
@ -43,72 +75,17 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
@SuppressWarnings("SuspiciousSystemArraycopy")
|
@SuppressWarnings("SuspiciousSystemArraycopy")
|
||||||
public static <T> T arrayExpand(T oldArray, int expand) {
|
public static <T> T arrayExpand(T oldArray, int expand) {
|
||||||
int length = java.lang.reflect.Array.getLength(oldArray);
|
int length = Array.getLength(oldArray);
|
||||||
Object newArray = java.lang.reflect.Array.newInstance(oldArray.getClass().getComponentType(), length + expand);
|
Object newArray = Array.newInstance(oldArray.getClass().getComponentType(), length + expand);
|
||||||
System.arraycopy(oldArray, 0, newArray, 0, length);
|
System.arraycopy(oldArray, 0, newArray, 0, length);
|
||||||
return (T) newArray;
|
return (T) newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("SuspiciousSystemArraycopy")
|
@SuppressWarnings("SuspiciousSystemArraycopy")
|
||||||
public static <T> T arrayExpandAtFirst(T oldArray, int expand) {
|
public static <T> T arrayExpandAtFirst(T oldArray, int expand) {
|
||||||
int length = java.lang.reflect.Array.getLength(oldArray);
|
int length = Array.getLength(oldArray);
|
||||||
Object newArray = java.lang.reflect.Array.newInstance(oldArray.getClass().getComponentType(), length + expand);
|
Object newArray = Array.newInstance(oldArray.getClass().getComponentType(), length + expand);
|
||||||
System.arraycopy(oldArray, 0, newArray, expand, length);
|
System.arraycopy(oldArray, 0, newArray, expand, length);
|
||||||
return (T) newArray;
|
return (T) newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T skipEmpty(T obj) {
|
|
||||||
return skipEmpty(obj, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T[] skipEmpty(T[] obj) {
|
|
||||||
return skipEmpty(obj, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T skipEmpty(T obj, T def) {
|
|
||||||
return Strings.isEmpty(String.valueOf(obj)) ? def : obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T[] skipEmpty(T[] obj, T[] def) {
|
|
||||||
if (obj.length == 0) {
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
T firstElement = skipEmpty(obj[0]);
|
|
||||||
return firstElement == null ? def : obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SafeVarargs
|
|
||||||
public static <T> List<T> asList(T... args) {
|
|
||||||
List<T> list = new ArrayList<>();
|
|
||||||
Collections.addAll(list, args);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
// *********************************
|
|
||||||
//
|
|
||||||
// Deprecated
|
|
||||||
//
|
|
||||||
// *********************************
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static String[] addFirst(String[] args, String... value) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
List<String> list = asList(args);
|
|
||||||
for (int i = value.length - 1; i >= 0; i--) {
|
|
||||||
list.add(0, value[i]);
|
|
||||||
}
|
|
||||||
return list.toArray(new String[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static String[] removeFirst(String[] args) {
|
|
||||||
if (args.length <= 1) {
|
|
||||||
return new String[0];
|
|
||||||
}
|
|
||||||
List<String> list = asList(args);
|
|
||||||
list.remove(0);
|
|
||||||
return list.toArray(new String[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
package io.izzel.taboolib.util.item.inventory;
|
package io.izzel.taboolib.util.item.inventory;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import io.izzel.taboolib.util.lite.Servers;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||||
import org.bukkit.event.inventory.InventoryInteractEvent;
|
import org.bukkit.event.inventory.InventoryInteractEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author 坏黑
|
* @Author 坏黑
|
||||||
@ -30,6 +36,10 @@ public class ClickEvent {
|
|||||||
return (InventoryDragEvent) event;
|
return (InventoryDragEvent) event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRawSlot() {
|
||||||
|
return clickType == ClickType.CLICK ? castClick().getRawSlot() : -1;
|
||||||
|
}
|
||||||
|
|
||||||
public char getSlot() {
|
public char getSlot() {
|
||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
@ -41,4 +51,16 @@ public class ClickEvent {
|
|||||||
public Player getClicker() {
|
public Player getClicker() {
|
||||||
return (Player) ((InventoryInteractEvent) event).getWhoClicked();
|
return (Player) ((InventoryInteractEvent) event).getWhoClicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ItemStack> getAffectItems() {
|
||||||
|
return clickType == ClickType.CLICK ? Servers.getAffectItemInClickEvent((InventoryClickEvent) event) : Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancelled(boolean c) {
|
||||||
|
((Cancellable) event).setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return ((Cancellable) event).isCancelled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class MenuBuilder {
|
|||||||
private Plugin plugin;
|
private Plugin plugin;
|
||||||
private String title;
|
private String title;
|
||||||
private int rows;
|
private int rows;
|
||||||
private char[][] items ;
|
private char[][] items = new char[0][0];
|
||||||
private ClickTask clickTask;
|
private ClickTask clickTask;
|
||||||
private CloseTask closeTask;
|
private CloseTask closeTask;
|
||||||
private boolean lockHand;
|
private boolean lockHand;
|
||||||
@ -86,7 +86,7 @@ public class MenuBuilder {
|
|||||||
}
|
}
|
||||||
return inventory;
|
return inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public char getSlot(int slot) {
|
public char getSlot(int slot) {
|
||||||
for (int i = 0; i < items.length && i < rows; i++) {
|
for (int i = 0; i < items.length && i < rows; i++) {
|
||||||
char[] line = items[i];
|
char[] line = items[i];
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
package io.izzel.taboolib.util.lite;
|
package io.izzel.taboolib.util.lite;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author 坏黑
|
* @Author 坏黑
|
||||||
@ -19,8 +25,7 @@ public class Servers {
|
|||||||
Field f = Enchantment.class.getDeclaredField("acceptingNew");
|
Field f = Enchantment.class.getDeclaredField("acceptingNew");
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
f.set(null, value);
|
f.set(null, value);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,4 +49,13 @@ public class Servers {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<ItemStack> getAffectItemInClickEvent(InventoryClickEvent e) {
|
||||||
|
List<ItemStack> list = Lists.newArrayList();
|
||||||
|
if (e.getClick() == ClickType.NUMBER_KEY) {
|
||||||
|
Optional.ofNullable(e.getWhoClicked().getInventory().getItem(e.getHotbarButton())).ifPresent(list::add);
|
||||||
|
}
|
||||||
|
Optional.ofNullable(e.getCurrentItem()).ifPresent(list::add);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user