Skip to content

Commit

Permalink
Pom updates, allow reload command to work in console
Browse files Browse the repository at this point in the history
  • Loading branch information
Esophose committed Jul 16, 2019
1 parent ed7e293 commit 063de34
Show file tree
Hide file tree
Showing 26 changed files with 143 additions and 61 deletions.
13 changes: 11 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.esophose.playerparticles</groupId>
<artifactId>PlayerParticles</artifactId>
<version>6.4</version>
<version>6.5</version>
<name>PlayerParticles</name>
<url>https://github.com/Esophose/PlayerParticles</url>
<description>Display particles around your player and blocks using customized styles and data!</description>
Expand All @@ -11,10 +11,19 @@
<resources>
<resource>
<directory>src</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.yml</exclude>
</excludes>
</resource>
<resource>
<directory>src</directory>
<filtering>true</filtering>
<includes>
<include>**/*.yml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
Expand Down Expand Up @@ -101,7 +110,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14-R0.1-SNAPSHOT</version>
<version>1.14.3-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,8 @@ public boolean requiresEffects() {
return true;
}

public boolean canConsoleExecute() {
return false;
}

}
5 changes: 5 additions & 0 deletions src/com/esophose/playerparticles/command/CommandModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public interface CommandModule {
* @return If the player must have effects to use this command
*/
boolean requiresEffects();

/**
* @return true if this command can be executed from console, otherwise false
*/
boolean canConsoleExecute();

/**
* Displays a command's usage to the player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ public boolean requiresEffects() {
return true;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void onCommandExecute(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();

if (args.length == 0) return commandNames;
Expand All @@ -42,4 +42,8 @@ public boolean requiresEffects() {
return true;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,8 @@ public boolean requiresEffects() {
return true;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ public boolean requiresEffects() {
return false;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -793,4 +793,8 @@ public boolean requiresEffects() {
return true;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ public boolean requiresEffects() {
return true;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,8 @@ public boolean requiresEffects() {
return false;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ public boolean requiresEffects() {
return false;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public boolean requiresEffects() {
return true;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Arrays;
import java.util.List;

import com.esophose.playerparticles.particles.OtherPPlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -96,27 +97,32 @@ public static List<String> getCommandNames() {
*/
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("pp")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Error: This command can only be executed by a player.");
String commandName = args.length > 0 ? args[0] : "";
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;
}

Player p = (Player) sender;

DataManager.getPPlayer(p.getUniqueId(), (pplayer) -> {
String commandName = args.length > 0 ? args[0] : "";
CommandModule commandModule = findMatchingCommand(commandName);

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);
}
if (commandModule.requiresEffects() && PermissionManager.getEffectNamesUserHasPermissionFor(p).isEmpty()) {
LangManager.sendMessage(pplayer, Lang.COMMAND_ERROR_NO_EFFECTS);
} else {
LangManager.sendMessage(pplayer, Lang.COMMAND_ERROR_UNKNOWN);
commandModule.onCommandExecute(pplayer, cmdArgs);
}
});
} else if (cmd.getName().equalsIgnoreCase("ppo")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class ReloadCommandModule implements CommandModule {

public void onCommandExecute(PPlayer pplayer, String[] args) {
if (PermissionManager.canReloadPlugin(pplayer.getPlayer())) {
if (PermissionManager.canReloadPlugin(pplayer.getMessageDestination())) {
PlayerParticles.getPlugin().reload(false);
LangManager.sendMessage(pplayer, Lang.RELOAD_SUCCESS);
PlayerParticles.getPlugin().getLogger().info("Reloaded configuration.");
Expand Down Expand Up @@ -41,4 +41,8 @@ public boolean requiresEffects() {
return false;
}

public boolean canConsoleExecute() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ public boolean requiresEffects() {
return true;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public boolean requiresEffects() {
return false;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ public boolean requiresEffects() {
return false;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ public boolean requiresEffects() {
return false;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public boolean requiresEffects() {
return false;
}

public boolean canConsoleExecute() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ public boolean requiresEffects() {
return false;
}

public boolean canConsoleExecute() {
return false;
}

}
42 changes: 13 additions & 29 deletions src/com/esophose/playerparticles/manager/DataManager.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
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.particles.FixedParticleEffect;
import com.esophose.playerparticles.particles.PPlayer;
Expand All @@ -19,6 +10,14 @@
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.ParticleStyle;
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,
Expand Down Expand Up @@ -55,6 +54,7 @@ public static PPlayer getPPlayer(UUID playerUUID) {
* @param callback The callback to execute with the found pplayer, or a newly generated one
*/
public static void getPPlayer(UUID playerUUID, ConfigurationCallback<PPlayer> callback) {

// Try to get them from cache first
PPlayer fromCache = getPPlayer(playerUUID);
if (fromCache != null) {
Expand Down Expand Up @@ -471,33 +471,17 @@ public static void removeFixedEffect(UUID playerUUID, int id) {
*
* @param asyncCallback The callback to run on a separate thread
*/
private static void async(SyncInterface asyncCallback) {
new BukkitRunnable() {
public void run() {
asyncCallback.execute();
}
}.runTaskAsynchronously(PlayerParticles.getPlugin());
private static void async(Runnable asyncCallback) {
Bukkit.getScheduler().runTaskAsynchronously(PlayerParticles.getPlugin(), asyncCallback);
}

/**
* Synchronizes the callback with the main thread
*
* @param syncCallback The callback to run on the main thread
*/
private static void sync(SyncInterface syncCallback) {
new BukkitRunnable() {
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();
private static void sync(Runnable syncCallback) {
Bukkit.getScheduler().runTask(PlayerParticles.getPlugin(), syncCallback);
}

/**
Expand Down
Loading

0 comments on commit 063de34

Please sign in to comment.