-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Main changes * Update README and also update the version checker Due to how the plugin reads the config, it falls back onto the default value if the value is not present. To get around this issue, I made slot #0 the slot that can't be removed. This can reduce issues due to it being a single slot and can simply have it's material set to 'air'.
- Loading branch information
Showing
15 changed files
with
468 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
.project | ||
.classpath | ||
/out/ | ||
dependency-reduced-pom.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
# CustomStats | ||
[](https://discord.gg/Z5MyDwp) [](https://github.com/7man7LMYT/CustomStats)[](http://hits.dwyl.com/7man7LMYT/CustomStats) | ||
|
||
bStats: https://bstats.org/plugin/bukkit/CustomStats/10123 | ||
[](https://discord.gg/Z5MyDwp) | ||
[](https://github.com/7man7LMYT/CustomStats) | ||
[](http://hits.dwyl.com/7man7LMYT/CustomStats) | ||
[](https://www.spigotmc.org/resources/88300/) | ||
[](https://7man7lmyt.github.io/CustomStats/) | ||
|
||
Spigot Link: https://www.spigotmc.org/resources/customstats.88300/ | ||
A Minecraft anarchy server oriented plugin that adds /stats. | ||
|
||
An anarchy server oriented plugin that adds /stats. | ||
Check out our [bStats page](https://bstats.org/plugin/bukkit/CustomStats/10123)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package me.gamersclub.customstats; | ||
|
||
import me.gamersclub.customstats.bStats.Metrics; | ||
import me.gamersclub.customstats.util.UpdateChecker; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.logging.Logger; | ||
|
||
public class CustomStats extends JavaPlugin { | ||
public final Logger log = this.getLogger(); | ||
public boolean floodgateIsInstalled = false; | ||
public boolean placeholderAPIInstalled = false; | ||
@SuppressWarnings("CanBeFinal") | ||
List<String> uuidsWithGuiOpen = new ArrayList<>(); | ||
|
||
public void onEnable() { | ||
log.info("CustomStats v2.0.0"); | ||
|
||
File configFile = new File(getDataFolder(), "config.yml"); | ||
if (!configFile.exists()) { | ||
saveResource("config.yml", false); | ||
} | ||
|
||
floodgateIsInstalled = this.getServer().getPluginManager().isPluginEnabled("floodgate"); | ||
if (floodgateIsInstalled) { | ||
log.info("Floodgate detected!"); | ||
} | ||
|
||
placeholderAPIInstalled = this.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"); | ||
if (placeholderAPIInstalled) { | ||
log.info("PlaceholderAPI detected!"); | ||
} | ||
|
||
log.info("Registering commands/events.."); | ||
Objects.requireNonNull(getCommand("stats")).setExecutor(new StatsCommand(this)); | ||
|
||
this.getServer().getPluginManager().registerEvents(new GuiListener(this), this); | ||
|
||
log.info("Starting Metrics.."); | ||
Metrics metrics = new Metrics(this, 10123); | ||
|
||
log.info("Checking for a newer version.."); | ||
new UpdateChecker(this, 88300).getVersion(version -> { | ||
if (this.getDescription().getVersion().equalsIgnoreCase(version)) { | ||
log.info("You are up to date! (v2.0.0)"); | ||
} else { | ||
log.warning("There is a new update available! \nDownload it at https://www.spigotmc.org/resources/88300/"); | ||
} | ||
}); | ||
|
||
log.info("Successfully started!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package me.gamersclub.customstats; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.event.inventory.InventoryCloseEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class GuiListener implements Listener { | ||
public GuiListener(CustomStats customStats) { | ||
this.customStats = customStats; | ||
} | ||
final CustomStats customStats; | ||
|
||
@EventHandler | ||
public void onInventoryClick (InventoryClickEvent event){ | ||
if (customStats.uuidsWithGuiOpen.contains(event.getWhoClicked().getUniqueId().toString())) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onInventoryClose (@NotNull InventoryCloseEvent event){ | ||
customStats.uuidsWithGuiOpen.remove(event.getPlayer().getUniqueId().toString()); | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
src/main/java/me/gamersclub/customstats/StatsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package me.gamersclub.customstats; | ||
|
||
import me.gamersclub.customstats.util.PlaceholderManager; | ||
import me.gamersclub.customstats.menus.StatForm; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.Material; | ||
import org.bukkit.command.*; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.geysermc.floodgate.api.FloodgateApi; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class StatsCommand implements CommandExecutor, TabExecutor { | ||
private final boolean floodgate; | ||
final CustomStats customStats; | ||
final PlaceholderManager placeholderManager; | ||
@SuppressWarnings("CanBeFinal") | ||
List<Integer> valid = new ArrayList<>(); | ||
|
||
public StatsCommand(CustomStats customStats) { | ||
this.customStats = customStats; | ||
this.floodgate = customStats.floodgateIsInstalled; | ||
this.placeholderManager = new PlaceholderManager(customStats); | ||
|
||
valid.add(9); | ||
valid.add(18); | ||
valid.add(27); | ||
valid.add(36); | ||
valid.add(45); | ||
valid.add(54); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String alias, String @NotNull [] args) { | ||
if (args.length == 0) { | ||
if (sender instanceof ConsoleCommandSender) { | ||
List<String> statCommand = customStats.getConfig().getStringList("stats.stat-command"); | ||
|
||
//color code is & | ||
for (String s : statCommand) { | ||
sender.sendMessage(ChatColor.translateAlternateColorCodes(('&'), placeholderManager.placeholderReplacer(null, s))); | ||
} | ||
} else { | ||
List<String> statCommand = customStats.getConfig().getStringList("stats.stat-command"); | ||
|
||
//color code is & | ||
for (String s : statCommand) { | ||
sender.sendMessage(ChatColor.translateAlternateColorCodes(('&'), placeholderManager.placeholderReplacer((Player) sender, s))); | ||
} | ||
} | ||
|
||
} else { | ||
if (args[0].equalsIgnoreCase("reload")) { | ||
if (sender.hasPermission("customstats.reload")) { | ||
customStats.reloadConfig(); | ||
customStats.getConfig(); | ||
sender.sendMessage(ChatColor.GREEN + "Configuration reloaded!"); | ||
} else { | ||
sender.sendMessage(ChatColor.RED + "Usage: /stats (menu)"); | ||
} | ||
} else if (args[0].equalsIgnoreCase("menu")) { | ||
if (sender instanceof Player) { | ||
Player player = (Player) sender; | ||
|
||
if (floodgate) { | ||
if (FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId())) { | ||
StatForm statForm = new StatForm(customStats, placeholderManager, player); | ||
statForm.sendStatForm(player.getUniqueId()); | ||
return true; | ||
} | ||
} | ||
|
||
String title = Objects.requireNonNull(customStats.getConfig().getString("stats.stat-menu.title")); | ||
int size = customStats.getConfig().getInt("stats.stat-menu.menu-size"); | ||
if (!valid.contains(size)) { | ||
customStats.log.warning(size + " is not a valid multiple of 9!"); | ||
sender.sendMessage(ChatColor.RED + "An internal issue occurred while running this command."); | ||
return true; | ||
} | ||
|
||
Inventory inventory = Bukkit.createInventory(player, size, ChatColor.translateAlternateColorCodes('&', title)); | ||
|
||
for (int i = 0; i < size; i++) { | ||
if (customStats.getConfig().contains("stats.stat-menu.items." + i)) { | ||
List<String> statsGui = customStats.getConfig().getStringList("stats.stat-menu.items." + i); | ||
|
||
ItemStack item = new ItemStack(Material.valueOf(statsGui.get(0).toUpperCase()), 1); | ||
|
||
//set item to name if not air | ||
if (item.getType() != Material.AIR) { | ||
ItemMeta itemMeta = item.getItemMeta(); | ||
String name = placeholderManager.placeholderReplacer(player, statsGui.get(1)); | ||
|
||
assert itemMeta != null; | ||
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); | ||
|
||
if (statsGui.size() > 2) { | ||
List<String> lore = new ArrayList<>(); | ||
for (int l = 2; l < statsGui.size(); l++) { | ||
lore.add(ChatColor.translateAlternateColorCodes('&',placeholderManager.placeholderReplacer(player, statsGui.get(l)))); | ||
} | ||
itemMeta.setLore(lore); | ||
} | ||
|
||
item.setItemMeta(itemMeta); | ||
} | ||
inventory.setItem(i, item); | ||
} else { | ||
inventory.clear(i); | ||
} | ||
} | ||
|
||
player.openInventory(inventory); | ||
customStats.uuidsWithGuiOpen.add(player.getUniqueId().toString()); | ||
} else { | ||
sender.sendMessage(ChatColor.RED + "You must be a player to use this command!"); | ||
} | ||
} else { | ||
sender.sendMessage(ChatColor.RED + "Usage: /stats (menu)"); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, String[] strings) { | ||
List<String> completions = new ArrayList<>(); | ||
completions.add("menu"); | ||
|
||
if (sender.hasPermission("customstats.reload")) { | ||
completions.add("reload"); | ||
} | ||
return completions; | ||
} | ||
} |
Oops, something went wrong.