Skip to content

Commit

Permalink
Fix loop initialization (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluemangoo authored Jul 19, 2024
1 parent 3992c79 commit df31300
Showing 1 changed file with 190 additions and 10 deletions.
200 changes: 190 additions & 10 deletions patches/server/0010-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,39 @@ index 0ab53d46f0b8f3f3791dd01766738522c86932e8..f60301047fc22fb72413fe95eb89e4d2
if (event.isCancelled()) {
return event;
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index 22f1ed383313829b8af4badda9ef8dc85cae8fd1..764a8b623b91acca040699839c52c2ecec6842ee 100644
index 22f1ed383313829b8af4badda9ef8dc85cae8fd1..03af280bffbd2070abaf1de4b0c963899a67854c 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -1,7 +1,7 @@
package org.bukkit.craftbukkit.scheduler;

import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
@@ -10,7 +10,6 @@ import java.util.PriorityQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -23,6 +22,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scheduler.BukkitWorker;
+import org.leavesmc.leaves.plugin.MinecraftInternalPlugin;

/**
* The fundamental concepts for this implementation:
@@ -46,6 +46,8 @@ import org.bukkit.scheduler.BukkitWorker;
*/
public class CraftScheduler implements BukkitScheduler {

+ public static final Plugin SERVER = new org.bukkit.plugin.java.JavaPlugin(){}; // Leaves - run async task
+ public static final Plugin MINECRAFT = new MinecraftInternalPlugin(); // Leaves - run async task
+
/**
* The start ID for the counter.
Expand Down Expand Up @@ -1401,7 +1426,7 @@ index 0000000000000000000000000000000000000000..0db337866c71283464d026a4f230016b
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/ServerBot.java b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
new file mode 100644
index 0000000000000000000000000000000000000000..47b207b6e24c4856304565ce1c9409ca7b6400f2
index 0000000000000000000000000000000000000000..0cb04bf5c5da387b295897997ae0692eb8baab6e
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
@@ -0,0 +1,745 @@
Expand Down Expand Up @@ -1644,7 +1669,7 @@ index 0000000000000000000000000000000000000000..47b207b6e24c4856304565ce1c9409ca
+
+ playerConnection.send(this.getAddEntityPacket(entityTracker.serverEntity));
+ if (login) {
+ Bukkit.getScheduler().runTaskLater(CraftScheduler.SERVER, () -> {
+ Bukkit.getScheduler().runTaskLater(CraftScheduler.MINECRAFT, () -> {
+ playerConnection.send(new ClientboundRotateHeadPacket(this, (byte) ((getYRot() * 256f) / 360f)));
+ }, 10);
+ } else {
Expand Down Expand Up @@ -2117,12 +2142,12 @@ index 0000000000000000000000000000000000000000..47b207b6e24c4856304565ce1c9409ca
+ }
+ return bot != null ? bot.getBukkitEntity() : null;
+ }
+ Bukkit.getScheduler().runTaskAsynchronously(CraftScheduler.SERVER, () -> {
+ Bukkit.getScheduler().runTaskAsynchronously(CraftScheduler.MINECRAFT, () -> {
+ if (skinName != null) {
+ this.skin = MojangAPI.getSkin(skinName);
+ }
+
+ Bukkit.getScheduler().runTask(CraftScheduler.SERVER, () -> {
+ Bukkit.getScheduler().runTask(CraftScheduler.MINECRAFT, () -> {
+ ServerBot bot = createBot(this);
+ if (bot != null && consumer != null) {
+ consumer.accept(bot);
Expand Down Expand Up @@ -3138,7 +3163,7 @@ index 0000000000000000000000000000000000000000..475bf440d40ac35720b01da18440cf0d
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..81e6b4368014599ace20d371eb941faf9f5482a8
index 0000000000000000000000000000000000000000..fe8c4ba7aff74dc297bdf4e271a2d7f1229c357d
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnAction.java
@@ -0,0 +1,56 @@
Expand Down Expand Up @@ -3187,7 +3212,7 @@ index 0000000000000000000000000000000000000000..81e6b4368014599ace20d371eb941faf
+ BlockEntity entity = bot.serverLevel().getBlockEntity(blockHitResult.getBlockPos());
+ if (entity instanceof TrappedChestBlockEntity chestBlockEntity) {
+ chestBlockEntity.startOpen(bot);
+ Bukkit.getScheduler().runTaskLater(CraftScheduler.SERVER, () -> chestBlockEntity.stopOpen(bot), 1);
+ Bukkit.getScheduler().runTaskLater(CraftScheduler.MINECRAFT, () -> chestBlockEntity.stopOpen(bot), 1);
+ return true;
+ }
+ } else {
Expand All @@ -3200,7 +3225,7 @@ index 0000000000000000000000000000000000000000..81e6b4368014599ace20d371eb941faf
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnOffhandAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnOffhandAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..8ef68e0e8a75760c974fdb0849f147aac0c168fa
index 0000000000000000000000000000000000000000..a69ede01e5e5df31a144f98e9871183793f5f377
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnOffhandAction.java
@@ -0,0 +1,56 @@
Expand Down Expand Up @@ -3249,7 +3274,7 @@ index 0000000000000000000000000000000000000000..8ef68e0e8a75760c974fdb0849f147aa
+ BlockEntity entity = bot.serverLevel().getBlockEntity(blockHitResult.getBlockPos());
+ if (entity instanceof TrappedChestBlockEntity chestBlockEntity) {
+ chestBlockEntity.startOpen(bot);
+ Bukkit.getScheduler().runTaskLater(CraftScheduler.SERVER, () -> chestBlockEntity.stopOpen(bot), 1);
+ Bukkit.getScheduler().runTaskLater(CraftScheduler.MINECRAFT, () -> chestBlockEntity.stopOpen(bot), 1);
+ return true;
+ }
+ } else {
Expand Down Expand Up @@ -3529,3 +3554,158 @@ index 0000000000000000000000000000000000000000..badd1d78398fc154254cd465c0a59c64
+ return Actions.unregister(name);
+ }
+}
diff --git a/src/main/java/org/leavesmc/leaves/plugin/MinecraftInternalPlugin.java b/src/main/java/org/leavesmc/leaves/plugin/MinecraftInternalPlugin.java
new file mode 100644
index 0000000000000000000000000000000000000000..356b2de6ffd82e42a5d0f20ac1e3de7f4b5a7013
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/plugin/MinecraftInternalPlugin.java
@@ -0,0 +1,149 @@
+package org.leavesmc.leaves.plugin;
+
+import org.bukkit.Server;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.generator.BiomeProvider;
+import org.bukkit.generator.ChunkGenerator;
+import org.bukkit.plugin.PluginBase;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.bukkit.plugin.PluginLoader;
+import org.bukkit.plugin.PluginLogger;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.List;
+
+public class MinecraftInternalPlugin extends PluginBase {
+ private boolean enabled = true;
+
+ private final PluginDescriptionFile pdf;
+
+ public MinecraftInternalPlugin() {
+ String pluginName = "Minecraft";
+ pdf = new PluginDescriptionFile(pluginName, "1.0", "nms");
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public File getDataFolder() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public PluginDescriptionFile getDescription() {
+ return pdf;
+ }
+ // Paper start
+ @Override
+ public io.papermc.paper.plugin.configuration.PluginMeta getPluginMeta() {
+ return pdf;
+ }
+ // Paper end
+
+ @Override
+ public FileConfiguration getConfig() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public InputStream getResource(String filename) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void saveConfig() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void saveDefaultConfig() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void saveResource(String resourcePath, boolean replace) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void reloadConfig() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public PluginLogger getLogger() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public PluginLoader getPluginLoader() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public Server getServer() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ @Override
+ public void onDisable() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void onLoad() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void onEnable() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean isNaggable() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void setNaggable(boolean canNag) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public @Nullable BiomeProvider getDefaultBiomeProvider(@NotNull String worldName, @Nullable String id) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public @NotNull io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager<org.bukkit.plugin.Plugin> getLifecycleManager() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+}

0 comments on commit df31300

Please sign in to comment.