From 2074d8152aec2cd6d0e2d8517f5da05529d412f4 Mon Sep 17 00:00:00 2001 From: artem Date: Tue, 29 May 2018 15:29:40 +0300 Subject: [PATCH] init --- plugin.yml | 26 +++++++++ setspawn/SetSpawn.java | 116 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 plugin.yml create mode 100644 setspawn/SetSpawn.java diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..0c7abce --- /dev/null +++ b/plugin.yml @@ -0,0 +1,26 @@ +name: SetSpawn +version: 3.0.2 +main: setspawn.SetSpawn +description: Set the spawn! + +commands: + setspawn: + usage: / + description: Set the spawn! + spawn: + usage: / + description: Go to the spawn! + ssreload: + usage: / + 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 \ No newline at end of file diff --git a/setspawn/SetSpawn.java b/setspawn/SetSpawn.java new file mode 100644 index 0000000..9d76a08 --- /dev/null +++ b/setspawn/SetSpawn.java @@ -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); + } + } + +}