Update to 1.10 & Cleanup

Updates the plugin to Minecraft 1.10 and refactors parts of the code to
make it look more clean.
This commit is contained in:
Esophose 2016-06-10 21:44:08 -06:00
parent 98c964fd58
commit fc6119a523
14 changed files with 271 additions and 241 deletions

View file

@ -1,65 +0,0 @@
/**
* 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;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class MessageManager {
/**
* The instance of the MessageManager, we only need one of these
*/
private static MessageManager instance = new MessageManager();
/**
* Values contained in the config used for custom messages
*/
private boolean messagesEnabled, prefix;
/**
* The prefix to place before all sent messages contained in the config
*/
private String messagePrefix;
/**
* Sets up all the above variables with values from the plugin config
*/
private MessageManager() {
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("&", "§");
}
/**
* Gets the instance of the MessageManager
*
* @return The instance of the MessageManager
*/
public static MessageManager getInstance() {
return instance;
}
/**
* Sends a message to a player
*
* @param player The player to send the message to
* @param message The message to send to the player
* @param color The chat color to put before the message
*/
public void sendMessage(Player player, String message, ChatColor color) {
if(!messagesEnabled) return;
if(this.prefix){
message = messagePrefix + color + " " + message;
}else{
message = color + message;
}
player.sendMessage(message);
}
}

View file

