Initial commit

This commit is contained in:
Yanis48 committed 2019-03-23 19:06:37 +01:00
commit 939bad925d
5 files changed
+111

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
+3
View File
@@ -0,0 +1,3 @@
.idea/
out/
*.iml
@@ -0,0 +1,61 @@
package com.yanis48.firstplayed;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class CommandFirstPlayed implements CommandExecutor, TabExecutor {
public Player player;
public FileConfiguration config = Bukkit.getPluginManager().getPlugin("FirstPlayed").getConfig();
public String date_format = config.getString("date_format");
public String message = config.getString("message");
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) {
if (!sender.hasPermission("firstplayed.me")) return false;
player = (Player) sender;
sendDate(sender, player);
return true;
} else if (args.length == 1) {
if (!sender.hasPermission("firstplayed.other")) return false;
String target = args[0];
if (Bukkit.getOnlinePlayers().contains(Bukkit.getPlayer(target))) {
sendDate(sender, Bukkit.getPlayerExact(target));
return true;
}
}
return false;
}
public void sendDate(CommandSender sender, Player target) {
if (sender instanceof Player) {
long timestamp = target.getFirstPlayed();
String date = new SimpleDateFormat(date_format).format(new Date(timestamp));
sender.sendMessage(String.format("§d" + message, target.getDisplayName(), date));
}
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 1 && sender.hasPermission("firstplayed.other")) {
List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getName().toLowerCase().startsWith(args[0].toLowerCase())) {
players.add(player.getName());
}
}
return players;
}
return new ArrayList<>();
}
}
@@ -0,0 +1,24 @@
package com.yanis48.firstplayed;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public class FirstPlayed extends JavaPlugin {
public FileConfiguration config = getConfig();
@Override
public void onEnable() {
this.getCommand("firstplayed").setExecutor(new CommandFirstPlayed());
config.addDefault("date_format", "MM/dd/yyyy HH:mm:ss");
config.addDefault("message", "%1s joined the server on %2s");
config.options().copyDefaults(true);
config.options().header("This is the configuration file for the FirstPlayed plugin.\nDate format uses letter codes, like M for month or s for seconds.\nIf you change the message, make sure to keep %1s and %2s, otherwise the plugin will not return anything.");
saveConfig();
}
@Override
public void onDisable() {
}
}
+21
View File
@@ -0,0 +1,21 @@
name: FirstPlayed
version: 1.0.1
author: Yanis48
main: com.yanis48.firstplayed.FirstPlayed
api-version: 1.13
commands:
firstplayed:
description: Shows when you joined the server
aliases: fp
permission: firstplayed.me
permission-message: §cYou do not have the permission to use this command.
usage: "§eUsage: §r/firstplayed [<player>]"
permissions:
firstplayed.me:
description: Allows you to get your own join date
default: op
firstplayed.other:
description: Allows you to get another player join date
default: op