Update 5.26

This commit is contained in:
sky 2020-04-16 00:00:22 +08:00
parent d9a8b73b51
commit bd18f3f4a1
5 changed files with 158 additions and 14 deletions

View File

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

View File

@ -1,5 +1,7 @@
package io.izzel.taboolib.module.lite; package io.izzel.taboolib.module.lite;
import io.izzel.taboolib.Version;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -29,6 +31,7 @@ public enum SimpleEquip {
private EquipmentSlot bukkit; private EquipmentSlot bukkit;
private String nms; private String nms;
private int slot; private int slot;
private boolean supported = Version.isAfter(Version.v1_9);
SimpleEquip(EquipmentSlot bukkit, String nms, int slot) { SimpleEquip(EquipmentSlot bukkit, String nms, int slot) {
this.bukkit = bukkit; this.bukkit = bukkit;
@ -37,18 +40,118 @@ public enum SimpleEquip {
} }
public void setItem(Player player, ItemStack item) { public void setItem(Player player, ItemStack item) {
if (this != HAND) { setItem((LivingEntity) player, item);
player.getInventory().setItem(slot, item); }
} else {
player.setItemInHand(item); public void setItem(LivingEntity entity, ItemStack item) {
switch (this) {
case HAND:
if (supported) {
entity.getEquipment().setItemInMainHand(item);
} else {
entity.getEquipment().setItemInHand(item);
}
break;
case OFF_HAND:
if (supported) {
entity.getEquipment().setItemInOffHand(item);
}
break;
case FEET:
entity.getEquipment().setBoots(item);
break;
case LEGS:
entity.getEquipment().setLeggings(item);
break;
case CHEST:
entity.getEquipment().setChestplate(item);
break;
case HEAD:
entity.getEquipment().setHelmet(item);
break;
}
}
public void setItemDropChance(LivingEntity entity, float chance) {
switch (this) {
case HAND:
if (supported) {
entity.getEquipment().setItemInMainHandDropChance(chance);
} else {
entity.getEquipment().setItemInHandDropChance(chance);
}
break;
case OFF_HAND:
if (supported) {
entity.getEquipment().setItemInOffHandDropChance(chance);
}
break;
case FEET:
entity.getEquipment().setBootsDropChance(chance);
break;
case LEGS:
entity.getEquipment().setLeggingsDropChance(chance);
break;
case CHEST:
entity.getEquipment().setChestplateDropChance(chance);
break;
case HEAD:
entity.getEquipment().setHelmetDropChance(chance);
break;
} }
} }
public ItemStack getItem(Player player) { public ItemStack getItem(Player player) {
if (this != HAND) { return getItem((LivingEntity) player);
return player.getInventory().getItem(slot); }
} else {
return player.getItemInHand(); public ItemStack getItem(LivingEntity entity) {
switch (this) {
case HAND:
if (supported) {
return entity.getEquipment().getItemInMainHand();
} else {
return entity.getEquipment().getItemInHand();
}
case OFF_HAND:
if (supported) {
return entity.getEquipment().getItemInOffHand();
}
case FEET:
return entity.getEquipment().getBoots();
case LEGS:
return entity.getEquipment().getLeggings();
case CHEST:
return entity.getEquipment().getChestplate();
case HEAD:
return entity.getEquipment().getHelmet();
default:
return null;
}
}
public float getItemDropChance(LivingEntity entity) {
switch (this) {
case HAND:
if (supported) {
return entity.getEquipment().getItemInMainHandDropChance();
} else {
return entity.getEquipment().getItemInHandDropChance();
}
case OFF_HAND:
if (supported) {
return entity.getEquipment().getItemInOffHandDropChance();
}
case FEET:
return entity.getEquipment().getBootsDropChance();
case LEGS:
return entity.getEquipment().getLeggingsDropChance();
case CHEST:
return entity.getEquipment().getChestplateDropChance();
case HEAD:
return entity.getEquipment().getHelmetDropChance();
default:
return 0f;
} }
} }
@ -61,7 +164,11 @@ public enum SimpleEquip {
} }
public static Map<SimpleEquip, ItemStack> getItems(Player player) { public static Map<SimpleEquip, ItemStack> getItems(Player player) {
return Arrays.stream(values()).collect(Collectors.toMap(equipment -> equipment, equipment -> equipment.getItem(player), (a, b) -> b)); return getItems((LivingEntity) player);
}
public static Map<SimpleEquip, ItemStack> getItems(LivingEntity entity) {
return Arrays.stream(values()).collect(Collectors.toMap(equipment -> equipment, equipment -> equipment.getItem(entity), (a, b) -> b));
} }
// ********************************* // *********************************

View File

@ -12,12 +12,16 @@ public class Numbers {
private static Random random = new Random(); private static Random random = new Random();
private static DecimalFormat doubleFormat = new DecimalFormat("#.##"); private static DecimalFormat doubleFormat = new DecimalFormat("#.##");
public static Random getRandom() {
return random;
}
public static boolean random(double v) { public static boolean random(double v) {
return random.nextDouble() <= v; return random.nextDouble() <= v;
} }
public static Random getRandom() { public static int random(int v) {
return random; return random.nextInt(v);
} }
public static Double format(Double num) { public static Double format(Double num) {

View File

@ -49,6 +49,10 @@ public class TagDataHandler implements Listener {
return getPlayerDataComputeIfAbsent(player).getNameDisplay(); return getPlayerDataComputeIfAbsent(player).getNameDisplay();
} }
public boolean isNameVisibility(Player player) {
return getPlayerDataComputeIfAbsent(player).isNameVisibility();
}
public void setPrefix(Player player, String prefix) { public void setPrefix(Player player, String prefix) {
updatePlayerVariable(getPlayerDataComputeIfAbsent(player).setPrefix(prefix)); updatePlayerVariable(getPlayerDataComputeIfAbsent(player).setPrefix(prefix));
updatePlayerListName(player); updatePlayerListName(player);
@ -64,6 +68,11 @@ public class TagDataHandler implements Listener {
updatePlayerListName(player); updatePlayerListName(player);
} }
public void setNameVisibility(Player player, boolean v) {
updatePlayerVariable(getPlayerDataComputeIfAbsent(player).setNameVisibility(v));
updatePlayerListName(player);
}
public void resetVariable(Player player) { public void resetVariable(Player player) {
updatePlayerVariable(getPlayerDataComputeIfAbsent(player).reset()); updatePlayerVariable(getPlayerDataComputeIfAbsent(player).reset());
updatePlayerListName(player); updatePlayerListName(player);
@ -104,6 +113,12 @@ public class TagDataHandler implements Listener {
if (entryTeam.getSuffix() == null || !entryTeam.getSuffix().equals(playerData.getSuffix())) { if (entryTeam.getSuffix() == null || !entryTeam.getSuffix().equals(playerData.getSuffix())) {
entryTeam.setSuffix(playerData.getSuffix()); entryTeam.setSuffix(playerData.getSuffix());
} }
Team.OptionStatus option = entryTeam.getOption(Team.Option.NAME_TAG_VISIBILITY);
if (option == Team.OptionStatus.ALWAYS && !playerData.isNameVisibility()) {
entryTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
} else if (option == Team.OptionStatus.NEVER && playerData.isNameVisibility()) {
entryTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
}
if (TabooLib.getConfig().getBoolean("TABLIST-AUTO-CLEAN-TEAM", true)) { if (TabooLib.getConfig().getBoolean("TABLIST-AUTO-CLEAN-TEAM", true)) {
TagUtils.cleanEmptyTeamInScoreboard(scoreboard); TagUtils.cleanEmptyTeamInScoreboard(scoreboard);
} }

View File

@ -1,7 +1,6 @@
package io.izzel.taboolib.util.tag; package io.izzel.taboolib.util.tag;
import io.izzel.taboolib.TabooLib; import io.izzel.taboolib.TabooLib;
import io.izzel.taboolib.util.Strings;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Objects; import java.util.Objects;
@ -18,6 +17,7 @@ public class TagPlayerData {
private String nameDisplay; private String nameDisplay;
private String prefix; private String prefix;
private String suffix; private String suffix;
private boolean nameAllow;
public TagPlayerData(Player player) { public TagPlayerData(Player player) {
this.uuid = player.getUniqueId(); this.uuid = player.getUniqueId();
@ -25,6 +25,7 @@ public class TagPlayerData {
this.nameDisplay = player.getName(); this.nameDisplay = player.getName();
this.prefix = ""; this.prefix = "";
this.suffix = ""; this.suffix = "";
this.nameAllow = true;
} }
public String getTeamHash() { public String getTeamHash() {
@ -39,12 +40,20 @@ public class TagPlayerData {
this.nameDisplay = getNameOrigin(); this.nameDisplay = getNameOrigin();
this.prefix = ""; this.prefix = "";
this.suffix = ""; this.suffix = "";
this.nameAllow = true;
return this; return this;
} }
@Override @Override
public String toString() { public String toString() {
return Strings.replaceWithOrder("TagPlayerData'{'uuid={0}, nameOrigin=''{1}'', nameDisplay=''{2}'', prefix=''{3}'', suffix=''{4}'''}'", uuid, nameOrigin, nameDisplay, prefix, suffix); return "TagPlayerData{" +
"uuid=" + uuid +
", nameOrigin='" + nameOrigin + '\'' +
", nameDisplay='" + nameDisplay + '\'' +
", prefix='" + prefix + '\'' +
", suffix='" + suffix + '\'' +
", nameAllow=" + nameAllow +
'}';
} }
// ********************************* // *********************************
@ -73,6 +82,15 @@ public class TagPlayerData {
return suffix == null ? "" : suffix; return suffix == null ? "" : suffix;
} }
public boolean isNameVisibility() {
return nameAllow;
}
public TagPlayerData setNameVisibility(boolean nameAllow) {
this.nameAllow = nameAllow;
return this;
}
public TagPlayerData setNameDisplay(String nameDisplay) { public TagPlayerData setNameDisplay(String nameDisplay) {
this.nameDisplay = nameDisplay.length() > 16 ? nameDisplay.substring(0, 16) : nameDisplay; this.nameDisplay = nameDisplay.length() > 16 ? nameDisplay.substring(0, 16) : nameDisplay;
return this; return this;