Add -sp/-spawnpoint parameter to set a player's spawnpoint after teleporting.

Also reworked the message system.
This commit is contained in:
Max Lee 2015-07-08 00:29:37 +02:00
parent 8417304ea7
commit 023dd8d8b7
3 changed files with 38 additions and 28 deletions

View File

@ -1,5 +1,6 @@
package de.themoep.bukkit.plugin.RandomTeleport; package de.themoep.bukkit.plugin.RandomTeleport;
import com.google.common.collect.ImmutableMap;
import de.themoep.bukkit.plugin.RandomTeleport.Listeners.SignListener; import de.themoep.bukkit.plugin.RandomTeleport.Listeners.SignListener;
import de.themoep.clancontrol.ClanControl; import de.themoep.clancontrol.ClanControl;
import de.themoep.clancontrol.Region; import de.themoep.clancontrol.Region;
@ -36,11 +37,6 @@ public class RandomTeleport extends JavaPlugin implements CommandExecutor {
public HashSet<UUID> playerlock = new HashSet<UUID> (); public HashSet<UUID> playerlock = new HashSet<UUID> ();
public int[] checkstat = new int[100]; public int[] checkstat = new int[100];
public String textsearch = ChatColor.GRAY + "RandomTeleport searches for a safe place in world {worldname}. . .";
public String textteleport = ChatColor.GRAY + "RandomTeleport teleported you to"; // + " X: " + xTp + " Y: " + yTp + " Z: " + zTp + "!"
public String textlocationerror = ChatColor.DARK_RED + "Error:" + ChatColor.RED + " RandomTeleport could not find a save location!";
public String textcooldownerror = ChatColor.RED + "You have to wait {cooldown_text}before using this RandomTeleport again!";
public int factionsApiVersion = 0; public int factionsApiVersion = 0;
public boolean worldguard = false; public boolean worldguard = false;
public boolean clancontrol = false; public boolean clancontrol = false;
@ -53,8 +49,6 @@ public class RandomTeleport extends JavaPlugin implements CommandExecutor {
saveDefaultConfig(); saveDefaultConfig();
loadMessages();
getLogger().log(Level.INFO, "Attempting to load cooldown.map..."); getLogger().log(Level.INFO, "Attempting to load cooldown.map...");
cooldown = (HashMap<String, Long>) readMap("cooldown.map"); cooldown = (HashMap<String, Long>) readMap("cooldown.map");
@ -84,19 +78,12 @@ public class RandomTeleport extends JavaPlugin implements CommandExecutor {
} }
public void loadMessages() {
getLogger().log(Level.INFO, "Loading messages from config.");
textsearch = ChatColor.translateAlternateColorCodes("&".charAt(0), this.getConfig().getString("msg.search"));
textteleport = ChatColor.translateAlternateColorCodes("&".charAt(0), this.getConfig().getString("msg.teleport"));
textlocationerror = ChatColor.translateAlternateColorCodes("&".charAt(0), this.getConfig().getString("msg.error.location"));
textcooldownerror = ChatColor.translateAlternateColorCodes("&".charAt(0), this.getConfig().getString("msg.error.cooldown"));
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) throws NumberFormatException { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) throws NumberFormatException {
if(cmd.getName().equalsIgnoreCase("randomteleport") || cmd.getName().equalsIgnoreCase("randomtp") || cmd.getName().equalsIgnoreCase("rtp")) { if(cmd.getName().equalsIgnoreCase("randomteleport") || cmd.getName().equalsIgnoreCase("randomtp") || cmd.getName().equalsIgnoreCase("rtp")) {
boolean forceBlocks = false; boolean forceBlocks = false;
boolean forceRegions = false; boolean forceRegions = false;
boolean loadedChunksOnly = false; boolean loadedChunksOnly = false;
boolean setSpawnpoint = false;
//boolean tppoints = false; //boolean tppoints = false;
boolean xoption = false; boolean xoption = false;
@ -138,7 +125,6 @@ public class RandomTeleport extends JavaPlugin implements CommandExecutor {
if(args.length == 1 && args[0].equalsIgnoreCase("reload") && sender.hasPermission("randomteleport.reload")) { if(args.length == 1 && args[0].equalsIgnoreCase("reload") && sender.hasPermission("randomteleport.reload")) {
reloadConfig(); reloadConfig();
loadMessages();
sender.sendMessage(ChatColor.GREEN + "Config reloaded!"); sender.sendMessage(ChatColor.GREEN + "Config reloaded!");
return true; return true;
} }
@ -293,6 +279,10 @@ public class RandomTeleport extends JavaPlugin implements CommandExecutor {
else if(args[i+1].equalsIgnoreCase("regions")) else if(args[i+1].equalsIgnoreCase("regions"))
forceRegions = true; forceRegions = true;
} }
} else if(args[i].equalsIgnoreCase("-sp") || args[i].equalsIgnoreCase("-spawnpoint")) {
if(i+1 >= args.length || args[i+1].startsWith("-")) {
setSpawnpoint = true;
}
} else { } else {
sender.sendMessage(ChatColor.DARK_RED + "Error:" + ChatColor.RED + " Your input contains a invalid option (" + args[i] + ")!"); sender.sendMessage(ChatColor.DARK_RED + "Error:" + ChatColor.RED + " Your input contains a invalid option (" + args[i] + ")!");
return false; return false;
@ -376,12 +366,12 @@ public class RandomTeleport extends JavaPlugin implements CommandExecutor {
if(playername.equalsIgnoreCase("CONSOLE")) { if(playername.equalsIgnoreCase("CONSOLE")) {
sender.sendMessage(ChatColor.DARK_RED + "Error:" + ChatColor.RED + " This teleport is on cooldown for player " + player.getName() + "!"); sender.sendMessage(ChatColor.DARK_RED + "Error:" + ChatColor.RED + " This teleport is on cooldown for player " + player.getName() + "!");
} }
player.sendMessage(textcooldownerror.replaceAll("\\{cooldown_text\\}", cooldown_text)); player.sendMessage(getTranslation("error.cooldown", ImmutableMap.of("cooldown_text", cooldown_text)));
playerlock.remove(player.getUniqueId()); playerlock.remove(player.getUniqueId());
return true; return true;
} }
player.sendMessage(textsearch.replaceAll("\\{worldname\\}", world.getName())); player.sendMessage(getTranslation("search", ImmutableMap.of("worldname", world.getName())));
// set center coordinates to player location // set center coordinates to player location
if(!xoption) { if(!xoption) {
@ -433,7 +423,7 @@ public class RandomTeleport extends JavaPlugin implements CommandExecutor {
if(count == 100) { if(count == 100) {
sender.sendMessage(ChatColor.DARK_RED + "Error:" + ChatColor.RED + " RandomTeleport could not find a save location!"); sender.sendMessage(ChatColor.DARK_RED + "Error:" + ChatColor.RED + " RandomTeleport could not find a save location!");
if(!sender.getName().equalsIgnoreCase(player.getName())){ if(!sender.getName().equalsIgnoreCase(player.getName())){
player.sendMessage(textlocationerror); player.sendMessage(getTranslation("error.location"));
} }
getLogger().info("Error: RandomTeleport could not find a save location after " + count + " tries for the player '" + playername + "' (minRange " + minRange + " maxRange " + maxRange + " xCenter " + xCenter + " zCenter " + zCenter + " forceBlocks=" + forceBlocks + " forceRegions=" + forceRegions + ")"); getLogger().info("Error: RandomTeleport could not find a save location after " + count + " tries for the player '" + playername + "' (minRange " + minRange + " maxRange " + maxRange + " xCenter " + xCenter + " zCenter " + zCenter + " forceBlocks=" + forceBlocks + " forceRegions=" + forceRegions + ")");
checkstat[count-1] = checkstat[count-1]++; checkstat[count-1] = checkstat[count-1]++;
@ -493,7 +483,7 @@ public class RandomTeleport extends JavaPlugin implements CommandExecutor {
z = zold; z = zold;
// attempts to teleport player, sends message if it fails // attempts to teleport player, sends message if it fails
if(!teleportPlayer(playername,x,z,world)) { if(!teleportPlayer(playername,x,z,world,setSpawnpoint)) {
sender.sendMessage(ChatColor.DARK_RED + "Error:" + ChatColor.RED + " Player '" + playername + "' is not online anymore!"); sender.sendMessage(ChatColor.DARK_RED + "Error:" + ChatColor.RED + " Player '" + playername + "' is not online anymore!");
} else { } else {
getLogger().fine("Used teleport location X: " + x + " Z: " + z + " for player '" + playername + "' RandomTeleportID: " + cooldownid); getLogger().fine("Used teleport location X: " + x + " Z: " + z + " for player '" + playername + "' RandomTeleportID: " + cooldownid);
@ -514,16 +504,21 @@ public class RandomTeleport extends JavaPlugin implements CommandExecutor {
* @param x Coordinate of the block as int * @param x Coordinate of the block as int
* @param z Coordinate of the block as int * @param z Coordinate of the block as int
* @param world The world we should teleport the player to * @param world The world we should teleport the player to
* @param setSpawnpoint if we should set the player's spawnpoint to the location or not
* @return true if player got teleported * @return true if player got teleported
*/ */
private boolean teleportPlayer(String playername, int x ,int z, World world) { private boolean teleportPlayer(String playername, int x ,int z, World world, boolean setSpawnpoint) {
final Player player = Bukkit.getServer().getPlayer(playername); final Player player = Bukkit.getServer().getPlayer(playername);
if(player != null && world != null) { if(player != null && world != null) {
final int yTp = world.getHighestBlockYAt(x, z); final int yTp = world.getHighestBlockYAt(x, z);
Location loc = new Location(world, x + 0.5, yTp + 0.5, z + 0.5);
player.teleport(new Location(world, x + 0.5, yTp + 0.5, z + 0.5)); player.teleport(loc);
player.sendMessage(textteleport + " X: " + x + " Y: " + yTp + " Z: " + z + "!"); player.sendMessage(getTranslation("teleport", ImmutableMap.of("x", Integer.toString(x), "y", Integer.toString(yTp), "z", Integer.toString(z))));
if(setSpawnpoint) {
player.setBedSpawnLocation(loc, true);
player.sendMessage(getTranslation("setspawnpoint"));
}
return true; return true;
} }
return false; return false;
@ -689,8 +684,22 @@ public class RandomTeleport extends JavaPlugin implements CommandExecutor {
return true; return true;
} }
public static RandomTeleport getInstance() { public String getTranslation(String key) {
return instance; if(getConfig().getString("msg." + key, "").isEmpty()) {
return ChatColor.RED + "Unknown language key: " + ChatColor.YELLOW + key;
} else {
return ChatColor.translateAlternateColorCodes('&', getConfig().getString("msg." + key));
}
}
public String getTranslation(String key, Map<String, String> replacements) {
String string = getTranslation(key);
// insert replacements
if(replacements != null)
for(String variable : replacements.keySet())
string = string.replaceAll("{"+variable+"}", replacements.get(variable));
return string;
} }
} }

View File

@ -9,7 +9,8 @@ presets:
msg: msg:
search: "&7RandomTeleport searches for a safe place in world {worldname}. . ." search: "&7RandomTeleport searches for a safe place in world {worldname}. . ."
teleport: "&7RandomTeleport teleported you to" teleport: "&7RandomTeleport teleported you to X: {x} Y: {y} Z: {z}!"
setspawnpoint: "&7Dein Respawnpoint wurde an deine Position gesetzt!"
error: error:
location: "&4Error: &cRandomTeleport could not find a save location!" location: "&4Error: &cRandomTeleport could not find a save location!"
cooldown: "&cYou have to wait {cooldown_text}before using this RandomTeleport again!" cooldown: "&cYou have to wait {cooldown_text}before using this RandomTeleport again!"

View File

@ -1,7 +1,7 @@
name: RandomTeleport name: RandomTeleport
main: de.themoep.bukkit.plugin.RandomTeleport.RandomTeleport main: de.themoep.bukkit.plugin.RandomTeleport.RandomTeleport
softdepend: [WorldGuard,Factions] softdepend: [WorldGuard,Factions]
version: 1.7.0 version: 1.7.2
description: provides a command to teleport the player to a random save location description: provides a command to teleport the player to a random save location
author: Phoenix616 author: Phoenix616
website: http://dev.bukkit.org/bukkit-plugins/randomteleport/ website: http://dev.bukkit.org/bukkit-plugins/randomteleport/