diff options
author | ementalo <ementalodev@gmx.co.uk> | 2012-05-28 00:37:28 +0100 |
---|---|---|
committer | ementalo <ementalodev@gmx.co.uk> | 2012-05-28 00:37:28 +0100 |
commit | 373a48da5412c6005f7ad2fe4bec41c68d4eb2a2 (patch) | |
tree | 3ebc11bffcb1dde3f3bd338fca97656d03511e70 /EssentialsSpawn/src | |
parent | 45c1e347b0698318ebd3772c540a9a52b6509daf (diff) | |
parent | b69a16bcf0abac1ebd2ca3d35520cfcb5b433e88 (diff) | |
download | Essentials-373a48da5412c6005f7ad2fe4bec41c68d4eb2a2.tar Essentials-373a48da5412c6005f7ad2fe4bec41c68d4eb2a2.tar.gz Essentials-373a48da5412c6005f7ad2fe4bec41c68d4eb2a2.tar.lz Essentials-373a48da5412c6005f7ad2fe4bec41c68d4eb2a2.tar.xz Essentials-373a48da5412c6005f7ad2fe4bec41c68d4eb2a2.zip |
Master -> 3.0
Diffstat (limited to 'EssentialsSpawn/src')
6 files changed, 0 insertions, 412 deletions
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java deleted file mode 100644 index c6c89a20d..000000000 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.earth2me.essentials.spawn; - -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; -import com.earth2me.essentials.commands.EssentialsCommand; -import org.bukkit.Server; - - -public class Commandsetspawn extends EssentialsCommand -{ - public Commandsetspawn() - { - super("setspawn"); - } - - @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception - { - final String group = args.length > 0 ? getFinalArg(args, 0) : "default"; - ((SpawnStorage)module).setSpawn(user.getLocation(), group); - user.sendMessage(_("spawnSet", group)); - } -} diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java deleted file mode 100644 index 6335d6c69..000000000 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.earth2me.essentials.spawn; - -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; -import com.earth2me.essentials.commands.EssentialsCommand; -import com.earth2me.essentials.commands.NotEnoughArgumentsException; -import org.bukkit.Location; -import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; - - -public class Commandspawn extends EssentialsCommand -{ - public Commandspawn() - { - super("spawn"); - } - - @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception - { - final Trade charge = new Trade(this.getName(), ess); - charge.isAffordableFor(user); - if (args.length > 0 && user.isAuthorized("essentials.spawn.others")) - { - final User otherUser = getPlayer(server, args, 0); - respawn(otherUser, null); - if (!otherUser.equals(user)) - { - otherUser.sendMessage(_("teleportAtoB", user.getDisplayName(), "spawn")); - user.sendMessage(_("teleporting")); - } - } - else - { - respawn(user, null); - } - } - - @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception - { - if (args.length < 1) - { - throw new NotEnoughArgumentsException(); - } - final User user = getPlayer(server, args, 0); - respawn(user, null); - user.sendMessage(_("teleportAtoB", user.getDisplayName(), "spawn")); - sender.sendMessage(_("teleporting")); - } - - private void respawn (final User user, final Trade charge) throws Exception { - final SpawnStorage spawns = (SpawnStorage)this.module; - final Location spawn = spawns.getSpawn(user.getGroup()); - user.getTeleport().teleport(spawn, charge, TeleportCause.COMMAND); - } -} diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java deleted file mode 100644 index f0c5ee466..000000000 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.earth2me.essentials.spawn; - -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.event.Event; -import org.bukkit.event.EventException; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.plugin.EventExecutor; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - - -public class EssentialsSpawn extends JavaPlugin -{ - private static final Logger LOGGER = Bukkit.getLogger(); - private transient IEssentials ess; - private transient SpawnStorage spawns; - - public void onEnable() - { - final PluginManager pluginManager = getServer().getPluginManager(); - ess = (IEssentials)pluginManager.getPlugin("Essentials"); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) - { - LOGGER.log(Level.WARNING, _("versionMismatchAll")); - } - if (!ess.isEnabled()) - { - this.setEnabled(false); - return; - } - - spawns = new SpawnStorage(ess); - ess.addReloadListener(spawns); - - final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess, spawns); - pluginManager.registerEvent(PlayerRespawnEvent.class, playerListener, ess.getSettings().getRespawnPriority(), new EventExecutor() - { - @Override - public void execute(final Listener ll, final Event event) throws EventException - { - ((EssentialsSpawnPlayerListener)ll).onPlayerRespawn((PlayerRespawnEvent)event); - } - }, this); - pluginManager.registerEvent(PlayerJoinEvent.class, playerListener, ess.getSettings().getRespawnPriority(), new EventExecutor() - { - @Override - public void execute(final Listener ll, final Event event) throws EventException - { - ((EssentialsSpawnPlayerListener)ll).onPlayerJoin((PlayerJoinEvent)event); - } - }, this); - } - - public void onDisable() - { - } - - @Override - public boolean onCommand(final CommandSender sender, final Command command, - final String commandLabel, final String[] args) - { - return ess.onCommandEssentials(sender, command, commandLabel, args, EssentialsSpawn.class.getClassLoader(), "com.earth2me.essentials.spawn.Command", "essentials.", spawns); - } -} diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java deleted file mode 100644 index ba71c176f..000000000 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.earth2me.essentials.spawn; - -import com.earth2me.essentials.*; -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.textreader.IText; -import com.earth2me.essentials.textreader.KeywordReplacer; -import com.earth2me.essentials.textreader.SimpleTextPager; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; - - -public class EssentialsSpawnPlayerListener implements Listener -{ - private final transient IEssentials ess; - private final transient SpawnStorage spawns; - private static final Logger LOGGER = Bukkit.getLogger(); - - public EssentialsSpawnPlayerListener(final IEssentials ess, final SpawnStorage spawns) - { - super(); - this.ess = ess; - this.spawns = spawns; - } - - public void onPlayerRespawn(final PlayerRespawnEvent event) - { - final User user = ess.getUser(event.getPlayer()); - - if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty()) - { - return; - } - - if (ess.getSettings().getRespawnAtHome()) - { - Location home; - final Location bed = user.getBedSpawnLocation(); - if (bed != null && bed.getBlock().getType() == Material.BED_BLOCK) - { - home = bed; - } - else - { - home = user.getHome(user.getLocation()); - } - if (home != null) - { - event.setRespawnLocation(home); - return; - } - } - final Location spawn = spawns.getSpawn(user.getGroup()); - if (spawn != null) - { - event.setRespawnLocation(spawn); - } - } - - public void onPlayerJoin(final PlayerJoinEvent event) - { - if (event.getPlayer().hasPlayedBefore()) - { - LOGGER.log(Level.FINE, "Old player join"); - return; - } - - final User user = ess.getUser(event.getPlayer()); - - if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn())) - { - ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L); - } - - if (ess.getSettings().getAnnounceNewPlayers()) - { - final IText output = new KeywordReplacer(ess.getSettings().getAnnounceNewPlayerFormat(), user, ess); - final SimpleTextPager pager = new SimpleTextPager(output); - ess.broadcastMessage(user, pager.getString(0)); - } - - final String kitName = ess.getSettings().getNewPlayerKit(); - if (!kitName.isEmpty()) - { - try - { - final Map<String, Object> kit = ess.getSettings().getKit(kitName.toLowerCase(Locale.ENGLISH)); - final List<String> items = Kit.getItems(user, kit); - Kit.expandItems(ess, user, items); - } - catch (Exception ex) - { - LOGGER.log(Level.WARNING, ex.getMessage()); - } - } - - LOGGER.log(Level.FINE, "New player join"); - } - - - private class NewPlayerTeleport implements Runnable - { - private final transient User user; - - public NewPlayerTeleport(final User user) - { - this.user = user; - } - - @Override - public void run() - { - if (user.getBase() instanceof OfflinePlayer) - { - return; - } - - try - { - final Location spawn = spawns.getSpawn(ess.getSettings().getNewbieSpawn()); - if (spawn != null) - { - user.getTeleport().now(spawn, false, TeleportCause.PLUGIN); - } - } - catch (Exception ex) - { - Bukkit.getLogger().log(Level.WARNING, _("teleportNewPlayerError"), ex); - } - } - } -} diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java deleted file mode 100644 index 9075d0b69..000000000 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.earth2me.essentials.spawn; - -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.IEssentialsModule; -import com.earth2me.essentials.settings.Spawns; -import com.earth2me.essentials.storage.AsyncStorageObjectHolder; -import java.io.File; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import org.bukkit.Location; -import org.bukkit.World; - - -public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule -{ - public SpawnStorage(final IEssentials ess) - { - super(ess, Spawns.class); - reloadConfig(); - } - - @Override - public File getStorageFile() - { - return new File(ess.getDataFolder(), "spawn.yml"); - } - - @Override - public void finishRead() - { - } - - @Override - public void finishWrite() - { - } - - public void setSpawn(final Location loc, final String group) - { - acquireWriteLock(); - try - { - if (getData().getSpawns() == null) - { - getData().setSpawns(new HashMap<String, Location>()); - } - getData().getSpawns().put(group.toLowerCase(Locale.ENGLISH), loc); - } - finally - { - unlock(); - } - - if ("default".equalsIgnoreCase(group)) - { - loc.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - } - } - - public Location getSpawn(final String group) - { - acquireReadLock(); - try - { - if (getData().getSpawns() == null || group == null) - { - return getWorldSpawn(); - } - final Map<String, Location> spawnMap = getData().getSpawns(); - String groupName = group.toLowerCase(Locale.ENGLISH); - if (!spawnMap.containsKey(groupName)) - { - groupName = "default"; - } - if (!spawnMap.containsKey(groupName)) - { - return getWorldSpawn(); - } - return spawnMap.get(groupName); - } - finally - { - unlock(); - } - } - - private Location getWorldSpawn() - { - for (World world : ess.getServer().getWorlds()) - { - if (world.getEnvironment() != World.Environment.NORMAL) - { - continue; - } - return world.getSpawnLocation(); - } - return ess.getServer().getWorlds().get(0).getSpawnLocation(); - } -} diff --git a/EssentialsSpawn/src/plugin.yml b/EssentialsSpawn/src/plugin.yml deleted file mode 100644 index 2c9fca434..000000000 --- a/EssentialsSpawn/src/plugin.yml +++ /dev/null @@ -1,16 +0,0 @@ -# This determines the command prefix when there are conflicts (/name:home, /name:help, etc.) -name: EssentialsSpawn -main: com.earth2me.essentials.spawn.EssentialsSpawn -# Note to developers: This next line cannot change, or the automatic versioning system will break. -version: TeamCity -website: http://tiny.cc/EssentialsCommands -description: Provides spawn control commands, utilizing Essentials. -authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits] -depend: [Essentials] -commands: - setspawn: - description: Set the spawnpoint to your current position. - usage: /<command> <group> - spawn: - description: Teleport to the spawnpoint. - usage: /<command> [player]
\ No newline at end of file |