This commit is contained in:
坏黑 2019-04-26 00:02:30 +08:00
parent e16b05494d
commit 8ee634f0c9
5 changed files with 110 additions and 1 deletions

View File

@ -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 = '4.76' version = '4.77'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8

View File

@ -52,6 +52,10 @@ public class TLocale {
Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, sender, args, clazz)); Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, sender, args, clazz));
} }
public static void broadcast(String path, String... args) {
Ref.getCallerClass(3).ifPresent(clazz -> Bukkit.getOnlinePlayers().forEach(player -> sendTo(path, player, args, clazz)));
}
public static String asString(String path, String... args) { public static String asString(String path, String... args) {
try { try {
return asString(path, Ref.getCallerClass(3).orElse(Main.class), args); return asString(path, Ref.getCallerClass(3).orElse(Main.class), args);
@ -119,6 +123,14 @@ public class TLocale {
return args.stream().map(var -> ChatColor.translateAlternateColorCodes('&', var)).collect(Collectors.toList()); return args.stream().map(var -> ChatColor.translateAlternateColorCodes('&', var)).collect(Collectors.toList());
} }
public static String setUncolored(String args) {
return ChatColor.stripColor(args);
}
public static List<String> setUncolored(List<String> args) {
return args.stream().map(ChatColor::stripColor).collect(Collectors.toList());
}
public static String setPlaceholders(CommandSender sender, String args) { public static String setPlaceholders(CommandSender sender, String args) {
return isPlaceholderPluginEnabled() ? sender instanceof Player ? PlaceholderAPI.setPlaceholders((Player) sender, args) : args : args; return isPlaceholderPluginEnabled() ? sender instanceof Player ? PlaceholderAPI.setPlaceholders((Player) sender, args) : args : args;
} }

View File

@ -8,6 +8,8 @@ import me.skymc.taboolib.commands.builder.SimpleCommandBuilder;
import me.skymc.taboolib.common.configuration.TConfiguration; import me.skymc.taboolib.common.configuration.TConfiguration;
import me.skymc.taboolib.common.packet.TPacketHandler; import me.skymc.taboolib.common.packet.TPacketHandler;
import me.skymc.taboolib.common.packet.TPacketListener; import me.skymc.taboolib.common.packet.TPacketListener;
import me.skymc.taboolib.cooldown.seconds.CooldownPack2;
import me.skymc.taboolib.cooldown.seconds.CooldownUtils2;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -71,6 +73,14 @@ public class TInjectLoader implements TabooLibLoader.Loader {
e.printStackTrace(); e.printStackTrace();
} }
}); });
// CooldownPack Inject
injectTypes.put(CooldownPack2.class, (plugin, field, args, instance) -> {
try {
CooldownUtils2.register((CooldownPack2) field.get(instance), plugin);
} catch (Throwable t) {
t.printStackTrace();
}
});
} }
@Override @Override

View File

@ -0,0 +1,78 @@
package me.skymc.taboolib.inventory;
import com.google.common.collect.Maps;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.Map;
/**
* @Author 坏黑
* @Since 2019-04-25 22:01
*/
public enum TEquipment {
HAND(EquipmentSlot.HAND, -1),
OFF_HAND(EquipmentSlot.OFF_HAND, 40),
FEET(EquipmentSlot.FEET, 36),
LEGS(EquipmentSlot.LEGS, 37),
CHEST(EquipmentSlot.CHEST, 38),
HEAD(EquipmentSlot.HEAD, 39);
private EquipmentSlot bukkit;
private int slot;
TEquipment(EquipmentSlot bukkit, int slot) {
this.bukkit = bukkit;
this.slot = slot;
}
public void setItem(Player player, ItemStack item) {
if (this != HAND) {
player.getInventory().setItem(slot, item);
} else {
player.setItemInHand(item);
}
}
public ItemStack getItem(Player player) {
if (this != HAND) {
return player.getInventory().getItem(slot);
} else {
return player.getItemInHand();
}
}
public static TEquipment fromBukkit(EquipmentSlot bukkit) {
return Arrays.stream(values()).filter(tEquipment -> tEquipment.bukkit == bukkit).findFirst().orElse(null);
}
public static Map<TEquipment, ItemStack> getItems(Player player) {
Map<TEquipment, ItemStack> map = Maps.newHashMap();
for (TEquipment equipment : values()) {
map.put(equipment, equipment.getItem(player));
}
return map;
}
// *********************************
//
// Getter and Setter
//
// *********************************
public EquipmentSlot getBukkit() {
return bukkit;
}
public int getSlot() {
return slot;
}
}

View File

@ -6,6 +6,7 @@ import com.ilummc.tlib.resources.TLocale;
import com.ilummc.tlib.util.Strings; import com.ilummc.tlib.util.Strings;
import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.string.ArrayUtils; import me.skymc.taboolib.string.ArrayUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -55,6 +56,14 @@ public class TellrawJson {
return new TellrawJson(); return new TellrawJson();
} }
public void broadcast() {
Bukkit.getOnlinePlayers().forEach(player -> send(player, new String[0]));
}
public void broadcast(String... args) {
Bukkit.getOnlinePlayers().forEach(player -> send(player, args));
}
public void send(CommandSender sender) { public void send(CommandSender sender) {
send(sender, new String[0]); send(sender, new String[0]);
} }