@ -15,6 +15,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import com.esophose.playerparticles.manager.PermissionManager;
public class ParticleCommandCompleter implements TabCompleter {
/**
@ -29,7 +31,7 @@ public class ParticleCommandCompleter implements TabCompleter {
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);
List<String> list = PermissionManager.getParticlesUserHasPermissionFor((Player)sender);
list.add("list");
list.add("styles");
list.add("style");
@ -38,7 +40,7 @@ public class ParticleCommandCompleter implements TabCompleter {
list.add("help");
return list;
}
if(args.length == 2) return PermissionHandler.getStylesUserHasPermissionFor((Player)sender);
if(args.length == 2) return PermissionManager.getStylesUserHasPermissionFor((Player)sender);
}
return null;
}

View file

@ -0,0 +1,142 @@
package com.esophose.playerparticles;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.esophose.playerparticles.libraries.particles.ParticleEffect.ParticleType;
import com.esophose.playerparticles.manager.ConfigManager;
import com.esophose.playerparticles.manager.MessageManager;
import com.esophose.playerparticles.manager.PermissionManager;
public class ParticleCommandExecutor implements CommandExecutor {
/**
* Called when a player does a command and continues if the command is /pp
* Executes all the commands and methods
* Does some sorcery
*
* @param sender Who executed the command
* @param cmd The command
* @param label The command label
* @param args The arguments following the command
* @return True if everything went as planned (should always be true)
*/
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(!(sender instanceof Player)) return true;
Player p = (Player) sender;
if(args.length == 1 && args[0].equalsIgnoreCase("worlds")) {
String worlds = "";
if(ConfigManager.getInstance().getDisabledWorlds() == null) {
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-disabled-worlds-none", null, null), ChatColor.GREEN);
}
for(String s : ConfigManager.getInstance().getDisabledWorlds()) {
worlds += s + ", ";
}
if(worlds.length() > 2) worlds = worlds.substring(0, worlds.length() - 2);
if(worlds.equals("")) {
worlds = MessageManager.getMessageFromConfig("message-disabled-worlds-none", null, null);
}else{
worlds = MessageManager.getMessageFromConfig("message-disabled-worlds", null, null) + " " + ChatColor.AQUA + worlds;
}
MessageManager.getInstance().sendMessage(p, worlds, ChatColor.GREEN);
return true;
}
if(args.length > 1 && args[0].equalsIgnoreCase("style")) {
String argument = args[1].replace("_", "");
if(ParticleStyle.styleFromString(argument) != null){
ParticleStyle style = ParticleStyle.styleFromString(argument);
if(!PermissionManager.hasStylePermission(p, style)) {
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-no-permission-style", null, ChatColor.AQUA + style.toString().toLowerCase() + ChatColor.RED), ChatColor.RED);
return true;
}
ConfigManager.getStyleInstance().setStyle(style, p);
ParticleCreator.addStyleMap(p, style);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-now-using-style", null, ChatColor.AQUA + style.toString().toLowerCase() + ChatColor.GREEN), ChatColor.GREEN);
return true;
}
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-invalid-type-style", null, null) + ChatColor.GREEN + " /pp styles", ChatColor.RED);
return true;
}
if(args.length != 1){
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-invalid-arguments", null, null) + ChatColor.GREEN + " /pp list", ChatColor.RED);
return true;
}
String argument = args[0].replace("_", "");
if(ParticleCreator.particleFromString(argument) != null){
ParticleType effect = ParticleCreator.particleFromString(argument);
if(!PermissionManager.hasPermission(p, effect)){
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-no-permission", ChatColor.AQUA + (effect.equals(ParticleType.RAINBOW) ? "rainbow" : effect.getName().toLowerCase() + ChatColor.RED), null), ChatColor.RED);
return true;
}
ConfigManager.getInstance().setParticle(effect, p);
ParticleCreator.addMap(p, effect);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-now-using", ChatColor.AQUA + (effect.equals(ParticleType.RAINBOW) ? "rainbow" : effect.getName().toLowerCase() + ChatColor.GREEN), null), ChatColor.GREEN);
return true;
}
if(argument.equalsIgnoreCase("clear")) {
ConfigManager.getInstance().resetParticle(p);
ParticleCreator.removeMap(p);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-cleared-particles", null, null), ChatColor.GREEN);
return true;
}
if(argument.equalsIgnoreCase("version")) {
MessageManager.getInstance().sendMessage(p, "Running PlayerParticles v" + PlayerParticles.getPlugin().getDescription().getVersion(), ChatColor.GOLD);
MessageManager.getInstance().sendMessage(p, "Plugin created by: Esophose", ChatColor.GOLD);
return true;
}
if(argument.equalsIgnoreCase("help")) {
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-available-commands", null, null), ChatColor.GREEN);
MessageManager.getInstance().sendMessage(p, "list, styles, style, worlds, version, help", ChatColor.AQUA);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null, null) + ChatColor.AQUA + " /pp <Command>", ChatColor.YELLOW);
return true;
}
if(argument.equalsIgnoreCase("list")) {
String toSend = MessageManager.getMessageFromConfig("message-use", null, null) + " ";
for(ParticleType effect : ParticleType.values()){
if(PermissionManager.hasPermission(p, effect)){
toSend = toSend + (effect.equals(ParticleType.RAINBOW) ? "rainbow" : effect.getName().toLowerCase()) + ", ";
continue;
}
}
if(toSend.equals(MessageManager.getMessageFromConfig("message-use", null, null) + " ")) {
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-no-particles", null, null), ChatColor.RED);
return true;
}
toSend = toSend + "clear";
MessageManager.getInstance().sendMessage(p, toSend, ChatColor.GREEN);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null, null) + ChatColor.AQUA + " /pp <Type>", ChatColor.YELLOW);
return true;
}
if(argument.equalsIgnoreCase("style")) {
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-invalid-type-style", null, null) + ChatColor.GREEN + " /pp styles", ChatColor.RED);
return true;
}
if(argument.equalsIgnoreCase("styles")) {
String toSend = MessageManager.getMessageFromConfig("message-use-style", null, null) + " ";
for(ParticleStyle style : ParticleStyle.values()){
if(PermissionManager.hasStylePermission(p, style)){
toSend = toSend + style.toString().toLowerCase();
toSend += ", ";
}
}
if(toSend.endsWith(", ")) {
toSend = toSend.substring(0, toSend.length() - 2);
}
if(toSend.equals(MessageManager.getMessageFromConfig("message-use-style", null, null) + " " + ParticleStyle.NONE.toString().toLowerCase())) {
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-no-styles", null, null), ChatColor.RED);
return true;
}
MessageManager.getInstance().sendMessage(p, toSend, ChatColor.GREEN);
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null, null) + ChatColor.AQUA + " /pp style <Type>", ChatColor.YELLOW);
return true;
}
MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-invalid-type", null, null) + ChatColor.GREEN + " /pp list", ChatColor.RED);
return true;
}
}

