This commit is contained in:
sky 2020-04-12 15:04:54 +08:00
parent 5c4941f536
commit d9a8b73b51
9 changed files with 76 additions and 24 deletions

View File

@ -2,13 +2,12 @@ package io.izzel.taboolib.client;
import io.izzel.taboolib.TabooLib; import io.izzel.taboolib.TabooLib;
import io.izzel.taboolib.client.packet.Packet; import io.izzel.taboolib.client.packet.Packet;
import io.izzel.taboolib.client.packet.PacketSerializer;
import io.izzel.taboolib.client.packet.impl.PacketCommand; import io.izzel.taboolib.client.packet.impl.PacketCommand;
import io.izzel.taboolib.client.packet.impl.PacketMessage; import io.izzel.taboolib.client.packet.impl.PacketMessage;
import io.izzel.taboolib.module.locale.TLocale;
import io.izzel.taboolib.module.command.lite.CommandBuilder; import io.izzel.taboolib.module.command.lite.CommandBuilder;
import io.izzel.taboolib.client.packet.PacketSerializer; import io.izzel.taboolib.module.locale.TLocale;
import io.izzel.taboolib.util.ArrayUtil; import io.izzel.taboolib.util.ArrayUtil;
import org.bukkit.Bukkit;
import org.bukkit.util.NumberConversions; import org.bukkit.util.NumberConversions;
import java.io.*; import java.io.*;
@ -34,7 +33,7 @@ public class TabooLibClient {
public static void init() { public static void init() {
if (TabooLibSettings.load()) { if (TabooLibSettings.load()) {
connect(); connect();
Bukkit.getScheduler().runTaskTimerAsynchronously(TabooLib.getPlugin(), TabooLibClient::reconnect, 0, 100); TabooLib.getPlugin().runTaskAsync(TabooLibClient::reconnect, 0, 100);
} else { } else {
TLocale.sendToConsole("COMMUNICATION.FAILED-LOAD-SETTINGS", TabooLibSettings.getThrowable().toString()); TLocale.sendToConsole("COMMUNICATION.FAILED-LOAD-SETTINGS", TabooLibSettings.getThrowable().toString());
} }

View File

@ -134,11 +134,11 @@ public class ListenerCommand implements Listener {
public void run(Player player) { public void run(Player player) {
player.sendMessage("§8[§fTabooLib§8] §7Lighting. §a(+)"); player.sendMessage("§8[§fTabooLib§8] §7Lighting. §a(+)");
TLight.create(player.getLocation().getBlock(), Type.BLOCK, 15); TLight.create(player.getLocation().getBlock(), Type.BLOCK, 15);
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> { TabooLib.getPlugin().runTask(() -> {
TLight.create(player.getLocation().getBlock(), Type.BLOCK, 5); TLight.create(player.getLocation().getBlock(), Type.BLOCK, 5);
player.sendMessage("§8[§fTabooLib§8] §7Lighting. §c(-)"); player.sendMessage("§8[§fTabooLib§8] §7Lighting. §c(-)");
}, 20); }, 20);
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> { TabooLib.getPlugin().runTask(() -> {
TLight.delete(player.getLocation().getBlock(), Type.BLOCK); TLight.delete(player.getLocation().getBlock(), Type.BLOCK);
player.sendMessage("§8[§fTabooLib§8] §7Lighting. §8(-)"); player.sendMessage("§8[§fTabooLib§8] §7Lighting. §8(-)");
}, 40); }, 40);

View File

@ -137,4 +137,64 @@ public class InternalPlugin implements Plugin {
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
return null; return null;
} }
public void runTask(Runnable runnable) {
Bukkit.getScheduler().runTask(this, () -> {
try {
runnable.run();
} catch (Throwable t) {
t.printStackTrace();
}
});
}
public void runTaskAsync(Runnable runnable) {
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
try {
runnable.run();
} catch (Throwable t) {
t.printStackTrace();
}
});
}
public void runTask(Runnable runnable, long delay) {
Bukkit.getScheduler().runTaskLater(this, () -> {
try {
runnable.run();
} catch (Throwable t) {
t.printStackTrace();
}
}, delay);
}
public void runTaskAsync(Runnable runnable, long delay) {
Bukkit.getScheduler().runTaskLaterAsynchronously(this, () -> {
try {
runnable.run();
} catch (Throwable t) {
t.printStackTrace();
}
}, delay);
}
public void runTask(Runnable runnable, long delay, long period) {
Bukkit.getScheduler().runTaskTimer(this, () -> {
try {
runnable.run();
} catch (Throwable t) {
t.printStackTrace();
}
}, delay, period);
}
public void runTaskAsync(Runnable runnable, long delay, long period) {
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
try {
runnable.run();
} catch (Throwable t) {
t.printStackTrace();
}
}, delay, period);
}
} }

View File

