Add new styles

Add five new event-based styles, make it so the message manager doesn't
have an extra system.out.println, fix a somewhat critical bug with fixed
effect clear permissions, make it so the ParticleStyleManager doesn't
absolutely break the plugin if somebody registers a style incorrectly in
an extension plugin.
This commit is contained in:
Esophose 2018-03-04 03:02:02 -07:00
parent 95a400a42c
commit e47da74d22
15 changed files with 374 additions and 80 deletions

View file

@ -524,7 +524,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
args = cmdArgs;
if (cmd.equalsIgnoreCase("create")) {
String[] f_args = args;
final String[] f_args = args;
ConfigManager.getInstance().hasPlayerReachedMaxFixedEffects(p.getUniqueId(), (reachedMax) -> {
if (reachedMax) {
MessageManager.sendMessage(p, MessageType.MAX_FIXED_EFFECTS_REACHED);
@ -815,7 +815,8 @@ public class ParticleCommandExecutor implements CommandExecutor {
ArrayList<FixedParticleEffect> fixedEffectsToRemove = new ArrayList<FixedParticleEffect>();
for (FixedParticleEffect fixedEffect : ParticleManager.fixedParticleEffects)
if (fixedEffect.getLocation().getWorld() == p.getLocation().getWorld() && fixedEffect.getLocation().distance(p.getLocation()) <= radius) fixedEffectsToRemove.add(fixedEffect);
if (fixedEffect.getLocation().getWorld() == p.getLocation().getWorld() && fixedEffect.getLocation().distance(p.getLocation()) <= radius)
fixedEffectsToRemove.add(fixedEffect);
for (FixedParticleEffect fixedEffect : fixedEffectsToRemove)
ConfigManager.getInstance().removeFixedEffect(fixedEffect.getOwnerUniqueId(), fixedEffect.getId(), (successful) -> { });

View file

@ -7,37 +7,35 @@
*/
/*
* TODO: v5
* + Add new style 'tornado'
* + Add new style 'fairy'
* + Add new style 'atom'
* + Add new style 'rings'
* + Add new style 'jump'
* + Add new style 'blockbreak'
* + Add new style 'blockplace'
* + Add new style 'hurt'
* + Add new style 'swords'
* + Make database queries async
* TODO: v5.1
* + Command to force set an effect/style for a player
* + Tab completion for fixed effects
* + Add new style 'tornado'
* + Add new style 'companion'
* + Add new style 'atom'
* + Add new style 'rings'
*/
/*
* Changelog v5:
* + Added GUI. Opens with /pp or /pp gui. Icons and messages are completely customizable from the config.
* + Added a GUI. Opens with /pp or /pp gui. Icons and messages are completely customizable from the config.
* + Added a way to disable the GUI, because I know somebody will ask
* + Added new style 'wings'
* + Added new style 'sphere'
* - Minecraft 1.7 and 1.8 are no longer supported. There is no reason to still be on a version that old.
* Fixed a bug where typing /pp data when you haven't been added to the playerData.yml/database yet threw an error
* Switched over to the Spigot Particle API
* Plugin is now built against Java 1.8.0_161 and Spigot 1.9.4
* Servers running Java 7 are no longer supported. Please upgrade to Java 8 if you haven't yet.
* Rewrote database connection system, should fix any memory leaks from before
* Reduced particle render distance from 512 to 192 (12 chunks), you won't notice a difference
* Database management should no longer contain memory leaks
* Fixed missing command 'fixed' from '/pp help' list
* Fixed missing command 'fixed' from tab completion
* + Added new style 'hurt'
* + Added new style 'swords'
* + Added new style 'blockbreak'
* + Added new style 'blockplace'
* + Added new style 'blockedit'
* - Minecraft 1.7 and 1.8 are no longer supported, there is no reason to still be on a version that old
* - Servers running Java 7 are no longer supported, please upgrade to Java 8 if you haven't yet
* * Fixed a bug where typing /pp data when you haven't been added to the playerData.yml/database yet threw an error
* * Switched over to the Spigot Particle API
* * Plugin is now built against Java 1.8.0_161 and Spigot 1.9.4-R0.1
* * Rewrote database connection system, should fix any memory leaks from before
* * Reduced particle render distance from 512 to 192 (12 chunks), you won't notice a difference
* * Fixed missing command 'fixed' from '/pp help' list
* * Fixed missing command 'fixed' from tab completion
*/
package com.esophose.playerparticles;

View file

@ -122,16 +122,12 @@ public class MessageManager {
* @param config The config to pull the message from
*/
protected void setMessage(FileConfiguration config) {
try {
String messageFromConfig = config.getString(configLocation);
if (messageFromConfig == null || messageFromConfig.length() == 0) {
messageFromConfig = "&cMissing message in config.yml. Contact a server administrator.";
PlayerParticles.getPlugin().getLogger().warning("Missing message in config.yml: " + this.configLocation);
}
this.message = ChatColor.translateAlternateColorCodes('&', messageFromConfig);
} catch (Exception ex) {
System.out.println(this.name());
String messageFromConfig = config.getString(configLocation);
if (messageFromConfig == null || messageFromConfig.length() == 0) {
messageFromConfig = "&cMissing message in config.yml. Contact a server administrator.";
PlayerParticles.getPlugin().getLogger().warning("Missing message in config.yml: " + this.configLocation);
}
this.message = ChatColor.translateAlternateColorCodes('&', messageFromConfig);
}
/**

View file

@ -85,7 +85,7 @@ public class PermissionManager {
* @return True if the player has permission
*/
public static boolean canUseForceReset(Player player) {
return player.hasPermission("playerparticles.*") || player.hasPermission("playerparticles.forcereset");
return player.hasPermission("playerparticles.forcereset");
}
/**
@ -98,15 +98,4 @@ public class PermissionManager {
return player.hasPermission("playerparticles.*") || player.hasPermission("playerparticles.fixed");
}
/**
* Checks if a player has permission to open the GUI
* Access is restricted if they have the following permission
*
* @param player The player to check the permission for
* @return False if the player's access to the GUI is revoked
*/
public static boolean canUseGui(Player player) {
return !player.hasPermission("playerparticles.gui.revoke");
}
}

View file

@ -2,6 +2,8 @@ package com.esophose.playerparticles.styles;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.esophose.playerparticles.PlayerParticles;
import com.esophose.playerparticles.styles.api.ParticleStyle;
@ -27,6 +29,11 @@ public class DefaultStyles {
public static final ParticleStyle THICK = new ParticleStyleThick();
public static final ParticleStyle WINGS = new ParticleStyleWings();
public static final ParticleStyle SPHERE = new ParticleStyleSphere();
public static final ParticleStyle SWORDS = new ParticleStyleSwords();
public static final ParticleStyle HURT = new ParticleStyleHurt();
public static final ParticleStyle BLOCKPLACE = new ParticleStyleBlockPlace();
public static final ParticleStyle BLOCKBREAK = new ParticleStyleBlockBreak();
public static final ParticleStyle BLOCKEDIT = new ParticleStyleBlockEdit();
/**
* Registers all the default styles to the ParticleStyleManager
@ -47,9 +54,21 @@ public class DefaultStyles {
ParticleStyleManager.registerStyle(THICK);
ParticleStyleManager.registerStyle(WINGS);
ParticleStyleManager.registerStyle(SPHERE);
ParticleStyleManager.registerCustomHandledStyle(SWORDS);
ParticleStyleManager.registerCustomHandledStyle(HURT);
ParticleStyleManager.registerCustomHandledStyle(BLOCKPLACE);
ParticleStyleManager.registerCustomHandledStyle(BLOCKBREAK);
ParticleStyleManager.registerCustomHandledStyle(BLOCKEDIT);
Bukkit.getPluginManager().registerEvents((Listener) MOVE, PlayerParticles.getPlugin());
Bukkit.getPluginManager().registerEvents((Listener) ARROWS, PlayerParticles.getPlugin());
PluginManager manager = Bukkit.getPluginManager();
Plugin playerParticles = PlayerParticles.getPlugin();
manager.registerEvents((Listener) MOVE, playerParticles);
manager.registerEvents((Listener) ARROWS, playerParticles);
manager.registerEvents((Listener) SWORDS, playerParticles);
manager.registerEvents((Listener) HURT, playerParticles);
manager.registerEvents((Listener) BLOCKPLACE, playerParticles);
manager.registerEvents((Listener) BLOCKBREAK, playerParticles);
manager.registerEvents((Listener) BLOCKEDIT, playerParticles);
}
}

View file

@ -0,0 +1,53 @@
package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.manager.ConfigManager;
import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleBlockBreak implements ParticleStyle, Listener {
public PParticle[] getParticles(PPlayer pplayer, Location location) {
List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < 15; i++)
particles.add(new PParticle(location.clone().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.05F));
return particles.toArray(new PParticle[particles.size()]);
}
public void updateTimers() {
}
public String getName() {
return "blockbreak";
}
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKBREAK && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKBREAK)) {
Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKBREAK.getParticles(pplayer, loc));
}
}
}

View file

@ -0,0 +1,56 @@
package com.esophose.playerparticles.styles;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.manager.ConfigManager;
import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleBlockEdit implements ParticleStyle, Listener {
public PParticle[] getParticles(PPlayer pplayer, Location location) {
return new PParticle[0]; // Particles are taken from DefaultStyles.BLOCKPLACE or DefaultStyles.BLOCKBREAK
}
public void updateTimers() {
}
public String getName() {
return "blockedit";
}
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKEDIT && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKEDIT)) {
Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKBREAK.getParticles(pplayer, loc));
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKEDIT && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKEDIT)) {
Location loc = event.getBlockPlaced().getLocation();
ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKPLACE.getParticles(pplayer, loc));
}
}
}

View file

@ -0,0 +1,53 @@
package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.manager.ConfigManager;
import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleBlockPlace implements ParticleStyle, Listener {
public PParticle[] getParticles(PPlayer pplayer, Location location) {
List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < 15; i++)
particles.add(new PParticle(location.clone().add(0.5, 0.5, 0.5), 0.75F, 0.75F, 0.75F, 0.05F));
return particles.toArray(new PParticle[particles.size()]);
}
public void updateTimers() {
}
public String getName() {
return "blockplace";
}
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKPLACE && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKPLACE)) {
Location loc = event.getBlockPlaced().getLocation();
ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKPLACE.getParticles(pplayer, loc));
}
}
}

View file

@ -0,0 +1,55 @@
package com.esophose.playerparticles.styles;
import org.bukkit.Location;
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 com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.manager.ConfigManager;
import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleHurt implements ParticleStyle, Listener {
public PParticle[] getParticles(PPlayer pplayer, Location location) {
PParticle[] baseParticles = DefaultStyles.THICK.getParticles(pplayer, location);
int multiplyingFactor = 3; // Uses the same logic as ParticleStyleThick except multiplies the resulting particles by 3x
PParticle[] particles = new PParticle[baseParticles.length * multiplyingFactor];
for (int i = 0; i < baseParticles.length * multiplyingFactor; i++) {
particles[i] = baseParticles[i % baseParticles.length];
}
return particles;
}
public void updateTimers() {
}
public String getName() {
return "hurt";
}
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.HURT && PermissionManager.hasStylePermission(player, DefaultStyles.HURT)) {
Location loc = player.getLocation().clone().add(0, 1, 0);
ParticleManager.displayParticles(pplayer, DefaultStyles.HURT.getParticles(pplayer, loc));
}
}
}
}

View file

@ -2,6 +2,7 @@ package com.esophose.playerparticles.styles;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
@ -9,19 +10,28 @@ import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.manager.ConfigManager;
import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleMove extends ParticleStyleNone implements Listener {
public class ParticleStyleMove implements ParticleStyle, Listener {
public PParticle[] getParticles(PPlayer pplayer, Location location) {
return DefaultStyles.NONE.getParticles(pplayer, location);
}
public void updateTimers() {
}
public String getName() {
return "move";
}
/**
* The event used to update the move style
*
* @param e The event
*/
@EventHandler
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerMove(PlayerMoveEvent e) {
PPlayer pplayer = ConfigManager.getInstance().getPPlayer(e.getPlayer().getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.MOVE) {
@ -33,8 +43,4 @@ public class ParticleStyleMove extends ParticleStyleNone implements Listener {
}
}
public boolean canBeFixed() {
return false;
}
}

View file

@ -0,0 +1,70 @@
package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
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.EntityDamageByEntityEvent;
import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.manager.ConfigManager;
import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleSwords implements ParticleStyle, Listener {
private static final List<String> SWORD_NAMES;
static {
SWORD_NAMES = new ArrayList<String>();
SWORD_NAMES.addAll(Arrays.asList("WOOD_SWORD", "STONE_SWORD", "IRON_SWORD", "GOLD_SWORD", "DIAMOND_SWORD"));
}
public PParticle[] getParticles(PPlayer pplayer, Location location) {
PParticle[] baseParticles = DefaultStyles.THICK.getParticles(pplayer, location);
int multiplyingFactor = 3; // Uses the same logic as ParticleStyleThick except multiplies the resulting particles by 3x
PParticle[] particles = new PParticle[baseParticles.length * multiplyingFactor];
for (int i = 0; i < baseParticles.length * multiplyingFactor; i++) {
particles[i] = baseParticles[i % baseParticles.length];
}
return particles;
}
public void updateTimers() {
}
public String getName() {
return "swords";
}
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDamageEntity(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity) {
Player player = (Player) event.getDamager();
LivingEntity entity = (LivingEntity) event.getEntity();
PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.SWORDS && PermissionManager.hasStylePermission(player, DefaultStyles.SWORDS)) {
if (player.getInventory().getItemInMainHand() != null && SWORD_NAMES.contains(player.getInventory().getItemInMainHand().getType().name())) {
Location loc = entity.getLocation().clone().add(0, 1, 0);
ParticleManager.displayParticles(pplayer, DefaultStyles.SWORDS.getParticles(pplayer, loc));
}
}
}
}
}

View file

@ -4,11 +4,12 @@ import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleThick extends ParticleStyleNone {
public class ParticleStyleThick implements ParticleStyle {
public PParticle[] getParticles(PPlayer pplayer, Location location) {
PParticle[] baseParticles = super.getParticles(pplayer, location);
PParticle[] baseParticles = DefaultStyles.NONE.getParticles(pplayer, location);
int multiplyingFactor = 15; // Uses the same logic as ParticleStyleNone except multiplies the resulting particles by 15x
PParticle[] particles = new PParticle[baseParticles.length * multiplyingFactor];
@ -27,4 +28,8 @@ public class ParticleStyleThick extends ParticleStyleNone {
return "thick";
}
public boolean canBeFixed() {
return true;
}
}

View file

@ -13,7 +13,7 @@ import com.esophose.playerparticles.util.VectorUtils;
public class ParticleStyleWings implements ParticleStyle {
int spawnTimer = 0; // Spawn particles every 3 ticks
private int spawnTimer = 0; // Spawn particles every 3 ticks
public PParticle[] getParticles(PPlayer pplayer, Location location) {
List<PParticle> particles = new ArrayList<PParticle>();

View file

@ -10,6 +10,8 @@ package com.esophose.playerparticles.styles.api;
import java.util.ArrayList;
import com.esophose.playerparticles.PlayerParticles;
public class ParticleStyleManager {
/**
@ -26,9 +28,9 @@ public class ParticleStyleManager {
public static void registerStyle(ParticleStyle style) {
for (ParticleStyle testAgainst : styles) {
if (testAgainst.getName().replace("_", "").equalsIgnoreCase(style.getName())) {
throw new ParticleStyleAlreadyRegisteredException("Tried to register two styles with the same name!");
PlayerParticles.getPlugin().getLogger().severe("Tried to register two styles with the same (or too similar) name: " + style.getName());
} else if (testAgainst.equals(style)) {
throw new ParticleStyleAlreadyRegisteredException("Tried to register the same style twice!");
PlayerParticles.getPlugin().getLogger().severe("Tried to register the same style twice: " + style.getName());
}
}
styles.add(style);
@ -85,17 +87,4 @@ public class ParticleStyleManager {
style.updateTimers();
}
/**
* The exception to throw if a style is already registered
*/
private static final class ParticleStyleAlreadyRegisteredException extends RuntimeException {
private static final long serialVersionUID = -6116170395810178020L;
private ParticleStyleAlreadyRegisteredException(String message) {
super(message);
}
}
}

View file

@ -475,9 +475,8 @@ database-user-password: ''
# icons to whatever block/item you want. #
# #
# Important Notes: #
# * If any of the block/item names are invalid it will notify you #
# in console and the icon in the GUI will be the barrier icon to #
# show that it failed to load. #
# * If any of the block/item names are invalid the icon in the GUI #
# will be the barrier icon to show that it failed to load. #
# * Do NOT change the particle/style name #
# * You MUST use the Spigot-given name for it to work. You can see #
# all the Spigot-given names at the link below: #
@ -552,6 +551,11 @@ gui-icon:
THICK: VINE
WINGS: ELYTRA
SPHERE: SNOW_BALL
SWORDS: IRON_SWORD
HURT: CACTUS
BLOCKPLACE: WOOD
BLOCKBREAK: IRON_PICKAXE
BLOCKEDIT: DISPENSER
# That's everything! You reached the end of the configuration.