0.1.0 - complete
- Add Stop - Remove Stop - Bluemap Support - Platform Support
This commit is contained in:
1 parent
0219183fe6
commit
467d8e71a3
12 files changed
+229
-2
No files matched your search
@@ -6,6 +6,7 @@ import com.rsscripting.rstaxi.commands.CabTabCompleter;
|
|||||||
import com.rsscripting.rstaxi.language.LanguageManager;
|
import com.rsscripting.rstaxi.language.LanguageManager;
|
||||||
import com.rsscripting.rstaxi.database.DatabaseManager;
|
import com.rsscripting.rstaxi.database.DatabaseManager;
|
||||||
import com.rsscripting.rstaxi.integrations.BlueMapManager;
|
import com.rsscripting.rstaxi.integrations.BlueMapManager;
|
||||||
|
import com.rsscripting.rstaxi.platform.PlatformProtectionListener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
@@ -45,6 +46,9 @@ public final class RSTaxi extends JavaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(
|
||||||
|
new PlatformProtectionListener(this), this);
|
||||||
|
|
||||||
getCommand("cab").setExecutor(new CabCommand(this));
|
getCommand("cab").setExecutor(new CabCommand(this));
|
||||||
getCommand("cab").setTabCompleter(new CabTabCompleter(this));
|
getCommand("cab").setTabCompleter(new CabTabCompleter(this));
|
||||||
|
|
||||||
|
|||||||
@@ -192,8 +192,13 @@ public final class CabCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = arguments.substring(1, closingQuote);
|
name = arguments.substring(1, closingQuote).trim();
|
||||||
icon = arguments.substring(closingQuote + 1).trim();
|
icon = arguments.substring(closingQuote + 1).trim();
|
||||||
|
|
||||||
|
if (icon.startsWith("'") || icon.startsWith("\"")) {
|
||||||
|
icon = icon.substring(1).trim();
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String[] parts = arguments.split("\\s+");
|
String[] parts = arguments.split("\\s+");
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,59 @@ public final class CabTabCompleter implements TabCompleter {
|
|||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// /cab add <destination> <icon>
|
||||||
|
if (args[0].equalsIgnoreCase("add")) {
|
||||||
|
if (!sender.hasPermission("rs-cab.add")) {
|
||||||
|
return suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
|
int iconIndex = 2;
|
||||||
|
|
||||||
|
// Detect a quoted destination that contains spaces.
|
||||||
|
if (args.length >= 2
|
||||||
|
&& (args[1].startsWith("'")
|
||||||
|
|| args[1].startsWith("\""))) {
|
||||||
|
|
||||||
|
char quote = args[1].charAt(0);
|
||||||
|
int closingIndex = -1;
|
||||||
|
|
||||||
|
for (int i = 1; i < args.length; i++) {
|
||||||
|
int quotePosition = args[i].lastIndexOf(quote);
|
||||||
|
|
||||||
|
// Ignore the opening quote at the beginning of the destination.
|
||||||
|
if (quotePosition > 0) {
|
||||||
|
closingIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destination is not finished yet.
|
||||||
|
if (closingIndex == -1) {
|
||||||
|
return suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
|
iconIndex = closingIndex + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only suggest icons when the cursor is in the icon argument.
|
||||||
|
if (args.length != iconIndex + 1) {
|
||||||
|
return suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
|
String input = args[iconIndex].toLowerCase(Locale.ROOT);
|
||||||
|
|
||||||
|
for (String icon :
|
||||||
|
plugin.getBlueMapManager().getAvailableIcons()) {
|
||||||
|
if (icon.toLowerCase(Locale.ROOT).startsWith(input)) {
|
||||||
|
suggestions.add(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// /cab remove <destination>
|
// /cab remove <destination>
|
||||||
if (args[0].equalsIgnoreCase("remove")) {
|
if (args[0].equalsIgnoreCase("remove")) {
|
||||||
if (!sender.hasPermission("rs-cab.delete")) {
|
if (!sender.hasPermission("rs-cab.delete")) {
|
||||||
|
|||||||
@@ -12,6 +12,14 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public final class BlueMapManager {
|
public final class BlueMapManager {
|
||||||
|
|
||||||
@@ -85,6 +93,7 @@ public final class BlueMapManager {
|
|||||||
stop.y(),
|
stop.y(),
|
||||||
stop.z()
|
stop.z()
|
||||||
)
|
)
|
||||||
|
.icon(stop.icon(), 8, 8)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
markerSet.getMarkers().put(markerId, marker);
|
markerSet.getMarkers().put(markerId, marker);
|
||||||
@@ -161,6 +170,7 @@ public final class BlueMapManager {
|
|||||||
stop.y(),
|
stop.y(),
|
||||||
stop.z()
|
stop.z()
|
||||||
)
|
)
|
||||||
|
.icon(stop.icon(), 8, 8)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
markerSet.getMarkers().put(markerId, marker);
|
markerSet.getMarkers().put(markerId, marker);
|
||||||
@@ -205,4 +215,51 @@ public final class BlueMapManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<String> getAvailableIcons() {
|
||||||
|
Set<String> supportedExtensions = Set.of(
|
||||||
|
".png", ".jpg", ".jpeg", ".svg", ".webp", ".gif"
|
||||||
|
);
|
||||||
|
|
||||||
|
return BlueMapAPI.getInstance()
|
||||||
|
.map(api -> {
|
||||||
|
Path assetsDirectory = api.getWebApp()
|
||||||
|
.getWebRoot()
|
||||||
|
.resolve("assets");
|
||||||
|
|
||||||
|
if (!Files.isDirectory(assetsDirectory)) {
|
||||||
|
return List.<String>of();
|
||||||
|
}
|
||||||
|
|
||||||
|
try (Stream<Path> paths = Files.walk(assetsDirectory)) {
|
||||||
|
return paths
|
||||||
|
.filter(Files::isRegularFile)
|
||||||
|
.filter(path -> {
|
||||||
|
String fileName = path.getFileName()
|
||||||
|
.toString()
|
||||||
|
.toLowerCase(Locale.ROOT);
|
||||||
|
|
||||||
|
return supportedExtensions.stream()
|
||||||
|
.anyMatch(fileName::endsWith);
|
||||||
|
})
|
||||||
|
.map(path -> api.getWebApp()
|
||||||
|
.getWebRoot()
|
||||||
|
.relativize(path)
|
||||||
|
.toString()
|
||||||
|
.replace('\\', '/'))
|
||||||
|
.sorted(String.CASE_INSENSITIVE_ORDER)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
plugin.getLogger().warning(
|
||||||
|
"Could not scan BlueMap assets: "
|
||||||
|
+ e.getMessage()
|
||||||
|
);
|
||||||
|
return List.<String>of();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.orElseGet(List::of);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
|
||||||
|
package com.rsscripting.rstaxi.platform;
|
||||||
|
|
||||||
|
import com.rsscripting.rstaxi.RSTaxi;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public final class PlatformProtectionListener implements Listener {
|
||||||
|
|
||||||
|
private final RSTaxi plugin;
|
||||||
|
|
||||||
|
private static final Map<String, int[]> OFFSETS = Map.of(
|
||||||
|
"north", new int[]{0, -1},
|
||||||
|
"northeast", new int[]{1, -1},
|
||||||
|
"east", new int[]{1, 0},
|
||||||
|
"southeast", new int[]{1, 1},
|
||||||
|
"south", new int[]{0, 1},
|
||||||
|
"southwest", new int[]{-1, 1},
|
||||||
|
"west", new int[]{-1, 0},
|
||||||
|
"northwest", new int[]{-1, -1}
|
||||||
|
);
|
||||||
|
|
||||||
|
public PlatformProtectionListener(RSTaxi plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
|
||||||
|
if (!plugin.getConfig().getBoolean(
|
||||||
|
"platform.protect-platforms", true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block block = event.getBlock();
|
||||||
|
|
||||||
|
if (isPlatformBlock(block)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPlatformBlock(Block block) {
|
||||||
|
|
||||||
|
Material target = getMaterial("platform.target-block");
|
||||||
|
|
||||||
|
// Is this the center target block?
|
||||||
|
if (block.getType() == target
|
||||||
|
&& hasRequiredSurroundings(block)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Could this block be one of the eight surrounding blocks?
|
||||||
|
for (int[] offset : OFFSETS.values()) {
|
||||||
|
|
||||||
|
Block possibleCenter = block.getRelative(
|
||||||
|
-offset[0], 0, -offset[1]);
|
||||||
|
|
||||||
|
if (possibleCenter.getType() == target
|
||||||
|
&& hasRequiredSurroundings(possibleCenter)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasRequiredSurroundings(Block center) {
|
||||||
|
|
||||||
|
for (Map.Entry<String, int[]> entry : OFFSETS.entrySet()) {
|
||||||
|
|
||||||
|
Material required = getMaterial(
|
||||||
|
"platform.layout." + entry.getKey());
|
||||||
|
|
||||||
|
int[] offset = entry.getValue();
|
||||||
|
|
||||||
|
Block surrounding = center.getRelative(
|
||||||
|
offset[0], 0, offset[1]);
|
||||||
|
|
||||||
|
if (surrounding.getType() != required) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Material getMaterial(String path) {
|
||||||
|
|
||||||
|
String name = plugin.getConfig().getString(path, "");
|
||||||
|
Material material = Material.matchMaterial(name);
|
||||||
|
|
||||||
|
if (material == null || !material.isBlock()) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Invalid platform material at " + path + ": " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ public final class StopManager {
|
|||||||
|
|
||||||
public record StopLocation(
|
public record StopLocation(
|
||||||
String name,
|
String name,
|
||||||
|
String icon,
|
||||||
String world,
|
String world,
|
||||||
double x,
|
double x,
|
||||||
double y,
|
double y,
|
||||||
@@ -52,7 +53,7 @@ public final class StopManager {
|
|||||||
throws SQLException {
|
throws SQLException {
|
||||||
|
|
||||||
String sql = """
|
String sql = """
|
||||||
SELECT name, world, x, y, z, yaw, pitch
|
SELECT name, icon, world, x, y, z, yaw, pitch
|
||||||
FROM stops
|
FROM stops
|
||||||
WHERE name = ?
|
WHERE name = ?
|
||||||
""";
|
""";
|
||||||
@@ -69,6 +70,7 @@ public final class StopManager {
|
|||||||
|
|
||||||
return new StopLocation(
|
return new StopLocation(
|
||||||
results.getString("name"),
|
results.getString("name"),
|
||||||
|
results.getString("icon"),
|
||||||
results.getString("world"),
|
results.getString("world"),
|
||||||
results.getDouble("x"),
|
results.getDouble("x"),
|
||||||
results.getDouble("y"),
|
results.getDouble("y"),
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,4 +8,5 @@ com\rsscripting\rstaxi\language\LanguageManager.class
|
|||||||
com\rsscripting\rstaxi\stops\StopManager.class
|
com\rsscripting\rstaxi\stops\StopManager.class
|
||||||
com\rsscripting\rstaxi\platform\PlatformValidator.class
|
com\rsscripting\rstaxi\platform\PlatformValidator.class
|
||||||
com\rsscripting\rstaxi\RSTaxi.class
|
com\rsscripting\rstaxi\RSTaxi.class
|
||||||
|
com\rsscripting\rstaxi\platform\PlatformProtectionListener.class
|
||||||
com\rsscripting\rstaxi\commands\CabTabCompleter.class
|
com\rsscripting\rstaxi\commands\CabTabCompleter.class
|
||||||
@@ -4,6 +4,7 @@ C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\command
|
|||||||
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\database\DatabaseManager.java
|
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\database\DatabaseManager.java
|
||||||
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\integrations\BlueMapManager.java
|
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\integrations\BlueMapManager.java
|
||||||
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\language\LanguageManager.java
|
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\language\LanguageManager.java
|
||||||
|
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\platform\PlatformProtectionListener.java
|
||||||
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\platform\PlatformValidator.java
|
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\platform\PlatformValidator.java
|
||||||
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\RSTaxi.java
|
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\RSTaxi.java
|
||||||
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\stops\StopManager.java
|
C:\Users\russe\IdeaProjects\RS-Taxi\src\main\java\com\rsscripting\rstaxi\stops\StopManager.java
|
||||||
Reference in new issue
Block a user