mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 14:50:56 +00:00
Bukkit command cleanup/fixes
This commit is contained in:
@@ -53,4 +53,15 @@ public interface TerraPlugin extends LoaderRegistrar {
|
|||||||
default String getVersion() {
|
default String getVersion() {
|
||||||
return "@VERSION@";
|
return "@VERSION@";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs a task that may or may not be thread safe, depending on platform.
|
||||||
|
* <p>
|
||||||
|
* Allows platforms to define what code is safe to be run asynchronously.
|
||||||
|
*
|
||||||
|
* @param task Task to be run.
|
||||||
|
*/
|
||||||
|
default void runPossiblyUnsafeTask(Runnable task) {
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class BiomeLocateCommand implements CommandTemplate {
|
|||||||
if(location != null) {
|
if(location != null) {
|
||||||
sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", biome.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.getLocation().getY(), 0)).distance(player.getLocation().toVector())));
|
sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", biome.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.getLocation().getY(), 0)).distance(player.getLocation().toVector())));
|
||||||
if(teleport) {
|
if(teleport) {
|
||||||
player.setLocation(new Location(player.getWorld(), location.getX(), player.getLocation().getY(), location.getZ()));
|
main.runPossiblyUnsafeTask(() -> player.setLocation(new Location(player.getWorld(), location.getX(), player.getLocation().getY(), location.getZ())));
|
||||||
}
|
}
|
||||||
} else LangUtil.send("command.biome.unable-to-locate", sender);
|
} else LangUtil.send("command.biome.unable-to-locate", sender);
|
||||||
}, main), "Biome Location Thread").start();
|
}, main), "Biome Location Thread").start();
|
||||||
|
|||||||
@@ -134,6 +134,11 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
|||||||
return eventManager;
|
return eventManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runPossiblyUnsafeTask(Runnable task) {
|
||||||
|
Bukkit.getScheduler().runTask(this, task);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
BukkitChunkGeneratorWrapper.saveAll();
|
BukkitChunkGeneratorWrapper.saveAll();
|
||||||
|
|||||||
+4
-1
@@ -14,6 +14,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class BukkitCommandAdapter implements CommandExecutor, TabCompleter {
|
public class BukkitCommandAdapter implements CommandExecutor, TabCompleter {
|
||||||
private final CommandManager manager;
|
private final CommandManager manager;
|
||||||
@@ -42,7 +44,8 @@ public class BukkitCommandAdapter implements CommandExecutor, TabCompleter {
|
|||||||
List<String> argList = new ArrayList<>(Arrays.asList(args));
|
List<String> argList = new ArrayList<>(Arrays.asList(args));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return manager.tabComplete(argList.remove(0), BukkitAdapter.adapt(sender), argList);
|
return manager.tabComplete(argList.remove(0), BukkitAdapter.adapt(sender), argList).stream()
|
||||||
|
.filter(s -> s.toLowerCase(Locale.ROOT).startsWith(args[args.length - 1].toLowerCase(Locale.ROOT))).sorted(String::compareTo).collect(Collectors.toList());
|
||||||
} catch(CommandException e) {
|
} catch(CommandException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|||||||
Reference in New Issue
Block a user