Merge remote-tracking branch 'refs/remotes/origin/master' into PlayerParticles-v4

# Conflicts:
#	src/com/esophose/playerparticles/ParticleCommandExecutor.java
#	src/com/esophose/playerparticles/PlayerParticles.java
#	src/com/esophose/playerparticles/library/Database.java
#	src/com/esophose/playerparticles/library/ParticleEffect.java
#	src/com/esophose/playerparticles/manager/ConfigManager.java
#	src/config.yml
This commit is contained in:
Esophose 2016-09-30 22:14:20 -06:00
commit 7663da5c3a
6 changed files with 267 additions and 0 deletions

View file

@ -129,7 +129,11 @@ public class ParticleCommandExecutor implements CommandExecutor {
*/
private void onData(Player p, String[] args) {
ParticleEffect effect = ConfigManager.getInstance().getPPlayer(p.getUniqueId()).getParticleEffect();
<<<<<<< HEAD
if ((!effect.hasProperty(ParticleProperty.REQUIRES_DATA) && !effect.hasProperty(ParticleProperty.COLORABLE)) || args.length == 1) {
=======
if (args.length == 1) {
>>>>>>> refs/remotes/origin/master
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
if (effect == ParticleEffect.NOTE) {
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-note-data-usage", null), ChatColor.YELLOW);
@ -210,32 +214,50 @@ public class ParticleCommandExecutor implements CommandExecutor {
int data = -1;
try {
<<<<<<< HEAD
material = ParticlesUtil.closestMatch(args[1]);
if (material == null) material = Material.matchMaterial(args[1]);
if (material == null) throw new Exception();
} catch (Exception e) {
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-item-data-unknown", args[1]), ChatColor.RED);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <itemName> <0-15>", ChatColor.YELLOW);
=======
material = Material.matchMaterial(args[1]);
} catch (Exception e) {
// Unknown item
>>>>>>> refs/remotes/origin/master
return;
}
try {
data = Integer.parseInt(args[2]);
} catch (Exception e) {
<<<<<<< HEAD
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-item-data-usage", null), ChatColor.RED);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <itemName> <0-15>", ChatColor.YELLOW);
=======
// Invalid data
>>>>>>> refs/remotes/origin/master
return;
}
if (material.isBlock()) {
<<<<<<< HEAD
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-item-data-mismatch", material.name()), ChatColor.RED);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <itemName> <0-15>", ChatColor.YELLOW);
=======
// Material must be an item
>>>>>>> refs/remotes/origin/master
return;
}
if (data < 0 || data > 15) {
<<<<<<< HEAD
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-item-data-invalid-arguments", null), ChatColor.RED);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <itemName> <0-15>", ChatColor.YELLOW);
=======
// Error data range must be between 0-15
>>>>>>> refs/remotes/origin/master
return;
}
@ -246,18 +268,25 @@ public class ParticleCommandExecutor implements CommandExecutor {
int data = -1;
try {
<<<<<<< HEAD
material = ParticlesUtil.closestMatch(args[1]);
if (material == null) material = Material.matchMaterial(args[1]);
if (material == null) throw new Exception();
} catch (Exception e) {
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-block-data-unknown", args[1]), ChatColor.RED);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <blockName> <0-15>", ChatColor.YELLOW);
=======
material = Material.matchMaterial(args[1]);
} catch (Exception e) {
// Unknown block
>>>>>>> refs/remotes/origin/master
return;
}
try {
data = Integer.parseInt(args[2]);
} catch (Exception e) {
<<<<<<< HEAD
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-block-data-usage", null), ChatColor.RED);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <blockName> <0-15>", ChatColor.YELLOW);
return;
@ -266,12 +295,24 @@ public class ParticleCommandExecutor implements CommandExecutor {
if (!material.isBlock()) {
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-block-data-mismatch", material.name()), ChatColor.RED);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <blockName> <0-15>", ChatColor.YELLOW);
=======
// Invalid data
return;
}
if (material.isBlock()) {
// Material must be a block
>>>>>>> refs/remotes/origin/master
return;
}
if (data < 0 || data > 15) {
<<<<<<< HEAD
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-block-data-invalid-arguments", null), ChatColor.RED);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <blockName> <0-15>", ChatColor.YELLOW);
=======
// Error data range must be between 0-15
>>>>>>> refs/remotes/origin/master
return;
}
@ -288,7 +329,11 @@ public class ParticleCommandExecutor implements CommandExecutor {
* @param args The arguments for the command
*/
private void onReset(Player p, String[] args) {
<<<<<<< HEAD
ConfigManager.getInstance().resetPPlayer(p.getUniqueId());
=======
ConfigManager.getInstance().saveEntirePPlayer(PPlayer.getNewPPlayer(p.getUniqueId()));
>>>>>>> refs/remotes/origin/master
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-reset", null), ChatColor.GREEN);
}

View file

@ -113,7 +113,11 @@ public class PlayerParticles extends JavaPlugin {
String user = getConfig().getString("database-user-name");
String pass = getConfig().getString("database-user-password");
mySQL = new MySQL(hostname, port, database, user, pass);
<<<<<<< HEAD
try (ResultSet res = mySQL.querySQL("SHOW TABLES LIKE 'playerparticles'")) { // Clean up the old mess
=======
try (ResultSet res = mySQL.querySQL("SHOW TABLES LIKE 'playerparticles'")) {
>>>>>>> refs/remotes/origin/master
if (res.next()) {
mySQL.updateSQL("DROP TABLE playerparticles");
}
@ -125,16 +129,26 @@ public class PlayerParticles extends JavaPlugin {
try (ResultSet res = mySQL.querySQL("SHOW TABLES LIKE 'pp_users'")) {
if (!res.next()) { // @formatter:off
mySQL.updateSQL("CREATE TABLE pp_users (player_uuid VARCHAR(36), effect VARCHAR(32), style VARCHAR(32));" +
<<<<<<< HEAD
"CREATE TABLE pp_data_item (player_uuid VARCHAR(36), material VARCHAR(32), data SMALLINT);" +
"CREATE TABLE pp_data_block (player_uuid VARCHAR(36), material VARCHAR(32), data SMALLINT);" +
"CREATE TABLE pp_data_color (player_uuid VARCHAR(36), r SMALLINT, g SMALLINT, b SMALLINT);" +
"CREATE TABLE pp_data_note (player_uuid VARCHAR(36), note SMALLINT);"
=======
"CREATE TABLE pp_data_item (player_uuid VARCHAR(36), material VARCHAR(32), data TINYINT);" +
"CREATE TABLE pp_data_block (player_uuid VARCHAR(36), material VARCHAR(32), data TINYINT);" +
"CREATE TABLE pp_data_color (player_uuid VARCHAR(36), r TINYINT, g TINYINT, b TINYINT)" +
"CREATE TABLE pp_data_note (player_uuid VARCHAR(36), note TINYINT)"
>>>>>>> refs/remotes/origin/master
); // @formatter:on
}
useMySQL = true;
} catch (ClassNotFoundException | SQLException e) {
getLogger().info("[PlayerParticles] Failed to connect to the MySQL Database! Check to see if your login information is correct!");
<<<<<<< HEAD
getLogger().info("Additional information: " + e.getMessage());
=======
>>>>>>> refs/remotes/origin/master
useMySQL = false;
}
} else {

View file

@ -96,8 +96,11 @@ public abstract class Database {
* See {@link java.sql.Statement#executeUpdate(String)}<br>
* If the connection is closed, it will be opened
*
<<<<<<< HEAD:src/com/esophose/playerparticles/library/Database.java
* Executes multiple updates broken up by semi-colons
*
=======
>>>>>>> refs/remotes/origin/master:src/com/esophose/playerparticles/library/Database.java
* @param query Query to be run
* @return Result Code, see {@link java.sql.Statement#executeUpdate(String)}
* @throws SQLException If the query cannot be executed
@ -126,6 +129,12 @@ public abstract class Database {
statement.close();
<<<<<<< HEAD:src/com/esophose/playerparticles/library/Database.java
return results[0];
=======
statement.close();
return result;
>>>>>>> refs/remotes/origin/master:src/com/esophose/playerparticles/library/Database.java
}
}

View file

@ -47,9 +47,14 @@ import com.esophose.playerparticles.library.ReflectionUtils.PackageType;
/**
* Modified a couple things for the plugin
<<<<<<< HEAD
* Updated to 1.10
*
* @author (of changes) Esophose
=======
*
* @author Esophose
>>>>>>> refs/remotes/origin/master
*/
public enum ParticleEffect {

View file

@ -73,6 +73,7 @@ public class ConfigManager {
config = YamlConfiguration.loadConfiguration(file);
}
<<<<<<< HEAD
/**
* Saves the playerData.yml file to disk
*/
@ -104,6 +105,39 @@ public class ConfigManager {
* @param playerUUID The UUID to match the PPlayer to
* @return
*/
=======
/**
* Saves the playerData.yml file to disk
*/
private void save() {
try {
config.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Gets a player from the save data, creates one if it doesn't exist and adds it to the list
*/
public PPlayer getPPlayer(UUID playerUUID) {
for (PPlayer pp : ParticleCreator.particlePlayers) {
if (pp.getUniqueId() == playerUUID) return pp;
}
PPlayer pplayer = buildPPlayer(playerUUID);
ParticleCreator.particlePlayers.add(pplayer);
return pplayer;
}
/**
* Gets a PPlayer matching the UUID given
* One will be created if it doesn't exist
*
* @param playerUUID The UUID to match the PPlayer to
* @return
*/
>>>>>>> refs/remotes/origin/master
private PPlayer buildPPlayer(UUID playerUUID) {
if (!PlayerParticles.useMySQL) {
if (config.getString(playerUUID.toString() + ".style.name") != null) {
@ -125,29 +159,45 @@ public class ConfigManager {
return new PPlayer(playerUUID, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData);
} else {
PPlayer pplayer = PPlayer.getNewPPlayer(playerUUID);
<<<<<<< HEAD
saveNewPPlayer(pplayer);
=======
saveEntirePPlayer(pplayer);
>>>>>>> refs/remotes/origin/master
return pplayer;
}
} else {
String id = playerUUID.toString(); // @formatter:off
try (ResultSet res = PlayerParticles.mySQL.querySQL("SELECT * FROM pp_users u " +
"JOIN pp_data_item i ON u.player_uuid = i.player_uuid " +
<<<<<<< HEAD
"JOIN pp_data_block b ON u.player_uuid = b.player_uuid " +
"JOIN pp_data_color c ON u.player_uuid = c.player_uuid " +
"JOIN pp_data_note n ON u.player_uuid = n.player_uuid " +
"WHERE u.player_uuid = '" + id + "'")) { // @formatter:on
=======
"JOIN pp_data_block b ON u.player_uuid = b.player_uuid" +
"JOIN pp_data_color c ON u.player_uuid = c.player_uuid" +
"JOIN pp_data_note n ON u.player_uuid = n.player_uuid" +
"WHERE player_uuid = '" + id + "'")) { // @formatter:on
>>>>>>> refs/remotes/origin/master
if (res.next()) {
ParticleEffect particleEffect = ParticleEffect.fromName(res.getString("u.effect"));
ParticleStyle particleStyle = ParticleStyleManager.styleFromString(res.getString("u.style"));
ItemData particleItemData = new ItemData(Material.matchMaterial(res.getString("i.material")), res.getByte("i.data"));
BlockData particleBlockData = new BlockData(Material.matchMaterial(res.getString("b.material")), res.getByte("b.data"));
<<<<<<< HEAD
OrdinaryColor particleColorData = new OrdinaryColor(Color.fromRGB(res.getInt("c.r"), res.getInt("c.g"), res.getInt("c.b")));
=======
OrdinaryColor particleColorData = new OrdinaryColor(Color.fromRGB(res.getByte("c.r"), res.getByte("c.g"), res.getByte("c.b")));
>>>>>>> refs/remotes/origin/master
NoteColor particleNoteColorData = new NoteColor(res.getByte("n.note"));
return new PPlayer(playerUUID, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData);
} else {
PPlayer pplayer = PPlayer.getNewPPlayer(playerUUID);
<<<<<<< HEAD
saveNewPPlayer(pplayer);
return pplayer;
}
@ -231,10 +281,17 @@ public class ConfigManager {
);
} // @formatter:on
} catch (ClassNotFoundException | SQLException e) {
=======
saveEntirePPlayer(pplayer);
return pplayer;
}
} catch (ClassNotFoundException | SQLException e) {
>>>>>>> refs/remotes/origin/master
e.printStackTrace();
}
}
<<<<<<< HEAD
ParticleCreator.updateIfContains(pplayer); // Update the player in case this is a /pp reset
}
@ -260,6 +317,114 @@ public class ConfigManager {
* @param playerUUID The UUID of the player
* @param particleStyle The effect that is being saved
*/
=======
return null; // This should never get called unless there is a database error
}
/**
* Saves an entire PPlayer to the database
* This is mainly used for when PPlayers are being created for the first time
* It can also be called when a player is getting reset with /pp reset
* Use the singular methods for updating individual parts of the PPlayer
*
* @param pplayer The PPlayer to save
*/
public void saveEntirePPlayer(PPlayer pplayer) {
if (!PlayerParticles.useMySQL) {
if (!config.isConfigurationSection(pplayer.getUniqueId().toString())) {
String id = pplayer.getUniqueId().toString();
config.createSection(id);
config.createSection(id + ".effect");
config.createSection(id + ".style");
config.createSection(id + ".itemData");
config.createSection(id + ".blockData");
config.createSection(id + ".colorData");
config.createSection(id + ".noteColorData");
}
ConfigurationSection section = config.getConfigurationSection(pplayer.getUniqueId().toString());
ConfigurationSection effectSection = section.getConfigurationSection("effect");
ConfigurationSection styleSection = section.getConfigurationSection("style");
ConfigurationSection itemDataSection = section.getConfigurationSection("itemData");
ConfigurationSection blockDataSection = section.getConfigurationSection("blockData");
ConfigurationSection colorDataSection = section.getConfigurationSection("colorData");
ConfigurationSection noteColorDataSection = section.getConfigurationSection("noteColorData");
effectSection.set("name", pplayer.getParticleEffect().getName());
styleSection.set("name", pplayer.getParticleStyle().getName());
itemDataSection.set("material", pplayer.getItemData().getMaterial().name());
itemDataSection.set("data", pplayer.getItemData().getData());
blockDataSection.set("material", pplayer.getBlockData().getMaterial().name());
blockDataSection.set("data", pplayer.getBlockData().getData());
colorDataSection.set("r", pplayer.getColorData().getRed());
colorDataSection.set("g", pplayer.getColorData().getGreen());
colorDataSection.set("b", pplayer.getColorData().getBlue());
noteColorDataSection.set("note", (byte) (pplayer.getNoteColorData().getValueX() * 24));
save();
} else {
try (ResultSet res = PlayerParticles.mySQL.querySQL("SELECT COUNT(*) FROM pp_users WHERE player_uuid = '" + pplayer.getUniqueId() + "'")) {
if (res.next()) { // @formatter:off
PlayerParticles.mySQL.updateSQL("UPDATE pp_users SET " +
"effect = '" + pplayer.getParticleEffect().getName() + "', " +
"style = '" + pplayer.getParticleStyle().getName() + "' " +
"WHERE player_uuid = " + pplayer.getUniqueId().toString() + "; " +
"UPDATE pp_data_item SET " +
"material = '" + pplayer.getItemData().getMaterial().name() + "', " +
"data = " + pplayer.getItemData().getData() + " " +
"WHERE player_uuid = " + pplayer.getUniqueId().toString() + "; " +
"UPDATE pp_date_block SET " +
"material = '" + pplayer.getBlockData().getMaterial().name() + "', " +
"data = " + pplayer.getBlockData().getData() + " " +
"WHERE player_uuid = " + pplayer.getUniqueId().toString() + "; " +
"UPDATE pp_data_color SET " +
"r = " + pplayer.getColorData().getRed() + ", " +
"g = " + pplayer.getColorData().getGreen() + ", " +
"b = " + pplayer.getColorData().getBlue() + " " +
"WHERE player_uuid = " + pplayer.getUniqueId().toString() + "; " +
"UPDATE pp_data_note SET" +
"note = " + (byte) (pplayer.getNoteColorData().getValueX() * 24) + " " +
"WHERE player_uuid = " + pplayer.getUniqueId().toString() + ";"
);
} else {
PlayerParticles.mySQL.updateSQL("INSERT INTO pp_users (player_uuid, effect, style) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
"'" + pplayer.getParticleEffect().getName() + "', " +
"'" + pplayer.getParticleStyle().getName() + "'" +
"); " +
"INSERT INTO pp_data_item (material, data) VALUES (" +
"'" + pplayer.getItemData().getMaterial().name() + "', " +
pplayer.getItemData().getData() +
"); " +
"INSERT INTO pp_data_block (material, data) VALUES (" +
"'" + pplayer.getBlockData().getMaterial().name() + "', " +
pplayer.getBlockData().getData() +
"); " +
"INSERT INTO pp_data_color (r, g, b) VALUES (" +
pplayer.getColorData().getRed() + ", " +
pplayer.getColorData().getGreen() + ", " +
pplayer.getColorData().getBlue() +
"); " +
"INSERT INTO pp_data_note (note) VALUES (" +
(byte) (pplayer.getNoteColorData().getValueX() * 24) +
");"
);
} // @formatter:on
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
ParticleCreator.updateIfContains(pplayer); // Update the player in case this is a /pp reset
}
/**
* Saves the effect to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleStyle The effect that is being saved
*/
>>>>>>> refs/remotes/origin/master
public void savePPlayer(UUID playerUUID, ParticleEffect particleEffect) {
if (!PlayerParticles.useMySQL) {
ConfigurationSection section = config.getConfigurationSection(playerUUID.toString() + ".effect");
@ -267,7 +432,11 @@ public class ConfigManager {
save();
} else {
try {
<<<<<<< HEAD
PlayerParticles.mySQL.updateSQL("UPDATE pp_users SET effect = '" + particleEffect.getName() + "' WHERE player_uuid = '" + playerUUID + "';");
=======
PlayerParticles.mySQL.updateSQL("UPDATE pp_users SET effect = '" + particleEffect.getName() + "' WHERE player_uuid = " + playerUUID + ";");
>>>>>>> refs/remotes/origin/master
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
@ -288,7 +457,11 @@ public class ConfigManager {
save();
} else {
try {
<<<<<<< HEAD
PlayerParticles.mySQL.updateSQL("UPDATE pp_users SET style = '" + particleStyle.getName() + "' WHERE player_uuid = '" + playerUUID + "';");
=======
PlayerParticles.mySQL.updateSQL("UPDATE pp_users SET style = '" + particleStyle.getName() + "' WHERE player_uuid = " + playerUUID + ";");
>>>>>>> refs/remotes/origin/master
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
@ -310,7 +483,11 @@ public class ConfigManager {
save();
} else {
try {
<<<<<<< HEAD
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_item SET material = '" + particleItemData.getMaterial().name() + "', data = '" + particleItemData.getData() + "' WHERE player_uuid = '" + playerUUID + "';");
=======
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_item SET material = '" + particleItemData.getMaterial().name() + "', data = '" + particleItemData.getData() + "' WHERE player_uuid = " + playerUUID + ";");
>>>>>>> refs/remotes/origin/master
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
@ -332,7 +509,11 @@ public class ConfigManager {
save();
} else {
try {
<<<<<<< HEAD
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_block SET material = '" + particleBlockData.getMaterial().name() + "', data = '" + particleBlockData.getData() + "' WHERE player_uuid = '" + playerUUID + "';");
=======
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_block SET material = '" + particleBlockData.getMaterial().name() + "', data = '" + particleBlockData.getData() + "' WHERE player_uuid = " + playerUUID + ";");
>>>>>>> refs/remotes/origin/master
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
@ -355,7 +536,11 @@ public class ConfigManager {
save();
} else {
try {
<<<<<<< HEAD
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_color SET r = " + particleColorData.getRed() + ", g = " + particleColorData.getGreen() + ", b = " + particleColorData.getBlue() + " WHERE player_uuid = '" + playerUUID + "';");
=======
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_color SET r = " + particleColorData.getRed() + ", g = " + particleColorData.getGreen() + ", b = " + particleColorData.getBlue() + " WHERE player_uuid = " + playerUUID + ";");
>>>>>>> refs/remotes/origin/master
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
@ -376,7 +561,11 @@ public class ConfigManager {
save();
} else {
try {
<<<<<<< HEAD
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_note SET note = " + (byte) (particleNoteColorData.getValueX() * 24) + " WHERE player_uuid = '" + playerUUID + "';");
=======
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_color SET note = " + (byte) (particleNoteColorData.getValueX() * 24) + " WHERE player_uuid = " + playerUUID + ";");
>>>>>>> refs/remotes/origin/master
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}

View file

@ -173,6 +173,11 @@ message-block-data-material-unknown: 'The block name you supplied is invalid'
# Default: 'The item name you supplied is invalid'
message-item-data-material-unknown: 'The item name you supplied is invalid'
<<<<<<< HEAD
=======
>>>>>>> refs/remotes/origin/master
# ------------- #
# Other #
# ------------- #