Skip to content

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stumper66 committed Dec 31, 2020
1 parent f1b0b26 commit 2df775a
Show file tree
Hide file tree
Showing 14 changed files with 374 additions and 133 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,28 @@ Includes optional integration into WorldGuard and will display whichever regions
## Configuration

Nothing special needed. Just place the .jar file into your plugins directory and restart the server.
by default it will log to a json file so player's last location will be logged.
Logging options include: mysql, json or none.
By default it will log to a json file so player's last location will be logged.
Logging options include: mysql, sqlite, json or none.

default configuration:
![config](/images/config1.png)

The online and offline player messages are fully customizeable to show only the items you want to see, change colors and more.

## Permissions

* FindPlayer.findp - basic permission to allow looking up player's locations
* FindPlayer.reload - reload the configuration
* FindPlayer.purge - delete any cached entries from memory and disk

## Examples:
![example1](/images/image1.png)
![example2](/images/image2.png)
![example2](/images/image2.png)

## Misc

Credit goes out to [ellienntatar] for making the original [FindPlayer].
I wanted to improve on it so make this version from the original concept.

[ellienntatar]: https://www.spigotmc.org/resources/authors/ellienntatar.886090/
[FindPlayer]: https://www.spigotmc.org/resources/findplayer.75642/
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>FindPlayer</groupId>
<artifactId>FindPlayer</artifactId>
<version>0.5</version>
<version>1.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
Expand Down Expand Up @@ -45,6 +45,10 @@
<id>sk89q-snapshots</id>
<url>http://maven.sk89q.com/artifactory/repo</url>
</repository>
<repository>
<id>org.xerial</id>
<url>https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -82,6 +86,11 @@
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.34.0</version>
</dependency>
</dependencies>

</project>
92 changes: 69 additions & 23 deletions src/findPlayer/FindPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

import org.bukkit.command.Command;
Expand All @@ -21,7 +23,7 @@ public class FindPlayer extends JavaPlugin implements Listener {
private final Logger logger = Logger.getLogger("Minecraft");
public FileConfiguration config;
private LoggingType loggingType = LoggingType.None;
public Boolean UseVerboseLogging;
public Boolean useDebug;
private IPlayerCache playerCache;
private String playerOnlinePreformedString;
private String playerOfflinePreformedString;
Expand All @@ -35,52 +37,77 @@ public void onEnable() {
config = getConfig();

this.hasWorldGuard = WorldGuardStuff.CheckForWorldGuard();
processConfig(false);
processConfig(null);
playerCache.PopulateData();



this.getCommand("findp").setExecutor(this);
getServer().getPluginManager().registerEvents(this, this);

PluginDescriptionFile pdf = this.getDescription();

logger.info("Has WorldGuard: " + this.hasWorldGuard.toString());
if (this.useDebug) logger.info("Has WorldGuard: " + this.hasWorldGuard.toString());
String msg = String.format("%s (%s) has been enabled", pdf.getName(), pdf.getVersion());
logger.info(msg);
}

@Override
public void onDisable() {
PluginDescriptionFile pdf = this.getDescription();
logger.info(pdf.getName() + " has been disabled");
if (this.useDebug) logger.info(pdf.getName() + " has been disabled");
}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("findp")) {
if(args.length == 1) {
if (args[0].equalsIgnoreCase("reload")) {
if (!sender.hasPermission("FindPlayer.reload")) {
sender.sendMessage(ChatColor.RED + "You don't have permisisons for this command");
return true;
}

saveDefaultConfig();
this.reloadConfig();
config = getConfig();
processConfig(true);
sender.sendMessage(ChatColor.YELLOW + "Reloaded the config.");
processConfig(sender);
sender.sendMessage(ChatColor.YELLOW + "Reloaded the config.");
}
else if (args[0].equalsIgnoreCase("test")) {
// not used right now
else if (args[0].equalsIgnoreCase("purge")) {
if (!sender.hasPermission("FindPlayer.purge")) {
sender.sendMessage(ChatColor.RED + "You don't have permisisons for this command");
return true;
}
playerCache.PurgeData();
sender.sendMessage(ChatColor.YELLOW + "Purged all cached data.");
}
else {
String SendMsg = getMessageForPlayer(args[0]);
sender.sendMessage(SendMsg);
}
} else {
sender.sendMessage(ChatColor.YELLOW + "Usage: /findp PlayerName|reload");
ChatColor g = ChatColor.GREEN;
ChatColor y = ChatColor.YELLOW;
sender.sendMessage(y + "Usage: /findp PlayerName" + g + "|" + y + "reload" + g + "|" + y + "purge");
}
}

return true;
}

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event){
if (this.loggingType == LoggingType.None) return;

Player p = event.getPlayer();
if (p == null) return;
Location loc = p.getLocation();

PlayerStoreInfo psi = new PlayerStoreInfo(p.getUniqueId(), p.getName(),
p.getWorld().getName(), loc);

playerCache.AddOrUpdatePlayerInfo(psi);
}

