Update to v3.8

Clean up a bunch of stuff and update to new version
This commit is contained in:
Esophose 2016-05-09 17:13:37 -06:00
parent a851ee037d
commit 3a730281f9
10 changed files with 94 additions and 53 deletions

View file

@ -10,14 +10,19 @@ package com.esophose.playerparticles;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.esophose.playerparticles.libraries.particles.ParticleEffect.ParticleType;
@ -183,4 +188,51 @@ public class ConfigManager {
}else return null;
}
public void updateConfig(JavaPlugin plugin) {
HashMap<String, Object> newConfig = getConfigVals();
FileConfiguration c = plugin.getConfig();
for (String var : c.getKeys(false)) {
newConfig.remove(var);
}
if (newConfig.size() != 0) {
for (String key : newConfig.keySet()) {
c.set(key, newConfig.get(key));
}
try {
c.set("version", getVersion());
c.save(new File(plugin.getDataFolder(), "config.yml"));
} catch (IOException e) {}
}
}
public HashMap<String, Object> getConfigVals() {
HashMap<String, Object> var = new HashMap<>();
YamlConfiguration config = new YamlConfiguration();
try {
config.loadFromString(stringFromInputStream(PlayerParticles.class.getResourceAsStream("/config.yml")));
} catch (InvalidConfigurationException e) {}
for (String key : config.getKeys(false)) {
var.put(key, config.get(key));
}
return var;
}
public double getVersion() {
double version = -1;
try {
YamlConfiguration config = new YamlConfiguration();
config.loadFromString(stringFromInputStream(PlayerParticles.class.getResourceAsStream("/config.yml")));
version = config.getDouble("version");
}catch(InvalidConfigurationException e) { }
return version;
}
public String stringFromInputStream(InputStream in) {
Scanner scanner = new Scanner(in);
String string = scanner.useDelimiter("\\A").next();
scanner.close();
return string;
}
}

View file

