mirror of
https://github.com/Freezy-Studios/BlazeSMP.git
synced 2025-04-22 04:44:04 +02:00
Added a Bukkit Runnable to update the player tags! Added a PlayerManager to handle the logic behind updateing and ordering the player in tab! Added JoinListener to set playertag on join! Added debugging, registered listener...!
This commit is contained in:
parent
5b184a8384
commit
0dad4cf59a
4 changed files with 78 additions and 2 deletions
|
@ -2,11 +2,15 @@ package me.freezy.plugins.papermc.blazesmp;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.freezy.plugins.papermc.blazesmp.command.ClanCommand;
|
import me.freezy.plugins.papermc.blazesmp.command.ClanCommand;
|
||||||
|
import me.freezy.plugins.papermc.blazesmp.listener.JoinListener;
|
||||||
import me.freezy.plugins.papermc.blazesmp.module.manager.Clans;
|
import me.freezy.plugins.papermc.blazesmp.module.manager.Clans;
|
||||||
import me.freezy.plugins.papermc.blazesmp.module.manager.Homes;
|
import me.freezy.plugins.papermc.blazesmp.module.manager.Homes;
|
||||||
import me.freezy.plugins.papermc.blazesmp.module.manager.ProtectedBlocks;
|
import me.freezy.plugins.papermc.blazesmp.module.manager.ProtectedBlocks;
|
||||||
|
import me.freezy.plugins.papermc.blazesmp.tasks.PlayerNameUpdate;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
public final class BlazeSMP extends JavaPlugin {
|
public final class BlazeSMP extends JavaPlugin {
|
||||||
|
@ -16,11 +20,14 @@ public final class BlazeSMP extends JavaPlugin {
|
||||||
@Getter private Clans clans;
|
@Getter private Clans clans;
|
||||||
@Getter private FileConfiguration configuration;
|
@Getter private FileConfiguration configuration;
|
||||||
@Getter private Logger log;
|
@Getter private Logger log;
|
||||||
|
@Getter private BukkitTask nameUpdateTask;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
this.log=getSLF4JLogger();
|
this.log=getSLF4JLogger();
|
||||||
|
|
||||||
|
this.log.info("Loading BlazeSMP...");
|
||||||
|
|
||||||
this.log.info("Loading Homes...");
|
this.log.info("Loading Homes...");
|
||||||
this.homes=new Homes();
|
this.homes=new Homes();
|
||||||
this.homes.load();
|
this.homes.load();
|
||||||
|
@ -41,19 +48,52 @@ public final class BlazeSMP extends JavaPlugin {
|
||||||
this.configuration= getConfig();
|
this.configuration= getConfig();
|
||||||
saveConfig();
|
saveConfig();
|
||||||
this.log.info("Loaded config!");
|
this.log.info("Loaded config!");
|
||||||
|
|
||||||
|
this.log.info("Loaded BlazeSMP!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
BlazeSMP.instance=this;
|
BlazeSMP.instance=this;
|
||||||
|
|
||||||
|
this.log.info("Enabling BlazeSMP...");
|
||||||
|
|
||||||
this.log.info("Registering Commands...");
|
this.log.info("Registering Commands...");
|
||||||
new ClanCommand().register();
|
new ClanCommand().register();
|
||||||
this.log.info("Registered Commands!");
|
this.log.info("Registered Commands!");
|
||||||
|
|
||||||
|
this.log.info("Registering EventListeners...");
|
||||||
|
PluginManager pm = getServer().getPluginManager();
|
||||||
|
pm.registerEvents(new JoinListener(), this);
|
||||||
|
this.log.info("Registered EventListeners!");
|
||||||
|
|
||||||
|
this.log.info("Starting Timer tasks...");
|
||||||
|
this.nameUpdateTask = new PlayerNameUpdate().runTaskTimer(this, 0L, 20L);
|
||||||
|
this.log.info("Started Timer tasks!");
|
||||||
|
|
||||||
|
this.log.info("Enabled BlazeSMP!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Plugin shutdown logic
|
this.log.info("Disabling BlazeSMP...");
|
||||||
|
|
||||||
|
this.log.info("Cancelling Timer tasks...");
|
||||||
|
this.nameUpdateTask.cancel();
|
||||||
|
this.log.info("Cancelled Timer tasks!");
|
||||||
|
|
||||||
|
this.log.info("Saving Homes...");
|
||||||
|
this.homes.save();
|
||||||
|
this.log.info("Saved Homes!");
|
||||||
|
|
||||||
|
this.log.info("Saving ProtectedBlocks...");
|
||||||
|
this.protectedBlocks.save();
|
||||||
|
this.log.info("Saved ProtectedBlocks!");
|
||||||
|
|
||||||
|
this.log.info("Saving Clans...");
|
||||||
|
this.clans.saveAllClans();
|
||||||
|
this.log.info("Saved Clans!");
|
||||||
|
|
||||||
|
this.log.info("Disabling BlazeSMP!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package me.freezy.plugins.papermc.blazesmp.listener;
|
||||||
|
|
||||||
|
import me.freezy.plugins.papermc.blazesmp.manager.PlayerManager;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
public class JoinListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
new PlayerManager().setPlayerTeam(player);
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,7 +46,7 @@ public class PlayerManager {
|
||||||
teamName="zzzm";
|
teamName="zzzm";
|
||||||
}
|
}
|
||||||
teamName+=generateRandomString(12);
|
teamName+=generateRandomString(12);
|
||||||
scoreboard.getTeams().clear();
|
if (!scoreboard.getTeams().isEmpty()) scoreboard.getTeams().clear();
|
||||||
Team team = scoreboard.getTeam(teamName);
|
Team team = scoreboard.getTeam(teamName);
|
||||||
if (team == null) {
|
if (team == null) {
|
||||||
team = scoreboard.registerNewTeam(teamName);
|
team = scoreboard.registerNewTeam(teamName);
|
||||||
|
@ -64,6 +64,13 @@ public class PlayerManager {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
team.prefix(prefix);
|
team.prefix(prefix);
|
||||||
|
Clan clan = clans.getClanByMember(playerUUID);
|
||||||
|
if (clan != null) {
|
||||||
|
team.suffix(Component.text(" ").append(clan.getTag()));
|
||||||
|
} else {
|
||||||
|
team.suffix(Component.empty());
|
||||||
|
}
|
||||||
|
team.addEntity(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateRandomString(int length) {
|
private String generateRandomString(int length) {
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package me.freezy.plugins.papermc.blazesmp.tasks;
|
||||||
|
|
||||||
|
import me.freezy.plugins.papermc.blazesmp.manager.PlayerManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class PlayerNameUpdate extends BukkitRunnable {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
|
new PlayerManager().setPlayerTeam(player);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue