mirror of
https://github.com/kaboomserver/extras.git
synced 2024-11-27 01:45:44 -05:00
Remove usage of deprecated APIs
This commit is contained in:
parent
7b51a42080
commit
9639dde2df
8 changed files with 67 additions and 47 deletions
|
@ -3,10 +3,10 @@ package pw.kaboom.extras.commands;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import pw.kaboom.extras.util.Utility;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
@ -24,8 +24,7 @@ public final class CommandConsole implements CommandExecutor {
|
||||||
|
|
||||||
Bukkit.dispatchCommand(
|
Bukkit.dispatchCommand(
|
||||||
Bukkit.getConsoleSender(),
|
Bukkit.getConsoleSender(),
|
||||||
"minecraft:say " + ChatColor.translateAlternateColorCodes(
|
"minecraft:say " + Utility.translateLegacyColors(String.join(" ", args))
|
||||||
'&', String.join(" ", args))
|
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import com.destroystokyo.paper.profile.PlayerProfile;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import pw.kaboom.extras.util.Utility;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -28,8 +28,7 @@ public final class CommandUsername implements CommandExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String nameColor = ChatColor.translateAlternateColorCodes(
|
final String nameColor = Utility.translateLegacyColors(String.join(" ", args));
|
||||||
'&', String.join(" ", args));
|
|
||||||
final String name = nameColor.substring(0, Math.min(16, nameColor.length()));
|
final String name = nameColor.substring(0, Math.min(16, nameColor.length()));
|
||||||
final long millis = lastUsedMillis.getOrDefault(player, 0L);
|
final long millis = lastUsedMillis.getOrDefault(player, 0L);
|
||||||
final long millisDifference = System.currentTimeMillis() - millis;
|
final long millisDifference = System.currentTimeMillis() - millis;
|
||||||
|
@ -61,10 +60,11 @@ public final class CommandUsername implements CommandExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlayerProfile profile = player.getPlayerProfile();
|
// Preserve UUIDs, as changing them breaks clients
|
||||||
|
final PlayerProfile newProfile = Bukkit.createProfileExact(player.getUniqueId(), name);
|
||||||
|
newProfile.setProperties(player.getPlayerProfile().getProperties());
|
||||||
|
|
||||||
profile.setName(name); // FIXME: Marked for removal
|
player.setPlayerProfile(newProfile);
|
||||||
player.setPlayerProfile(profile);
|
|
||||||
lastUsedMillis.put(player, System.currentTimeMillis());
|
lastUsedMillis.put(player, System.currentTimeMillis());
|
||||||
|
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
|
|
|
@ -1,21 +1,13 @@
|
||||||
package pw.kaboom.extras.modules.block;
|
package pw.kaboom.extras.modules.block;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockFadeEvent;
|
|
||||||
import org.bukkit.event.block.BlockFormEvent;
|
|
||||||
import org.bukkit.event.block.BlockFromToEvent;
|
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
import org.bukkit.event.block.BlockRedstoneEvent;
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
|
|
||||||
import com.destroystokyo.paper.event.block.BlockDestroyEvent;
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import pw.kaboom.extras.Main;
|
import pw.kaboom.extras.Main;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package pw.kaboom.extras.modules.player;
|
||||||
import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
|
import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
|
||||||
import com.destroystokyo.paper.profile.ProfileProperty;
|
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.title.Title;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
@ -20,6 +22,7 @@ import pw.kaboom.extras.modules.server.ServerTabComplete;
|
||||||
import pw.kaboom.extras.modules.player.skin.SkinManager;
|
import pw.kaboom.extras.modules.player.skin.SkinManager;
|
||||||
import pw.kaboom.extras.util.Utility;
|
import pw.kaboom.extras.util.Utility;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
@ -28,9 +31,9 @@ public final class PlayerConnection implements Listener {
|
||||||
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
|
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
|
||||||
private static final String TITLE = CONFIG.getString("playerJoinTitle");
|
private static final String TITLE = CONFIG.getString("playerJoinTitle");
|
||||||
private static final String SUBTITLE = CONFIG.getString("playerJoinSubtitle");
|
private static final String SUBTITLE = CONFIG.getString("playerJoinSubtitle");
|
||||||
private static final int FADE_IN = 10;
|
private static final Duration FADE_IN = Duration.ofMillis(50);
|
||||||
private static final int STAY = 160;
|
private static final Duration STAY = Duration.ofMillis(8000);
|
||||||
private static final int FADE_OUT = 5;
|
private static final Duration FADE_OUT = Duration.ofMillis(250);
|
||||||
|
|
||||||
private static final boolean ENABLE_KICK = CONFIG.getBoolean("enableKick");
|
private static final boolean ENABLE_KICK = CONFIG.getBoolean("enableKick");
|
||||||
private static final boolean ENABLE_JOIN_RESTRICTIONS = CONFIG.getBoolean(
|
private static final boolean ENABLE_JOIN_RESTRICTIONS = CONFIG.getBoolean(
|
||||||
|
@ -46,7 +49,7 @@ public final class PlayerConnection implements Listener {
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
|
||||||
"A player with that username is already logged in");
|
Component.text("A player with that username is already logged in"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*try {
|
/*try {
|
||||||
|
@ -67,15 +70,12 @@ public final class PlayerConnection implements Listener {
|
||||||
void onPlayerJoin(final PlayerJoinEvent event) {
|
void onPlayerJoin(final PlayerJoinEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
if (TITLE != null
|
if (TITLE != null || SUBTITLE != null) {
|
||||||
|| SUBTITLE != null) {
|
player.showTitle(Title.title(
|
||||||
player.sendTitle(
|
Component.text(TITLE),
|
||||||
TITLE,
|
Component.text(SUBTITLE),
|
||||||
SUBTITLE,
|
Title.Times.times(FADE_IN, STAY, FADE_OUT)
|
||||||
FADE_IN,
|
));
|
||||||
STAY,
|
|
||||||
FADE_OUT
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName());
|
ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName());
|
||||||
|
|
|
@ -2,6 +2,8 @@ package pw.kaboom.extras.modules.player;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.ExperienceOrb;
|
import org.bukkit.entity.ExperienceOrb;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
@ -15,6 +17,7 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import pw.kaboom.extras.util.Utility;
|
||||||
|
|
||||||
public final class PlayerDamage implements Listener {
|
public final class PlayerDamage implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -34,19 +37,17 @@ public final class PlayerDamage implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onFoodLevelChange(final FoodLevelChangeEvent event) {
|
void onFoodLevelChange(final FoodLevelChangeEvent event) {
|
||||||
final HumanEntity player = event.getEntity();
|
final HumanEntity player = event.getEntity();
|
||||||
|
final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
if (player.getMaxHealth() <= 0) {
|
if (attribute == null) return;
|
||||||
player.setMaxHealth(Double.POSITIVE_INFINITY);
|
if (attribute.getValue() <= 0) {
|
||||||
|
Utility.resetAttribute(attribute);
|
||||||
player.setHealth(20);
|
player.setHealth(20);
|
||||||
player.setMaxHealth(20);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerDeath(final PlayerDeathEvent event) {
|
void onPlayerDeath(final PlayerDeathEvent event) {
|
||||||
final Player player = event.getEntity();
|
final Player player = event.getEntity();
|
||||||
|
@ -70,7 +71,11 @@ public final class PlayerDamage implements Listener {
|
||||||
xp.setExperience(event.getDroppedExp());
|
xp.setExperience(event.getDroppedExp());
|
||||||
}
|
}
|
||||||
|
|
||||||
player.setMaxHealth(20);
|
final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
if (attribute != null) {
|
||||||
|
Utility.resetAttribute(attribute);
|
||||||
|
}
|
||||||
|
|
||||||
player.setHealth(20);
|
player.setHealth(20);
|
||||||
|
|
||||||
if (player.getBedSpawnLocation() != null) {
|
if (player.getBedSpawnLocation() != null) {
|
||||||
|
@ -80,9 +85,11 @@ public final class PlayerDamage implements Listener {
|
||||||
player.teleportAsync(world.getSpawnLocation());
|
player.teleportAsync(world.getSpawnLocation());
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
player.setMaxHealth(Double.POSITIVE_INFINITY);
|
final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
if (attribute != null) {
|
||||||
|
Utility.resetAttribute(attribute);
|
||||||
|
}
|
||||||
player.setHealth(20);
|
player.setHealth(20);
|
||||||
player.setMaxHealth(20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.setExp(event.getNewExp());
|
player.setExp(event.getNewExp());
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
package pw.kaboom.extras.modules.player;
|
package pw.kaboom.extras.modules.player;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.Sign;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
package pw.kaboom.extras.modules.player;
|
package pw.kaboom.extras.modules.player;
|
||||||
|
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
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;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import pw.kaboom.extras.util.Utility;
|
||||||
|
|
||||||
public final class PlayerTeleport implements Listener {
|
public final class PlayerTeleport implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
|
void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
if (player.getMaxHealth() <= 0) {
|
final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
player.setMaxHealth(Double.POSITIVE_INFINITY);
|
if (attribute == null) return;
|
||||||
|
if (attribute.getValue() <= 0) {
|
||||||
|
Utility.resetAttribute(attribute);
|
||||||
player.setHealth(20);
|
player.setHealth(20);
|
||||||
player.setMaxHealth(20);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package pw.kaboom.extras.util;
|
package pw.kaboom.extras.util;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
|
import org.bukkit.attribute.AttributeModifier;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public final class Utility {
|
public final class Utility {
|
||||||
|
@ -13,4 +16,24 @@ public final class Utility {
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void resetAttribute(final AttributeInstance attribute) {
|
||||||
|
for (final AttributeModifier modifier: attribute.getModifiers()) {
|
||||||
|
attribute.removeModifier(modifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute.setBaseValue(attribute.getDefaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Support hex color codes, too (they aren't supported in Spigot either)
|
||||||
|
public static String translateLegacyColors(@Nonnull String text) {
|
||||||
|
char[] b = text.toCharArray();
|
||||||
|
for (int i = 0; i < b.length - 1; i++) {
|
||||||
|
if (b[i] == '&' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRrXx".indexOf(b[i + 1]) > -1) {
|
||||||
|
b[i] = '\u00a7';
|
||||||
|
b[i + 1] = Character.toLowerCase(b[i + 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new String(b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue