commit
2074d8152a
2 changed files with 142 additions and 0 deletions
@ -0,0 +1,26 @@
|
||||
name: SetSpawn |
||||
version: 3.0.2 |
||||
main: setspawn.SetSpawn |
||||
description: Set the spawn! |
||||
|
||||
commands: |
||||
setspawn: |
||||
usage: /<command> |
||||
description: Set the spawn! |
||||
spawn: |
||||
usage: /<command> |
||||
description: Go to the spawn! |
||||
ssreload: |
||||
usage: /<command> |
||||
description: Reload the config! |
||||
|
||||
permissions: |
||||
spawn.set: |
||||
description: Use the setspawn command. |
||||
default: op |
||||
spawn.reload: |
||||
description: Use the ssreload command. |
||||
default: op |
||||
spawn.spawn: |
||||
description: Use the spawn command. |
||||
default: op |
@ -0,0 +1,116 @@
|
||||
package setspawn; |
||||
|
||||
import org.bukkit.Bukkit; |
||||
import org.bukkit.ChatColor; |
||||
import org.bukkit.Effect; |
||||
import org.bukkit.Location; |
||||
import org.bukkit.World; |
||||
import org.bukkit.command.Command; |
||||
import org.bukkit.command.CommandSender; |
||||
import org.bukkit.entity.Player; |
||||
import org.bukkit.event.EventHandler; |
||||
import org.bukkit.event.Listener; |
||||
import org.bukkit.event.player.PlayerJoinEvent; |
||||
import org.bukkit.plugin.java.JavaPlugin; |
||||
import org.bukkit.scheduler.BukkitRunnable; |
||||
|
||||
public class SetSpawn extends JavaPlugin implements Listener { |
||||
|
||||
private String notPerm = ChatColor.RED + "У вас нет прав на использование команды!"; |
||||
|
||||
public void onEnable() { |
||||
Bukkit.getPluginManager().registerEvents(this, this); |
||||
getLogger().info("Spawn has been enabled!"); |
||||
getConfig().addDefault("Spawn-Message", "&0[&fСпавн&0]&r: &2Вы на спавне!"); |
||||
getConfig().addDefault("Set-Spawn-Message", "&0[&fСпавн&0]&r: &eВы установили спавн!"); |
||||
getConfig().addDefault("No-Spawn-Message", "&0[&fСпавн&0]&r: &cСпавн не установлен!"); |
||||
getConfig().addDefault("Reload-Message", "&0[&fСпавн&0]&r: &2Настройки перезагружены!"); |
||||
getConfig().addDefault("Spawn-Effect", true); |
||||
getConfig().addDefault("On-Join-Spawn", true); |
||||
getConfig().addDefault("On-First-Spawn", true); |
||||
getConfig().addDefault("Cooldown", 5); |
||||
getConfig().options().copyDefaults(true); |
||||
saveConfig(); |
||||
} |
||||
|
||||
public void onDisable() { |
||||
getLogger().info("Spawn has been disabled!"); |
||||
} |
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { |
||||
final Player p = (Player) sender; |
||||
if (!sender.hasPermission("spawn.spawn")) { |
||||
sender.sendMessage(notPerm); |
||||
return true; |
||||
} |
||||
if (cmd.getName().equalsIgnoreCase("spawn")) { |
||||
if (getConfig().getConfigurationSection("spawn") == null) { |
||||
p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("No-Spawn-Message"))); |
||||
return true; |
||||
} |
||||
World w = Bukkit.getServer().getWorld(getConfig().getString("spawn.world")); |
||||
double x = getConfig().getDouble("spawn.x"); |
||||
double y = getConfig().getDouble("spawn.y"); |
||||
double z = getConfig().getDouble("spawn.z"); |
||||
float yaw = (float) getConfig().getDouble("spawn.yaw"); |
||||
float pitch = (float) getConfig().getDouble("spawn.pitch"); |
||||
final Location loc = new Location(w, x, y, z, yaw, pitch); |
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { |
||||
public void run() { |
||||
p.teleport(loc); |
||||
p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Spawn-Message"))); |
||||
if (getConfig().getBoolean("Spawn-Effect")) { |
||||
p.getWorld().playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 0); |
||||
p.getWorld().playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 0); |
||||
p.getWorld().playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 0); |
||||
p.getWorld().playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 0); |
||||
} |
||||
} |
||||
}, 20 * getConfig().getInt("Cooldown")); |
||||
return true; |
||||
} |
||||
if (!sender.hasPermission("spawn.set")) { |
||||
sender.sendMessage(notPerm); |
||||
return true; |
||||
} |
||||
if (cmd.getName().equalsIgnoreCase("setspawn")) { |
||||
getConfig().set("spawn.world", p.getLocation().getWorld().getName()); |
||||
getConfig().set("spawn.x", p.getLocation().getX()); |
||||
getConfig().set("spawn.y", p.getLocation().getY()); |
||||
getConfig().set("spawn.z", p.getLocation().getZ()); |
||||
getConfig().set("spawn.yaw", p.getLocation().getYaw()); |
||||
getConfig().set("spawn.pitch", p.getLocation().getPitch()); |
||||
saveConfig(); |
||||
p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Set-Spawn-Message"))); |
||||
return true; |
||||
} |
||||
if (!sender.hasPermission("spawn.reload")) { |
||||
sender.sendMessage(notPerm); |
||||
} |
||||
if (cmd.getName().equalsIgnoreCase("ssreload")) { |
||||
reloadConfig(); |
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Reload-Message"))); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
@EventHandler |
||||
public void onJoin(PlayerJoinEvent e) { |
||||
final Player p = e.getPlayer(); |
||||
if (getConfig().getBoolean("On-Join-Spawn") || (getConfig().getBoolean("On-First-Spawn") && !e.getPlayer().hasPlayedBefore())) { |
||||
new BukkitRunnable() { |
||||
public void run() { |
||||
World w = Bukkit.getServer().getWorld(getConfig().getString("spawn.world")); |
||||
double x = getConfig().getDouble("spawn.x"); |
||||
double y = getConfig().getDouble("spawn.y"); |
||||
double z = getConfig().getDouble("spawn.z"); |
||||
float yaw = (float) getConfig().getDouble("spawn.yaw"); |
||||
float pitch = (float) getConfig().getDouble("spawn.pitch"); |
||||
p.teleport(new Location(w, x, y, z, yaw, pitch)); |
||||
} |
||||
}.runTaskLater(this, 20L); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue