Pom updates, allow reload command to work in console

This commit is contained in:
Esophose 2019-07-16 01:32:45 -06:00
parent ed7e2937a9
commit 063de34095
26 changed files with 143 additions and 61 deletions

13
pom.xml
View file

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.esophose.playerparticles</groupId> <groupId>com.esophose.playerparticles</groupId>
<artifactId>PlayerParticles</artifactId> <artifactId>PlayerParticles</artifactId>
<version>6.4</version> <version>6.5</version>
<name>PlayerParticles</name> <name>PlayerParticles</name>
<url>https://github.com/Esophose/PlayerParticles</url> <url>https://github.com/Esophose/PlayerParticles</url>
<description>Display particles around your player and blocks using customized styles and data!</description> <description>Display particles around your player and blocks using customized styles and data!</description>
@ -11,10 +11,19 @@
<resources> <resources>
<resource> <resource>
<directory>src</directory> <directory>src</directory>
<filtering>false</filtering>
<excludes> <excludes>
<exclude>**/*.java</exclude> <exclude>**/*.java</exclude>
<exclude>**/*.yml</exclude>
</excludes> </excludes>
</resource> </resource>
<resource>
<directory>src</directory>
<filtering>true</filtering>
<includes>
<include>**/*.yml</include>
</includes>
</resource>
</resources> </resources>
<plugins> <plugins>
<plugin> <plugin>
@ -101,7 +110,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.14-R0.1-SNAPSHOT</version> <version>1.14.3-R0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -203,4 +203,8 @@ public class AddCommandModule implements CommandModule {
return true; return true;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -53,6 +53,11 @@ public interface CommandModule {
*/ */
boolean requiresEffects(); boolean requiresEffects();
/**
* @return true if this command can be executed from console, otherwise false
*/
boolean canConsoleExecute();
/** /**
* Displays a command's usage to the player * Displays a command's usage to the player
* *

View file

@ -67,4 +67,8 @@ public class DataCommandModule implements CommandModule {
return true; return true;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -16,7 +16,7 @@ public class DefaultCommandModule implements CommandModule {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
List<String> matches = new ArrayList<String>(); List<String> matches = new ArrayList<>();
List<String> commandNames = ParticleCommandHandler.getCommandNames(); List<String> commandNames = ParticleCommandHandler.getCommandNames();
if (args.length == 0) return commandNames; if (args.length == 0) return commandNames;
@ -42,4 +42,8 @@ public class DefaultCommandModule implements CommandModule {
return true; return true;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -314,4 +314,8 @@ public class EditCommandModule implements CommandModule {
return true; return true;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -53,4 +53,8 @@ public class EffectsCommandModule implements CommandModule {
return false; return false;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -793,4 +793,8 @@ public class FixedCommandModule implements CommandModule {
return true; return true;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -62,4 +62,8 @@ public class GUICommandModule implements CommandModule {
return true; return true;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -315,4 +315,8 @@ public class GroupCommandModule implements CommandModule {
return false; return false;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -38,4 +38,8 @@ public class HelpCommandModule implements CommandModule {
return false; return false;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -50,4 +50,8 @@ public class ListCommandModule implements CommandModule {
return true; return true;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.esophose.playerparticles.particles.OtherPPlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -96,27 +97,32 @@ public class ParticleCommandHandler implements CommandExecutor, TabCompleter {
*/ */
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("pp")) { if (cmd.getName().equalsIgnoreCase("pp")) {
if (!(sender instanceof Player)) { String commandName = args.length > 0 ? args[0] : "";
sender.sendMessage(ChatColor.RED + "Error: This command can only be executed by a player."); CommandModule commandModule = findMatchingCommand(commandName);
if (commandModule == null) {
sender.sendMessage(LangManager.getText(Lang.COMMAND_ERROR_UNKNOWN));
return true;
}
String[] cmdArgs = args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0];
if (!commandModule.canConsoleExecute()) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Error: This command can only be executed by a player.");
return true;
}
} else {
commandModule.onCommandExecute(new OtherPPlayer(sender), cmdArgs);
return true; return true;
} }
Player p = (Player) sender; Player p = (Player) sender;
DataManager.getPPlayer(p.getUniqueId(), (pplayer) -> { DataManager.getPPlayer(p.getUniqueId(), (pplayer) -> {
String commandName = args.length > 0 ? args[0] : ""; if (commandModule.requiresEffects() && PermissionManager.getEffectNamesUserHasPermissionFor(p).isEmpty()) {
CommandModule commandModule = findMatchingCommand(commandName); LangManager.sendMessage(pplayer, Lang.COMMAND_ERROR_NO_EFFECTS);
if (commandModule != null) {
if (commandModule.requiresEffects() && PermissionManager.getEffectNamesUserHasPermissionFor(p).isEmpty()) {
LangManager.sendMessage(pplayer, Lang.COMMAND_ERROR_NO_EFFECTS);
} else {
String[] cmdArgs = new String[0];
if (args.length > 1) cmdArgs = Arrays.copyOfRange(args, 1, args.length);
commandModule.onCommandExecute(pplayer, cmdArgs);
}
} else { } else {
LangManager.sendMessage(pplayer, Lang.COMMAND_ERROR_UNKNOWN); commandModule.onCommandExecute(pplayer, cmdArgs);
} }
}); });
} else if (cmd.getName().equalsIgnoreCase("ppo")) { } else if (cmd.getName().equalsIgnoreCase("ppo")) {

View file

@ -12,7 +12,7 @@ import com.esophose.playerparticles.particles.PPlayer;
public class ReloadCommandModule implements CommandModule { public class ReloadCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
if (PermissionManager.canReloadPlugin(pplayer.getPlayer())) { if (PermissionManager.canReloadPlugin(pplayer.getMessageDestination())) {
PlayerParticles.getPlugin().reload(false); PlayerParticles.getPlugin().reload(false);
LangManager.sendMessage(pplayer, Lang.RELOAD_SUCCESS); LangManager.sendMessage(pplayer, Lang.RELOAD_SUCCESS);
PlayerParticles.getPlugin().getLogger().info("Reloaded configuration."); PlayerParticles.getPlugin().getLogger().info("Reloaded configuration.");
@ -41,4 +41,8 @@ public class ReloadCommandModule implements CommandModule {
return false; return false;
} }
public boolean canConsoleExecute() {
return true;
}
} }

View file

@ -130,4 +130,8 @@ public class RemoveCommandModule implements CommandModule {
return true; return true;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -37,4 +37,8 @@ public class ResetCommandModule implements CommandModule {
return false; return false;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -48,4 +48,8 @@ public class StylesCommandModule implements CommandModule {
return false; return false;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -41,4 +41,8 @@ public class ToggleCommandModule implements CommandModule {
return false; return false;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -37,4 +37,8 @@ public class VersionCommandModule implements CommandModule {
return false; return false;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -45,4 +45,8 @@ public class WorldsCommandModule implements CommandModule {
return false; return false;
} }
public boolean canConsoleExecute() {
return false;
}
} }

View file

@ -1,14 +1,5 @@
package com.esophose.playerparticles.manager; package com.esophose.playerparticles.manager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.scheduler.BukkitRunnable;
import com.esophose.playerparticles.PlayerParticles; import com.esophose.playerparticles.PlayerParticles;
import com.esophose.playerparticles.particles.FixedParticleEffect; import com.esophose.playerparticles.particles.FixedParticleEffect;
import com.esophose.playerparticles.particles.PPlayer; import com.esophose.playerparticles.particles.PPlayer;
@ -19,6 +10,14 @@ import com.esophose.playerparticles.particles.ParticleGroup;
import com.esophose.playerparticles.particles.ParticlePair; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.util.ParticleUtils; import com.esophose.playerparticles.util.ParticleUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/** /**
* All data changes to PPlayers such as group or fixed effect changes must be done through here, * All data changes to PPlayers such as group or fixed effect changes must be done through here,
@ -55,6 +54,7 @@ public class DataManager {
* @param callback The callback to execute with the found pplayer, or a newly generated one * @param callback The callback to execute with the found pplayer, or a newly generated one
*/ */
public static void getPPlayer(UUID playerUUID, ConfigurationCallback<PPlayer> callback) { public static void getPPlayer(UUID playerUUID, ConfigurationCallback<PPlayer> callback) {
// Try to get them from cache first // Try to get them from cache first
PPlayer fromCache = getPPlayer(playerUUID); PPlayer fromCache = getPPlayer(playerUUID);
if (fromCache != null) { if (fromCache != null) {
@ -471,12 +471,8 @@ public class DataManager {
* *
* @param asyncCallback The callback to run on a separate thread * @param asyncCallback The callback to run on a separate thread
*/ */
private static void async(SyncInterface asyncCallback) { private static void async(Runnable asyncCallback) {
new BukkitRunnable() { Bukkit.getScheduler().runTaskAsynchronously(PlayerParticles.getPlugin(), asyncCallback);
public void run() {
asyncCallback.execute();
}
}.runTaskAsynchronously(PlayerParticles.getPlugin());
} }
/** /**
@ -484,20 +480,8 @@ public class DataManager {
* *
* @param syncCallback The callback to run on the main thread * @param syncCallback The callback to run on the main thread
*/ */
private static void sync(SyncInterface syncCallback) { private static void sync(Runnable syncCallback) {
new BukkitRunnable() { Bukkit.getScheduler().runTask(PlayerParticles.getPlugin(), syncCallback);
public void run() {
syncCallback.execute();
}
}.runTask(PlayerParticles.getPlugin());
}
/**
* Provides an easy way to run a section of code either synchronously or asynchronously using a callback
*/
@FunctionalInterface
private interface SyncInterface {
void execute();
} }
/** /**

View file

@ -12,6 +12,7 @@ import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.styles.DefaultStyles; import com.esophose.playerparticles.styles.DefaultStyles;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.styles.api.ParticleStyleManager; import com.esophose.playerparticles.styles.api.ParticleStyleManager;
import org.bukkit.permissions.Permissible;
public class PermissionManager { public class PermissionManager {
@ -42,24 +43,24 @@ public class PermissionManager {
} }
/** /**
* Checks if a Player has a PlayerParticles permission * Checks if a Permissible has a PlayerParticles permission
* *
* @param p The Player * @param p The Permissible
* @return True if the Player has permission * @return True if the Player has permission
*/ */
public boolean check(Player p) { public boolean check(Permissible p) {
String permission = PERMISSION_PREFIX + this.permissionString; String permission = PERMISSION_PREFIX + this.permissionString;
return p.hasPermission(permission); return p.hasPermission(permission);
} }
/** /**
* Checks if a Player has a PlayerParticles permission with a sub-permission * Checks if a Permissible has a PlayerParticles permission with a sub-permission
* *
* @param p The Player * @param p The Permissibhle
* @param subPermission The sub-permission * @param subPermission The sub-permission
* @return True if the Player has permission * @return True if the Player has permission
*/ */
public boolean check(Player p, String subPermission) { public boolean check(Permissible p, String subPermission) {
String permission = PERMISSION_PREFIX + this.permissionString + '.' + subPermission; String permission = PERMISSION_PREFIX + this.permissionString + '.' + subPermission;
return p.hasPermission(permission); return p.hasPermission(permission);
} }
@ -77,7 +78,7 @@ public class PermissionManager {
*/ */
public static boolean canOverride(CommandSender sender) { public static boolean canOverride(CommandSender sender) {
if (!(sender instanceof Player)) return true; if (!(sender instanceof Player)) return true;
return PPermission.ALL.check((Player)sender); return PPermission.ALL.check(sender);
} }
/** /**
@ -286,11 +287,11 @@ public class PermissionManager {
/** /**
* Checks if a player has permission to use /pp reload * Checks if a player has permission to use /pp reload
* *
* @param player The player to check the permission for * @param sender The sender to check the permission for
* @return True if the player has permission to reload the plugin's settings * @return True if the sender has permission to reload the plugin's settings
*/ */
public static boolean canReloadPlugin(Player player) { public static boolean canReloadPlugin(CommandSender sender) {
return PPermission.ALL.check(player) || PPermission.RELOAD.check(player); return PPermission.ALL.check(sender) || PPermission.RELOAD.check(sender);
} }
} }

View file

@ -2,10 +2,19 @@ package com.esophose.playerparticles.particles;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.UUID;
public class OtherPPlayer extends PPlayer { public class OtherPPlayer extends PPlayer {
private CommandSender sender; private CommandSender sender;
public OtherPPlayer(CommandSender sender) {
super(UUID.randomUUID(), new ArrayList<>(), new ArrayList<>(), false);
this.sender = sender;
}
public OtherPPlayer(CommandSender sender, PPlayer other) { public OtherPPlayer(CommandSender sender, PPlayer other) {
super(other.getUniqueId(), other.getParticleGroups(), other.getFixedParticles(), !other.canSeeParticles()); super(other.getUniqueId(), other.getParticleGroups(), other.getFixedParticles(), !other.canSeeParticles());

View file

@ -88,7 +88,7 @@ public enum ParticleEffect {
UNDERWATER("SUSPENDED_DEPTH", "SUSPENDED_DEPTH"), UNDERWATER("SUSPENDED_DEPTH", "SUSPENDED_DEPTH"),
WITCH("SPELL_WITCH", "SPELL_WTICH"); WITCH("SPELL_WITCH", "SPELL_WTICH");
public static boolean VERSION_13; // This is a particle unique to Minecraft 1.13, this is a reliable way of telling what server version is running public static boolean VERSION_13;
private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<>(); private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<>();
private static Constructor<?> DustOptions_CONSTRUCTOR; private static Constructor<?> DustOptions_CONSTRUCTOR;
private static Method createBlockData_METHOD; private static Method createBlockData_METHOD;

View file

@ -13,7 +13,7 @@
# This value is the version of the plugin that last modified the config file # This value is the version of the plugin that last modified the config file
# Changing this value manually will likely result in data loss and errors! # Changing this value manually will likely result in data loss and errors!
# Do not change this manually unless specifically told to by the plugin author # Do not change this manually unless specifically told to by the plugin author
version: 6.4 version: ${project.version}
# Check for new versions of the plugin # Check for new versions of the plugin
# Default: true # Default: true

View file

@ -1,6 +1,6 @@
name: PlayerParticles name: PlayerParticles
main: com.esophose.playerparticles.PlayerParticles main: com.esophose.playerparticles.PlayerParticles
version: 6.4 version: ${project.version}
api-version: 1.13 api-version: 1.13
description: Display particles around your player and blocks using customized styles and data! description: Display particles around your player and blocks using customized styles and data!
author: Esophose author: Esophose