Merge remote-tracking branch 'origin/master'

This commit is contained in:
IzzelAliz 2020-01-07 22:56:44 +08:00
commit 3849ec950a
15 changed files with 197 additions and 113 deletions

View File

@ -6,7 +6,7 @@ plugins {
} }
group = 'me.skymc' group = 'me.skymc'
version = '5.12' version = '5.13'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8

View File

@ -46,42 +46,31 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
public static void loadCommandRegister(BaseMainCommand baseMainCommand) { public static void loadCommandRegister(BaseMainCommand baseMainCommand) {
List<Method> methods = new ArrayList<>(); List<Method> methods = new ArrayList<>();
List<CommandField> fields = new ArrayList<>(); List<CommandField> fields = new ArrayList<>();
baseMainCommand.getLinkClasses().forEach(clazz -> java.util.Arrays.stream(clazz.getDeclaredMethods()).filter(method -> method.getAnnotation(SubCommand.class) != null).forEach(methods::add)); baseMainCommand.getLinkClasses()
.forEach(clazz -> java.util.Arrays.stream(clazz.getDeclaredMethods())
.filter(method -> method.getAnnotation(SubCommand.class) != null).forEach(m -> {
m.setAccessible(true);
methods.add(m);
}));
if (methods.size() > 0) { if (methods.size() > 0) {
methods.sort(Comparator.comparingDouble(a -> a.getAnnotation(SubCommand.class).priority())); methods.sort(Comparator.comparingDouble(a -> a.getAnnotation(SubCommand.class).priority()));
methods.forEach(method -> { methods.forEach(method -> {
BaseSubCommand subCommand = null;
try { try {
method.setAccessible(true); BaseSubCommand subCommand = null;
// lite parameter // lite parameter
if (Arrays.equals(method.getParameterTypes(), new Class[] {CommandSender.class, String[].class})) { if (Arrays.equals(method.getParameterTypes(), new Class[] {CommandSender.class, String[].class})) {
subCommand = new BaseSubCommand() { subCommand = buildSubCommand(baseMainCommand, method)
@Override .label(method.getName())
public void onCommand(CommandSender sender, Command command, String label, String[] args) { .annotation(method.getAnnotation(SubCommand.class));
try {
method.invoke(baseMainCommand, sender, args);
} catch (Throwable t) {
t.printStackTrace();
} }
} // player only parameter
}; else if (Arrays.equals(method.getParameterTypes(), new Class[] {Player.class, String[].class})) {
} subCommand = buildSubCommand(baseMainCommand, method)
// fully parameter .player()
else if (Arrays.equals(method.getParameterTypes(), new Class[] {CommandSender.class, Command.class, String.class, String[].class})) { .label(method.getName())
subCommand = new BaseSubCommand() { .annotation(method.getAnnotation(SubCommand.class));
@Override
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
method.invoke(baseMainCommand, sender, command, label, args);
} catch (Throwable t) {
t.printStackTrace();
}
}
};
} }
if (subCommand != null) { if (subCommand != null) {
subCommand.setLabel(method.getName());
subCommand.setAnnotation(method.getAnnotation(SubCommand.class));
baseMainCommand.registerSubCommand(subCommand); baseMainCommand.registerSubCommand(subCommand);
} }
} catch (Throwable ignored) { } catch (Throwable ignored) {
@ -95,8 +84,7 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
try { try {
commandField.getField().setAccessible(true); commandField.getField().setAccessible(true);
BaseSubCommand subCommand = (BaseSubCommand) commandField.getField().get(commandField.getParent().newInstance()); BaseSubCommand subCommand = (BaseSubCommand) commandField.getField().get(commandField.getParent().newInstance());
subCommand.setLabel(commandField.getField().getName()); subCommand.label(commandField.getField().getName()).annotation(commandField.getField().getAnnotation(SubCommand.class));
subCommand.setAnnotation(commandField.getField().getAnnotation(SubCommand.class));
baseMainCommand.registerSubCommand(subCommand); baseMainCommand.registerSubCommand(subCommand);
} catch (Throwable ignored) { } catch (Throwable ignored) {
} }
@ -107,6 +95,19 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
} }
} }
private static BaseSubCommand buildSubCommand(BaseMainCommand baseMainCommand, Method method) {
return new BaseSubCommand() {
@Override
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
method.invoke(baseMainCommand, sender, args);
} catch (Throwable t) {
t.printStackTrace();
}
}
};
}
public void setRegisterCommand(PluginCommand registerCommand) { public void setRegisterCommand(PluginCommand registerCommand) {
this.registerCommand = registerCommand; this.registerCommand = registerCommand;
} }

View File

@ -16,15 +16,10 @@ import java.util.stream.IntStream;
public abstract class BaseSubCommand { public abstract class BaseSubCommand {
private String label; private String label;
private boolean player;
private SubCommand annotation; private SubCommand annotation;
public void setAnnotation(SubCommand annotation) { abstract public void onCommand(CommandSender sender, Command command, String label, String[] args);
this.annotation = annotation;
}
public void setLabel(String label) {
this.label = label;
}
public String getLabel() { public String getLabel() {
return label; return label;
@ -43,7 +38,7 @@ public abstract class BaseSubCommand {
} }
public CommandType getType() { public CommandType getType() {
return annotation.type(); return player ? CommandType.PLAYER : annotation.type();
} }
public boolean ignoredLabel() { public boolean ignoredLabel() {
@ -70,5 +65,18 @@ public abstract class BaseSubCommand {
return TLocale.asString(Strings.isEmpty(getDescription()) ? "COMMANDS.INTERNAL.COMMAND-HELP-EMPTY" : "COMMANDS.INTERNAL.COMMAND-HELP", label, getLabel(), Arrays.stream(getArguments()).map(parameter -> parameter.toString() + " ").collect(Collectors.joining()), getDescription()); return TLocale.asString(Strings.isEmpty(getDescription()) ? "COMMANDS.INTERNAL.COMMAND-HELP-EMPTY" : "COMMANDS.INTERNAL.COMMAND-HELP", label, getLabel(), Arrays.stream(getArguments()).map(parameter -> parameter.toString() + " ").collect(Collectors.joining()), getDescription());
} }
abstract public void onCommand(CommandSender sender, Command command, String label, String[] args); protected BaseSubCommand label(String label) {
this.label = label;
return this;
}
protected BaseSubCommand player() {
player = true;
return this;
}
protected BaseSubCommand annotation(SubCommand annotation) {
this.annotation = annotation;
return this;
}
} }

View File

@ -31,6 +31,7 @@ public class LocalPlayer {
files.forEach((name, file) -> { files.forEach((name, file) -> {
try { try {
file.save(toFile(name)); file.save(toFile(name));
} catch (NullPointerException ignored) {
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }
@ -43,6 +44,7 @@ public class LocalPlayer {
if (toPlayer(name) == null) { if (toPlayer(name) == null) {
try { try {
files.remove(name).save(toFile(name)); files.remove(name).save(toFile(name));
} catch (NullPointerException ignored) {
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }

View File

@ -63,50 +63,50 @@ public class SimpleReflection {
} }
public static void setFieldValue(Class<?> nmsClass, Object instance, String fieldName, Object value) { public static void setFieldValue(Class<?> nmsClass, Object instance, String fieldName, Object value) {
try {
Map<String, Field> fields = fieldCached.get(nmsClass.getName()); Map<String, Field> fields = fieldCached.get(nmsClass.getName());
if (fields == null) { if (fields == null) {
return; throw new RuntimeException("Not Found Cache.");
} }
Field field = fields.get(fieldName); Field field = fields.get(fieldName);
if (value == null) { if (value == null) {
return; throw new RuntimeException("Not Found Field.");
} }
try {
field.set(instance, value); field.set(instance, value);
} catch (Exception e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static Object getFieldValue(Class<?> nmsClass, Object instance, String fieldName) { public static Object getFieldValue(Class<?> nmsClass, Object instance, String fieldName) {
try {
Map<String, Field> fields = fieldCached.get(nmsClass.getName()); Map<String, Field> fields = fieldCached.get(nmsClass.getName());
if (fields == null) { if (fields == null) {
return null; throw new RuntimeException("Not Found Cache.");
} }
Field field = fields.get(fieldName); Field field = fields.get(fieldName);
if (field == null) { if (field == null) {
return null; throw new RuntimeException("Not Found Field.");
} }
try {
return field.get(instance); return field.get(instance);
} catch (Exception e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
public static <T> T getFieldValue(Class<?> nmsClass, Object instance, String fieldName, T def) { public static <T> T getFieldValue(Class<?> nmsClass, Object instance, String fieldName, T def) {
try {
Map<String, Field> fields = fieldCached.get(nmsClass.getName()); Map<String, Field> fields = fieldCached.get(nmsClass.getName());
if (fields == null) { if (fields == null) {
return def; throw new RuntimeException("Not Found Cache.");
} }
Field field = fields.get(fieldName); Field field = fields.get(fieldName);
if (field == null) { if (field == null) {
return def; throw new RuntimeException("Not Found Field.");
} }
try {
return (T) field.get(instance); return (T) field.get(instance);
} catch (Exception e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
return def; return def;

View File

@ -2,6 +2,7 @@ package io.izzel.taboolib.module.nms;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.izzel.taboolib.module.inject.TInject; import io.izzel.taboolib.module.inject.TInject;
import io.izzel.taboolib.module.nms.nbt.Attribute;
import io.izzel.taboolib.module.nms.nbt.NBTAttribute; import io.izzel.taboolib.module.nms.nbt.NBTAttribute;
import io.izzel.taboolib.module.nms.nbt.NBTCompound; import io.izzel.taboolib.module.nms.nbt.NBTCompound;
import io.izzel.taboolib.module.nms.nbt.NBTList; import io.izzel.taboolib.module.nms.nbt.NBTList;
@ -67,4 +68,6 @@ public abstract class NMS {
} }
abstract public List<NBTAttribute> getBaseAttribute(ItemStack item); abstract public List<NBTAttribute> getBaseAttribute(ItemStack item);
abstract public Object toNMS(Attribute attribute);
} }

View File

@ -4,10 +4,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import io.izzel.taboolib.Version; import io.izzel.taboolib.Version;
import io.izzel.taboolib.module.lite.SimpleReflection; import io.izzel.taboolib.module.lite.SimpleReflection;
import io.izzel.taboolib.module.nms.nbt.NBTAttribute; import io.izzel.taboolib.module.nms.nbt.*;
import io.izzel.taboolib.module.nms.nbt.NBTCompound;
import io.izzel.taboolib.module.nms.nbt.NBTList;
import io.izzel.taboolib.module.nms.nbt.NBTOperation;
import io.izzel.taboolib.module.packet.TPacketHandler; import io.izzel.taboolib.module.packet.TPacketHandler;
import net.minecraft.server.v1_12_R1.ChatMessageType; import net.minecraft.server.v1_12_R1.ChatMessageType;
import net.minecraft.server.v1_12_R1.EntityVillager; import net.minecraft.server.v1_12_R1.EntityVillager;
@ -16,6 +13,7 @@ import net.minecraft.server.v1_12_R1.NBTTagCompound;
import net.minecraft.server.v1_13_R2.EnumHand; import net.minecraft.server.v1_13_R2.EnumHand;
import net.minecraft.server.v1_13_R2.IRegistry; import net.minecraft.server.v1_13_R2.IRegistry;
import net.minecraft.server.v1_8_R3.*; import net.minecraft.server.v1_8_R3.*;
import net.minecraft.server.v1_8_R3.NBTBase;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.craftbukkit.v1_12_R1.CraftParticle; import org.bukkit.craftbukkit.v1_12_R1.CraftParticle;
@ -263,6 +261,12 @@ public class NMSImpl extends NMS {
return list; return list;
} }
@Override
public Object toNMS(Attribute attribute) {
SimpleReflection.checkAndSave(GenericAttributes.class);
return SimpleReflection.getFieldValue(GenericAttributes.class, null, attribute.name());
}
private Object toNBTBase(io.izzel.taboolib.module.nms.nbt.NBTBase base) { private Object toNBTBase(io.izzel.taboolib.module.nms.nbt.NBTBase base) {
switch (base.getType().getId()) { switch (base.getType().getId()) {
case 1: case 1:

View File

@ -0,0 +1,62 @@
package io.izzel.taboolib.module.nms.nbt;
import io.izzel.taboolib.module.nms.NMS;
import java.util.Arrays;
/**
* @Author sky
* @Since 2019-12-11 19:31
*/
public enum Attribute {
MAX_HEALTH("generic.maxHealth", new String[] {"health", "maxHealth"}),
FOLLOW_RANGE("generic.followRange", new String[] {"follow", "followRange"}),
KNOCKBACK_RESISTANCE("generic.knockbackResistance", new String[] {"knockback", "knockbackResistance"}),
MOVEMENT_SPEED("generic.movementSpeed", new String[] {"speed", "movementSpeed", "walkSpeed"}),
FLYING_SPEED("generic.flyingSpeed", new String[] {"flySpeed", "flyingSpeed"}),
ATTACK_DAMAGE("generic.attackDamage", new String[] {"damage", "attackDamage"}),
ATTACK_KNOCKBACK("generic.attackKnockback", new String[] {"damageKnockback", "attackKnockback"}),
ATTACK_SPEED("generic.attackSpeed", new String[] {"damageSpeed", "attackSpeed"}),
ARMOR("generic.armor", new String[] {"armor"}),
ARMOR_TOUGHNESS("generic.armorToughness", new String[] {"toughness", "armorToughness"}),
LUCK("generic.luck", new String[] {"luck"});
String minecraftKey;
String[] simplifiedKey;
Attribute(String minecraftKey, String[] simplifiedKey) {
this.minecraftKey = minecraftKey;
this.simplifiedKey = simplifiedKey;
}
public String getMinecraftKey() {
return minecraftKey;
}
public String[] getSimplifiedKey() {
return simplifiedKey;
}
public Object toNMS() {
return NMS.handle().toNMS(this);
}
public boolean match(String source) {
return name().equalsIgnoreCase(source) || minecraftKey.equalsIgnoreCase(source) || Arrays.stream(simplifiedKey).anyMatch(key -> key.equalsIgnoreCase(source));
}
public static Attribute parse(String source) {
return Arrays.stream(values()).filter(attribute -> attribute.match(source)).findFirst().orElse(null);
}
}

View File

@ -1,6 +1,8 @@
package io.izzel.taboolib.module.nms.nbt; package io.izzel.taboolib.module.nms.nbt;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import io.izzel.taboolib.module.nms.NMS;
import org.bukkit.inventory.ItemStack;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
@ -24,6 +26,10 @@ public class NBTCompound extends NBTBase implements Map<String, NBTBase> {
this.data = this; this.data = this;
} }
public void saveTo(ItemStack item) {
item.setItemMeta(NMS.handle().saveNBT(item, this).getItemMeta());
}
@Override @Override
public int size() { public int size() {
return value.size(); return value.size();

View File

@ -6,6 +6,7 @@ import io.izzel.taboolib.module.lite.SimpleEquip;
import io.izzel.taboolib.module.lite.SimpleI18n; import io.izzel.taboolib.module.lite.SimpleI18n;
import io.izzel.taboolib.module.locale.TLocale; import io.izzel.taboolib.module.locale.TLocale;
import io.izzel.taboolib.module.nms.NMS; import io.izzel.taboolib.module.nms.NMS;
import io.izzel.taboolib.module.nms.nbt.Attribute;
import io.izzel.taboolib.module.nms.nbt.NBTBase; import io.izzel.taboolib.module.nms.nbt.NBTBase;
import io.izzel.taboolib.module.nms.nbt.NBTCompound; import io.izzel.taboolib.module.nms.nbt.NBTCompound;
import io.izzel.taboolib.module.nms.nbt.NBTList; import io.izzel.taboolib.module.nms.nbt.NBTList;
@ -54,6 +55,14 @@ public class Items {
return !isNull(item); return !isNull(item);
} }
public static boolean hasName(ItemStack i) {
return !isNull(i) && i.getItemMeta().hasDisplayName();
}
public static boolean hasName(ItemStack i, String a) {
return hasName(i) && getName(i).contains(a);
}
public static boolean hasLore(ItemStack i, String a) { public static boolean hasLore(ItemStack i, String a) {
return hasLore(i) && i.getItemMeta().getLore().toString().contains(a); return hasLore(i) && i.getItemMeta().getLore().toString().contains(a);
} }
@ -62,10 +71,6 @@ public class Items {
return !isNull(i) && i.getItemMeta().hasLore(); return !isNull(i) && i.getItemMeta().hasLore();
} }
public static boolean hasName(ItemStack i) {
return !isNull(i) && i.getItemMeta().hasDisplayName();
}
public static Material asMaterial(String args) { public static Material asMaterial(String args) {
try { try {
Material material = Material.getMaterial(args.toUpperCase()); Material material = Material.getMaterial(args.toUpperCase());
@ -111,24 +116,7 @@ public class Items {
} }
public static String asAttribute(String name) { public static String asAttribute(String name) {
switch (name.toLowerCase()) { return Attribute.parse(name).getMinecraftKey();
case "damage":
return "generic.attackDamage";
case "attackspeed":
return "generic.attackSpeed";
case "health":
return "generic.maxHealth";
case "speed":
return "generic.movementSpeed";
case "knockback":
return "generic.knockbackResistance";
case "armor":
return "generic.armor";
case "luck":
return "generic.luck";
default:
return null;
}
} }
public static ItemStack replaceName(ItemStack item, String nameOld, String nameNew) { public static ItemStack replaceName(ItemStack item, String nameOld, String nameNew) {

View File

@ -30,25 +30,27 @@ class ClickListener implements Listener {
@EventHandler @EventHandler
public void e(PluginDisableEvent e) { public void e(PluginDisableEvent e) {
Bukkit.getOnlinePlayers().stream().filter(player -> player.getOpenInventory().getTopInventory().getHolder() instanceof MenuHolder && e.getPlugin().equals(((MenuHolder) player.getOpenInventory().getTopInventory().getHolder()).getBuilder().getPlugin())).forEach(HumanEntity::closeInventory); Bukkit.getOnlinePlayers().stream().filter(player -> MenuHolder.get(player.getOpenInventory().getTopInventory()) != null).forEach(HumanEntity::closeInventory);
} }
@EventHandler @EventHandler
public void e(InventoryOpenEvent e) { public void e(InventoryOpenEvent e) {
if (e.getInventory().getHolder() instanceof MenuHolder) { MenuBuilder builder = MenuHolder.get(e.getInventory());
Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> ((MenuHolder) e.getInventory().getHolder()).getBuilder().getBuildTask().run(e.getInventory())); if (builder != null) {
Bukkit.getScheduler().runTaskAsynchronously(TabooLib.getPlugin(), () -> ((MenuHolder) e.getInventory().getHolder()).getBuilder().getBuildTaskAsync().run(e.getInventory())); Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> builder.getBuildTask().run(e.getInventory()), 1);
Bukkit.getScheduler().runTaskLaterAsynchronously(TabooLib.getPlugin(), () -> builder.getBuildTaskAsync().run(e.getInventory()), 1);
} }
} }
@EventHandler @EventHandler
public void e(InventoryClickEvent e) { public void e(InventoryClickEvent e) {
if (e.getInventory().getHolder() instanceof MenuHolder) { MenuBuilder builder = MenuHolder.get(e.getInventory());
if (builder != null) {
// lock hand // lock hand
if (((MenuHolder) e.getInventory().getHolder()).getBuilder().isLockHand() && (e.getRawSlot() - e.getInventory().getSize() - 27 == e.getWhoClicked().getInventory().getHeldItemSlot() || (e.getClick() == org.bukkit.event.inventory.ClickType.NUMBER_KEY && e.getHotbarButton() == e.getWhoClicked().getInventory().getHeldItemSlot()))) { if (builder.isLockHand() && (e.getRawSlot() - e.getInventory().getSize() - 27 == e.getWhoClicked().getInventory().getHeldItemSlot() || (e.getClick() == org.bukkit.event.inventory.ClickType.NUMBER_KEY && e.getHotbarButton() == e.getWhoClicked().getInventory().getHeldItemSlot()))) {
e.setCancelled(true); e.setCancelled(true);
} }
Optional.ofNullable(((MenuHolder) e.getInventory().getHolder()).getBuilder().getClickTask()).ifPresent(t -> t.run(new ClickEvent(ClickType.CLICK, e, ((MenuHolder) e.getInventory().getHolder()).getBuilder().getSlot(e.getRawSlot())))); Optional.ofNullable(builder.getClickTask()).ifPresent(t -> t.run(new ClickEvent(ClickType.CLICK, e, builder.getSlot(e.getRawSlot()))));
// drop on empty area // drop on empty area
if (!e.isCancelled() && Items.nonNull(e.getCurrentItem()) && e.getClick() == org.bukkit.event.inventory.ClickType.DROP) { if (!e.isCancelled() && Items.nonNull(e.getCurrentItem()) && e.getClick() == org.bukkit.event.inventory.ClickType.DROP) {
Item item = Vectors.itemDrop((Player) e.getWhoClicked(), e.getCurrentItem()); Item item = Vectors.itemDrop((Player) e.getWhoClicked(), e.getCurrentItem());
@ -78,15 +80,17 @@ class ClickListener implements Listener {
@EventHandler @EventHandler
public void e(InventoryDragEvent e) { public void e(InventoryDragEvent e) {
if (e.getInventory().getHolder() instanceof MenuHolder) { MenuBuilder builder = MenuHolder.get(e.getInventory());
Optional.ofNullable(((MenuHolder) e.getInventory().getHolder()).getBuilder().getClickTask()).ifPresent(t -> t.run(new ClickEvent(ClickType.DRAG, e, ' '))); if (builder != null) {
builder.getClickTask().run(new ClickEvent(ClickType.DRAG, e, ' '));
} }
} }
@EventHandler @EventHandler
public void e(InventoryCloseEvent e) { public void e(InventoryCloseEvent e) {
if (e.getInventory().getHolder() instanceof MenuHolder) { MenuBuilder builder = MenuHolder.get(e.getInventory());
Optional.ofNullable(((MenuHolder) e.getInventory().getHolder()).getBuilder().getCloseTask()).ifPresent(t -> t.run(e)); if (builder != null) {
builder.getCloseTask().run(e);
} }
} }

View File

@ -23,10 +23,14 @@ public class MenuBuilder {
private String title; private String title;
private int rows; private int rows;
private char[][] items = new char[0][0]; private char[][] items = new char[0][0];
private ClickTask clickTask; private ClickTask clickTask = r -> {
private CloseTask closeTask; };
private BuildTask buildTask; private CloseTask closeTask = r -> {
private BuildTask buildTaskAsync; };
private BuildTask buildTask = r -> {
};
private BuildTask buildTaskAsync = r -> {
};
private boolean lockHand; private boolean lockHand;
public MenuBuilder(Plugin plugin) { public MenuBuilder(Plugin plugin) {
@ -41,6 +45,10 @@ public class MenuBuilder {
return new MenuBuilder(Ref.getCallerPlugin(Ref.getCallerClass(3).orElse(TabooLib.class))); return new MenuBuilder(Ref.getCallerPlugin(Ref.getCallerClass(3).orElse(TabooLib.class)));
} }
public void open(Player player) {
player.openInventory(build());
}
public MenuBuilder lockHand() { public MenuBuilder lockHand() {
this.lockHand = true; this.lockHand = true;
return this; return this;
@ -94,10 +102,6 @@ public class MenuBuilder {
return this; return this;
} }
public void open(Player player) {
player.openInventory(build());
}
public Inventory build() { public Inventory build() {
Inventory inventory = Bukkit.createInventory(new MenuHolder(this), rows, String.valueOf(title)); Inventory inventory = Bukkit.createInventory(new MenuHolder(this), rows, String.valueOf(title));
for (int i = 0; i < items.length && i < rows; i++) { for (int i = 0; i < items.length && i < rows; i++) {

View File

@ -23,4 +23,8 @@ class MenuHolder implements InventoryHolder {
public Inventory getInventory() { public Inventory getInventory() {
return null; return null;
} }
public static MenuBuilder get(Inventory inventory) {
return inventory.getHolder() instanceof MenuHolder ? ((MenuHolder) inventory.getHolder()).getBuilder() : null;
}
} }

View File

@ -15,5 +15,4 @@ object AsyncTask {
def apply(init: Long, period: Long)(task: => Any)(implicit plugin: Plugin): Int = { def apply(init: Long, period: Long)(task: => Any)(implicit plugin: Plugin): Int = {
ScalaTaskExecutor(task).runTaskTimerAsynchronously(plugin, init, period).getTaskId ScalaTaskExecutor(task).runTaskTimerAsynchronously(plugin, init, period).getTaskId
} }
} }

View File

@ -29,5 +29,4 @@ class Example extends JavaPlugin with Listener {
class a class a
assert(this == JavaPlugin.getProvidingPlugin(classOf[a])) assert(this == JavaPlugin.getProvidingPlugin(classOf[a]))
} }
} }