@ -107,7 +107,7 @@ public class Hologram {
public Hologram flash(List<String> text, int period) { public Hologram flash(List<String> text, int period) {
for (int i = 0; i < text.size(); i++) { for (int i = 0; i < text.size(); i++) {
String line = text.get(i); String line = text.get(i);
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> flash(line), period * i); TabooLib.getPlugin().runTask(() -> flash(line), period * i);
} }
return this; return this;
} }
@ -129,7 +129,7 @@ public class Hologram {
public Hologram flash(Vector vector, int period, int times) { public Hologram flash(Vector vector, int period, int times) {
for (int i = 0; i < times; i++) { for (int i = 0; i < times; i++) {
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> flash(location.add(vector)), period * i); TabooLib.getPlugin().runTask(() -> flash(location.add(vector)), period * i);
} }
return this; return this;
} }
@ -156,7 +156,7 @@ public class Hologram {
} }
public Hologram deleteOn(int delay) { public Hologram deleteOn(int delay) {
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), this::delete, delay); TabooLib.getPlugin().runTask(this::delete, delay);
return this; return this;
} }

View File

@ -45,7 +45,7 @@ class THologramHandler implements Listener {
static boolean d(Player player, Packet packet) { static boolean d(Player player, Packet packet) {
if (packet.is("PacketPlayInPosition") && !learned) { if (packet.is("PacketPlayInPosition") && !learned) {
learned = true; learned = true;
Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> learn(player)); TabooLib.getPlugin().runTask(() -> learn(player));
} }
if (packet.is("PacketPlayInUseEntity")) { if (packet.is("PacketPlayInUseEntity")) {
int id = packet.read("a", Integer.TYPE); int id = packet.read("a", Integer.TYPE);

View File

@ -35,14 +35,14 @@ class ClickListener implements Listener {
public void e(InventoryOpenEvent e) { public void e(InventoryOpenEvent e) {
MenuBuilder builder = MenuHolder.get(e.getInventory()); MenuBuilder builder = MenuHolder.get(e.getInventory());
if (builder != null) { if (builder != null) {
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> { TabooLib.getPlugin().runTask(() -> {
try { try {
builder.getBuildTask().run(e.getInventory()); builder.getBuildTask().run(e.getInventory());
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }
}, 1); }, 1);
Bukkit.getScheduler().runTaskLaterAsynchronously(TabooLib.getPlugin(), () -> { TabooLib.getPlugin().runTaskAsync(() -> {
try { try {
builder.getBuildTaskAsync().run(e.getInventory()); builder.getBuildTaskAsync().run(e.getInventory());
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -3,7 +3,6 @@ package io.izzel.taboolib.util.lite;
import io.izzel.taboolib.TabooLib; import io.izzel.taboolib.TabooLib;
import io.izzel.taboolib.module.inject.PlayerContainer; import io.izzel.taboolib.module.inject.PlayerContainer;
import io.izzel.taboolib.module.inject.TListener; import io.izzel.taboolib.module.inject.TListener;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -38,7 +37,7 @@ public class Catchers implements Listener {
if (playerdata.containsKey(e.getPlayer().getName()) && contains(e.getPlayer())) { if (playerdata.containsKey(e.getPlayer().getName()) && contains(e.getPlayer())) {
e.setCancelled(true); e.setCancelled(true);
// 1.14 supported. // 1.14 supported.
Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> { TabooLib.getPlugin().runTask(() -> {
Catcher catcher = playerdata.get(e.getPlayer().getName()).getFirst(); Catcher catcher = playerdata.get(e.getPlayer().getName()).getFirst();
// 退出 // 退出
if (e.getMessage().split(" ")[0].matches(catcher.quit())) { if (e.getMessage().split(" ")[0].matches(catcher.quit())) {

View File

@ -8,7 +8,6 @@ import io.izzel.taboolib.module.nms.impl.Position;
import io.izzel.taboolib.module.packet.Packet; import io.izzel.taboolib.module.packet.Packet;
import io.izzel.taboolib.module.packet.TPacket; import io.izzel.taboolib.module.packet.TPacket;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -80,12 +79,8 @@ public class Signs {
if (data == null) { if (data == null) {
return true; return true;
} }
Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> { TabooLib.getPlugin().runTask(() -> {
try { data.catcher.accept(packet.read("b", new String[0]));
data.catcher.accept(packet.read("b", new String[0]));
} catch (Throwable t) {
t.printStackTrace();
}
}); });
signs.remove(data); signs.remove(data);
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -1,7 +1,6 @@
package io.izzel.taboolib.util.lite; package io.izzel.taboolib.util.lite;
import io.izzel.taboolib.TabooLib; import io.izzel.taboolib.TabooLib;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -37,11 +36,11 @@ public class SoundPack {
} }
public void play(Player p) { public void play(Player p) {
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> p.playSound(p.getLocation(), this.sound, this.a, this.b), delay); TabooLib.getPlugin().runTask(() -> p.playSound(p.getLocation(), this.sound, this.a, this.b), delay);
} }
public void play(Location l) { public void play(Location l) {
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> l.getWorld().playSound(l, this.sound, this.a, this.b), delay); TabooLib.getPlugin().runTask(() -> l.getWorld().playSound(l, this.sound, this.a, this.b), delay);
} }
public void parse(String s) { public void parse(String s) {