Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Updated GitHub repository. Fixed chest and GUI system checks bug. Mad…
Browse files Browse the repository at this point in the history
…e FoliaLib a single instance reference. Added two new methods to retrieve clan data by ClanPlayer. Added firing of ClanHomeTeleportEvent when not running on Folia. Small code cleanup. Changed plugin version to `1.4.2`.
  • Loading branch information
BuildTools committed Nov 3, 2023
1 parent b526b14 commit 1d3e019
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 78 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.loving11ish</groupId>
<artifactId>ClansLite</artifactId>
<version>1.4.2-BETA-02</version>
<version>1.4.2</version>
<packaging>jar</packaging>

<name>ClansLite</name>
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/me/loving11ish/clans/Clans.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public final class Clans extends JavaPlugin {

private final PluginDescriptionFile pluginInfo = getDescription();
private final String pluginVersion = pluginInfo.getVersion();
private FoliaLib foliaLib = new FoliaLib(this);

private static Clans plugin;
private static FoliaLib foliaLib;
private static FloodgateApi floodgateApi;
private static VersionCheckerUtils versionCheckerUtils;
private static boolean chestsEnabled = false;
Expand All @@ -65,6 +65,7 @@ public final class Clans extends JavaPlugin {
public void onEnable() {
//Plugin startup logic
plugin = this;
foliaLib = new FoliaLib(this);
versionCheckerUtils = new VersionCheckerUtils();
versionCheckerUtils.setVersion();

Expand Down Expand Up @@ -303,21 +304,15 @@ public void onEnable() {
});

//Start auto save task
foliaLib.getImpl().runLaterAsync(new Runnable() {
@Override
public void run() {
TaskTimerUtils.runClansAutoSave();
console.sendMessage(ColorUtils.translateColorCodes(messagesFileManager.getMessagesConfig().getString("auto-save-started")));
}
foliaLib.getImpl().runLaterAsync(() -> {
TaskTimerUtils.runClansAutoSave();
console.sendMessage(ColorUtils.translateColorCodes(messagesFileManager.getMessagesConfig().getString("auto-save-started")));
}, 5L, TimeUnit.SECONDS);

//Start auto invite clear task
foliaLib.getImpl().runLaterAsync(new Runnable() {
@Override
public void run() {
TaskTimerUtils.runClanInviteClear();
console.sendMessage(ColorUtils.translateColorCodes(messagesFileManager.getMessagesConfig().getString("auto-invite-wipe-started")));
}
foliaLib.getImpl().runLaterAsync(() -> {
TaskTimerUtils.runClanInviteClear();
console.sendMessage(ColorUtils.translateColorCodes(messagesFileManager.getMessagesConfig().getString("auto-invite-wipe-started")));
}, 5L, TimeUnit.SECONDS);
}

Expand Down Expand Up @@ -437,6 +432,10 @@ public static Clans getPlugin() {
return plugin;
}

public static FoliaLib getFoliaLib() {
return foliaLib;
}

public static FloodgateApi getFloodgateApi() {
return floodgateApi;
}
Expand Down
68 changes: 27 additions & 41 deletions src/main/java/me/loving11ish/clans/commands/ClanAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,22 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
p.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("plugin-reload-broadcast-start")));
}
}
FoliaLib foliaLib = new FoliaLib(Clans.getPlugin());
FoliaLib foliaLib = Clans.getFoliaLib();
Clans.getPlugin().onDisable();
foliaLib.getImpl().runLater(new Runnable() {
@Override
public void run() {
Bukkit.getPluginManager().getPlugin("ClansLite").onEnable();
}
}, 5L, TimeUnit.SECONDS);
foliaLib.getImpl().runLater(new Runnable() {
@Override
public void run() {
Clans.getPlugin().reloadConfig();
ClanCommand.updateBannedTagsList();
Clans.getPlugin().messagesFileManager.reloadMessagesConfig();
Clans.getPlugin().clanGUIFileManager.reloadClanGUIConfig();
player.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("plugin-reload-successful")));
for (Player p : onlinePlayers){
if (p.getName().equalsIgnoreCase(player.getName())){
continue;
}
if (!onlinePlayers.isEmpty()){
p.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("plugin-reload-successful")));
}
foliaLib.getImpl().runLater(() ->
Bukkit.getPluginManager().getPlugin("ClansLite").onEnable(), 5L, TimeUnit.SECONDS);
foliaLib.getImpl().runLater(() -> {
Clans.getPlugin().reloadConfig();
ClanCommand.updateBannedTagsList();
Clans.getPlugin().messagesFileManager.reloadMessagesConfig();
Clans.getPlugin().clanGUIFileManager.reloadClanGUIConfig();
player.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("plugin-reload-successful")));
for (Player p : onlinePlayers){
if (p.getName().equalsIgnoreCase(player.getName())){
continue;
}
if (!onlinePlayers.isEmpty()){
p.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("plugin-reload-successful")));
}
}
}, 5L, TimeUnit.SECONDS);
Expand Down Expand Up @@ -176,26 +169,19 @@ public void run() {
p.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("plugin-reload-broadcast-start")));
}
}
FoliaLib foliaLib = new FoliaLib(Clans.getPlugin());
FoliaLib foliaLib = Clans.getFoliaLib();
Clans.getPlugin().onDisable();
foliaLib.getImpl().runLater(new Runnable() {
@Override
public void run() {
Bukkit.getPluginManager().getPlugin("ClansLite").onEnable();
}
}, 5L, TimeUnit.SECONDS);
foliaLib.getImpl().runLater(new Runnable() {
@Override
public void run() {
Clans.getPlugin().reloadConfig();
ClanCommand.updateBannedTagsList();
Clans.getPlugin().messagesFileManager.reloadMessagesConfig();
Clans.getPlugin().clanGUIFileManager.reloadClanGUIConfig();
console.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("plugin-reload-successful")));
for (Player p : onlinePlayers){
if (!onlinePlayers.isEmpty()){
p.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("plugin-reload-successful")));
}
foliaLib.getImpl().runLater(() ->
Bukkit.getPluginManager().getPlugin("ClansLite").onEnable(), 5L, TimeUnit.SECONDS);
foliaLib.getImpl().runLater(() -> {
Clans.getPlugin().reloadConfig();
ClanCommand.updateBannedTagsList();
Clans.getPlugin().messagesFileManager.reloadMessagesConfig();
Clans.getPlugin().clanGUIFileManager.reloadClanGUIConfig();
console.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("plugin-reload-successful")));
for (Player p : onlinePlayers){
if (!onlinePlayers.isEmpty()){
p.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("plugin-reload-successful")));
}
}
}, 5L, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ClanCommand implements CommandExecutor {
private static List<String> bannedTags;

public static void updateBannedTagsList(){
FoliaLib foliaLib = new FoliaLib(Clans.getPlugin());
FoliaLib foliaLib = Clans.getFoliaLib();
bannedTaskUpdateTask = foliaLib.getImpl().runLaterAsync(() ->
bannedTags = Clans.getPlugin().getConfig().getStringList("clan-tags.disallowed-tags"), 1L, TimeUnit.SECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public boolean clanListSubCommand(CommandSender sender) {
Player player = (Player) sender;
Set<Map.Entry<UUID, Clan>> clans = ClansStorageUtil.getClans();
StringBuilder clansString = new StringBuilder();
if (clans.size() == 0) {
if (clans.isEmpty()) {
player.sendMessage(ColorUtils.translateColorCodes(messagesConfig.getString("no-clans-to-list")));
} else {
clansString.append(ColorUtils.translateColorCodes(messagesConfig.getString("clans-list-header") + "\n"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ChestBreakEvent implements Listener {

@EventHandler
public void onChestBreak(BlockBreakEvent event){
if (!clansConfig.getBoolean("protections.chests.enabled")){
if (!Clans.isChestsEnabled()){
return;
}
if (event.getBlock().getType().equals(Material.CHEST)){
Expand Down Expand Up @@ -94,7 +94,7 @@ public void onChestBreak(BlockBreakEvent event){

@EventHandler
public void onTNTDestruction(EntityExplodeEvent event){
if (!clansConfig.getBoolean("protections.chests.enabled")){
if (!Clans.isChestsEnabled()){
return;
}
if (event.getEntity() instanceof TNTPrimed){
Expand All @@ -118,7 +118,7 @@ public void onTNTDestruction(EntityExplodeEvent event){

@EventHandler
public void onCreeperDestruction(EntityExplodeEvent event){
if (!clansConfig.getBoolean("protections.chests.enabled")){
if (!Clans.isChestsEnabled()){
return;
}
if (event.getEntity() instanceof Creeper){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

public class ChestOpenEvent implements Listener {

FileConfiguration clansConfig = Clans.getPlugin().getConfig();
FileConfiguration messagesConfig = Clans.getPlugin().messagesFileManager.getMessagesConfig();

private static final String CLAN_PLACEHOLDER = "%CLAN%";

@EventHandler
public void onChestOpen(PlayerInteractEvent event){
if (!clansConfig.getBoolean("protections.chests.enabled")){
if (!Clans.isChestsEnabled()){
return;
}
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void onPlayerHit(EntityDamageByEntityEvent event){
if (clansConfig.getBoolean("protections.pvp.enable-bypass-permission")){
if (attackingPlayer.hasPermission("clanslite.bypass.pvp")
||attackingPlayer.hasPermission("clanslite.bypass.*")
||attackingPlayer.hasPermission("clanslite.bypass")
||attackingPlayer.hasPermission("clanslite.*")
||attackingPlayer.isOp()){
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public void onPlayerPreConnect(AsyncPlayerPreLoginEvent event) {
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &c&lChest protection system disabled!"));
}
}else {
Clans.setGUIEnabled(false);
Clans.setChestsEnabled(false);
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &cYour current server version does not support PersistentDataContainers!"));
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &c&lChest protection system disabled!"));
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &c&lGlobal GUI system disabled!"));
Expand All @@ -54,12 +56,15 @@ public void onPlayerPreConnect(AsyncPlayerPreLoginEvent event) {
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &c&lGlobal GUI system disabled!"));
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &c&lChest protection system disabled!"));
}else {
Clans.setGUIEnabled(false);
Clans.setChestsEnabled(false);
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &cYour current server version does not support PersistentDataContainers!"));
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &c&lChest protection system disabled!"));
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &c&lGlobal GUI system disabled!"));
}
console.sendMessage(ColorUtils.translateColorCodes("&4-------------------------------------------"));
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &4This plugin is only supported on online servers or servers running in an online network situation!"));
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &4Some features may behave incorrectly or may be broken completely!"));
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &4Please set &e'online-mode=true' &4in &e'server.properties'"));
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &4Or ensure your proxy setup is correct and your proxy is set to online mode!"));
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite: &4&lNO SUPPORT WILL BE GIVEN UNLESS THE ABOVE IS CHANGED/SETUP CORRECTLY!"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ else if(event.getCurrentItem().getType().equals(Material.STONE_BUTTON)){
public void setMenuItems() {
addMenuControls();
if (guiConfig.getBoolean("clan-list.icons.auto-refresh-data.enabled")){
FoliaLib foliaLib = new FoliaLib(Clans.getPlugin());
FoliaLib foliaLib = Clans.getFoliaLib();
autoGUIRefreshTask = foliaLib.getImpl().runTimerAsync(new Runnable() {
@Override
public void run() {
Expand All @@ -136,11 +136,14 @@ public void run() {
Clan clan = ClansStorageUtil.findClanByOfflineOwner(clanOwnerPlayer);

ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta skull = (SkullMeta) playerHead.getItemMeta();
skull.setOwningPlayer(UsermapStorageUtil.getBukkitOfflinePlayerByUUID(ownerUUID));
playerHead.setItemMeta(skull);
if (clansConfig.getBoolean("general.developer-debug-mode.enabled")){
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite-Debug: &aRetrieved player head info for UUID: &d" + clanOwnerUUIDString));

if (Clans.isOnlineMode()){
SkullMeta skull = (SkullMeta) playerHead.getItemMeta();
skull.setOwningPlayer(UsermapStorageUtil.getBukkitOfflinePlayerByUUID(ownerUUID));
playerHead.setItemMeta(skull);
if (clansConfig.getBoolean("general.developer-debug-mode.enabled")){
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite-Debug: &aRetrieved player head info for UUID: &d" + clanOwnerUUIDString));
}
}

ItemMeta meta = playerHead.getItemMeta();
Expand Down Expand Up @@ -238,11 +241,14 @@ public void run() {
Clan clan = ClansStorageUtil.findClanByOfflineOwner(clanOwnerPlayer);

ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta skull = (SkullMeta) playerHead.getItemMeta();
skull.setOwningPlayer(UsermapStorageUtil.getBukkitOfflinePlayerByUUID(ownerUUID));
playerHead.setItemMeta(skull);
if (clansConfig.getBoolean("general.developer-debug-mode.enabled")){
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite-Debug: &aRetrieved player head info for UUID: &d" + clanOwnerUUIDString));

if (Clans.isOnlineMode()){
SkullMeta skull = (SkullMeta) playerHead.getItemMeta();
skull.setOwningPlayer(UsermapStorageUtil.getBukkitOfflinePlayerByUUID(ownerUUID));
playerHead.setItemMeta(skull);
if (clansConfig.getBoolean("general.developer-debug-mode.enabled")){
console.sendMessage(ColorUtils.translateColorCodes("&6ClansLite-Debug: &aRetrieved player head info for UUID: &d" + clanOwnerUUIDString));
}
}

ItemMeta meta = playerHead.getItemMeta();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public UpdateChecker(int resourceId) {
}

public void getVersion(final Consumer<String> consumer) {
FoliaLib foliaLib = new FoliaLib(Clans.getPlugin());
FoliaLib foliaLib = Clans.getFoliaLib();
foliaLib.getImpl().runAsync((task) -> {
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
if (scanner.hasNext()) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/me/loving11ish/clans/utils/ClansStorageUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.loving11ish.clans.utils;

import me.loving11ish.clans.models.ClanPlayer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
Expand Down Expand Up @@ -238,6 +239,11 @@ public static Clan findClanByOfflineOwner(OfflinePlayer offlinePlayer){
return clansList.get(uuid);
}

public static Clan findClanOwnerByClanPlayer(ClanPlayer clanPlayer){
UUID uuid = UUID.fromString(clanPlayer.getJavaUUID());
return clansList.get(uuid);
}

public static Clan findClanByPlayer(Player player){
for (Clan clan : clansList.values()){
if (findClanByOwner(player) != null) {
Expand Down Expand Up @@ -270,6 +276,22 @@ public static Clan findClanByOfflinePlayer(OfflinePlayer player){
return null;
}

public static Clan findClanPlayerByClanPlayer(ClanPlayer clanPlayer){
for (Clan clan : clansList.values()){
if (findClanOwnerByClanPlayer(clanPlayer) != null){
return clan;
}
if (clan.getClanMembers() != null){
for (String member : clan.getClanMembers()){
if (member.equals(clanPlayer.getJavaUUID())){
return clan;
}
}
}
}
return null;
}

public static void updatePrefix(Player player, String prefix){
UUID uuid = player.getUniqueId();
if (!isClanOwner(player)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TaskTimerUtils {

static ConsoleCommandSender console = Bukkit.getConsoleSender();
static FileConfiguration config = Clans.getPlugin().getConfig();
static FoliaLib foliaLib = new FoliaLib(Clans.getPlugin());
static FoliaLib foliaLib = Clans.getFoliaLib();

public static WrappedTask autoSaveTask;
public static WrappedTask inviteClearTask;
Expand Down
Loading

0 comments on commit 1d3e019

Please sign in to comment.