Add messages for spawn tp, command added to change the spawn coordinates.
This commit is contained in:
@@ -6,6 +6,7 @@ import fantasypvp.kand_smp.events.Events;
|
||||
import fantasypvp.kand_smp.items.LightningGear;
|
||||
import fantasypvp.kand_smp.items.TrueNetherite;
|
||||
import fantasypvp.kand_smp.items.Witherite;
|
||||
import me.danthepythonman.spawntp.commands.SetSpawnCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class Kand_smp extends JavaPlugin {
|
||||
@@ -20,7 +21,8 @@ public final class Kand_smp extends JavaPlugin {
|
||||
getServer().getPluginManager().registerEvents(new Events(), this);
|
||||
|
||||
getCommand("lightning_sword").setExecutor(new CmdLightningSword());
|
||||
getCommand("spawn").setExecutor(new CmdTeleportSpawn());
|
||||
getCommand("spawn").setExecutor(new CmdTeleportSpawn(this));
|
||||
getCommand("setSpawnTp").setExecutor(new SetSpawnCommand(this));
|
||||
|
||||
getServer().broadcastMessage("§aKand SMP has been enabled!");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fantasypvp.kand_smp.commands;
|
||||
|
||||
import fantasypvp.kand_smp.items.LightningGear;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -14,8 +15,14 @@ public class CmdLightningSword implements CommandExecutor {
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
if (command.getName().equalsIgnoreCase("lightning_sword")) {
|
||||
player.getInventory().addItem(LightningGear.lightning_sword);
|
||||
|
||||
if(player.hasPermission("lightning_sword")) {
|
||||
if (command.getName().equalsIgnoreCase("lightning_sword")) {
|
||||
player.getInventory().addItem(LightningGear.lightning_sword);
|
||||
}
|
||||
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED+"You don't have permission to run this command.");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,22 +1,89 @@
|
||||
package fantasypvp.kand_smp.commands;
|
||||
|
||||
//Was made by DanThePythonMan
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CmdTeleportSpawn implements CommandExecutor {
|
||||
public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
|
||||
if (command.getName().equalsIgnoreCase("spawn")) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("Only players can use this command");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
Location location = player.getWorld().getSpawnLocation();
|
||||
|
||||
player.teleport(location);
|
||||
return true;
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
|
||||
|
||||
public CmdTeleportSpawn(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
boolean success = false;
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("You must be a player to execute this command!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
player.sendMessage(ChatColor.GREEN + "Sending you to spawn");
|
||||
|
||||
String coordinates = getCoordinates();
|
||||
|
||||
if (coordinates == null) {
|
||||
player.sendMessage(ChatColor.RED + "An error occurred, you will not be teleported.");
|
||||
} else {
|
||||
|
||||
int x, y, z;
|
||||
|
||||
String[] coordsList = coordinates.split(" ");
|
||||
|
||||
x = Integer.parseInt(coordsList[0]);
|
||||
y = Integer.parseInt(coordsList[1]);
|
||||
z = Integer.parseInt(coordsList[2]);
|
||||
|
||||
Location location = new Location(player.getWorld(), x,y,z);
|
||||
|
||||
player.teleport(location);
|
||||
|
||||
success = true;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
private String getCoordinates() {
|
||||
File dataFolder = plugin.getDataFolder();
|
||||
if (!dataFolder.exists()) {
|
||||
dataFolder.mkdirs();
|
||||
}
|
||||
|
||||
try {
|
||||
File file = new File(dataFolder, "spawnCoords.txt");
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FileReader fileReader = new FileReader(file);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
String line = bufferedReader.readLine();
|
||||
bufferedReader.close();
|
||||
|
||||
return line;
|
||||
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("Error occurred while reading spawn coordinates: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package me.danthepythonman.spawntp.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SetSpawnCommand implements CommandExecutor {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public SetSpawnCommand(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("You must be a player to execute this command!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
if(!player.hasPermission("SpawnTP.canSetSpawn")){
|
||||
|
||||
player.sendMessage(ChatColor.RED+"You don't have permission to run this.");
|
||||
|
||||
}else{
|
||||
|
||||
|
||||
String coordinates = getCoordinates(player);
|
||||
|
||||
try {
|
||||
if (SetCoordinates(coordinates)) {
|
||||
player.sendMessage(ChatColor.GREEN + "Spawn Coordinates set!");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(ChatColor.RED + "Unable to set spawn coordinates");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getCoordinates(Player player) {
|
||||
// return (player.getLocation().getX() + " " + player.getLocation().getY() + " " + player.getLocation().getZ());
|
||||
|
||||
String x,y,z;
|
||||
|
||||
x=String.format("%.0f",player.getLocation().getX());
|
||||
y=String.format("%.0f",player.getLocation().getY());
|
||||
z=String.format("%.0f",player.getLocation().getZ());
|
||||
|
||||
return (x +" " + y + " "+ z);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private boolean SetCoordinates(String coordinates) throws IOException {
|
||||
File dataFolder = plugin.getDataFolder();
|
||||
if (!dataFolder.exists()) {
|
||||
dataFolder.mkdirs();
|
||||
}
|
||||
|
||||
File file = new File(dataFolder, "spawnCoords.txt");
|
||||
try (FileWriter fileWriter = new FileWriter(file, false)) {
|
||||
fileWriter.write(coordinates);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("Spawn TP Plugin couldn't save coordinates. Error: " + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,4 +8,14 @@ commands:
|
||||
usage: /lightning_sword
|
||||
spawn:
|
||||
description: Spawn player
|
||||
usage: /spawn
|
||||
usage: /spawn
|
||||
setSpawnTp:
|
||||
description: Sets the world spawn tp point
|
||||
usage: /setSpawnTp
|
||||
permissions:
|
||||
lightning_sword:
|
||||
description: Allows player to run /lightning_sword
|
||||
default: op
|
||||
setSpawnTp:
|
||||
description: allows player to run /setSpawnTp
|
||||
default: op
|
||||
|
||||
Reference in New Issue
Block a user