Skip to content

Commit

Permalink
remove bedrock tools
Browse files Browse the repository at this point in the history
  • Loading branch information
tanyaofei committed Jul 29, 2024
1 parent 4659a77 commit a6f20aa
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 87 deletions.
6 changes: 0 additions & 6 deletions fakeplayer-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.github.hello09x</groupId>
<artifactId>bedrock</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
4 changes: 2 additions & 2 deletions fakeplayer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@

<dependency>
<groupId>io.github.hello09x</groupId>
<artifactId>bedrock</artifactId>
<artifactId>devtools-core</artifactId>
</dependency>

<dependency>
<groupId>io.github.hello09x</groupId>
<artifactId>devtools-core</artifactId>
<artifactId>devtools-command</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.zaxxer.hikari.HikariConfig;
import io.github.hello09x.bedrock.util.RegistrablePlugin;
import io.github.hello09x.devtools.core.PluginEventModule;
import io.github.hello09x.devtools.core.TranslationModule;
import io.github.hello09x.devtools.core.transaction.TranslationConfig;
import io.github.hello09x.devtools.core.transaction.TranslatorUtils;
import io.github.hello09x.devtools.core.utils.Exceptions;
import io.github.hello09x.devtools.core.utils.Lambdas;
import io.github.hello09x.devtools.database.DatabaseModule;
import io.github.hello09x.fakeplayer.core.command.CommandRegistry;
import io.github.hello09x.fakeplayer.core.config.Config;
import io.github.hello09x.fakeplayer.core.listener.FakeplayerListener;
import io.github.hello09x.fakeplayer.core.listener.PlayerListener;
import io.github.hello09x.fakeplayer.core.listener.ReplenishListener;
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
import io.github.hello09x.fakeplayer.core.manager.WildFakeplayerManager;
import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository;
import io.github.hello09x.fakeplayer.core.util.update.UpdateChecker;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.concurrent.CompletableFuture;

