Skip to content

Commit

Permalink
v2.4.4
Browse files Browse the repository at this point in the history
* Create a backup of messages.yml before updating it XAUTH-132
* New feature AutoUpdater
* GameMode will now be saved to playerData and is saved/restored accordingly
  • Loading branch information
lycano committed Oct 22, 2013
1 parent 0780134 commit 0bb19c4
Show file tree
Hide file tree
Showing 23 changed files with 956 additions and 258 deletions.
4 changes: 2 additions & 2 deletions src/main/assembly/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<includes>
<include>config.yml</include>
<include>messages.yml</include>
<include>plugin.yml</include>
<include>updater.yml</include>
</includes>
</fileSet>
<fileSet>
Expand All @@ -28,7 +28,7 @@
<file>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<outputDirectory>/</outputDirectory>
<destName>${project.build.finalName}.${project.packaging}</destName>
<destName>${project.build.finalName}.${project.packaging}</destName>
</file>
</files>
</assembly>
47 changes: 34 additions & 13 deletions src/main/java/de/luricos/bukkit/xAuth/MessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MessageHandler {
private final xAuth plugin;
Expand All @@ -37,39 +39,58 @@ public class MessageHandler {

public MessageHandler(final xAuth plugin) {
this.plugin = plugin;
this.configFile = new File(plugin.getDataFolder(), fileName);
this.configFile = new File(plugin.getDataFolder(), this.fileName);
this.config = YamlConfiguration.loadConfiguration(this.configFile);

this.updateConfig();
}

public FileConfiguration getConfig() {
if (config == null) {
reloadConfig();
public void updateConfig() {
YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(this.plugin.getResource(this.fileName));

// check if current messages file is different from resource messages. If not create a backup of the current one.
if ((this.config.options().header() == null) || (!(this.config.options().header().equals(newConfig.options().header())))) {
String backupDateString = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date().getTime());

xAuthLog.info("New messages.yml found in plugin. Creating backup of the current one.");
try {
this.config.save(new File(plugin.getDataFolder(), "messages-" + backupDateString + ".yml"));

this.config = newConfig;
this.saveConfig();
} catch (IOException e) {
xAuthLog.severe("Could not save a backup of message configuration to messages-" + backupDateString + ".yml", e);
}
}
}

return config;
public FileConfiguration getConfig() {
return this.config;
}

public void reloadConfig() {
if (configFile == null) {
configFile = new File(plugin.getDataFolder(), fileName);
if (this.config == null) {
this.configFile = new File(plugin.getDataFolder(), "messages.yml");
}
config = YamlConfiguration.loadConfiguration(configFile);
this.config = YamlConfiguration.loadConfiguration(this.configFile);

InputStream defConfigStream = plugin.getResource(fileName);
// Look for defaults in the jar
InputStream defConfigStream = plugin.getResource("messages.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
config.setDefaults(defConfig);
this.config.setDefaults(defConfig);
}
}

public void saveConfig() {
if (config == null || configFile == null) {
if (this.config == null || this.configFile == null) {
return;
}

try {
getConfig().save(configFile);
this.getConfig().save(this.configFile);
} catch (IOException e) {
xAuthLog.severe("Could not save message configuration to " + configFile, e);
xAuthLog.severe("Could not save message configuration to " + this.configFile, e);
}
}

Expand Down
22 changes: 15 additions & 7 deletions src/main/java/de/luricos/bukkit/xAuth/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package de.luricos.bukkit.xAuth;

import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
Expand All @@ -32,37 +33,44 @@ public class PlayerData {
private Collection<PotionEffect> potEffects;
private int fireTicks;
private int remainingAir;
private GameMode gameMode;

public PlayerData(ItemStack[] items, ItemStack[] armor, Location location, Collection<PotionEffect> potEffects, int fireTicks, int remainingAir) {
public PlayerData(ItemStack[] items, ItemStack[] armor, Location location, Collection<PotionEffect> potEffects, int fireTicks, int remainingAir, GameMode gameMode) {
this.items = items;
this.armor = armor;
this.location = location;
this.potEffects = potEffects;
this.fireTicks = fireTicks;
this.remainingAir = remainingAir;
this.gameMode = gameMode;
}

public ItemStack[] getItems() {
return items;
return this.items;
}

public ItemStack[] getArmor() {
return armor;
return this.armor;
}

public Location getLocation() {
return location;
return this.location;
}

public Collection<PotionEffect> getPotionEffects() {
return potEffects;
return this.potEffects;
}

public int getFireTicks() {
return fireTicks;
return this.fireTicks;
}

public int getRemainingAir() {
return remainingAir;
return this.remainingAir;
}

public GameMode getGameMode() {
return this.gameMode;
}

}
15 changes: 11 additions & 4 deletions src/main/java/de/luricos/bukkit/xAuth/PlayerDataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import de.luricos.bukkit.xAuth.exceptions.xAuthPlayerDataException;
import de.luricos.bukkit.xAuth.utils.xAuthLog;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentWrapper;
Expand Down Expand Up @@ -55,12 +56,13 @@ public void storeData(xAuthPlayer xp, Player p) {
Collection<PotionEffect> potEffects = p.getActivePotionEffects();
int fireTicks = p.isDead() ? 0 : p.getFireTicks();
int remainingAir = p.getRemainingAir();
GameMode gameMode = p.getGameMode();

String strItems = null;
String strArmor = null;
String strLoc = null;
String strPotFx = buildPotFxString(potEffects);
xp.setPlayerData(new PlayerData(items, armor, loc, potEffects, fireTicks, remainingAir));
xp.setPlayerData(new PlayerData(items, armor, loc, potEffects, fireTicks, remainingAir, gameMode));

boolean hideInv = plugin.getConfig().getBoolean("guest.hide-inventory");
boolean hideLoc = plugin.getConfig().getBoolean("guest.protect-location");
Expand Down Expand Up @@ -95,10 +97,10 @@ public void storeData(xAuthPlayer xp, Player p) {
try {
String sql;
if (plugin.getDatabaseController().isMySQL())
sql = String.format("INSERT IGNORE INTO `%s` VALUES (?, ?, ?, ?, ?, ?, ?)",
sql = String.format("INSERT IGNORE INTO `%s` VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
plugin.getDatabaseController().getTable(Table.PLAYERDATA));
else
sql = String.format("INSERT INTO `%s` SELECT ?, ?, ?, ?, ?, ?, ? FROM DUAL WHERE NOT EXISTS (SELECT * FROM `%s` WHERE `playername` = ?)",
sql = String.format("INSERT INTO `%s` SELECT ?, ?, ?, ?, ?, ?, ?, ? FROM DUAL WHERE NOT EXISTS (SELECT * FROM `%s` WHERE `playername` = ?)",
plugin.getDatabaseController().getTable(Table.PLAYERDATA), plugin.getDatabaseController().getTable(Table.PLAYERDATA));

ps = conn.prepareStatement(sql);
Expand All @@ -109,8 +111,9 @@ public void storeData(xAuthPlayer xp, Player p) {
ps.setString(5, strPotFx);
ps.setInt(6, fireTicks);
ps.setInt(7, remainingAir);
ps.setString(8, gameMode.name());
if (!plugin.getDatabaseController().isMySQL())
ps.setString(8, p.getName());
ps.setString(9, p.getName());
ps.executeUpdate();
} catch (SQLException e) {
xAuthLog.severe("Failed to insert player data into database!", e);
Expand Down Expand Up @@ -238,6 +241,7 @@ public void restoreData(xAuthPlayer xp, String playerName) {
Collection<PotionEffect> potFx = null;
int fireTicks = 0;
int remainingAir = 300;
GameMode gameMode = xp.getGameMode();

// Use cached copy of player data, if it exists
PlayerData playerData = xp.getPlayerData();
Expand All @@ -248,6 +252,7 @@ public void restoreData(xAuthPlayer xp, String playerName) {
potFx = playerData.getPotionEffects();
fireTicks = playerData.getFireTicks();
remainingAir = playerData.getRemainingAir();
gameMode = playerData.getGameMode();
} else {
Connection conn = plugin.getDatabaseController().getConnection();
PreparedStatement ps = null;
Expand Down Expand Up @@ -277,6 +282,7 @@ public void restoreData(xAuthPlayer xp, String playerName) {

fireTicks = rs.getInt("fireticks");
remainingAir = rs.getInt("remainingair");
gameMode = GameMode.valueOf(rs.getString("gamemode"));
}
} catch (SQLException e) {
xAuthLog.severe("Failed to load playerdata from database for player: " + playerName, e);
Expand Down Expand Up @@ -320,6 +326,7 @@ public void restoreData(xAuthPlayer xp, String playerName) {

player.setFireTicks(fireTicks);
player.setRemainingAir(remainingAir);
player.setGameMode(gameMode);
} catch (xAuthPlayerDataException e) {
xAuthLog.severe(e.getMessage());
}
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/de/luricos/bukkit/xAuth/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import de.luricos.bukkit.xAuth.utils.xAuthLog;
import de.luricos.bukkit.xAuth.utils.xAuthUtils;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
Expand Down Expand Up @@ -135,7 +136,7 @@ private xAuthPlayer loadPlayer(String playerName) {

addPlayerId(rs.getInt("id"), playerName);

return new xAuthPlayer(playerName, rs.getInt("id"), !rs.getBoolean("active"), rs.getBoolean("resetpw"), xAuthPlayer.Status.REGISTERED, rs.getInt("pwtype"), rs.getBoolean("premium"));
return new xAuthPlayer(playerName, rs.getInt("id"), !rs.getBoolean("active"), rs.getBoolean("resetpw"), xAuthPlayer.Status.REGISTERED, rs.getInt("pwtype"), rs.getBoolean("premium"), GameMode.valueOf(plugin.getConfig().getString("guest.gamemode", Bukkit.getDefaultGameMode().name())));
} catch (SQLException e) {
xAuthLog.severe(String.format("Failed to load player: %s", playerName), e);
return null;
Expand Down Expand Up @@ -174,7 +175,7 @@ public void handleReload(Player[] players) {
plugin.getAuthClass(xp).offline(p.getName());
} else {
xp.setStatus(xAuthPlayer.Status.AUTHENTICATED);
xp.setGameMode(p.getGameMode());
// remove xp.setGameMode(Bukkit.getDefaultGameMode()) - Moved to xAuthPlayer constructor
plugin.getAuthClass(xp).online(p.getName());
}
} else if (mustRegister(p)) {
Expand Down Expand Up @@ -245,9 +246,8 @@ public void protect(final xAuthPlayer xp) {

plugin.getPlayerDataHandler().storeData(xp, p);

// set GameMode for xAuthPlayer when protecting player to whatever it is currently if its unequal to the xAuthPlayer GameMode
if (!p.getGameMode().equals(xp.getGameMode()))
xp.setGameMode(p.getGameMode());
// set GameMode to configured guest gamemode
p.setGameMode(GameMode.valueOf(plugin.getConfig().getString("guest.gamemode", Bukkit.getDefaultGameMode().name())));

xp.setLastNotifyTime(new Timestamp(System.currentTimeMillis()));

Expand All @@ -274,9 +274,7 @@ public void unprotect(final xAuthPlayer xp) {

plugin.getPlayerDataHandler().restoreData(xp, p.getName());

// update xAuthPlayer gameMode
if (!xp.getGameMode().equals(p.getGameMode()))
xp.setGameMode(p.getGameMode());
// moved p.setGameMode(xp.getGameMode()) to doLogin

// guest protection cancel task. See @PlayerManager.protect(final xAuthPlayer p)
int timeoutTaskId = this.getTasks().getPlayerTask(p.getName(), xAuthTask.xAuthTaskType.KICK_TIMEOUT).getTaskId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
xAuthPlayer xp = xAuth.getPlugin().getPlayerManager().getPlayer(player);

if (xp.isGuest()) {
xAuth.getPlugin().getMessageHandler().sendMessage("changepw.error.logged", xp.getPlayer());
this.getMessageHandler().sendMessage("changepw.error.logged", xp.getPlayer());
return true;
}

if (xp.isLocked()) {
xAuth.getPlugin().getMessageHandler().sendMessage("misc.active", xp.getPlayer());
this.getMessageHandler().sendMessage("misc.active", xp.getPlayer());
return true;
}

Expand All @@ -63,17 +63,17 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

private boolean changePwCommand(xAuthPlayer xp, Player p, String[] args) {
if (!xp.isAuthenticated()) {
xAuth.getPlugin().getMessageHandler().sendMessage("changepw.error.logged", xp.getPlayer());
this.getMessageHandler().sendMessage("changepw.error.logged", xp.getPlayer());
return true;
}

if (args.length < 2) {
xAuth.getPlugin().getMessageHandler().sendMessage("changepw.usage", xp.getPlayer());
this.getMessageHandler().sendMessage("changepw.usage", xp.getPlayer());
return true;
}

if (!xAuth.getPermissionManager().has(p, "xauth.allow.player.command.changepw")) {
xAuth.getPlugin().getMessageHandler().sendMessage("changepw.permission", p);
this.getMessageHandler().sendMessage("changepw.permission", p);
return true;
}

Expand All @@ -85,7 +85,7 @@ private boolean changePwCommand(xAuthPlayer xp, Player p, String[] args) {

String response = a.getResponse();
if (response != null)
xAuth.getPlugin().getMessageHandler().sendMessage(response, xp.getPlayer());
this.getMessageHandler().sendMessage(response, xp.getPlayer());

if (success) {
xAuthLog.info(xp.getName() + " has changed their password");
Expand All @@ -98,12 +98,12 @@ private boolean changePwCommand(xAuthPlayer xp, Player p, String[] args) {

private boolean resetPwCommand(xAuthPlayer xp, Player p, String[] args) {
if (args.length != 1) {
xAuth.getPlugin().getMessageHandler().sendMessage("resetpw.reset-usage", xp.getPlayer());
this.getMessageHandler().sendMessage("resetpw.reset-usage", xp.getPlayer());
return true;
}

if (!xAuth.getPermissionManager().has(p, "xauth.allow.player.command.resetpw")) {
xAuth.getPlugin().getMessageHandler().sendMessage("resetpw.permission", p);
this.getMessageHandler().sendMessage("resetpw.permission", p);
return true;
}

Expand All @@ -113,7 +113,7 @@ private boolean resetPwCommand(xAuthPlayer xp, Player p, String[] args) {

String response = a.getResponse();
if (response != null)
xAuth.getPlugin().getMessageHandler().sendMessage(response, xp.getPlayer());
this.getMessageHandler().sendMessage(response, xp.getPlayer());

if (success) {
xAuthLog.info(xp.getName() + " has changed their password");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

Player player = (Player) sender;
if (xAuth.getPlugin().getPlayerManager().getPlayer(player).isAuthenticated()) {
xAuth.getPlugin().getMessageHandler().sendMessage("login.error.authenticated", player);
this.getMessageHandler().sendMessage("login.error.authenticated", player);
return true;
}

xAuthPlayer xp = xAuth.getPlugin().getPlayerManager().getPlayer(player, true);

if (args.length < 1) {
xAuth.getPlugin().getMessageHandler().sendMessage("login.usage", xp.getPlayer());
this.getMessageHandler().sendMessage("login.usage", xp.getPlayer());
return true;
}

Expand Down Expand Up @@ -78,7 +78,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

if (response != null)
xAuth.getPlugin().getMessageHandler().sendMessage(response, xp.getPlayer());
this.getMessageHandler().sendMessage(response, xp.getPlayer());

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
response = "logout.error.logged";
}

xAuth.getPlugin().getMessageHandler().sendMessage(response, player);
this.getMessageHandler().sendMessage(response, player);
//@TODO do we need idle kick after logout? Should it also respect mustRegister?

return true;
Expand Down
Loading

0 comments on commit 0bb19c4

Please sign in to comment.