testing new version
This commit is contained in:
parent
ef65431d40
commit
e06ee55259
17 changed files with 499 additions and 181 deletions
4
pom.xml
4
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>net.benjidial.nswp</groupId>
|
||||
<artifactId>NSWP</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
|
||||
<name>NewSimpleWaypoints</name>
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.20.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
16
readme.txt
Normal file
16
readme.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
=== New Simple Waypoints ===
|
||||
|
||||
This plugin allows players on a Spigot server to save waypoints and teleport
|
||||
back to them, as well as teleport to other players if those players allow it.
|
||||
|
||||
To build the plugin (assuming you have Maven installed), just run "mvn verify".
|
||||
The plugin jar will be placed in the "target" directory. To install the plugin,
|
||||
just copy that jar file into the "plugins" directory of the server. The first
|
||||
time that the server starts after that, a SQLite database will be created.
|
||||
|
||||
See the file "src/main/resources/plugin.yml" for a list of commands. In order
|
||||
to use the /wtp command, a player must have the nswp.waypoints permission. In
|
||||
order to use the /wtpallow and /wtpa commands, a player must have the nswp.tpa
|
||||
permission. You can use a plugin like LuckPerms to grant these permissions.
|
||||
|
||||
Enjoy!
|
|
@ -10,6 +10,7 @@ import java.sql.SQLException;
|
|||
import java.util.ArrayList;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Database {
|
||||
static Connection connection;
|
||||
|
@ -57,7 +58,6 @@ public class Database {
|
|||
}
|
||||
|
||||
public static Location getWBack(Player player) throws SQLException {
|
||||
createWBacks();
|
||||
PreparedStatement statement = connection.prepareStatement(
|
||||
"SELECT * FROM wbacks WHERE player_uuid = ?"
|
||||
);
|
||||
|
@ -69,7 +69,6 @@ public class Database {
|
|||
}
|
||||
|
||||
public static void setWBack(Player player, Location location) throws SQLException {
|
||||
createWBacks();
|
||||
PreparedStatement statement = connection.prepareStatement(
|
||||
"REPLACE INTO wbacks(player_uuid, world, x, y, z, pitch, yaw) VALUES(?, ?, ?, ?, ?, ?, ?)"
|
||||
);
|
||||
|
@ -101,11 +100,11 @@ public class Database {
|
|||
);
|
||||
}
|
||||
|
||||
public static ArrayList<Waypoint> searchWaypoints(Player player, String start) throws SQLException {
|
||||
public static ArrayList<Waypoint> searchWaypoints(Player player, String searchString) throws SQLException {
|
||||
PreparedStatement statement = connection.prepareStatement(
|
||||
"SELECT * FROM " + waypointTableName(player) + " WHERE name LIKE ? ESCAPE '!' ORDER BY world, name ASC"
|
||||
);
|
||||
statement.setString(1, "%" + start.replace("!", "!!").replace("_", "!_") + "%");
|
||||
statement.setString(1, "%" + searchString.replace("!", "!!").replace("_", "!_") + "%");
|
||||
ResultSet results = statement.executeQuery();
|
||||
ArrayList<Waypoint> list = new ArrayList<Waypoint>();
|
||||
while (results.next())
|
||||
|
@ -154,4 +153,104 @@ public class Database {
|
|||
else
|
||||
player.sendMessage("Waypoint deleted.");
|
||||
}
|
||||
|
||||
public static void createTPATable() throws SQLException {
|
||||
PreparedStatement statement = connection.prepareStatement(
|
||||
"CREATE TABLE IF NOT EXISTS tpa_allowed (" +
|
||||
"from TEXT NOT NULL, " +
|
||||
"to TEXT NOT NULL" +
|
||||
")"
|
||||
);
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
public static boolean isTPAAllowed(Player from, Player to) throws SQLException {
|
||||
PreparedStatement statement = connection.prepareStatement(
|
||||
"SELECT * FROM tpa_allowed WHERE from = ? AND to = ?"
|
||||
);
|
||||
statement.setString(1, playerID(from));
|
||||
statement.setString(2, playerID(to));
|
||||
ResultSet results = statement.executeQuery();
|
||||
return results.next();
|
||||
}
|
||||
|
||||
public static void allowTPA(Player from, Player to) throws SQLException {
|
||||
PreparedStatement statement = connection.prepareStatement(
|
||||
"INSERT INTO tpa_allowed(from, to) VALUES(?, ?)"
|
||||
);
|
||||
statement.setString(1, playerID(from));
|
||||
statement.setString(2, playerID(to));
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
public static int disallowTPA(String fromName, Player to) throws SQLException {
|
||||
//this is kinda scrungled but i think it should work.
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(
|
||||
"SELECT * FROM tpa_allowed WHERE to = ?"
|
||||
);
|
||||
statement.setString(1, playerID(to));
|
||||
ResultSet table = statement.executeQuery();
|
||||
|
||||
int removed = 0;
|
||||
|
||||
while (table.next()) {
|
||||
String fromID = table.getString("from");
|
||||
|
||||
if (Bukkit.getOfflinePlayer(UUID.fromString(fromID)).getName() == fromName) {
|
||||
PreparedStatement deleteStatement = connection.prepareStatement(
|
||||
"DELETE FROM tpa_allowed WHERE from = ? AND to = ?"
|
||||
);
|
||||
deleteStatement.setString(1, fromID);
|
||||
deleteStatement.setString(2, playerID(to));
|
||||
deleteStatement.executeUpdate();
|
||||
++removed;
|
||||
}
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getOnlineTPADisallowedTo(Player to) throws SQLException {
|
||||
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
if (!isTPAAllowed(player, to))
|
||||
results.add(player.getName());
|
||||
|
||||
return results;
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<String> getTPAAllowedTo(Player to) throws SQLException {
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(
|
||||
"SELECT * FROM tpa_allowed WHERE to = ?"
|
||||
);
|
||||
statement.setString(1, playerID(to));
|
||||
ResultSet table = statement.executeQuery();
|
||||
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
while (table.next()) {
|
||||
String name = Bukkit.getOfflinePlayer(UUID.fromString(table.getString("from"))).getName();
|
||||
//there is no way to disallow a player whose name is not know. but, to allow a player,
|
||||
//they have to be online, and so their name should be known.
|
||||
if (name != null)
|
||||
results.add(name);
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<String> getOnlineTPAAllowedFrom(Player from) throws SQLException {
|
||||
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
if (isTPAAllowed(from, player))
|
||||
results.add(player.getName());
|
||||
|
||||
return results;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import net.benjidial.nswp.commands.*;
|
|||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.sql.SQLException;
|
||||
import java.io.File;
|
||||
|
||||
|
@ -13,23 +12,30 @@ public class Plugin extends JavaPlugin {
|
|||
public static Logger logger;
|
||||
|
||||
public void onEnable() {
|
||||
|
||||
logger = getLogger();
|
||||
getDataFolder().mkdirs();
|
||||
|
||||
try {
|
||||
Database.connect(new File(getDataFolder(), "database.db").getPath());
|
||||
Database.createWBacks();
|
||||
Database.createTPATable();
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
logger.log(Level.SEVERE, "Database error: (not enabling plugin)");
|
||||
logger.severe("Database error (not enabling plugin):");
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
getCommand("wlist" ).setExecutor(new ListWaypoints());
|
||||
getCommand("wsave" ).setExecutor(new SaveWaypoint());
|
||||
getCommand("wtp" ).setExecutor(new TeleportToWaypoint());
|
||||
getCommand("wdel" ).setExecutor(new DeleteWaypoint());
|
||||
getCommand("wback" ).setExecutor(new WaypointBack());
|
||||
getCommand("wtpallow").setExecutor(new AllowTPA());
|
||||
getCommand("wdel").setExecutor(new DeleteWaypoint());
|
||||
getCommand("wtpdeny").setExecutor(new DenyTPA());
|
||||
getCommand("wlist").setExecutor(new ListWaypoints());
|
||||
getCommand("wrename").setExecutor(new RenameWaypoint());
|
||||
getCommand("wsave").setExecutor(new SaveWaypoint());
|
||||
getCommand("wtp").setExecutor(new TeleportToWaypoint());
|
||||
getCommand("wtpa").setExecutor(new TPA());
|
||||
getCommand("wback").setExecutor(new WaypointBack());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.benjidial.nswp;
|
|||
import org.bukkit.Location;
|
||||
|
||||
public class Waypoint {
|
||||
|
||||
public Waypoint(String name, Location location) {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
|
@ -10,4 +11,9 @@ public class Waypoint {
|
|||
|
||||
public String name;
|
||||
public Location location;
|
||||
|
||||
public String toString() {
|
||||
return name + " (" + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ() + " in " + location.getWorld().getName() + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
39
src/main/java/net/benjidial/nswp/commands/AllowTPA.java
Normal file
39
src/main/java/net/benjidial/nswp/commands/AllowTPA.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package net.benjidial.nswp.commands;
|
||||
|
||||
import net.benjidial.nswp.Database;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class AllowTPA extends PlayerCommand {
|
||||
|
||||
public List<String> getTabCompletions(Player sender, String[] args) throws SQLException {
|
||||
return filterByArg(Database.getOnlineTPADisallowedTo(sender), args, 0);
|
||||
}
|
||||
|
||||
public boolean doCommand(Player sender, String[] args) throws SQLException {
|
||||
|
||||
if (args.length != 1)
|
||||
return false;
|
||||
|
||||
Player other = Bukkit.getPlayer(args[0]);
|
||||
if (other == null) {
|
||||
sender.sendMessage("Could not find " + args[0] + ". Are they online?");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Database.isTPAAllowed(other, sender)) {
|
||||
sender.sendMessage(other.getName() + " is already allowed to teleport to you.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Database.allowTPA(other, sender);
|
||||
sender.sendMessage(other.getName() + " is now allowed to teleport to you.");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,20 +1,36 @@
|
|||
package net.benjidial.nswp.commands;
|
||||
|
||||
import net.benjidial.nswp.Database;
|
||||
import net.benjidial.nswp.Waypoint;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteWaypoint extends WaypointCommand {
|
||||
public CompletionType getCompletionType() {
|
||||
return CompletionType.Waypoint;
|
||||
public class DeleteWaypoint extends PlayerCommand {
|
||||
|
||||
public List<String> getTabCompletions(Player sender, String[] args) throws SQLException {
|
||||
return searchWaypointsByArg(sender, args, 0);
|
||||
}
|
||||
|
||||
public boolean body(Player player, String[] args) throws SQLException {
|
||||
public boolean doCommand(Player sender, String[] args) throws SQLException {
|
||||
|
||||
if (args.length != 1)
|
||||
return false;
|
||||
Database.deleteWaypoint(player, args[0]);
|
||||
|
||||
Database.createWaypointTable(sender);
|
||||
|
||||
Waypoint wp = Database.lookupWaypoint(sender, args[0]);
|
||||
if (wp != null) {
|
||||
Database.deleteWaypoint(sender, args[0]);
|
||||
sender.sendMessage("Deleted " + wp.toString() + ".");
|
||||
}
|
||||
else
|
||||
sender.sendMessage("You do not have a waypoint " + args[0] + ".");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
32
src/main/java/net/benjidial/nswp/commands/DenyTPA.java
Normal file
32
src/main/java/net/benjidial/nswp/commands/DenyTPA.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package net.benjidial.nswp.commands;
|
||||
|
||||
import net.benjidial.nswp.Database;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class DenyTPA extends PlayerCommand {
|
||||
|
||||
public List<String> getTabCompletions(Player sender, String[] args) throws SQLException {
|
||||
return filterByArg(Database.getTPAAllowedTo(sender), args, 0);
|
||||
}
|
||||
|
||||
public boolean doCommand(Player sender, String[] args) throws SQLException {
|
||||
|
||||
if (args.length != 1)
|
||||
return false;
|
||||
|
||||
int removed = Database.disallowTPA(args[0], sender);
|
||||
|
||||
if (removed == 0)
|
||||
sender.sendMessage("Did not find anyone allowed to teleport to you with the name " + args[0] + ".");
|
||||
else
|
||||
sender.sendMessage(args[0] + " is no longer allowed to teleport to you.");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,36 +4,40 @@ import net.benjidial.nswp.Database;
|
|||
import net.benjidial.nswp.Waypoint;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListWaypoints extends WaypointCommand {
|
||||
public CompletionType getCompletionType() {
|
||||
return CompletionType.Waypoint;
|
||||
public class ListWaypoints extends PlayerCommand {
|
||||
|
||||
public List<String> getTabCompletions(Player sender, String[] args) throws SQLException {
|
||||
return searchWaypointsByArg(sender, args, 0);
|
||||
}
|
||||
|
||||
public boolean body(Player player, String[] args) throws SQLException {
|
||||
public boolean doCommand(Player sender, String[] args) throws SQLException {
|
||||
|
||||
if (args.length > 1)
|
||||
return false;
|
||||
ArrayList<Waypoint> waypoints = Database.searchWaypoints(player, args.length == 0 ? "" : args[0]);
|
||||
if (waypoints.size() == 0) {
|
||||
player.sendMessage("No waypoints found.");
|
||||
|
||||
Database.createWaypointTable(sender);
|
||||
ArrayList<Waypoint> wps = Database.searchWaypoints(sender, args.length == 0 ? "" : args[0]);
|
||||
|
||||
if (wps.size() == 0) {
|
||||
sender.sendMessage("0 waypoints found.");
|
||||
return true;
|
||||
}
|
||||
if (waypoints.size() == 1)
|
||||
player.sendMessage("1 waypoint found:");
|
||||
|
||||
if (wps.size() == 1)
|
||||
sender.sendMessage("1 waypoint found:");
|
||||
else
|
||||
player.sendMessage(waypoints.size() + " waypoints found:");
|
||||
World lastWorld = null;
|
||||
for (Waypoint waypoint : waypoints) {
|
||||
if (waypoint.location.getWorld() != lastWorld) {
|
||||
lastWorld = waypoint.location.getWorld();
|
||||
player.sendMessage(" " + lastWorld.getName() + ": ");
|
||||
}
|
||||
player.sendMessage(" " + waypoint.name);
|
||||
}
|
||||
sender.sendMessage(wps.size() + " waypoints found:");
|
||||
|
||||
for (Waypoint wp : wps)
|
||||
sender.sendMessage(" " + wp.toString());
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
88
src/main/java/net/benjidial/nswp/commands/PlayerCommand.java
Normal file
88
src/main/java/net/benjidial/nswp/commands/PlayerCommand.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
package net.benjidial.nswp.commands;
|
||||
|
||||
import net.benjidial.nswp.Database;
|
||||
import net.benjidial.nswp.Waypoint;
|
||||
import net.benjidial.nswp.Plugin;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class PlayerCommand implements TabExecutor {
|
||||
|
||||
public static List<String> filterByArg(List<String> list, String[] args, int index) {
|
||||
|
||||
ArrayList<String> filtered = new ArrayList<>();
|
||||
String searchString = args.length <= index ? "" : args[index];
|
||||
|
||||
for (String candidate : list)
|
||||
if (candidate.contains(searchString))
|
||||
filtered.add(candidate);
|
||||
|
||||
return filtered;
|
||||
|
||||
}
|
||||
|
||||
public static List<String> searchWaypointsByArg(Player player, String[] args, int index) throws SQLException {
|
||||
|
||||
Database.createWaypointTable(player);
|
||||
|
||||
ArrayList<String> filtered = new ArrayList<>();
|
||||
String searchString = args.length <= index ? "" : args[index];
|
||||
|
||||
for (Waypoint wp : Database.searchWaypoints(player, searchString))
|
||||
filtered.add(wp.name);
|
||||
|
||||
return filtered;
|
||||
|
||||
}
|
||||
|
||||
public List<String> getTabCompletions(Player sender, String[] args) throws SQLException {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (!(sender instanceof Player))
|
||||
return new ArrayList<>();
|
||||
|
||||
try {
|
||||
return getTabCompletions((Player)sender, args);
|
||||
}
|
||||
|
||||
catch (SQLException ex) {
|
||||
Plugin.logger.severe("Database error:");
|
||||
ex.printStackTrace();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract boolean doCommand(Player sender, String[] args) throws SQLException;
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("This command may only be run by a player.");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
return doCommand((Player)sender, args);
|
||||
}
|
||||
|
||||
catch (SQLException ex) {
|
||||
sender.sendMessage("Database error.");
|
||||
Plugin.logger.severe("Database error:");
|
||||
ex.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -6,32 +6,45 @@ import net.benjidial.nswp.Waypoint;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RenameWaypoint extends WaypointCommand {
|
||||
public CompletionType getCompletionType() {
|
||||
return CompletionType.Waypoint;
|
||||
public class RenameWaypoint extends PlayerCommand {
|
||||
|
||||
public List<String> getTabCompletions(Player sender, String[] args) throws SQLException {
|
||||
if (args.length > 1)
|
||||
return new ArrayList<String>();
|
||||
return searchWaypointsByArg(sender, args, 0);
|
||||
}
|
||||
|
||||
public boolean doCommand(Player sender, String[] args) throws SQLException {
|
||||
|
||||
if (args.length != 2)
|
||||
return false;
|
||||
|
||||
Database.createWaypointTable(sender);
|
||||
Waypoint wp = Database.lookupWaypoint(sender, args[0]);
|
||||
|
||||
if (wp == null) {
|
||||
sender.sendMessage("You do not have a waypoint " + args[0] + ".");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean body(Player player, String[] args) throws SQLException {
|
||||
if (args.length != 2) return false;
|
||||
|
||||
if (Database.lookupWaypoint(player, args[1]) != null) {
|
||||
player.sendMessage("Waypoint with that name already exists!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Waypoint waypoint = Database.lookupWaypoint(player, args[0]);
|
||||
|
||||
if (waypoint == null) {
|
||||
player.sendMessage("No waypoint with that name.");
|
||||
} else {
|
||||
Database.deleteWaypoint(player, args[0]);
|
||||
waypoint.name = args[1];
|
||||
Database.addWaypoint(player, waypoint);
|
||||
}
|
||||
|
||||
return true;
|
||||
Waypoint otherWP = Database.lookupWaypoint(sender, args[1]);
|
||||
if (otherWP != null) {
|
||||
sender.sendMessage("You already have a waypoint " + otherWP.toString() + ".");
|
||||
return true;
|
||||
}
|
||||
|
||||
String oldToString = wp.toString();
|
||||
wp.name = args[1];
|
||||
|
||||
Database.deleteWaypoint(sender, args[0]);
|
||||
Database.addWaypoint(sender, wp);
|
||||
|
||||
sender.sendMessage("Renamed " + oldToString + " to " + args[1] + ".");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,16 +7,27 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class SaveWaypoint extends WaypointCommand {
|
||||
public CompletionType getCompletionType() {
|
||||
return CompletionType.None;
|
||||
}
|
||||
public class SaveWaypoint extends PlayerCommand {
|
||||
|
||||
public boolean doCommand(Player sender, String[] args) throws SQLException {
|
||||
|
||||
public boolean body(Player player, String[] args) throws SQLException {
|
||||
if (args.length != 1)
|
||||
return false;
|
||||
Waypoint waypoint = new Waypoint(args[0], player.getLocation());
|
||||
Database.addWaypoint(player, waypoint);
|
||||
|
||||
Database.createWaypointTable(sender);
|
||||
|
||||
Waypoint wp = Database.lookupWaypoint(sender, args[0]);
|
||||
if (wp != null) {
|
||||
sender.sendMessage("You already have a waypoint " + wp.toString() + ".");
|
||||
return true;
|
||||
}
|
||||
|
||||
wp = new Waypoint(args[0], sender.getLocation());
|
||||
Database.addWaypoint(sender, wp);
|
||||
|
||||
sender.sendMessage("Added " + wp.toString() + ".");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
40
src/main/java/net/benjidial/nswp/commands/TPA.java
Normal file
40
src/main/java/net/benjidial/nswp/commands/TPA.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package net.benjidial.nswp.commands;
|
||||
|
||||
import net.benjidial.nswp.Database;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class TPA extends PlayerCommand {
|
||||
|
||||
public List<String> getTabCompletions(Player sender, String[] args) throws SQLException {
|
||||
return filterByArg(Database.getOnlineTPAAllowedFrom(sender), args, 0);
|
||||
}
|
||||
|
||||
public boolean doCommand(Player sender, String[] args) throws SQLException {
|
||||
|
||||
if (args.length != 1)
|
||||
return false;
|
||||
|
||||
Player other = Bukkit.getPlayer(args[0]);
|
||||
if (other == null) {
|
||||
sender.sendMessage("Could not find " + args[0] + ". Are they online?");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Database.isTPAAllowed(sender, other)) {
|
||||
sender.sendMessage("You are not allowed to teleport to " + other.getName() + ".");
|
||||
sender.sendMessage("They must first run /wtpallow " + sender.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
Database.setWBack(sender, sender.getLocation());
|
||||
sender.teleport(other);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -6,22 +6,31 @@ import net.benjidial.nswp.Waypoint;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class TeleportToWaypoint extends WaypointCommand {
|
||||
public CompletionType getCompletionType() {
|
||||
return CompletionType.Waypoint;
|
||||
public class TeleportToWaypoint extends PlayerCommand {
|
||||
|
||||
public List<String> getTabCompletions(Player sender, String[] args) throws SQLException {
|
||||
return searchWaypointsByArg(sender, args, 0);
|
||||
}
|
||||
|
||||
public boolean body(Player player, String[] args) throws SQLException {
|
||||
public boolean doCommand(Player sender, String[] args) throws SQLException {
|
||||
|
||||
if (args.length != 1)
|
||||
return false;
|
||||
Waypoint waypoint = Database.lookupWaypoint(player, args[0]);
|
||||
if (waypoint == null)
|
||||
player.sendMessage("No waypoint with that name.");
|
||||
else {
|
||||
Database.setWBack(player, player.getLocation());
|
||||
player.teleport(waypoint.location);
|
||||
|
||||
Database.createWaypointTable(sender);
|
||||
|
||||
Waypoint wp = Database.lookupWaypoint(sender, args[0]);
|
||||
if (wp == null) {
|
||||
sender.sendMessage("You do not have a waypoint " + args[0] + ".");
|
||||
return true;
|
||||
}
|
||||
|
||||
Database.setWBack(sender, sender.getLocation());
|
||||
sender.teleport(wp.location);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,21 +7,24 @@ import org.bukkit.Location;
|
|||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class WaypointBack extends WaypointCommand {
|
||||
public CompletionType getCompletionType() {
|
||||
return CompletionType.None;
|
||||
}
|
||||
public class WaypointBack extends PlayerCommand {
|
||||
|
||||
public boolean doCommand(Player sender, String[] args) throws SQLException {
|
||||
|
||||
public boolean body(Player player, String[] args) throws SQLException {
|
||||
if (args.length != 0)
|
||||
return false;
|
||||
Location wback = Database.getWBack(player);
|
||||
if (wback == null)
|
||||
player.sendMessage("You have not teleported to any waypoints.");
|
||||
else {
|
||||
Database.setWBack(player, player.getLocation());
|
||||
player.teleport(wback);
|
||||
|
||||
Location wback = Database.getWBack(sender);
|
||||
|
||||
if (wback == null) {
|
||||
sender.sendMessage("You have never teleported anywhere with NewSimpleWaypoints.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Database.setWBack(sender, sender.getLocation());
|
||||
sender.teleport(wback);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
package net.benjidial.nswp.commands;
|
||||
|
||||
import net.benjidial.nswp.Database;
|
||||
import net.benjidial.nswp.Waypoint;
|
||||
import net.benjidial.nswp.Plugin;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class WaypointCommand implements TabExecutor {
|
||||
enum CompletionType {
|
||||
None, Waypoint
|
||||
}
|
||||
|
||||
public abstract CompletionType getCompletionType();
|
||||
|
||||
public ArrayList<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("Only players may use waypoints.");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
|
||||
switch (getCompletionType()) {
|
||||
case Waypoint:
|
||||
if (args.length > 1)
|
||||
return new ArrayList<>();
|
||||
try {
|
||||
Database.createWaypointTable(player);
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
for (Waypoint waypoint : Database.searchWaypoints(player, args.length == 0 ? "" : args[0]))
|
||||
results.add(waypoint.name);
|
||||
return results;
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
Plugin.logger.log(Level.SEVERE, "Database error:");
|
||||
ex.printStackTrace();
|
||||
sender.sendMessage("Database error.");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
default:
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean body(Player player, String[] args) throws SQLException;
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String name, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("Only players may use waypoints.");
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
Player player = (Player)sender;
|
||||
Database.createWaypointTable(player);
|
||||
return body(player, args);
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
Plugin.logger.log(Level.SEVERE, "Database error:");
|
||||
ex.printStackTrace();
|
||||
sender.sendMessage("Database error.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,30 +1,37 @@
|
|||
main: net.benjidial.nswp.Plugin
|
||||
name: NewSimpleWaypoints
|
||||
version: 2.1-SNAPSHOT
|
||||
api-version: 1.19
|
||||
version: '2.2-SNAPSHOT'
|
||||
api-version: '1.20'
|
||||
author: benji@benjidial.net
|
||||
|
||||
commands:
|
||||
wlist:
|
||||
description: Lists a user's waypoints
|
||||
usage: /wlist [<query>]
|
||||
permission: nswp.use
|
||||
wsave:
|
||||
description: Saves a waypoint
|
||||
usage: /wsave <name>
|
||||
permission: nswp.use
|
||||
wtp:
|
||||
description: Teleports to a waypoint
|
||||
usage: /wtp <name>
|
||||
permission: nswp.use
|
||||
wtpallow:
|
||||
description: Allows another player to /wtpa to you.
|
||||
usage: /wtpallow <player>
|
||||
permission: nswp.tpa
|
||||
wdel:
|
||||
description: Deletes a waypoint
|
||||
description: Deletes a waypoint.
|
||||
usage: /wdel <name>
|
||||
permission: nswp.use
|
||||
wback:
|
||||
description: Teleports a player to where they were the last time they ran wtp or wback
|
||||
usage: /wback
|
||||
permission: nswp.use
|
||||
wtpdeny:
|
||||
description: Disallows another player from /wtpa'ing to you.
|
||||
usage: /wtpdeny <player>
|
||||
wlist:
|
||||
description: Searches your waypoints for a particular string, or lists them all.
|
||||
usage: /wlist [<string>]
|
||||
wrename:
|
||||
description: Renames a waypoint
|
||||
description: Renames a waypoint.
|
||||
usage: /wrename <old-name> <new-name>
|
||||
permission: nswp.use
|
||||
wsave:
|
||||
description: Saves a waypoint.
|
||||
usage: /wsave <name>
|
||||
wtp:
|
||||
description: Teleports to a waypoint.
|
||||
usage: /wtp <name>
|
||||
permission: nswp.waypoints
|
||||
wtpa:
|
||||
description: Teleports to another player.
|
||||
usage: /wtpa <player>
|
||||
permission: nswp.tpa
|
||||
wback:
|
||||
description: Teleports to where you were the last time you teleported somewhere with NewSimpleWaypoints.
|
||||
usage: /wback
|
||||
|
|
Loading…
Add table
Reference in a new issue