Archived
I drank a shit load of monster and pulled two all-nighters, I have no idea what all i did to be honest
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package dev.astridlabs.playtimerewardsplus.Commands;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.DataTypes.PlayerData;
|
||||
import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandPlaytime implements CommandExecutor {
|
||||
private Plugin plugin;
|
||||
|
||||
public CommandPlaytime(Plugin plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) {
|
||||
if(sender instanceof Player){
|
||||
Player player = (Player) sender;
|
||||
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.PluginChatPrefix + "&aYour current playtime is: &7"+Integer.toString(plugin.db.getPlayer(player.getUniqueId()).getPlaytime()/3600)+" Hours"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package dev.astridlabs.playtimerewardsplus.Commands;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.DataTypes.PlayerData;
|
||||
import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandSeen implements CommandExecutor {
|
||||
private Plugin plugin;
|
||||
|
||||
public CommandSeen(Plugin plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if(sender instanceof Player){
|
||||
Player player = (Player) sender;
|
||||
|
||||
String pName = args[0];
|
||||
Player mentioned = Bukkit.getPlayer(pName);
|
||||
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.PluginChatPrefix+"&8--------&7 "+mentioned.getDisplayName()+" &8--------"));
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.PluginChatPrefix+"&aPlayers Playtime: &7"+Integer.toString(plugin.db.getPlayer(mentioned.getUniqueId()).getPlaytime()/3600)+" Hours"));
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.PluginChatPrefix+"&aPlayers Logoff Location (X,Y,Z): &7"+plugin.config.getSavedX(mentioned.getUniqueId())+" "+plugin.config.getSavedY(mentioned.getUniqueId())+" "+plugin.config.getSavedZ(mentioned.getUniqueId())));
|
||||
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package dev.astridlabs.playtimerewardsplus.Commands;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.DataTypes.PlayerData;
|
||||
import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Debug implements CommandExecutor {
|
||||
private Plugin plugin;
|
||||
private String DebugPrefix = "&7[&cDEBUG MODE&7] ";
|
||||
|
||||
public Debug(Plugin plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if(sender instanceof Player){
|
||||
Player player = (Player) sender;
|
||||
if(args[0].equals("time")){
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.PluginChatPrefix+DebugPrefix + "&aUser playtime in seconds is: "+this.plugin.db.getPlayer(player.getUniqueId()).getPlaytime()));
|
||||
}
|
||||
|
||||
if(args[0].equals("location")){
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.PluginChatPrefix+DebugPrefix + "&aLast player locaiton coordinates (X,Y,Z): "+this.plugin.db.getPlayer(player.getUniqueId()).getLastLocation().getX()+" "+this.plugin.db.getPlayer(player.getUniqueId()).getLastLocation().getY()+" "+this.plugin.db.getPlayer(player.getUniqueId()).getLastLocation().getZ()));
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.PluginChatPrefix+DebugPrefix + "&aCurrent player locaiton coordinates (X,Y,Z): "+this.plugin.db.getPlayer(player.getUniqueId()).getCurrentLocation().getX()+" "+this.plugin.db.getPlayer(player.getUniqueId()).getCurrentLocation().getY()+" "+this.plugin.db.getPlayer(player.getUniqueId()).getCurrentLocation().getZ()));
|
||||
|
||||
}
|
||||
|
||||
if(args[0].equals("location")){
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.PluginChatPrefix+DebugPrefix + "&aForce dumping memory to disk, this could cause file corruption"));
|
||||
plugin.config.savePlayers();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package dev.astridlabs.playtimerewardsplus.Controllers;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.DataTypes.PlayerData;
|
||||
import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ConfigController {
|
||||
private Plugin plugin;
|
||||
private File customConfigFile;
|
||||
private FileConfiguration customConfig;
|
||||
|
||||
|
||||
public ConfigController(Plugin plugin){
|
||||
this.plugin = plugin;
|
||||
this.customConfig = plugin.getConfig();
|
||||
}
|
||||
|
||||
public void savePlayers(){
|
||||
for (PlayerData player : plugin.db.playerList) {
|
||||
customConfig.set("data."+player.getUuid()+".playtime", player.getPlaytime());
|
||||
customConfig.set("data."+player.getUuid()+".displayName", player.getDisplayName());
|
||||
customConfig.set("data."+player.getUuid()+".lastLocation.X", player.getCurrentLocation().getBlockX());
|
||||
customConfig.set("data."+player.getUuid()+".lastLocation.Y", player.getCurrentLocation().getBlockY());
|
||||
customConfig.set("data."+player.getUuid()+".lastLocation.Z", player.getCurrentLocation().getBlockZ());
|
||||
}
|
||||
try {
|
||||
customConfig.save(customConfigFile);
|
||||
} catch (IOException e) {
|
||||
this.plugin.getServer().getLogger().log(Level.SEVERE, "ERROR OCCURED WHILE SAVING! DATA LOSS COULD OCCUR! ", e);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Custom Config Handler //
|
||||
/////////////////////////////
|
||||
public FileConfiguration getCustomConfig() {
|
||||
return this.customConfig;
|
||||
}
|
||||
|
||||
public void createCustomConfig() throws IOException, InvalidConfigurationException {
|
||||
customConfigFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
if (!customConfigFile.exists()) {
|
||||
customConfigFile.getParentFile().mkdirs();
|
||||
plugin.saveResource("config.yml", false);
|
||||
}
|
||||
|
||||
customConfig= new YamlConfiguration();
|
||||
customConfig.load(customConfigFile);
|
||||
|
||||
}
|
||||
|
||||
public String getSavedX(UUID uuid){
|
||||
return this.customConfig.getString("data."+uuid.toString()+"lastLocation.X");
|
||||
}
|
||||
public String getSavedY(UUID uuid){
|
||||
return this.customConfig.getString("data."+uuid.toString()+"lastLocation.Y");
|
||||
}
|
||||
public String getSavedZ(UUID uuid){
|
||||
return this.customConfig.getString("data."+uuid.toString()+"lastLocation.Z");
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// GASM.java (General Activation Sequence Manager)
|
||||
// - In charge of making sure things do their thing when they are supposed to
|
||||
//
|
||||
// (c) Owen Rummage 2020
|
||||
|
||||
package dev.astridlabs.playtimerewardsplus.Controllers;
|
||||
|
||||
public class GASM {
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
package dev.astridlabs.playtimerewardsplus.Controllers;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.DataTypes.PlayerData;
|
||||
import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -13,8 +14,15 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class PlayerDatabase {
|
||||
public List<PlayerData> playerList = new ArrayList<PlayerData>();
|
||||
public Plugin plugin;
|
||||
|
||||
public PlayerDatabase(Plugin plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
public PlayerData getPlayer(UUID uuid){
|
||||
PlayerData returnedPlayer = null;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package dev.astridlabs.playtimerewardsplus.Events;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerJoin implements Listener {
|
||||
|
||||
public Plugin plugin;
|
||||
|
||||
public PlayerJoin(Plugin pl){
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
event.setJoinMessage("Welcome, " + event.getPlayer().getName() + "!");
|
||||
plugin.db.createPlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
// PlaceholderAPIIntegration.java
|
||||
// - Send data to PlaceholderAPI for other plugins to use
|
||||
//
|
||||
// (c) Owen Rummage 2020
|
||||
package dev.astridlabs.playtimerewardsplus.Integrations;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class PlaceholderAPIIntegration extends PlaceholderExpansion {
|
||||
|
||||
/*
|
||||
* The identifier, shouldn't contain any _ or %
|
||||
*/
|
||||
private Plugin plugin;
|
||||
|
||||
public PlaceholderAPIIntegration(Plugin plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist(){
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean canRegister(){
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String getAuthor(){
|
||||
return "O_dude";
|
||||
}
|
||||
@Override
|
||||
public String getIdentifier(){
|
||||
return "playtimerewards";
|
||||
}
|
||||
@Override
|
||||
public String getVersion(){
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String onPlaceholderRequest(Player player, String identifier) {
|
||||
|
||||
// We check if the player is null (not online) before any player-related placeholder
|
||||
if(player == null){
|
||||
return "";
|
||||
}
|
||||
|
||||
// Placeholder: %playtimerewards_prefix%
|
||||
if(identifier.equals("prefix")) {
|
||||
return plugin.PlaceholderChatPrefix.replace("%time%", "&a"+ Integer.toString(plugin.db.getPlayer(player.getUniqueId()).getPlaytime()/3600)+"&7h");
|
||||
}
|
||||
|
||||
if(identifier.equals("playtime")) {
|
||||
return Integer.toString(plugin.db.getPlayer(player.getUniqueId()).getPlaytime());
|
||||
}
|
||||
|
||||
if(identifier.equals("lastloc_x")) {
|
||||
return Double.toString(plugin.db.getPlayer(player.getUniqueId()).getLastLocation().getX());
|
||||
}
|
||||
if(identifier.equals("lastloc_y")) {
|
||||
return Double.toString(plugin.db.getPlayer(player.getUniqueId()).getLastLocation().getY());
|
||||
}
|
||||
if(identifier.equals("lastloc_z")) {
|
||||
return Double.toString(plugin.db.getPlayer(player.getUniqueId()).getLastLocation().getZ());
|
||||
}
|
||||
if(identifier.equals("curloc_x")) {
|
||||
return Double.toString(plugin.db.getPlayer(player.getUniqueId()).getCurrentLocation().getX());
|
||||
}
|
||||
if(identifier.equals("curloc_y")) {
|
||||
return Double.toString(plugin.db.getPlayer(player.getUniqueId()).getCurrentLocation().getY());
|
||||
}
|
||||
if(identifier.equals("curloc_z")) {
|
||||
return Double.toString(plugin.db.getPlayer(player.getUniqueId()).getCurrentLocation().getZ());
|
||||
}
|
||||
|
||||
|
||||
// We return null, if an invalid placeholder was called.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package dev.astridlabs.playtimerewardsplus;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.DataTypes.PlayerData;
|
||||
import dev.astridlabs.playtimerewardsplus.Plugin;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MasterClock extends BukkitRunnable {
|
||||
private final Plugin plugin;
|
||||
private Integer clockTicks = 0;
|
||||
|
||||
public MasterClock(Plugin plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
clockTicks++;
|
||||
|
||||
if((clockTicks/72000) > 1){
|
||||
this.plugin.config.savePlayers();
|
||||
this.plugin.getServer().getLogger().log(Level.INFO, "Hourly save completed! Data loss avoided");
|
||||
}
|
||||
|
||||
// What you want to schedule goes here
|
||||
for(Player p : plugin.getServer().getOnlinePlayers()) {
|
||||
updatePlaytime(p);
|
||||
updatePlayerLocations(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlaytime(Player pl){
|
||||
PlayerData player = plugin.db.getPlayer(pl.getUniqueId());
|
||||
Integer playtime = player.getPlaytime();
|
||||
Integer newplaytime = playtime+1;
|
||||
player.setPlaytime(newplaytime);
|
||||
}
|
||||
|
||||
public void updatePlayerLocations(Player pl){
|
||||
PlayerData player = plugin.db.getPlayer(pl.getUniqueId());
|
||||
|
||||
if(player.getCurrentLocation() == null){
|
||||
player.setCurrentLocation(pl.getLocation());
|
||||
}else{
|
||||
player.setLastLocation(player.getCurrentLocation());
|
||||
player.setCurrentLocation(pl.getLocation());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,66 @@
|
||||
package dev.astridlabs.playtimerewardsplus;
|
||||
|
||||
import dev.astridlabs.playtimerewardsplus.Commands.CommandPlaytime;
|
||||
import dev.astridlabs.playtimerewardsplus.Commands.CommandSeen;
|
||||
import dev.astridlabs.playtimerewardsplus.Commands.Debug;
|
||||
import dev.astridlabs.playtimerewardsplus.Controllers.ConfigController;
|
||||
import dev.astridlabs.playtimerewardsplus.Controllers.PlayerDatabase;
|
||||
import dev.astridlabs.playtimerewardsplus.Events.PlayerJoin;
|
||||
import dev.astridlabs.playtimerewardsplus.Integrations.PlaceholderAPIIntegration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Plugin extends JavaPlugin {
|
||||
|
||||
//Initialize Everything
|
||||
public PlayerDatabase db = new PlayerDatabase(this);
|
||||
public BukkitScheduler scheduler = getServer().getScheduler();
|
||||
public ConfigController config = new ConfigController(this);
|
||||
|
||||
//Config
|
||||
public String PluginChatPrefix;
|
||||
public String PlaceholderChatPrefix;
|
||||
|
||||
@Override
|
||||
public void onEnable(){
|
||||
//Get the clock running
|
||||
new MasterClock(this).runTaskTimer(this, 0L, 20L);
|
||||
|
||||
|
||||
try {
|
||||
config.createCustomConfig();
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to createCustomConfig");
|
||||
} catch (InvalidConfigurationException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to createCustomConfig");
|
||||
}
|
||||
|
||||
|
||||
|
||||
PlaceholderChatPrefix = getConfig().getString("Config.PlaceholderChatPrefix")+" ";
|
||||
PluginChatPrefix = getConfig().getString("Config.PluginChatPrefix")+" ";
|
||||
//Initialize Events
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerJoin(this), this); // This fires the event and allows any listener to listen to the event
|
||||
|
||||
//Only initialize if PlaceholderAPI is actually installed
|
||||
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new PlaceholderAPIIntegration(this).register();
|
||||
}
|
||||
|
||||
//Initialize Commands
|
||||
this.getCommand("pt").setExecutor(new CommandPlaytime(this));
|
||||
this.getCommand("ptdebug").setExecutor(new Debug(this));
|
||||
this.getCommand("ptseen").setExecutor(new CommandSeen(this));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(){
|
||||
|
||||
config.savePlayers();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.UUID;
|
||||
|
||||
public class PlayerData {
|
||||
|
||||
private Integer Playtime;
|
||||
private int Playtime = 0;
|
||||
private UUID uuid;
|
||||
private String DisplayName;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user