From 4244566e594bbeab15e251d419fd7140d5966656 Mon Sep 17 00:00:00 2001 From: "Gabriele C." Date: Thu, 9 Jul 2015 10:54:13 +0200 Subject: [PATCH 1/6] Should speed up the compilation --- pom.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index fcccfad1..a6bacb27 100644 --- a/pom.xml +++ b/pom.xml @@ -24,10 +24,10 @@ 1.8.7-R0.1-SNAPSHOT - + jenkins - http://ci.xephi.fr + http://ci.xephi.fr/job/AuthMeReloaded/ @@ -116,16 +116,16 @@ spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ + https://hub.spigotmc.org/nexus/content/repositories/snapshots Plugin Metrics - http://repo.mcstats.org/content/repositories/public + http://repo.mcstats.org/content/repositories/releases - + vault-repo http://nexus.theyeticave.net/content/repositories/pub_releases @@ -152,19 +152,19 @@ luricos-releases - http://repo.luricos.de/content/repositories/releases/ + http://repo.luricos.de/content/repositories/bukkit-plugins comphenix-snapshots - http://repo.comphenix.net/content/repositories/snapshots/ + http://repo.comphenix.net/content/repositories/snapshots onarandombox - http://repo.onarandombox.com/content/groups/public + http://repo.onarandombox.com/content/repositories/multiverse From 4bcf457a5962c1dd42c81342a7bffd6c1d62568c Mon Sep 17 00:00:00 2001 From: "Gabriele C." Date: Thu, 9 Jul 2015 11:09:16 +0200 Subject: [PATCH 2/6] Update circle.yml --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 85064c5c..157f6ff5 100644 --- a/circle.yml +++ b/circle.yml @@ -3,7 +3,7 @@ machine: version: oraclejdk7 general: artifacts: - - "target/*.jar" + - "target/AuthMe-*.jar" test: override: - mvn clean install From 7a4550246fb0d345b85534809f21d248140bd5b3 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 9 Jul 2015 18:04:43 +0200 Subject: [PATCH 3/6] Fix Fly and GameMode --- src/main/java/fr/xephi/authme/AuthMe.java | 2 +- src/main/java/fr/xephi/authme/api/API.java | 14 +----- .../xephi/authme/cache/limbo/LimboCache.java | 5 +- .../authme/listener/AuthMeEntityListener.java | 48 +++++++++---------- .../authme/listener/AuthMePlayerListener.java | 24 +++++----- .../plugin/manager/CitizensCommunicator.java | 2 +- .../authme/process/join/AsyncronousJoin.java | 4 +- .../login/ProcessSyncronousPlayerLogin.java | 15 ++++-- .../logout/ProcessSyncronousPlayerLogout.java | 6 ++- .../authme/process/quit/AsyncronousQuit.java | 2 +- 10 files changed, 59 insertions(+), 63 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index c1b99337..4a097b93 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -460,7 +460,7 @@ public class AuthMe extends JavaPlugin { public void savePlayer(Player player) throws IllegalStateException, NullPointerException { try { - if ((citizens.isNPC(player, this)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) { + if ((citizens.isNPC(player)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) { return; } } catch (Exception e) { diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 1117dbdf..c60de121 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -67,25 +67,13 @@ public class API { return PlayerCache.getInstance().isAuthenticated(player.getName()); } - /** - * - * @param player - * @return true if player is a npc - */ - @Deprecated - public boolean isaNPC(Player player) { - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) - return true; - return CombatTagComunicator.isNPC(player); - } - /** * * @param player * @return true if player is a npc */ public boolean isNPC(Player player) { - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return true; return CombatTagComunicator.isNPC(player); } diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java index c09c27b3..a67a3d1c 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java @@ -39,7 +39,7 @@ public class LimboCache { boolean flying = false; if (playerData.doesCacheExist(player)) { - StoreInventoryEvent event = new StoreInventoryEvent(player, playerData); + final StoreInventoryEvent event = new StoreInventoryEvent(player, playerData); Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) { inv = event.getInventory(); @@ -90,6 +90,9 @@ public class LimboCache { player.sendMessage("Your inventory has been cleaned!"); } } + if (gameMode == GameMode.CREATIVE) { + flying = false; + } gameMode = GameMode.SURVIVAL; } if (player.isDead()) { diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java index 52829e7a..56b637e9 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java @@ -5,8 +5,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityTargetEvent; @@ -29,7 +29,7 @@ public class AuthMeEntityListener implements Listener { this.instance = instance; } - @EventHandler (priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOWEST) public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) { return; @@ -44,7 +44,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(entity, instance)) + if (instance.citizens.isNPC(entity)) return; Player player = (Player) entity; @@ -67,7 +67,7 @@ public class AuthMeEntityListener implements Listener { event.setCancelled(true); } - @EventHandler (priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOWEST) public void onEntityTarget(EntityTargetEvent event) { if (event.isCancelled()) { return; @@ -79,7 +79,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(entity, instance)) + if (instance.citizens.isNPC(entity)) return; Player player = (Player) entity; @@ -97,22 +97,22 @@ public class AuthMeEntityListener implements Listener { event.setTarget(null); event.setCancelled(true); } - + @EventHandler(priority = EventPriority.LOWEST) - public void onDmg(EntityDamageByEntityEvent event) { - if (event.isCancelled()) { + public void onDmg(EntityDamageByEntityEvent event) { + if (event.isCancelled()) { return; } - - Entity entity = event.getDamager(); - - if (entity == null || !(entity instanceof Player)) { + + Entity entity = event.getDamager(); + + if (entity == null || !(entity instanceof Player)) { return; } - - Player player = (Player) entity; - String name = player.getName().toLowerCase(); - + + Player player = (Player) entity; + String name = player.getName().toLowerCase(); + if (PlayerCache.getInstance().isAuthenticated(name)) { return; } @@ -122,11 +122,11 @@ public class AuthMeEntityListener implements Listener { return; } } - - event.setCancelled(true); - } - @EventHandler (priority = EventPriority.LOWEST) + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.LOWEST) public void onFoodLevelChange(FoodLevelChangeEvent event) { if (event.isCancelled()) { return; @@ -137,7 +137,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(entity, instance)) + if (instance.citizens.isNPC(entity)) return; Player player = (Player) entity; @@ -168,7 +168,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(entity, instance)) + if (instance.citizens.isNPC(entity)) return; Player player = (Player) entity; @@ -205,7 +205,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(player, instance)) + if (instance.citizens.isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName())) { @@ -237,7 +237,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(player, instance)) + if (instance.citizens.isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName())) { diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 21885897..cda89dc5 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -50,7 +50,6 @@ import fr.xephi.authme.settings.Settings; public class AuthMePlayerListener implements Listener { - public static GameMode gm = GameMode.SURVIVAL; public static ConcurrentHashMap gameMode = new ConcurrentHashMap(); public static ConcurrentHashMap joinMessage = new ConcurrentHashMap(); private Messages m = Messages.getInstance(); @@ -328,7 +327,7 @@ public class AuthMePlayerListener implements Listener { Player player = event.getPlayer(); String name = player.getName().toLowerCase(); - if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { + if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } @@ -407,7 +406,7 @@ public class AuthMePlayerListener implements Listener { final String name = player.getName().toLowerCase(); boolean isAuthAvailable = data.isAuthAvailable(name); - if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { + if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } @@ -616,7 +615,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(name)) { @@ -644,7 +643,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { @@ -673,7 +672,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { @@ -702,7 +701,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { @@ -727,7 +726,7 @@ public class AuthMePlayerListener implements Listener { Player player = event.getPlayer(); String name = player.getName().toLowerCase(); - if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { + if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } @@ -755,7 +754,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { @@ -827,7 +826,7 @@ public class AuthMePlayerListener implements Listener { if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) return; - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(name)) @@ -855,8 +854,6 @@ public class AuthMePlayerListener implements Listener { return; if (event.getPlayer() == null || event == null) return; - if (!Settings.isForceSurvivalModeEnabled) - return; Player player = event.getPlayer(); @@ -868,7 +865,7 @@ public class AuthMePlayerListener implements Listener { if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) return; - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(name)) @@ -880,6 +877,7 @@ public class AuthMePlayerListener implements Listener { if (causeByAuthMe.containsKey(name) && causeByAuthMe.get(name)) return; + event.setCancelled(true); } } diff --git a/src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java b/src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java index b9331435..d09a5fcd 100644 --- a/src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java +++ b/src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java @@ -13,7 +13,7 @@ public class CitizensCommunicator { this.instance = instance; } - public boolean isNPC(final Entity player, AuthMe instance) { + public boolean isNPC(final Entity player) { if (!this.instance.isCitizensActive) return false; try { diff --git a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java index 78fd0f8d..d1375404 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java @@ -53,7 +53,7 @@ public class AsyncronousJoin { AuthMePlayerListener.gameMode.put(name, player.getGameMode()); BukkitScheduler sched = plugin.getServer().getScheduler(); - if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { + if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } @@ -216,7 +216,7 @@ public class AsyncronousJoin { public void run() { if (player.isOp()) player.setOp(false); - if (!Settings.isMovementAllowed) { + if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { player.setAllowFlight(true); player.setFlying(true); } diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java index eaee58ee..276a8c23 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java @@ -10,7 +10,6 @@ import org.bukkit.potion.PotionEffectType; import fr.xephi.authme.AuthMe; import fr.xephi.authme.Utils; import fr.xephi.authme.Utils.groupType; -import fr.xephi.authme.api.API; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.backup.FileCache; import fr.xephi.authme.cache.limbo.LimboCache; @@ -53,8 +52,13 @@ public class ProcessSyncronousPlayerLogin implements Runnable { protected void restoreOpState() { player.setOp(limbo.getOperator()); if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { - player.setAllowFlight(limbo.isFlying()); - player.setFlying(limbo.isFlying()); + if (limbo.getGameMode() != GameMode.CREATIVE) { + player.setAllowFlight(limbo.isFlying()); + player.setFlying(limbo.isFlying()); + } else { + player.setAllowFlight(false); + player.setFlying(false); + } } } @@ -120,8 +124,8 @@ public class ProcessSyncronousPlayerLogin implements Runnable { * ProtectInventoryEvent after Teleporting Also it's the current * world inventory ! */ + player.setGameMode(limbo.getGameMode()); if (!Settings.forceOnlyAfterLogin) { - player.setGameMode(limbo.getGameMode()); // Inventory - Make it after restore GameMode , cause we need to // restore the // right inventory in the right gamemode @@ -146,7 +150,8 @@ public class ProcessSyncronousPlayerLogin implements Runnable { } else { teleportBackFromSpawn(); } - } else if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { + } else + if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { teleportToSpawn(); } else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) { packQuitLocation(); diff --git a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java index 1a0ddab6..29077488 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java @@ -51,8 +51,10 @@ public class ProcessSyncronousPlayerLogout implements Runnable { if (Settings.applyBlindEffect) player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); player.setOp(false); - player.setAllowFlight(true); - player.setFlying(true); + if (!Settings.isMovementAllowed) { + player.setAllowFlight(true); + player.setFlying(true); + } // Player is now logout... Time to fire event ! sched.scheduleSyncDelayedTask(plugin, new Runnable() { diff --git a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java index 5e34fd00..6394cac8 100644 --- a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java @@ -45,7 +45,7 @@ public class AsyncronousQuit { public void process() { final Player player = p; - if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { + if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } From e904038f4ef1d45ce515d6ff984f562bae493d99 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 9 Jul 2015 18:56:47 +0200 Subject: [PATCH 4/6] Change how first spawn work --- src/main/java/fr/xephi/authme/AuthMe.java | 10 ++--- .../events/FirstSpawnTeleportEvent.java | 40 +++++++++++++++++++ .../authme/process/join/AsyncronousJoin.java | 35 ++++++++++++++-- 3 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/events/FirstSpawnTeleportEvent.java diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 4a097b93..f11b5105 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -566,8 +566,8 @@ public class AuthMe extends JavaPlugin { Location spawnLoc = world.getSpawnLocation(); for (int i = spawnPriority.length - 1; i >= 0; i--) { String s = spawnPriority[i]; - if (s.equalsIgnoreCase("default") && getDefaultSpawn(world) != null) - spawnLoc = getDefaultSpawn(world); + if (s.equalsIgnoreCase("default") && getDefaultSpawn() != null) + spawnLoc = getDefaultSpawn(); if (s.equalsIgnoreCase("multiverse") && getMultiverseSpawn(world) != null) spawnLoc = getMultiverseSpawn(world); if (s.equalsIgnoreCase("essentials") && getEssentialsSpawn() != null) @@ -580,8 +580,8 @@ public class AuthMe extends JavaPlugin { return spawnLoc; } - private Location getDefaultSpawn(World world) { - return world.getSpawnLocation(); + private Location getDefaultSpawn() { + return this.getServer().getWorld(Settings.defaultWorld).getSpawnLocation(); } private Location getMultiverseSpawn(World world) { @@ -607,7 +607,7 @@ public class AuthMe extends JavaPlugin { return Spawn.getInstance().getFirstSpawn(); if (Spawn.getInstance().getSpawn() != null) return Spawn.getInstance().getSpawn(); - return null; + return this.getServer().getWorld(Settings.defaultWorld).getSpawnLocation(); } public void downloadGeoIp() { diff --git a/src/main/java/fr/xephi/authme/events/FirstSpawnTeleportEvent.java b/src/main/java/fr/xephi/authme/events/FirstSpawnTeleportEvent.java new file mode 100644 index 00000000..079a4614 --- /dev/null +++ b/src/main/java/fr/xephi/authme/events/FirstSpawnTeleportEvent.java @@ -0,0 +1,40 @@ +package fr.xephi.authme.events; + +import org.bukkit.Location; +import org.bukkit.entity.Player; + +/** + * + * Called if a player is teleported to the authme first spawn + * + * @author Xephi59 + */ +public class FirstSpawnTeleportEvent extends CustomEvent { + + private Player player; + private Location to; + private Location from; + + public FirstSpawnTeleportEvent(Player player, Location from, Location to) { + this.player = player; + this.from = from; + this.to = to; + } + + public Player getPlayer() { + return player; + } + + public void setTo(Location to) { + this.to = to; + } + + public Location getTo() { + return to; + } + + public Location getFrom() { + return from; + } + +} diff --git a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java index d1375404..12e3f3f7 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java @@ -22,12 +22,14 @@ import fr.xephi.authme.cache.backup.FileCache; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.events.FirstSpawnTeleportEvent; import fr.xephi.authme.events.ProtectInventoryEvent; import fr.xephi.authme.events.SpawnTeleportEvent; import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.plugin.manager.CombatTagComunicator; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask; @@ -149,7 +151,7 @@ public class AsyncronousJoin { return; } if (!Settings.noTeleport) - if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { + if (!needFirstspawn() && Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { sched.scheduleSyncDelayedTask(plugin, new Runnable() { @Override @@ -249,6 +251,31 @@ public class AsyncronousJoin { LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); } + private boolean needFirstspawn() { + if (database.isAuthAvailable(player.getName().toLowerCase()) && player.hasPlayedBefore()) + return false; + else { + if (Spawn.getInstance().getFirstSpawn() == null || Spawn.getInstance().getFirstSpawn().getWorld() == null) + return false; + final Location loc = Spawn.getInstance().getFirstSpawn(); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + + @Override + public void run() { + FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent(player, player.getLocation(), loc); + plugin.getServer().getPluginManager().callEvent(tpEvent); + if (!tpEvent.isCancelled()) { + if (player != null && player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) { + player.teleport(tpEvent.getTo()); + } + } + } + + }); + return true; + } + } + private void placePlayerSafely(final Player player, final Location spawnLoc) { Location loc = null; @@ -258,14 +285,16 @@ public class AsyncronousJoin { return; if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) return; + if (!database.isAuthAvailable(player.getName().toLowerCase()) || !player.hasPlayedBefore()) + return; Block b = player.getLocation().getBlock(); - if (b.getType() == Material.PORTAL || b.getType() == Material.ENDER_PORTAL || b.getType() == Material.LAVA || b.getType() == Material.STATIONARY_LAVA) { + if (b.getType() == Material.PORTAL || b.getType() == Material.ENDER_PORTAL) { m.send(player, "unsafe_spawn"); if (spawnLoc.getWorld() != null) loc = spawnLoc; } else { Block c = player.getLocation().add(0D, 1D, 0D).getBlock(); - if (c.getType() == Material.PORTAL || c.getType() == Material.ENDER_PORTAL || c.getType() == Material.LAVA || c.getType() == Material.STATIONARY_LAVA) { + if (c.getType() == Material.PORTAL || c.getType() == Material.ENDER_PORTAL) { m.send(player, "unsafe_spawn"); if (spawnLoc.getWorld() != null) loc = spawnLoc; From 30b3dff96561ee3ddb74ad13bfd9fcc4b47ade4a Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 9 Jul 2015 19:14:14 +0200 Subject: [PATCH 5/6] Er... idk why these changes disappear T.T --- src/main/java/fr/xephi/authme/SendMailSSL.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/SendMailSSL.java b/src/main/java/fr/xephi/authme/SendMailSSL.java index 5c1288d6..2382124f 100644 --- a/src/main/java/fr/xephi/authme/SendMailSSL.java +++ b/src/main/java/fr/xephi/authme/SendMailSSL.java @@ -46,9 +46,8 @@ public class SendMailSSL { final String subject = Settings.getMailSubject; final String smtp = Settings.getmailSMTP; final String password = Settings.getmailPassword; - final String mailText = Settings.getMailText; + final String mailText = Settings.getMailText.replace("", auth.getNickname()).replace("", plugin.getServer().getServerName()).replace("", newPass); final String mail = auth.getEmail(); - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override From f114019e5f43add7c3873ce7b0f15134364ceb65 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 9 Jul 2015 19:24:00 +0200 Subject: [PATCH 6/6] Option to send an image as new password --- .../java/fr/xephi/authme/ImageGenerator.java | 33 +++++++++++++++++++ .../java/fr/xephi/authme/SendMailSSL.java | 21 ++++++++++++ .../fr/xephi/authme/settings/Settings.java | 8 ++++- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/main/java/fr/xephi/authme/ImageGenerator.java diff --git a/src/main/java/fr/xephi/authme/ImageGenerator.java b/src/main/java/fr/xephi/authme/ImageGenerator.java new file mode 100644 index 00000000..0a635c28 --- /dev/null +++ b/src/main/java/fr/xephi/authme/ImageGenerator.java @@ -0,0 +1,33 @@ +package fr.xephi.authme; + +import java.awt.Color; +import java.awt.Font; +import java.awt.GradientPaint; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + +public class ImageGenerator { + + private String pass; + private AuthMe plugin; + + public ImageGenerator(AuthMe plugin, String pass) { + this.pass = pass; + this.plugin = plugin; + } + + public BufferedImage generateImage() { + BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED); + Graphics2D graphics = image.createGraphics(); + graphics.setColor(Color.BLACK); + graphics.fillRect(0, 0, 200, 40); + GradientPaint gradientPaint = new GradientPaint(10, 5, Color.WHITE, 20, 10, Color.WHITE, true); + graphics.setPaint(gradientPaint); + Font font = new Font("Comic Sans MS", Font.BOLD, 30); + graphics.setFont(font); + graphics.drawString(pass, 5, 30); + graphics.dispose(); + image.flush(); + return image; + } +} diff --git a/src/main/java/fr/xephi/authme/SendMailSSL.java b/src/main/java/fr/xephi/authme/SendMailSSL.java index 2382124f..1927071f 100644 --- a/src/main/java/fr/xephi/authme/SendMailSSL.java +++ b/src/main/java/fr/xephi/authme/SendMailSSL.java @@ -1,9 +1,14 @@ package fr.xephi.authme; +import java.io.File; import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.Properties; +import javax.activation.DataHandler; +import javax.activation.DataSource; +import javax.activation.FileDataSource; +import javax.imageio.ImageIO; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.Multipart; @@ -73,10 +78,26 @@ public class SendMailSSL { messageBodyPart.setText(mailText); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); + + // Generate an image ? + File file = null; + if (Settings.generateImage) { + ImageGenerator gen = new ImageGenerator(plugin, newPass); + file = new File(plugin.getDataFolder() + File.separator + auth.getNickname() + "_new_pass.jpg"); + ImageIO.write(gen.generateImage(), "jpg", file); + messageBodyPart = new MimeBodyPart(); + DataSource source = new FileDataSource(file); + messageBodyPart.setDataHandler(new DataHandler(source)); + messageBodyPart.setFileName(auth.getNickname() + "_new_pass.jpg"); + multipart.addBodyPart(messageBodyPart); + } + message.setContent(multipart); Transport transport = session.getTransport("smtp"); transport.connect(smtp, acc, password); transport.sendMessage(message, message.getAllRecipients()); + if (file != null) + file.delete(); } catch (Exception e) { System.out.println("Some error occured while trying to send a mail to " + mail); diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 0696c604..fc689197 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -70,7 +70,7 @@ public final class Settings extends YamlConfiguration { purgePermissions, enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport, - applyBlindEffect, customAttributes; + applyBlindEffect, customAttributes, generateImage; public static String getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, @@ -269,6 +269,7 @@ public final class Settings extends YamlConfiguration { forceRegisterCommands = (List) configFile.getList("settings.forceRegisterCommands", new ArrayList()); forceRegisterCommandsAsConsole = (List) configFile.getList("settings.forceRegisterCommandsAsConsole", new ArrayList()); customAttributes = configFile.getBoolean("Hooks.customAttributes"); + generateImage = configFile.getBoolean("Email.generateImage", true); // Load the welcome message getWelcomeMessage(plugin); @@ -435,6 +436,7 @@ public final class Settings extends YamlConfiguration { forceRegisterCommands = (List) configFile.getList("settings.forceRegisterCommands", new ArrayList()); forceRegisterCommandsAsConsole = (List) configFile.getList("settings.forceRegisterCommandsAsConsole", new ArrayList()); customAttributes = configFile.getBoolean("Hooks.customAttributes"); + generateImage = configFile.getBoolean("Email.generateImage", true); // Reload the welcome message getWelcomeMessage(AuthMe.getInstance()); @@ -587,6 +589,10 @@ public final class Settings extends YamlConfiguration { } if (contains("Hooks.notifications")) set("Hooks.notifications", null); + if (!contains("Email.generateImage")) { + set("Email.generateImage", true); + changes = true; + } if (changes) { plugin.getLogger().warning("Merge new Config Options - I'm not an error, please don't report me");