public final class Main extends RegistrablePlugin {
public final class Main extends JavaPlugin {

@Getter
private static Main instance;
Expand Down Expand Up @@ -107,11 +110,16 @@ public void checkForUpdatesAsync() {

@Override
public void onDisable() {
super.onDisable();
{
var messenger = getServer().getMessenger();
messenger.unregisterIncomingPluginChannel(this);
messenger.unregisterOutgoingPluginChannel(this);
Exceptions.suppress(this, () -> injector.getInstance(FakeplayerManager.class).onDisable());
Exceptions.suppress(this, () -> injector.getInstance(UsedIdRepository.class).onDisable());
}
{
Exceptions.suppress(this, () -> {
var messenger = getServer().getMessenger();
messenger.unregisterIncomingPluginChannel(this);
messenger.unregisterOutgoingPluginChannel(this);
});
}
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.util.function.Predicate;
import java.util.stream.Stream;

import static io.github.hello09x.bedrock.command.Commands.command;
import static io.github.hello09x.bedrock.command.Commands.int32;
import static io.github.hello09x.devtools.command.exception.Commands.command;
import static io.github.hello09x.devtools.command.exception.Commands.int32;
import static net.kyori.adventure.text.Component.translatable;

public abstract class CommandSupports {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.google.inject.Singleton;
import dev.jorel.commandapi.executors.CommandArguments;
import io.github.hello09x.bedrock.page.Page;
import io.github.hello09x.devtools.command.exception.Page;
import io.github.hello09x.fakeplayer.core.command.Permission;
import io.github.hello09x.fakeplayer.core.util.Mth;
import org.apache.commons.lang3.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.google.inject.Inject;
import com.google.inject.Singleton;
import io.github.hello09x.bedrock.util.AddressUtils;
import io.github.hello09x.devtools.core.message.MessageException;
import io.github.hello09x.devtools.core.message.RuntimeMessageException;
import io.github.hello09x.devtools.core.utils.Exceptions;
import io.github.hello09x.fakeplayer.api.spi.Action;
import io.github.hello09x.fakeplayer.api.spi.NMSBridge;
import io.github.hello09x.fakeplayer.core.Main;
Expand All @@ -17,6 +17,7 @@
import io.github.hello09x.fakeplayer.core.manager.naming.SequenceName;
import io.github.hello09x.fakeplayer.core.manager.naming.exception.IllegalCustomNameException;
import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository;
import io.github.hello09x.fakeplayer.core.util.AddressUtils;
import io.github.hello09x.fakeplayer.core.util.Commands;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
Expand All @@ -36,6 +37,7 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.logging.Logger;
Expand All @@ -56,6 +58,7 @@ public class FakeplayerManager {
private final UserConfigManager configManager;
private final NMSBridge nms;
private final Config config;
private final ScheduledExecutorService lagMonitor;

@Inject
public FakeplayerManager(Invsee invsee, UsedIdRepository usedIdRepository, NameManager nameManager, FakeplayerList playerList, UserConfigManager configManager, NMSBridge nms, Config config) {
Expand All @@ -67,8 +70,8 @@ public FakeplayerManager(Invsee invsee, UsedIdRepository usedIdRepository, NameM
this.nms = nms;
this.config = config;

var timer = Executors.newSingleThreadScheduledExecutor();
timer.scheduleWithFixedDelay(() -> {
this.lagMonitor = Executors.newSingleThreadScheduledExecutor();
this.lagMonitor.scheduleWithFixedDelay(() -> {
if (Bukkit.getServer().getTPS()[1] < config.getKaleTps()) {
Bukkit.getScheduler().runTask(Main.getInstance(), () -> {
if (this.removeAll("low tps") > 0) {
Expand All @@ -78,9 +81,6 @@ public FakeplayerManager(Invsee invsee, UsedIdRepository usedIdRepository, NameM
}
}, 0, 60, TimeUnit.SECONDS
);

Main.getInstance().registerOnDisable(() -> this.removeAll("Plugin disabled"));
Main.getInstance().registerOnDisable(timer::shutdown);
}

/**
Expand Down Expand Up @@ -527,5 +527,9 @@ private void checkLimit(@NotNull CommandSender creator) throws MessageException
}
}

public void onDisable() {
Exceptions.suppress(Main.getInstance(), () -> this.removeAll("Plugin disabled"));
Exceptions.suppress(Main.getInstance(), this.lagMonitor::shutdownNow);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import io.github.hello09x.devtools.core.utils.Exceptions;
import io.github.hello09x.fakeplayer.core.Main;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
Expand All @@ -27,7 +28,6 @@ public class UsedIdRepository {
@Inject
public UsedIdRepository() {
this.load();
Main.getInstance().registerOnDisable(this::saveAll);
}

public boolean contains(@NotNull UUID uuid) {
Expand Down Expand Up @@ -85,5 +85,9 @@ public void saveAll() {
}
}

public void onDisable() {
Exceptions.suppress(Main.getInstance(), this::saveAll);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.hello09x.fakeplayer.core.util;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.net.InetSocketAddress;
import java.util.Optional;

/**
* @author tanyaofei
* @since 2024/7/29
**/
public class AddressUtils {

/**
* 获取 IP 地址
* <p>如果不是玩家则返回 127.0.0.1, 如果该玩家已离线则返回 0.0.0.0 </p>
*
* @param sender 玩家
* @return IP 地址
*/
public static @NotNull String getAddress(@NotNull CommandSender sender) {
if (sender instanceof Player p) {
return Optional.ofNullable(p.getAddress()).map(InetSocketAddress::getHostString).orElse("0.0.0.0");
} else {
return "127.0.0.1";
}
}
}
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@

<dependency>
<groupId>io.github.hello09x</groupId>
<artifactId>bedrock</artifactId>
<version>0.0.1</version>
<artifactId>devtools-core</artifactId>
<version>0.1.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>io.github.hello09x</groupId>
<artifactId>devtools-core</artifactId>
<artifactId>devtools-command</artifactId>
<version>0.1.1-SNAPSHOT</version>
</dependency>

Expand Down

0 comments on commit a6f20aa

Please sign in to comment.