@ -14,7 +14,7 @@ import org.bukkit.entity.Player;
public class MessageManager {
private static MessageManager instance = new MessageManager();
private boolean messagesEnabled, prefix, checkForUpdates;
private boolean messagesEnabled, prefix;
private String messagePrefix;
private MessageManager() {
@ -22,25 +22,12 @@ public class MessageManager {
prefix = PlayerParticles.getPlugin().getConfig().getBoolean("use-message-prefix");
messagePrefix = PlayerParticles.getPlugin().getConfig().getString("message-prefix");
messagePrefix = messagePrefix.replace("&", "§");
checkForUpdates = PlayerParticles.getPlugin().getConfig().getBoolean("check-updates");
}
public void reload() {
messagesEnabled = PlayerParticles.getPlugin().getConfig().getBoolean("messages-enabled");
prefix = PlayerParticles.getPlugin().getConfig().getBoolean("use-message-prefix");
messagePrefix = PlayerParticles.getPlugin().getConfig().getString("message-prefix");
messagePrefix = messagePrefix.replace("&", "§");
checkForUpdates = PlayerParticles.getPlugin().getConfig().getBoolean("check-updates");
}
public static MessageManager getInstance() {
return instance;
}
public boolean shouldCheckUpdates() {
return checkForUpdates;
}
public void sendMessage(Player player, String message, ChatColor color) {
if(!messagesEnabled) return;
if(this.prefix){

View file

@ -19,13 +19,9 @@ public class ParticleCommandCompleter implements TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
if(cmd.getName().equalsIgnoreCase("pp")) {
if(args.length == 1) {
List<String> list = PermissionHandler.getParticlesUserHasPermissionFor((Player)sender);
if(PermissionHandler.canReload((Player)sender)) list.add("reload");
list.add("list");
list.add("styles");
list.add("style");
@ -33,17 +29,9 @@ public class ParticleCommandCompleter implements TabCompleter {
list.add("worlds");
list.add("help");
return list;
}
if(args.length == 2) {
return PermissionHandler.getStylesUserHasPermissionFor((Player)sender);
if(args.length == 2) return PermissionHandler.getStylesUserHasPermissionFor((Player)sender);
}
}
return null;
}

View file

@ -80,11 +80,13 @@ public class ParticleCreator extends BukkitRunnable implements Listener {
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
if(map.containsKey(e.getPlayer().getName()) && styleMap.get(e.getPlayer().getName()) == ParticleStyle.MOVE) {
if(PermissionHandler.hasStylePermission(e.getPlayer(), ParticleStyle.MOVE)) {
Location loc = e.getPlayer().getLocation();
loc.setY(loc.getY() + 1);
handleStyleNone(map.get(e.getPlayer().getName()), loc);
}
}
}
public static void addMap(Player player, ParticleType effect){
map.remove(player.getName());
@ -188,7 +190,6 @@ public class ParticleCreator extends BukkitRunnable implements Listener {
Location newLocation = new Location(location.getWorld(), newX, newY, newZ);
particle.display(newLocation);
}
return;
}else if(style == ParticleStyle.HALO) {
if(step % 2 == 0) return;
ParticleEffect particle = null;
@ -205,13 +206,11 @@ public class ParticleCreator extends BukkitRunnable implements Listener {
Location newLocation = new Location(location.getWorld(), newX, newY, newZ);
particle.display(newLocation);
}
return;
}else if(style == ParticleStyle.POINT) {
ParticleEffect particle = null;
if(effect == ParticleType.RAINBOW || effect == ParticleType.NOTE) particle = new ParticleEffect(effect, 0.0F, 0.0F, 0.0F, 1.0F, 1);
else particle = new ParticleEffect(effect, 0.0F, 0.0F, 0.0F, 0.0F, 1);
particle.display(location.add(0.0, 1.5, 0.0));
return;
}else if(style == ParticleStyle.SPIN) {
ParticleEffect particle = null;
if(effect == ParticleType.RAINBOW || effect == ParticleType.NOTE) particle = new ParticleEffect(effect, 0.0F, 0.0F, 0.0F, 1.0F, 1);
@ -235,7 +234,15 @@ public class ParticleCreator extends BukkitRunnable implements Listener {
double dz = -(Math.sin((helixStep / 90) * (Math.PI * 2) + ((Math.PI / 2) * i))) * ((60 - Math.abs(helixYStep)) / 60);
particle.display(new Location(location.getWorld(), location.getX() + dx, location.getY() + dy, location.getZ() + dz));
}
return;
}else if(style == ParticleStyle.ORB) {
ParticleEffect particle = null;
if(effect == ParticleType.RAINBOW || effect == ParticleType.NOTE) particle = new ParticleEffect(effect, 0.0F, 0.0F, 0.0F, 1.0F, 1);
else particle = new ParticleEffect(effect, 0.0F, 0.0F, 0.0F, 0.0F, 1);
for(int i = 0; i < 4; i++) {
double dx = -(Math.cos((helixStep / 90) * (Math.PI * 2) + ((Math.PI / 2) * i)));
double dz = -(Math.sin((helixStep / 90) * (Math.PI * 2) + ((Math.PI / 2) * i)));
particle.display(new Location(location.getWorld(), location.getX() + dx, location.getY(), location.getZ() + dz));
}
}
}

View file

@ -16,7 +16,8 @@ public enum ParticleStyle {
POINT,
MOVE,
SPIN,
QUADHELIX;
QUADHELIX,
ORB;
public static ParticleStyle styleFromString(String particle){
for(ParticleStyle style : ParticleStyle.values()){

View file

@ -67,11 +67,4 @@ public class PermissionHandler {
return list;
}
public static boolean canReload(Player p) {
if(p.hasPermission("playerparticles.reload") || p.hasPermission("playerparticles.*")) {
return true;
}
return false;
}
}

View file

@ -43,7 +43,7 @@ public class PlayerParticles extends JavaPlugin {
getCommand("pp").setTabCompleter(new ParticleCommandCompleter());
Bukkit.getPluginManager().registerEvents(new ParticleCreator(), this);
Bukkit.getPluginManager().registerEvents(new PluginUpdateListener(), this);
if(getConfig().getDouble("version") < Double.parseDouble(getDescription().getVersion())){
if(getConfig().getDouble("version") < Double.parseDouble(getDescription().getVersion())) {
File configFile = new File(getDataFolder(), "config.yml");
configFile.delete();
saveDefaultConfig();
@ -56,20 +56,23 @@ public class PlayerParticles extends JavaPlugin {
startTasks();
// Check for an update
if(MessageManager.getInstance().shouldCheckUpdates()) {
if(shouldCheckUpdates()) {
Updater updater = new Updater(this, 82823, this.getFile(), Updater.UpdateType.NO_DOWNLOAD, false);
if(Double.parseDouble(updater.getLatestName().replaceAll("PlayerParticles v", "")) > Double.parseDouble(getPlugin().getDescription().getVersion())) {
updateVersion = updater.getLatestName().replaceAll("PlayerParticles v", "");
System.out.println("[PlayerParticles] An update (v" + updateVersion + ") is available! You are running v" + getPlugin().getDescription().getVersion());
getLogger().info("[PlayerParticles] An update (v" + updateVersion + ") is available! You are running v" + getPlugin().getDescription().getVersion());
}
}
}
public static Plugin getPlugin(){
return Bukkit.getPluginManager().getPlugin("PlayerParticles");
}
public boolean shouldCheckUpdates() {
return getConfig().getBoolean("check-updates");
}
private void checkDatabase() {
if(getConfig().getBoolean("database-enable")) {
String hostname = getConfig().getString("database-hostname");
@ -85,13 +88,13 @@ public class PlayerParticles extends JavaPlugin {
useMySQL = true;
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
System.out.println("Failed to connect to MySQL Database! Check to see if your config is correct!");
getLogger().info("Failed to connect to MySQL Database! Check to see if your config is correct!");
useMySQL = false;
}
}else{
useMySQL = false;
}
System.out.println("[PlayerParticles] Using mySQL for data storage: " + useMySQL);
getLogger().info("[PlayerParticles] Using mySQL for data storage: " + useMySQL);
}
private void startTasks() {

View file

@ -1,3 +1,11 @@
/**
* Copyright Esophose 2016
* While using any of the code provided by this plugin
* you must not claim it as your own. This plugin may
* be modified and installed on a server, but may not
* be distributed to any person by any means.
*/
package com.esophose.playerparticles.updater;
import org.bukkit.ChatColor;

View file

@ -11,10 +11,10 @@
# ====================================================#
# DO NOT CHANGE THIS UNDER ANY CIRCUMSTANCE (Will reset your config)
version: 3.7
version: 3.8
# There are 20 minecraft ticks per second
# The default value of 20 means a particle will be displayed every tick
# The default value of 1 means a particle will be displayed once every tick
# That means 20 particles will be displayed per second
# If ticks-per-particle was set to 5, then 4 particles would be displayed per second since 20/5 is 4
# If your server is experiencing lag after installing this plugin, raising this value should help

View file

@ -1,7 +1,9 @@
name: PlayerParticles
main: com.esophose.playerparticles.PlayerParticles
version: 3.7
description: Make Particles Around Players
version: 3.8
description: Make particles around players.
author: Esophose
website: http://dev.bukkit.org/bukkit-plugins/playerparticles/
commands:
pp:
description: Particles Command.