mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-09 01:47:54 +01:00
commit
642e1133ee
@ -2,7 +2,7 @@ package net.minestom.server.bossbar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the displayed color of a {@link BossBar}.
|
* Represents the displayed color of a {@link BossBar}.
|
||||||
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar}
|
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar.Color}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public enum BarColor {
|
public enum BarColor {
|
||||||
|
@ -3,7 +3,7 @@ package net.minestom.server.bossbar;
|
|||||||
/**
|
/**
|
||||||
* Used to define the number of segments on a {@link BossBar}.
|
* Used to define the number of segments on a {@link BossBar}.
|
||||||
*
|
*
|
||||||
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar}
|
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar.Overlay}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public enum BarDivision {
|
public enum BarDivision {
|
||||||
|
@ -20,7 +20,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
* <p>
|
* <p>
|
||||||
* You can retrieve all the boss bars of a {@link Player} with {@link #getBossBars(Player)}.
|
* You can retrieve all the boss bars of a {@link Player} with {@link #getBossBars(Player)}.
|
||||||
*
|
*
|
||||||
* @deprecated Use {@link net.kyori.adventure.audience.Audience#showBossBar(net.kyori.adventure.bossbar.BossBar)}
|
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class BossBar implements Viewable {
|
public class BossBar implements Viewable {
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package net.minestom.server.chat;
|
package net.minestom.server.chat;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a click event for a specific portion of the message.
|
* Represents a click event for a specific portion of the message.
|
||||||
|
* @deprecated Use {@link ClickEvent}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class ChatClickEvent {
|
public class ChatClickEvent {
|
||||||
|
@ -4,24 +4,31 @@ import it.unimi.dsi.fastutil.chars.Char2ObjectMap;
|
|||||||
import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.ComponentBuilder;
|
||||||
|
import net.kyori.adventure.text.format.*;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import net.minestom.server.color.Color;
|
import net.minestom.server.color.Color;
|
||||||
|
import net.minestom.server.color.DyeColor;
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a color in a text. You can either use one of the pre-made colors
|
* Represents a color in a text. You can either use one of the pre-made colors
|
||||||
* or make your own using RGB. {@link ChatColor#fromRGB(byte, byte, byte)}.
|
* or make your own using RGB. {@link ChatColor#fromRGB(byte, byte, byte)}.
|
||||||
* <p>
|
* <p>
|
||||||
* Immutable class.
|
* Immutable class.
|
||||||
|
* @deprecated For chat colors, use {@link TextColor} or {@link NamedTextColor}. For styles, use {@link TextDecoration}.
|
||||||
|
* For colors in other contexts, see {@link Color} or {@link DyeColor}.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public final class ChatColor {
|
public final class ChatColor implements StyleBuilderApplicable {
|
||||||
|
|
||||||
// Special
|
// Special
|
||||||
public static final ChatColor NO_COLOR = new ChatColor();
|
public static final ChatColor NO_COLOR = new ChatColor();
|
||||||
@ -310,4 +317,26 @@ public final class ChatColor {
|
|||||||
|
|
||||||
return header + code + footer;
|
return header + code + footer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Contract(mutates = "param")
|
||||||
|
public void styleApply(Style.@NotNull Builder style) {
|
||||||
|
if (this.isEmpty()) {
|
||||||
|
style.color(NamedTextColor.WHITE);
|
||||||
|
} else if (Objects.equals(this.codeName, "reset")) {
|
||||||
|
style.color(NamedTextColor.WHITE);
|
||||||
|
|
||||||
|
for (TextDecoration value : TextDecoration.NAMES.values()) {
|
||||||
|
style.decoration(value, TextDecoration.State.FALSE);
|
||||||
|
}
|
||||||
|
} else if (this.isSpecial() && this.codeName != null) {
|
||||||
|
TextDecoration decoration = TextDecoration.NAMES.value(this.codeName);
|
||||||
|
|
||||||
|
if (decoration != null) {
|
||||||
|
style.decorate(decoration);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
style.color(TextColor.color(this.red, this.green, this.blue));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a hover event for a specific portion of the message.
|
* Represents a hover event for a specific portion of the message.
|
||||||
|
* @deprecated Use {@link HoverEvent}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class ChatHoverEvent {
|
public class ChatHoverEvent {
|
||||||
|
@ -2,10 +2,12 @@ package net.minestom.server.chat;
|
|||||||
|
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class used to convert JSON string to proper chat message representation.
|
* Class used to convert JSON string to proper chat message representation.
|
||||||
|
* @deprecated Use {@link GsonComponentSerializer}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public final class ChatParser {
|
public final class ChatParser {
|
||||||
|
@ -2,6 +2,8 @@ package net.minestom.server.chat;
|
|||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -16,6 +18,7 @@ import java.util.regex.Pattern;
|
|||||||
* <p>
|
* <p>
|
||||||
* To create one, you simply call one of the static methods like {@link #of(ChatColor, String)},
|
* To create one, you simply call one of the static methods like {@link #of(ChatColor, String)},
|
||||||
* you can then continue to append text with {@link #append(ChatColor, String)}.
|
* you can then continue to append text with {@link #append(ChatColor, String)}.
|
||||||
|
* @deprecated Use {@link Component#text(String, TextColor)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class ColoredText extends JsonMessage {
|
public class ColoredText extends JsonMessage {
|
||||||
|
@ -16,6 +16,7 @@ import java.util.Objects;
|
|||||||
* Examples are {@link ColoredText} and {@link RichMessage}.
|
* Examples are {@link ColoredText} and {@link RichMessage}.
|
||||||
*
|
*
|
||||||
* @see <a href="https://wiki.vg/Chat">Chat Format</a>
|
* @see <a href="https://wiki.vg/Chat">Chat Format</a>
|
||||||
|
* @deprecated Use {@link Component}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class JsonMessage implements ComponentLike {
|
public abstract class JsonMessage implements ComponentLike {
|
||||||
|
@ -2,6 +2,7 @@ package net.minestom.server.chat;
|
|||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -18,6 +19,7 @@ import java.util.List;
|
|||||||
* You will need to call the static method to initialize the message {@link #of(ColoredText)},
|
* You will need to call the static method to initialize the message {@link #of(ColoredText)},
|
||||||
* events can be assigned with {@link #setClickEvent(ChatClickEvent)} and {@link #setHoverEvent(ChatHoverEvent)}
|
* events can be assigned with {@link #setClickEvent(ChatClickEvent)} and {@link #setHoverEvent(ChatHoverEvent)}
|
||||||
* and new text element can also be appended {@link #append(ColoredText)}.
|
* and new text element can also be appended {@link #append(ColoredText)}.
|
||||||
|
* @deprecated Use {@link Component}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class RichMessage extends JsonMessage {
|
public class RichMessage extends JsonMessage {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package net.minestom.server.chat;
|
package net.minestom.server.chat;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.TranslatableComponent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a translatable component which can be used in {@link ColoredText}.
|
* Represents a translatable component which can be used in {@link ColoredText}.
|
||||||
|
* @deprecated Use {@link TranslatableComponent}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class TranslatableText {
|
public class TranslatableText {
|
||||||
|
@ -18,21 +18,17 @@ public interface CommandSender extends PermissionHandler, Audience {
|
|||||||
* Sends a raw string message.
|
* Sends a raw string message.
|
||||||
*
|
*
|
||||||
* @param message the message to send
|
* @param message the message to send
|
||||||
*
|
|
||||||
* @deprecated Use {@link #sendMessage(Component)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
default void sendMessage(@NotNull String message) {
|
||||||
default void sendMessage(@NotNull String message) { this.sendMessage(Component.text(message)); }
|
this.sendMessage(Component.text(message));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends multiple raw string messages.
|
* Sends multiple raw string messages.
|
||||||
*
|
*
|
||||||
* @param messages the messages to send
|
* @param messages the messages to send
|
||||||
*
|
|
||||||
* @deprecated Use {@link #sendMessage(Component)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
default void sendMessage(@NotNull String @NotNull[] messages) {
|
||||||
default void sendMessage(@NotNull String[] messages) {
|
|
||||||
for (String message : messages) {
|
for (String message : messages) {
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
@ -57,7 +53,7 @@ public interface CommandSender extends PermissionHandler, Audience {
|
|||||||
* @return true if 'this' is a player, false otherwise
|
* @return true if 'this' is a player, false otherwise
|
||||||
*/
|
*/
|
||||||
default boolean isPlayer() {
|
default boolean isPlayer() {
|
||||||
return this instanceof Player;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,7 +62,7 @@ public interface CommandSender extends PermissionHandler, Audience {
|
|||||||
* @return true if 'this' is the console, false otherwise
|
* @return true if 'this' is the console, false otherwise
|
||||||
*/
|
*/
|
||||||
default boolean isConsole() {
|
default boolean isConsole() {
|
||||||
return this instanceof ConsoleSender;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +73,7 @@ public interface CommandSender extends PermissionHandler, Audience {
|
|||||||
* @see #isPlayer()
|
* @see #isPlayer()
|
||||||
*/
|
*/
|
||||||
default Player asPlayer() {
|
default Player asPlayer() {
|
||||||
return (Player) this;
|
throw new ClassCastException("CommandSender is not a Player");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,6 +84,6 @@ public interface CommandSender extends PermissionHandler, Audience {
|
|||||||
* @see #isConsole()
|
* @see #isConsole()
|
||||||
*/
|
*/
|
||||||
default ConsoleSender asConsole() {
|
default ConsoleSender asConsole() {
|
||||||
return (ConsoleSender) this;
|
throw new ClassCastException("CommandSender is not the ConsoleSender");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,20 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
* Represents the console when sending a command to the server.
|
* Represents the console when sending a command to the server.
|
||||||
*/
|
*/
|
||||||
public class ConsoleSender implements CommandSender {
|
public class ConsoleSender implements CommandSender {
|
||||||
|
private static final PlainComponentSerializer PLAIN_SERIALIZER = PlainComponentSerializer.plain();
|
||||||
private final static Logger LOGGER = LoggerFactory.getLogger(ConsoleSender.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleSender.class);
|
||||||
|
|
||||||
private final Set<Permission> permissions = new CopyOnWriteArraySet<>();
|
private final Set<Permission> permissions = new CopyOnWriteArraySet<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(@NotNull String message) {
|
||||||
|
LOGGER.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) {
|
public void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) {
|
||||||
// we don't use the serializer here as we just need the plain text of the message
|
// we don't use the serializer here as we just need the plain text of the message
|
||||||
LOGGER.info(PlainComponentSerializer.plain().serialize(message));
|
this.sendMessage(PLAIN_SERIALIZER.serialize(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -32,4 +37,14 @@ public class ConsoleSender implements CommandSender {
|
|||||||
public Set<Permission> getAllPermissions() {
|
public Set<Permission> getAllPermissions() {
|
||||||
return permissions;
|
return permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConsole() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsoleSender asConsole() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.event.HoverEvent;
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
import net.kyori.adventure.text.event.HoverEvent.ShowEntity;
|
import net.kyori.adventure.text.event.HoverEvent.ShowEntity;
|
||||||
import net.kyori.adventure.text.event.HoverEventSource;
|
import net.kyori.adventure.text.event.HoverEventSource;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import net.kyori.adventure.title.Title;
|
import net.kyori.adventure.title.Title;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.advancements.AdvancementTab;
|
import net.minestom.server.advancements.AdvancementTab;
|
||||||
@ -803,7 +804,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void sendJsonMessage(@NotNull String json) {
|
public void sendJsonMessage(@NotNull String json) {
|
||||||
this.sendMessage(json);
|
this.sendMessage(GsonComponentSerializer.gson().deserialize(json));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2666,6 +2667,16 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
this.identity = Identity.identity(uuid);
|
this.identity = Identity.identity(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPlayer() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player asPlayer() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the main or off hand of the player.
|
* Represents the main or off hand of the player.
|
||||||
*/
|
*/
|
||||||
|
@ -9,6 +9,7 @@ import net.minestom.server.entity.type.projectile.EntityProjectile;
|
|||||||
import net.minestom.server.utils.Position;
|
import net.minestom.server.utils.Position;
|
||||||
import net.minestom.server.utils.time.Cooldown;
|
import net.minestom.server.utils.time.Cooldown;
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
import net.minestom.server.utils.time.TimeUnit;
|
||||||
|
import net.minestom.server.utils.time.UpdateOption;
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -19,6 +20,8 @@ import java.util.function.Function;
|
|||||||
*/
|
*/
|
||||||
public class CombinedAttackGoal extends GoalSelector {
|
public class CombinedAttackGoal extends GoalSelector {
|
||||||
|
|
||||||
|
private final Cooldown cooldown = new Cooldown(new UpdateOption(5, TimeUnit.TICK));
|
||||||
|
|
||||||
private final int meleeRangeSquared;
|
private final int meleeRangeSquared;
|
||||||
private final int meleeDelay;
|
private final int meleeDelay;
|
||||||
private final TimeUnit meleeTimeUnit;
|
private final TimeUnit meleeTimeUnit;
|
||||||
@ -90,6 +93,10 @@ public class CombinedAttackGoal extends GoalSelector {
|
|||||||
Check.argCondition(desirableRange > rangedRange, "Desirable range can not exceed ranged range!");
|
Check.argCondition(desirableRange > rangedRange, "Desirable range can not exceed ranged range!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Cooldown getCooldown() {
|
||||||
|
return this.cooldown;
|
||||||
|
}
|
||||||
|
|
||||||
public void setProjectileGenerator(Function<Entity, EntityProjectile> projectileGenerator) {
|
public void setProjectileGenerator(Function<Entity, EntityProjectile> projectileGenerator) {
|
||||||
this.projectileGenerator = projectileGenerator;
|
this.projectileGenerator = projectileGenerator;
|
||||||
}
|
}
|
||||||
@ -159,9 +166,12 @@ public class CombinedAttackGoal extends GoalSelector {
|
|||||||
// Otherwise going to the target.
|
// Otherwise going to the target.
|
||||||
Position targetPosition = target.getPosition();
|
Position targetPosition = target.getPosition();
|
||||||
if (pathPosition == null || !pathPosition.isSimilar(targetPosition)) {
|
if (pathPosition == null || !pathPosition.isSimilar(targetPosition)) {
|
||||||
|
if (this.cooldown.isReady(time)) {
|
||||||
|
this.cooldown.refreshLastUpdate(time);
|
||||||
navigator.setPathTo(targetPosition);
|
navigator.setPathTo(targetPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnd() {
|
public boolean shouldEnd() {
|
||||||
|
@ -8,6 +8,7 @@ import net.minestom.server.entity.pathfinding.Navigator;
|
|||||||
import net.minestom.server.utils.Position;
|
import net.minestom.server.utils.Position;
|
||||||
import net.minestom.server.utils.time.Cooldown;
|
import net.minestom.server.utils.time.Cooldown;
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
import net.minestom.server.utils.time.TimeUnit;
|
||||||
|
import net.minestom.server.utils.time.UpdateOption;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,6 +17,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
*/
|
*/
|
||||||
public class MeleeAttackGoal extends GoalSelector {
|
public class MeleeAttackGoal extends GoalSelector {
|
||||||
|
|
||||||
|
private final Cooldown cooldown = new Cooldown(new UpdateOption(5, TimeUnit.TICK));
|
||||||
|
|
||||||
private long lastHit;
|
private long lastHit;
|
||||||
private final int delay;
|
private final int delay;
|
||||||
private final TimeUnit timeUnit;
|
private final TimeUnit timeUnit;
|
||||||
@ -37,6 +40,10 @@ public class MeleeAttackGoal extends GoalSelector {
|
|||||||
this.timeUnit = timeUnit;
|
this.timeUnit = timeUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Cooldown getCooldown() {
|
||||||
|
return this.cooldown;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldStart() {
|
public boolean shouldStart() {
|
||||||
this.cachedTarget = findTarget();
|
this.cachedTarget = findTarget();
|
||||||
@ -77,10 +84,13 @@ public class MeleeAttackGoal extends GoalSelector {
|
|||||||
final Position pathPosition = navigator.getPathPosition();
|
final Position pathPosition = navigator.getPathPosition();
|
||||||
final Position targetPosition = target.getPosition();
|
final Position targetPosition = target.getPosition();
|
||||||
if (pathPosition == null || !pathPosition.isSimilar(targetPosition)) {
|
if (pathPosition == null || !pathPosition.isSimilar(targetPosition)) {
|
||||||
|
if (this.cooldown.isReady(time)) {
|
||||||
|
this.cooldown.refreshLastUpdate(time);
|
||||||
navigator.setPathTo(targetPosition);
|
navigator.setPathTo(targetPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnd() {
|
public boolean shouldEnd() {
|
||||||
|
@ -9,6 +9,7 @@ import net.minestom.server.entity.type.projectile.EntityProjectile;
|
|||||||
import net.minestom.server.utils.Position;
|
import net.minestom.server.utils.Position;
|
||||||
import net.minestom.server.utils.time.Cooldown;
|
import net.minestom.server.utils.time.Cooldown;
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
import net.minestom.server.utils.time.TimeUnit;
|
||||||
|
import net.minestom.server.utils.time.UpdateOption;
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -16,6 +17,8 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public class RangedAttackGoal extends GoalSelector {
|
public class RangedAttackGoal extends GoalSelector {
|
||||||
|
|
||||||
|
private final Cooldown cooldown = new Cooldown(new UpdateOption(5, TimeUnit.TICK));
|
||||||
|
|
||||||
private long lastShot;
|
private long lastShot;
|
||||||
private final int delay;
|
private final int delay;
|
||||||
private final TimeUnit timeUnit;
|
private final TimeUnit timeUnit;
|
||||||
@ -52,6 +55,10 @@ public class RangedAttackGoal extends GoalSelector {
|
|||||||
Check.argCondition(desirableRange > attackRange, "Desirable range can not exceed attack range!");
|
Check.argCondition(desirableRange > attackRange, "Desirable range can not exceed attack range!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Cooldown getCooldown() {
|
||||||
|
return this.cooldown;
|
||||||
|
}
|
||||||
|
|
||||||
public void setProjectileGenerator(Function<Entity, EntityProjectile> projectileGenerator) {
|
public void setProjectileGenerator(Function<Entity, EntityProjectile> projectileGenerator) {
|
||||||
this.projectileGenerator = projectileGenerator;
|
this.projectileGenerator = projectileGenerator;
|
||||||
}
|
}
|
||||||
@ -111,9 +118,12 @@ public class RangedAttackGoal extends GoalSelector {
|
|||||||
}
|
}
|
||||||
Position targetPosition = target.getPosition();
|
Position targetPosition = target.getPosition();
|
||||||
if (pathPosition == null || !pathPosition.isSimilar(targetPosition)) {
|
if (pathPosition == null || !pathPosition.isSimilar(targetPosition)) {
|
||||||
|
if (this.cooldown.isReady(time)) {
|
||||||
|
this.cooldown.refreshLastUpdate(time);
|
||||||
navigator.setPathTo(targetPosition);
|
navigator.setPathTo(targetPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnd() {
|
public boolean shouldEnd() {
|
||||||
|
@ -77,7 +77,7 @@ public class ExtensionManager {
|
|||||||
/**
|
/**
|
||||||
* Loads all extensions in the extension folder into this server.
|
* Loads all extensions in the extension folder into this server.
|
||||||
* <br><br>
|
* <br><br>
|
||||||
*
|
* <p>
|
||||||
* Pipeline:
|
* Pipeline:
|
||||||
* <br>
|
* <br>
|
||||||
* Finds all .jar files in the extensions folder.
|
* Finds all .jar files in the extensions folder.
|
||||||
@ -88,32 +88,32 @@ public class ExtensionManager {
|
|||||||
* <br>
|
* <br>
|
||||||
* Verifies that all properties of extension.json are correctly set.
|
* Verifies that all properties of extension.json are correctly set.
|
||||||
* <br><br>
|
* <br><br>
|
||||||
*
|
* <p>
|
||||||
* It then sorts all those jars by their load order (making sure that an extension's dependencies load before it)
|
* It then sorts all those jars by their load order (making sure that an extension's dependencies load before it)
|
||||||
* <br>
|
* <br>
|
||||||
* Note: Cyclic dependencies will stop both extensions from being loaded.
|
* Note: Cyclic dependencies will stop both extensions from being loaded.
|
||||||
* <br><br>
|
* <br><br>
|
||||||
*
|
* <p>
|
||||||
* Afterwards, it loads all external dependencies and adds them to the extension's files
|
* Afterwards, it loads all external dependencies and adds them to the extension's files
|
||||||
* <br><br>
|
* <br><br>
|
||||||
*
|
* <p>
|
||||||
* Then removes any invalid extensions (Invalid being its Load Status isn't SUCCESS)
|
* Then removes any invalid extensions (Invalid being its Load Status isn't SUCCESS)
|
||||||
* <br><br>
|
* <br><br>
|
||||||
*
|
* <p>
|
||||||
* After that, it set its classloaders so each extension is self-contained,
|
* After that, it set its classloaders so each extension is self-contained,
|
||||||
* <br><br>
|
* <br><br>
|
||||||
*
|
* <p>
|
||||||
* Removes invalid extensions again,
|
* Removes invalid extensions again,
|
||||||
* <br><br>
|
* <br><br>
|
||||||
*
|
* <p>
|
||||||
* and loads all of those extensions into Minestom
|
* and loads all of those extensions into Minestom
|
||||||
* <br>
|
* <br>
|
||||||
* (Extension fields are set via reflection after each extension is verified, then loaded.)
|
* (Extension fields are set via reflection after each extension is verified, then loaded.)
|
||||||
* <br><br>
|
* <br><br>
|
||||||
*
|
* <p>
|
||||||
* If the extension successfully loads, add it to the global extension Map (Name to Extension)
|
* If the extension successfully loads, add it to the global extension Map (Name to Extension)
|
||||||
* <br><br>
|
* <br><br>
|
||||||
*
|
* <p>
|
||||||
* And finally make a scheduler to clean observers per extension.
|
* And finally make a scheduler to clean observers per extension.
|
||||||
*/
|
*/
|
||||||
public void loadExtensions() {
|
public void loadExtensions() {
|
||||||
@ -193,7 +193,6 @@ public class ExtensionManager {
|
|||||||
* Loads an extension into Minestom.
|
* Loads an extension into Minestom.
|
||||||
*
|
*
|
||||||
* @param discoveredExtension The extension. Make sure to verify its integrity, set its class loader, and its files.
|
* @param discoveredExtension The extension. Make sure to verify its integrity, set its class loader, and its files.
|
||||||
*
|
|
||||||
* @return An extension object made from this DiscoveredExtension
|
* @return An extension object made from this DiscoveredExtension
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -213,7 +212,8 @@ public class ExtensionManager {
|
|||||||
try {
|
try {
|
||||||
jarClass = Class.forName(mainClass, true, loader);
|
jarClass = Class.forName(mainClass, true, loader);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
LOGGER.error("Could not find main class '{}' in extension '{}'.", mainClass, extensionName, e);
|
LOGGER.error("Could not find main class '{}' in extension '{}'. If it is, be sure to run your server using Bootstrap#bootstrap",
|
||||||
|
mainClass, extensionName, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +295,7 @@ public class ExtensionManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all extensions from the extensions folder and make them discovered.
|
* Get all extensions from the extensions folder and make them discovered.
|
||||||
*
|
* <p>
|
||||||
* It skims the extension folder, discovers and verifies each extension, and returns those created DiscoveredExtensions.
|
* It skims the extension folder, discovers and verifies each extension, and returns those created DiscoveredExtensions.
|
||||||
*
|
*
|
||||||
* @return A list of discovered extensions from this folder.
|
* @return A list of discovered extensions from this folder.
|
||||||
@ -354,7 +354,6 @@ public class ExtensionManager {
|
|||||||
* Grabs a discovered extension from a jar.
|
* Grabs a discovered extension from a jar.
|
||||||
*
|
*
|
||||||
* @param file The jar to grab it from (a .jar is a formatted .zip file)
|
* @param file The jar to grab it from (a .jar is a formatted .zip file)
|
||||||
*
|
|
||||||
* @return The created DiscoveredExtension.
|
* @return The created DiscoveredExtension.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -391,7 +390,8 @@ public class ExtensionManager {
|
|||||||
extensionMap.put(discoveredExtension.getName().toLowerCase(), discoveredExtension);
|
extensionMap.put(discoveredExtension.getName().toLowerCase(), discoveredExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
allExtensions: // go through all the discovered extensions and get their dependencies as extensions
|
allExtensions:
|
||||||
|
// go through all the discovered extensions and get their dependencies as extensions
|
||||||
for (DiscoveredExtension discoveredExtension : discoveredExtensions) {
|
for (DiscoveredExtension discoveredExtension : discoveredExtensions) {
|
||||||
|
|
||||||
List<DiscoveredExtension> dependencies = new ArrayList<>(discoveredExtension.getDependencies().length);
|
List<DiscoveredExtension> dependencies = new ArrayList<>(discoveredExtension.getDependencies().length);
|
||||||
@ -481,6 +481,7 @@ public class ExtensionManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this list of extensions are loaded
|
* Checks if this list of extensions are loaded
|
||||||
|
*
|
||||||
* @param extensions The list of extensions to check against.
|
* @param extensions The list of extensions to check against.
|
||||||
* @return If all of these extensions are loaded.
|
* @return If all of these extensions are loaded.
|
||||||
*/
|
*/
|
||||||
@ -603,7 +604,7 @@ public class ExtensionManager {
|
|||||||
try {
|
try {
|
||||||
for (String codeModifierClass : extension.getCodeModifiers()) {
|
for (String codeModifierClass : extension.getCodeModifiers()) {
|
||||||
boolean loaded = modifiableClassLoader.loadModifier(extension.files.toArray(new URL[0]), codeModifierClass);
|
boolean loaded = modifiableClassLoader.loadModifier(extension.files.toArray(new URL[0]), codeModifierClass);
|
||||||
if(!loaded) {
|
if (!loaded) {
|
||||||
extension.addMissingCodeModifier(codeModifierClass);
|
extension.addMissingCodeModifier(codeModifierClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -613,17 +614,17 @@ public class ExtensionManager {
|
|||||||
Mixins.addConfiguration(mixinConfigFile);
|
Mixins.addConfiguration(mixinConfigFile);
|
||||||
LOGGER.info("Found mixin in extension {}: {}", extension.getName(), mixinConfigFile);
|
LOGGER.info("Found mixin in extension {}: {}", extension.getName(), mixinConfigFile);
|
||||||
} catch (ServiceNotAvailableError | MixinError | MixinException e) {
|
} catch (ServiceNotAvailableError | MixinError | MixinException e) {
|
||||||
if(MinecraftServer.getExceptionManager() != null) {
|
if (MinecraftServer.getExceptionManager() != null) {
|
||||||
MinecraftServer.getExceptionManager().handleException(e);
|
MinecraftServer.getExceptionManager().handleException(e);
|
||||||
} else {
|
} else {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
LOGGER.error("Could not load Mixin configuration: "+mixinConfigFile);
|
LOGGER.error("Could not load Mixin configuration: " + mixinConfigFile);
|
||||||
extension.setFailedToLoadMixinFlag();
|
extension.setFailedToLoadMixinFlag();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if(MinecraftServer.getExceptionManager() != null) {
|
if (MinecraftServer.getExceptionManager() != null) {
|
||||||
MinecraftServer.getExceptionManager().handleException(e);
|
MinecraftServer.getExceptionManager().handleException(e);
|
||||||
} else {
|
} else {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -35,8 +35,8 @@ public class ClientPlayPacketsHandler extends ClientPacketsHandler {
|
|||||||
register(0x1B, ClientPlayerDiggingPacket::new);
|
register(0x1B, ClientPlayerDiggingPacket::new);
|
||||||
register(0x1C, ClientEntityActionPacket::new);
|
register(0x1C, ClientEntityActionPacket::new);
|
||||||
register(0x1D, ClientSteerVehiclePacket::new);
|
register(0x1D, ClientSteerVehiclePacket::new);
|
||||||
register(0x1E, ClientRecipeBookData::new);
|
register(0x1E, ClientSetRecipeBookStatePacket::new);
|
||||||
register(0x1F, ClientRecipeBookData::new);
|
register(0x1F, ClientSetDisplayedRecipePacket::new);
|
||||||
|
|
||||||
|
|
||||||
register(0x20, ClientNameItemPacket::new);
|
register(0x20, ClientNameItemPacket::new);
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
package net.minestom.server.network.packet.client.play;
|
|
||||||
|
|
||||||
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
|
||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class ClientRecipeBookData extends ClientPlayPacket {
|
|
||||||
|
|
||||||
public int type;
|
|
||||||
|
|
||||||
public String recipeId = "";
|
|
||||||
|
|
||||||
public boolean craftingRecipeBookOpen;
|
|
||||||
public boolean craftingRecipeFilterActive;
|
|
||||||
public boolean smeltingRecipeBookOpen;
|
|
||||||
public boolean smeltingRecipeFilterActive;
|
|
||||||
public boolean blastingRecipeBookOpen;
|
|
||||||
public boolean blastingRecipeFilterActive;
|
|
||||||
public boolean smokingRecipeBookOpen;
|
|
||||||
public boolean smokingRecipeFilterActive;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void read(@NotNull BinaryReader reader) {
|
|
||||||
this.type = reader.readVarInt();
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case 0:
|
|
||||||
this.recipeId = reader.readSizedString(256);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
this.craftingRecipeBookOpen = reader.readBoolean();
|
|
||||||
this.craftingRecipeFilterActive = reader.readBoolean();
|
|
||||||
this.smeltingRecipeBookOpen = reader.readBoolean();
|
|
||||||
this.smeltingRecipeFilterActive = reader.readBoolean();
|
|
||||||
this.blastingRecipeBookOpen = reader.readBoolean();
|
|
||||||
this.blastingRecipeFilterActive = reader.readBoolean();
|
|
||||||
this.smokingRecipeBookOpen = reader.readBoolean();
|
|
||||||
this.smokingRecipeFilterActive = reader.readBoolean();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
|
||||||
writer.writeVarInt(type);
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case 0:
|
|
||||||
if(recipeId.length() > 256)
|
|
||||||
throw new IllegalArgumentException("recipeId must be less than 256 bytes");
|
|
||||||
writer.writeSizedString(recipeId);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
writer.writeBoolean(this.craftingRecipeBookOpen);
|
|
||||||
writer.writeBoolean(this.craftingRecipeFilterActive);
|
|
||||||
writer.writeBoolean(this.smeltingRecipeBookOpen);
|
|
||||||
writer.writeBoolean(this.smeltingRecipeFilterActive);
|
|
||||||
writer.writeBoolean(this.blastingRecipeBookOpen);
|
|
||||||
writer.writeBoolean(this.blastingRecipeFilterActive);
|
|
||||||
writer.writeBoolean(this.smokingRecipeBookOpen);
|
|
||||||
writer.writeBoolean(this.smokingRecipeFilterActive);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,21 @@
|
|||||||
|
package net.minestom.server.network.packet.client.play;
|
||||||
|
|
||||||
|
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
||||||
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ClientSetDisplayedRecipePacket extends ClientPlayPacket {
|
||||||
|
|
||||||
|
public String recipeId = "";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(@NotNull BinaryReader reader) {
|
||||||
|
this.recipeId = reader.readSizedString(256);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
|
writer.writeSizedString(recipeId);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package net.minestom.server.network.packet.client.play;
|
||||||
|
|
||||||
|
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
||||||
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ClientSetRecipeBookStatePacket extends ClientPlayPacket {
|
||||||
|
|
||||||
|
public BookType type = BookType.CRAFTING;
|
||||||
|
public boolean bookOpen;
|
||||||
|
public boolean filterActive;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(@NotNull BinaryReader reader) {
|
||||||
|
this.type = BookType.values()[reader.readVarInt()];
|
||||||
|
this.bookOpen = reader.readBoolean();
|
||||||
|
this.filterActive = reader.readBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
|
writer.writeVarInt(type.ordinal());
|
||||||
|
writer.writeBoolean(bookOpen);
|
||||||
|
writer.writeBoolean(filterActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum BookType {
|
||||||
|
CRAFTING, FURNACE, BLAST_FURNACE, SMOKER
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,10 @@ public final class Cooldown {
|
|||||||
this.lastUpdate = System.currentTimeMillis();
|
this.lastUpdate = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UpdateOption getUpdateOption() {
|
||||||
|
return this.updateOption;
|
||||||
|
}
|
||||||
|
|
||||||
public void refreshLastUpdate(long lastUpdate) {
|
public void refreshLastUpdate(long lastUpdate) {
|
||||||
this.lastUpdate = lastUpdate;
|
this.lastUpdate = lastUpdate;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user