You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
5.4 KiB
116 lines
5.4 KiB
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); |
|
} |
|
} |
|
|
|
}
|
|
|