private String getMessageForPlayer(String playerName) {
// try to find player entity from name. Will only work if they are online
Player p = Bukkit.getPlayer(playerName);
Expand Down Expand Up @@ -108,38 +135,57 @@ private String getMessageForPlayer(String playerName) {
return formulateMessage(this.playerOfflinePreformedString, psi, null, this.hasWorldGuard);
}

private void processConfig(Boolean isReload) {
this.UseVerboseLogging = config.getBoolean("verbose-logging", false);
private void processConfig(CommandSender sender) {
this.useDebug = config.getBoolean("debug", false);
long writeTimeMs = config.getLong("json-write-time-ms", 5000L);
String loggingType = config.getString("player-logging-type");
if (Helpers.isNullOrEmpty(loggingType)) loggingType = "json";

Boolean isReload = (sender != null);

if (!isReload) {
// can only change this by restarting server
String loggingType = config.getString("player-logging-type");
if (Helpers.isNullOrEmpty(loggingType)) loggingType = "json";

switch (loggingType.toLowerCase()) {
case "mysql":
this.loggingType = LoggingType.Mysql;
PlayerCache_SQL.SQL_ConfigInfo sconfig = new PlayerCache_SQL.SQL_ConfigInfo();
PlayerCache_SQL.MySQL_ConfigInfo sconfig = new PlayerCache_SQL.MySQL_ConfigInfo();
sconfig.database = config.getString("mysql-database");
sconfig.hostname = config.getString("mysql-hostname");
sconfig.username = config.getString("mysql-username");
sconfig.password = config.getString("mysql-password");

PlayerCache_SQL sql = new PlayerCache_SQL(sconfig);
playerCache = sql;
if (!sql.openConnection())
logger.warning("Unable to open mysql connection");
PlayerCache_SQL mysql = new PlayerCache_SQL(sconfig, useDebug);
playerCache = mysql;
mysql.openConnection();
break;
case "sqlite":
this.loggingType = LoggingType.Sqlite;
PlayerCache_SQL sqlite = new PlayerCache_SQL(this.getDataFolder(), useDebug);
playerCache = sqlite;
sqlite.openConnection();
break;
case "json":
this.loggingType = LoggingType.Json;
playerCache = new PlayerCache_Json(this.getDataFolder());
playerCache = new PlayerCache_Json(this.getDataFolder(), writeTimeMs, useDebug);
break;
default:
this.loggingType = LoggingType.None;
break;
}

if (this.UseVerboseLogging) logger.info("Using logging type of " + this.loggingType.toString());
if (this.useDebug) logger.info("Using logging type of " + this.loggingType.toString());
}
else {
// is reload
if (playerCache != null) {
playerCache.UpdateDebug(useDebug);
playerCache.UpdateFileWriteTime(writeTimeMs);
}

if (this.loggingType.toString().toLowerCase() != loggingType) {
sender.sendMessage(ChatColor.RED + "Warning! You must restart the server to change the logging type.");
}
}

String[] PreformedMessages = new String[] {
Expand Down Expand Up @@ -262,6 +308,6 @@ private String preformulateMessage(String str) {
}

private enum LoggingType{
None, Json, Mysql
None, Json, Mysql, Sqlite
}
}
8 changes: 8 additions & 0 deletions src/findPlayer/IPlayerCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public interface IPlayerCache {
PlayerStoreInfo GetPlayerInfo(UUID userId);

void PopulateData();

void PurgeData();

void Close();

void UpdateDebug(Boolean useDebug);

void UpdateFileWriteTime(long fileWriteTimeMs);
}
4 changes: 3 additions & 1 deletion src/findPlayer/PlayerCache_Base.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package findPlayer;

import java.io.File;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.UUID;
Expand All @@ -14,7 +15,8 @@ public PlayerCache_Base() {

public final Logger logger;
public HashMap<UUID, PlayerStoreInfo> Mapping;
public TreeMap<String, UUID> NameMappings;
public final TreeMap<String, UUID> NameMappings;
public File dataFile;

public PlayerStoreInfo GetPlayerInfo(String Playername) {
if (!NameMappings.containsKey(Playername)) return null;
Expand Down
Loading

0 comments on commit 2df775a

Please sign in to comment.