mirror of
https://github.com/LeavesMC/Leaves.git
synced 2026-01-04 15:41:31 +00:00
Improve and clean up
This commit is contained in:
@@ -13,11 +13,13 @@ public class SimpleBytebufManager implements BytebufManager {
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void registerListener(Plugin plugin, PacketListener listener) {
|
||||
internal.listenerMap.put(listener, plugin);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void unregisterListener(Plugin plugin, PacketListener listener) {
|
||||
internal.listenerMap.remove(listener);
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.Map;
|
||||
|
||||
import static org.leavesmc.leaves.bytebuf.packet.PacketType.*;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({"deprecation", "rawtypes", "unchecked"})
|
||||
public class InternalBytebufHandler {
|
||||
|
||||
private class PacketHandler extends ChannelDuplexHandler {
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -57,22 +56,15 @@ public class LeavesCommandUtil {
|
||||
ArrayList<String> results = Lists.newArrayList();
|
||||
|
||||
if (!collection.isEmpty()) {
|
||||
Iterator iterator = Iterables.transform(collection, Functions.toStringFunction()).iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
String s1 = (String) iterator.next();
|
||||
|
||||
for (String s1 : Iterables.transform(collection, Functions.toStringFunction())) {
|
||||
if (matches(last, s1) && (sender.hasPermission(basePermission + s1) || sender.hasPermission(overridePermission))) {
|
||||
results.add(s1);
|
||||
}
|
||||
}
|
||||
|
||||
if (results.isEmpty()) {
|
||||
iterator = collection.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Object object = iterator.next();
|
||||
|
||||
for (Object object : collection) {
|
||||
if (object instanceof ResourceLocation && matches(last, ((ResourceLocation) object).getPath())) {
|
||||
results.add(String.valueOf(object));
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class CraftBot extends CraftPlayer implements Bot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) {
|
||||
public boolean teleport(Location location, PlayerTeleportEvent.@NotNull TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) {
|
||||
Preconditions.checkArgument(location != null, "location cannot be null");
|
||||
Preconditions.checkState(location.getWorld().equals(this.getWorld()), "[Leaves] Fakeplayers do not support changing world, Please use leaves fakeplayer-api instead!");
|
||||
return super.teleport(location, cause, flags);
|
||||
|
||||
@@ -26,12 +26,7 @@ public class CraftBotManager implements BotManager {
|
||||
|
||||
public CraftBotManager() {
|
||||
this.botList = MinecraftServer.getServer().getBotList();
|
||||
this.botViews = Collections.unmodifiableList(Lists.transform(botList.bots, new Function<ServerBot, CraftBot>() {
|
||||
@Override
|
||||
public CraftBot apply(ServerBot bot) {
|
||||
return bot.getBukkitEntity();
|
||||
}
|
||||
}));
|
||||
this.botViews = Collections.unmodifiableList(Lists.transform(botList.bots, bot -> bot.getBukkitEntity()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.papermc.paper.plugin.provider.configuration.serializer.PermissionConfi
|
||||
import io.papermc.paper.plugin.provider.configuration.serializer.constraints.PluginConfigConstraints;
|
||||
import io.papermc.paper.plugin.provider.configuration.type.PermissionConfiguration;
|
||||
import org.bukkit.craftbukkit.util.ApiVersion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
|
||||
@@ -38,7 +39,7 @@ public class LeavesPluginMeta extends PaperPluginMeta {
|
||||
options.serializers((serializers) ->
|
||||
serializers.register(new ScalarSerializer<>(ApiVersion.class) {
|
||||
@Override
|
||||
public ApiVersion deserialize(final Type type, final Object obj) throws SerializationException {
|
||||
public ApiVersion deserialize(final @NotNull Type type, final @NotNull Object obj) throws SerializationException {
|
||||
try {
|
||||
final ApiVersion version = ApiVersion.getOrCreateVersion(obj.toString());
|
||||
if (version.isOlderThan(MINIMUM)) {
|
||||
@@ -51,7 +52,7 @@ public class LeavesPluginMeta extends PaperPluginMeta {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object serialize(final ApiVersion item, final Predicate<Class<?>> typeSupported) {
|
||||
protected @NotNull Object serialize(final ApiVersion item, final @NotNull Predicate<Class<?>> typeSupported) {
|
||||
return item.getVersionString();
|
||||
}
|
||||
})
|
||||
|
||||
@@ -29,47 +29,46 @@ public class ElytraAeronauticsHelper {
|
||||
|
||||
public static void setActive(boolean active) {
|
||||
isActive = active;
|
||||
if (isActive) {
|
||||
tickTask = Bukkit.getGlobalRegionScheduler().runAtFixedRate(MinecraftInternalPlugin.INSTANCE, task -> {
|
||||
proxyTickingFireworks.removeIf(Entity::isRemoved);
|
||||
for (FireworkRocketEntity firework : proxyTickingFireworks) {
|
||||
firework.life++;
|
||||
Vec3 handHoldingItemAngle;
|
||||
if (firework.attachedToEntity == null || firework.life > firework.lifetime) {
|
||||
firework.discard();
|
||||
continue;
|
||||
}
|
||||
if (firework.attachedToEntity.isFallFlying()) {
|
||||
if (firework.attachedToEntity instanceof ServerPlayer player) {
|
||||
player.connection.send(new ClientboundSetEntityMotionPacket(player));
|
||||
}
|
||||
Vec3 lookAngle = firework.attachedToEntity.getLookAngle();
|
||||
Vec3 deltaMovement = firework.attachedToEntity.getDeltaMovement();
|
||||
firework.attachedToEntity.setDeltaMovement(deltaMovement.add(
|
||||
lookAngle.x * 0.1 + (lookAngle.x * 1.5 - deltaMovement.x) * 0.5,
|
||||
lookAngle.y * 0.1 + (lookAngle.y * 1.5 - deltaMovement.y) * 0.5,
|
||||
lookAngle.z * 0.1 + (lookAngle.z * 1.5 - deltaMovement.z) * 0.5
|
||||
));
|
||||
firework.attachedToEntity.hurtMarked = true;
|
||||
handHoldingItemAngle = firework.attachedToEntity.getHandHoldingItemAngle(Items.FIREWORK_ROCKET);
|
||||
} else {
|
||||
handHoldingItemAngle = Vec3.ZERO;
|
||||
}
|
||||
|
||||
firework.setPos(
|
||||
firework.attachedToEntity.getX() + handHoldingItemAngle.x,
|
||||
firework.attachedToEntity.getY() + handHoldingItemAngle.y,
|
||||
firework.attachedToEntity.getZ() + handHoldingItemAngle.z
|
||||
);
|
||||
firework.setDeltaMovement(firework.attachedToEntity.getDeltaMovement());
|
||||
}
|
||||
}, 1, 1);
|
||||
} else {
|
||||
if (!isActive) {
|
||||
if (tickTask != null) {
|
||||
tickTask.cancel();
|
||||
}
|
||||
tickTask = null;
|
||||
}
|
||||
tickTask = Bukkit.getGlobalRegionScheduler().runAtFixedRate(MinecraftInternalPlugin.INSTANCE, task -> {
|
||||
proxyTickingFireworks.removeIf(Entity::isRemoved);
|
||||
for (FireworkRocketEntity firework : proxyTickingFireworks) {
|
||||
firework.life++;
|
||||
Vec3 handHoldingItemAngle;
|
||||
if (firework.attachedToEntity == null || firework.life > firework.lifetime) {
|
||||
firework.discard();
|
||||
continue;
|
||||
}
|
||||
if (firework.attachedToEntity.isFallFlying()) {
|
||||
if (firework.attachedToEntity instanceof ServerPlayer player) {
|
||||
player.connection.send(new ClientboundSetEntityMotionPacket(player));
|
||||
}
|
||||
Vec3 lookAngle = firework.attachedToEntity.getLookAngle();
|
||||
Vec3 deltaMovement = firework.attachedToEntity.getDeltaMovement();
|
||||
firework.attachedToEntity.setDeltaMovement(deltaMovement.add(
|
||||
lookAngle.x * 0.1 + (lookAngle.x * 1.5 - deltaMovement.x) * 0.5,
|
||||
lookAngle.y * 0.1 + (lookAngle.y * 1.5 - deltaMovement.y) * 0.5,
|
||||
lookAngle.z * 0.1 + (lookAngle.z * 1.5 - deltaMovement.z) * 0.5
|
||||
));
|
||||
firework.attachedToEntity.hurtMarked = true;
|
||||
handHoldingItemAngle = firework.attachedToEntity.getHandHoldingItemAngle(Items.FIREWORK_ROCKET);
|
||||
} else {
|
||||
handHoldingItemAngle = Vec3.ZERO;
|
||||
}
|
||||
|
||||
firework.setPos(
|
||||
firework.attachedToEntity.getX() + handHoldingItemAngle.x,
|
||||
firework.attachedToEntity.getY() + handHoldingItemAngle.y,
|
||||
firework.attachedToEntity.getZ() + handHoldingItemAngle.z
|
||||
);
|
||||
firework.setDeltaMovement(firework.attachedToEntity.getDeltaMovement());
|
||||
}
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
public static boolean proxySpawnAndTick(FireworkRocketEntity entity) {
|
||||
|
||||
@@ -235,6 +235,7 @@ public class HopperCounter {
|
||||
entry(Items.AMETHYST_SHARD, Blocks.AMETHYST_BLOCK)
|
||||
);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Nullable
|
||||
public static TextColor guessColor(@NotNull MinecraftServer server, Item item) {
|
||||
RegistryAccess registryAccess = server.registryAccess();
|
||||
|
||||
@@ -37,7 +37,7 @@ public class LeavesVersionFetcher extends PaperVersionFetcher {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Component getVersionMessage(@NotNull String serverVersion) {
|
||||
public Component getVersionMessage() {
|
||||
final Component updateMessage;
|
||||
final ServerBuildInfo build = ServerBuildInfo.buildInfo();
|
||||
if (build.buildNumber().isEmpty() && build.gitCommit().isEmpty()) {
|
||||
|
||||
@@ -28,6 +28,7 @@ public class ReturnPortalManager {
|
||||
private static final String FROM_POS = "FromPos";
|
||||
private static final String TO_POS = "ToPos";
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static BlockPos findPortalAt(Player player, ResourceKey<Level> dim, BlockPos pos) {
|
||||
MinecraftServer server = player.level().getServer();
|
||||
if (server != null) {
|
||||
|
||||
Reference in New Issue
Block a user