View file

@ -25,6 +25,8 @@ import org.bukkit.scheduler.BukkitRunnable;
import com.esophose.playerparticles.libraries.particles.ParticleEffect;
import com.esophose.playerparticles.libraries.particles.ParticleEffect.ParticleType;
import com.esophose.playerparticles.manager.ConfigManager;
import com.esophose.playerparticles.manager.PermissionManager;
public class ParticleCreator extends BukkitRunnable implements Listener {
@ -118,7 +120,7 @@ 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)) {
if(PermissionManager.hasStylePermission(e.getPlayer(), ParticleStyle.MOVE)) {
Location loc = e.getPlayer().getLocation();
loc.setY(loc.getY() + 1);
handleStyleNone(map.get(e.getPlayer().getName()), loc);
@ -243,7 +245,7 @@ public class ParticleCreator extends BukkitRunnable implements Listener {
for(Player player : Bukkit.getOnlinePlayers()){
if(!map.containsKey(player.getName()) || ConfigManager.getInstance().isWorldDisabled(player.getWorld().getName())) continue;
ParticleType effect = map.get(player.getName());
if(PermissionHandler.hasPermission(player, effect)){
if(PermissionManager.hasPermission(player, effect)){
Location loc = player.getLocation();
loc.setY(loc.getY() + 1);
displayParticle(effect, styleMap.get(player.getName()), loc);

View file

@ -17,15 +17,10 @@ import java.sql.SQLException;
import java.sql.Statement;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.esophose.playerparticles.libraries.databases.MySQL;
import com.esophose.playerparticles.libraries.particles.ParticleEffect.ParticleType;
import com.esophose.playerparticles.library.database.MySQL;
import com.esophose.playerparticles.updater.PluginUpdateListener;
import com.esophose.playerparticles.updater.Updater;
@ -54,6 +49,7 @@ public class PlayerParticles extends JavaPlugin {
* Makes sure the database is accessable
* Updates the map and styleMap @see ParticleCreator
* Starts the particle spawning task
* Registers the command executor
* Checks for any updates if checking is enabled in the config
*/
public void onEnable(){
@ -73,7 +69,8 @@ public class PlayerParticles extends JavaPlugin {
ParticleCreator.updateStyleMap();
startTasks();
// Check for an update
getCommand("pp").setExecutor(new ParticleCommandExecutor());
if(shouldCheckUpdates()) {
getLogger().info("[PlayerParticles] Checking for an update...");
Updater updater = new Updater(this, 82823, this.getFile(), Updater.UpdateType.NO_DOWNLOAD, false);
@ -128,7 +125,7 @@ public class PlayerParticles extends JavaPlugin {
getLogger().info("[PlayerParticles] Failed to connect to MySQL Database! Check to see if your config is correct!");
useMySQL = false;
}
}else{
} else {
useMySQL = false;
}
getLogger().info("[PlayerParticles] Using mySQL for data storage: " + useMySQL);
@ -140,136 +137,10 @@ public class PlayerParticles extends JavaPlugin {
*/
private void startTasks() {
double ticks = getConfig().getDouble("ticks-per-particle");
if(ticks == 0.5){
if(ticks == 0.5) {
new ParticleCreator().runTaskTimer(this, 20, 1);
new ParticleCreator().runTaskTimer(this, 20, 1);
}else
new ParticleCreator().runTaskTimer(this, 20, (long) ticks);
}
/**
* Called when a player does a command and continues if the command is /pp
* Executes all the commands and methods
* Does some sorcery
*
* Needs to be rewritten as a separate CommandManager
*
* @param sender Who executed the command
* @param cmd The command
* @param label The command label
* @param args The arguments following the command
* @return True if everything went as planned (should always be true)
*/
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(!(sender instanceof Player)) return true;
Player p = (Player) sender;
if(args.length == 1 && args[0].equalsIgnoreCase("worlds")) {
String worlds = "";
if(ConfigManager.getInstance().getDisabledWorlds() == null) {
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-disabled-worlds-none")).replace("&", "§"), ChatColor.GREEN);
}
for(String s : ConfigManager.getInstance().getDisabledWorlds()) {
worlds += s + ", ";
}
if(worlds.length() > 2) worlds = worlds.substring(0, worlds.length() - 2);
if(worlds.equals("")) {
worlds = ((String)getConfig().get("message-disabled-worlds-none")).replace("&", "§");
}else{
worlds = ((String)getConfig().get("message-disabled-worlds")).replace("&", "§") + " " + ChatColor.AQUA + worlds;
}
MessageManager.getInstance().sendMessage(p, worlds, ChatColor.GREEN);
return true;
}
if(args.length > 1 && args[0].equalsIgnoreCase("style")) {
String argument = args[1].replace("_", "");
if(ParticleStyle.styleFromString(argument) != null){
ParticleStyle style = ParticleStyle.styleFromString(argument);
if(!PermissionHandler.hasStylePermission(p, style)) {
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-no-permission-style")).replace("{STYLE}", ChatColor.AQUA + style.toString().toLowerCase() + ChatColor.RED).replace("&", "§"), ChatColor.RED);
return true;
}
ConfigManager.getStyleInstance().setStyle(style, p);
ParticleCreator.addStyleMap(p, style);
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-now-using-style")).replace("{STYLE}", ChatColor.AQUA + style.toString().toLowerCase() + ChatColor.GREEN).replace("&", "§"), ChatColor.GREEN);
return true;
}
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-invalid-type-style")).replace("&", "§") + ChatColor.GREEN + " /pp styles", ChatColor.RED);
return true;
}
if(args.length != 1){
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-invalid-arguments")).replace("&", "§") + ChatColor.GREEN + " /pp list", ChatColor.RED);
return true;
}
String argument = args[0].replace("_", "");
if(ParticleCreator.particleFromString(argument) != null){
ParticleType effect = ParticleCreator.particleFromString(argument);
if(!PermissionHandler.hasPermission(p, effect)){
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-no-permission")).replace("{PARTICLE}", ChatColor.AQUA + (effect.equals(ParticleType.RAINBOW) ? "rainbow" : effect.getName().toLowerCase() + ChatColor.RED)).replace("&", "§"), ChatColor.RED);
return true;
}
ConfigManager.getInstance().setParticle(effect, p);
ParticleCreator.addMap(p, effect);
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-now-using")).replace("{PARTICLE}", ChatColor.AQUA + (effect.equals(ParticleType.RAINBOW) ? "rainbow" : effect.getName().toLowerCase() + ChatColor.GREEN)).replace("&", "§"), ChatColor.GREEN);
return true;
}
if(argument.equalsIgnoreCase("clear")) {
ConfigManager.getInstance().resetParticle(p);
ParticleCreator.removeMap(p);
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-cleared-particles")).replace("&", "§"), ChatColor.GREEN);
return true;
}
if(argument.equalsIgnoreCase("version")) {
MessageManager.getInstance().sendMessage(p, "Running PlayerParticles v" + getDescription().getVersion(), ChatColor.GOLD);
MessageManager.getInstance().sendMessage(p, "Plugin created by: Esophose", ChatColor.GOLD);
return true;
}
if(argument.equalsIgnoreCase("help")) {
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-available-commands")).replace("&", "§"), ChatColor.GREEN);
MessageManager.getInstance().sendMessage(p, "list, styles, style, worlds, version, help", ChatColor.AQUA);
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-usage")).replace("&", "§") + ChatColor.AQUA + " /pp <Command>", ChatColor.YELLOW);
return true;
}
if(argument.equalsIgnoreCase("list")) {
String toSend = ((String)getConfig().get("message-use")).replace("&", "§") + " ";
for(ParticleType effect : ParticleType.values()){
if(PermissionHandler.hasPermission(p, effect)){
toSend = toSend + (effect.equals(ParticleType.RAINBOW) ? "rainbow" : effect.getName().toLowerCase()) + ", ";
continue;
}
}
if(toSend.equals(getConfig().get("message-use") + " ")){
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-no-particles")).replace("&", "§"), ChatColor.RED);
return true;
}
toSend = toSend + "clear";
MessageManager.getInstance().sendMessage(p, toSend, ChatColor.GREEN);
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-usage")).replace("&", "§") + ChatColor.AQUA + " /pp <Type>", ChatColor.YELLOW);
return true;
}
if(argument.equalsIgnoreCase("style")) {
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-invalid-type-style")).replace("&", "§") + ChatColor.GREEN + " /pp styles", ChatColor.RED);
return true;
}
if(argument.equalsIgnoreCase("styles")) {
String toSend = ((String)getConfig().get("message-use-style")).replace("&", "§") + " ";
for(ParticleStyle style : ParticleStyle.values()){
if(PermissionHandler.hasStylePermission(p, style)){
toSend = toSend + (style.toString().toLowerCase()) + ", ";
continue;
}
}
if(toSend.equals(((String)getConfig().get("message-use-style")).replace("&", "§") + " ")) {
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-no-styles")).replace("&", "§"), ChatColor.RED);
return true;
}
MessageManager.getInstance().sendMessage(p, toSend, ChatColor.GREEN);
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-usage")).replace("&", "§") + ChatColor.AQUA + " /pp style <Type>", ChatColor.YELLOW);
return true;
}
MessageManager.getInstance().sendMessage(p, ((String)getConfig().get("message-invalid-type")).replace("&", "§") + ChatColor.GREEN + " /pp list", ChatColor.RED);
return true;
} else new ParticleCreator().runTaskTimer(this, 20, (long) ticks);
}
}

View file

@ -73,35 +73,27 @@ public class ParticleEffect {
double v = 0;
if (!vString.isEmpty()){
String[] array = vString.split("_");
v = Double.parseDouble(array[0] + "." + array[1]);
v = Integer.parseInt(array[1]); // Take the second value to fix MC 1.10 looking like 1.1 and failing to be greater than 1.7
}
try {
if (v < 1.7) {
if (v < 7) { // Maintain support for versions below 1.6 (Probably doesn't even work)
netty = false;
packetClass = getNmsClass("Packet63WorldParticles");
packetConstructor = packetClass.getConstructor();
fields = packetClass.getDeclaredFields();
}
else {
} else { // Use the greater than 1.7 particle packet class
packetClass = getNmsClass("PacketPlayOutWorldParticles");
if (v < 1.8){
Bukkit.getLogger().info("[PlayerParticles] Server is < 1.8 - Falling back to old version");
packetConstructor = packetClass.getConstructor(String.class, float.class, float.class, float.class,
float.class, float.class, float.class, float.class, int.class);
}
else { // use the new constructor for 1.8
Bukkit.getLogger().info("[PlayerParticles] Server is >= 1.8 - Using new version");
if (v < 8){
packetConstructor = packetClass.getConstructor(String.class, float.class, float.class, float.class, float.class, float.class, float.class, float.class, int.class);
} else { // use the new constructor for 1.8
newParticlePacketConstructor = true;
enumParticle = (Class<Enum>)getNmsClass("EnumParticle");
packetConstructor = packetClass.getDeclaredConstructor(enumParticle, boolean.class, float.class,
float.class, float.class, float.class, float.class, float.class, float.class, int.class,
int[].class);
packetConstructor = packetClass.getDeclaredConstructor(enumParticle, boolean.class, float.class, float.class, float.class, float.class, float.class, float.class, float.class, int.class, int[].class);
}
}
}
catch (Exception ex){
} catch (Exception ex) {
ex.printStackTrace();
Bukkit.getLogger().severe("[ParticleLib] Failed to initialize NMS components!");
Bukkit.getLogger().severe("[PlayerParticles] Failed to initialize NMS components! This occurs if you are running the plugin on a version of Minecraft that is not supported!");
compatible = false;
}
}
@ -192,7 +184,7 @@ public class ParticleEffect {
}
/**
* Constructs a new particle packet.
* Constructs a new particle packet
* @param location the location to spawn the particle effect at
* @return the constructed packet
*/
@ -245,15 +237,15 @@ public class ParticleEffect {
}
catch (IllegalAccessException ex){
ex.printStackTrace();
Bukkit.getLogger().severe("[ParticleLib] Failed to construct particle effect packet!");
Bukkit.getLogger().severe("[PlayerParticles] Failed to construct particle effect packet!");
}
catch (InstantiationException ex){
ex.printStackTrace();
Bukkit.getLogger().severe("[ParticleLib] Failed to construct particle effect packet!");
Bukkit.getLogger().severe("[PlayerParticles] Failed to construct particle effect packet!");
}
catch (InvocationTargetException ex){
ex.printStackTrace();
Bukkit.getLogger().severe("[ParticleLib] Failed to construct particle effect packet!");
Bukkit.getLogger().severe("[PlayerParticles] Failed to construct particle effect packet!");
}
return null;
}
@ -281,15 +273,15 @@ public class ParticleEffect {
}
catch (IllegalAccessException ex){
ex.printStackTrace();
Bukkit.getLogger().severe("[ParticleLib] Failed to send packet!");
Bukkit.getLogger().severe("[PlayerParticles] Failed to send packet!");
}
catch (InvocationTargetException ex){
ex.printStackTrace();
Bukkit.getLogger().severe("[ParticleLib] Failed to send packet!");
Bukkit.getLogger().severe("[PlayerParticles] Failed to send packet!");
}
catch (NoSuchFieldException ex){
ex.printStackTrace();
Bukkit.getLogger().severe("[ParticleLib] Failed to send packet!");
Bukkit.getLogger().severe("[PlayerParticles] Failed to send packet!");
}
}
@ -328,7 +320,7 @@ public class ParticleEffect {
}
catch (ClassNotFoundException ex){
ex.printStackTrace();
Bukkit.getLogger().severe("[ParticleLib] Failed to load NMS class " + name + "!");
Bukkit.getLogger().severe("[PlayerParticles] Failed to load NMS class " + name + "!");
}
return clazz;
}
@ -345,15 +337,15 @@ public class ParticleEffect {
}
/**
* Gets whether ParticleLib is compatible with the server software.
* @return whether ParticleLib is compatible with the server software.
* Gets whether PlayerParticles is compatible with the server software.
* @return whether PlayerParticles is compatible with the server software.
*/
public static boolean isCompatible(){
return compatible;
}
/**
* Enum representing valid particle types in Minecraft 1.8
* Enum representing valid particle types in Minecraft 1.10 minus a few which are too similar or too spammy
*/
public enum ParticleType {

View file

@ -1,4 +1,4 @@
package com.esophose.playerparticles.libraries.databases;
package com.esophose.playerparticles.library.database;
import java.sql.Connection;
import java.sql.ResultSet;

View file

@ -1,4 +1,4 @@
package com.esophose.playerparticles.libraries.databases;
package com.esophose.playerparticles.library.database;
import java.sql.Connection;
import java.sql.DriverManager;

View file

@ -6,7 +6,7 @@
* be distributed to any person by any means.
*/
package com.esophose.playerparticles;
package com.esophose.playerparticles.manager;
import java.io.File;
import java.io.IOException;
@ -19,6 +19,9 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import com.esophose.playerparticles.ParticleCreator;
import com.esophose.playerparticles.ParticleStyle;
import com.esophose.playerparticles.PlayerParticles;
import com.esophose.playerparticles.libraries.particles.ParticleEffect.ParticleType;
public class ConfigManager {

View file

@ -0,0 +1,82 @@
/**
* 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.manager;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.esophose.playerparticles.PlayerParticles;
public class MessageManager {
/**
* The instance of the MessageManager, we only need one of these
*/
private static MessageManager instance = new MessageManager();
/**
* Values contained in the config used for custom messages
*/
private boolean messagesEnabled, prefixEnabled;
/**
* The prefix to place before all sent messages contained in the config
*/
private String messagePrefix;
/**
* Sets up all the above variables with values from the plugin config
*/
private MessageManager() {
this.messagesEnabled = PlayerParticles.getPlugin().getConfig().getBoolean("messages-enabled");
this.prefixEnabled = PlayerParticles.getPlugin().getConfig().getBoolean("use-message-prefix");
this.messagePrefix = PlayerParticles.getPlugin().getConfig().getString("message-prefix");
this.messagePrefix = this.messagePrefix.replace("&", "§");
}
/**
* Gets the instance of the MessageManager
*
* @return The instance of the MessageManager
*/
public static MessageManager getInstance() {
return instance;
}
/**
* Sends a message to a player
*
* @param player The player to send the message to
* @param message The message to send to the player
* @param color The chat color to put before the message
*/
public void sendMessage(Player player, String message, ChatColor color) {
if(!this.messagesEnabled) return;
if(this.prefixEnabled) {
message = this.messagePrefix + color + " " + message;
}else{
message = color + message;
}
player.sendMessage(message);
}
/**
* Gets a message from the config with the formatting specified
*
* @param target The string to find in the config
* @param particleReplacement The replacement for {PARTICLE}, can be null
* @param styleReplacement The replacement for {STYLE}, can be null
* @return The message requested with the applied formatting
*/
public static String getMessageFromConfig(String target, String particleReplacement, String styleReplacement) {
String message = ChatColor.translateAlternateColorCodes('&', PlayerParticles.getPlugin().getConfig().getString(target));
if(particleReplacement != null) message = message.replaceAll("\\{PARTICLE\\}", particleReplacement);
if(styleReplacement != null) message = message.replaceAll("\\{STYLE\\}", styleReplacement);
return message;
}
}

View file

@ -6,16 +6,17 @@
* be distributed to any person by any means.
*/
package com.esophose.playerparticles;
package com.esophose.playerparticles.manager;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import com.esophose.playerparticles.ParticleStyle;
import com.esophose.playerparticles.libraries.particles.ParticleEffect.ParticleType;
public class PermissionHandler {
public class PermissionManager {
/**
* Checks if a player has permission to use an effect

View file

@ -13,8 +13,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import com.esophose.playerparticles.MessageManager;
import com.esophose.playerparticles.PlayerParticles;
import com.esophose.playerparticles.manager.MessageManager;
public class PluginUpdateListener implements Listener {

View file

@ -11,7 +11,7 @@
# ====================================================#
# DO NOT CHANGE THIS UNDER ANY CIRCUMSTANCE (Will reset your config)
version: 3.8
version: 3.9
# There are 20 minecraft ticks per second
# The default value of 1 means a particle will be displayed once every tick

View file

@ -1,6 +1,6 @@
name: PlayerParticles
main: com.esophose.playerparticles.PlayerParticles
version: 3.8
version: 3.9
description: Make particles around players.
author: Esophose
website: http://dev.bukkit.org/bukkit-plugins/playerparticles/