Rank system, but need to remove sidebar to make tab list work... idk why
This commit is contained in:
parent
c99dbcfa6c
commit
532bea2e0c
10 changed files with 310 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
|||
package com.night.nullvalkyrie;
|
||||
package com.night.nullvalkyrie.Chests;
|
||||
|
||||
import com.night.nullvalkyrie.commands.MenuCommand;
|
||||
import org.bukkit.ChatColor;
|
|
@ -1,4 +1,4 @@
|
|||
package com.night.nullvalkyrie;
|
||||
package com.night.nullvalkyrie.Chests;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
|
@ -1,14 +1,21 @@
|
|||
package com.night.nullvalkyrie;
|
||||
|
||||
import com.night.nullvalkyrie.Chests.MenuListener;
|
||||
import com.night.nullvalkyrie.NameTag.NameTagManager;
|
||||
import com.night.nullvalkyrie.RankSys.RankListener;
|
||||
import com.night.nullvalkyrie.RankSys.RankManager;
|
||||
import com.night.nullvalkyrie.SideBar.SideBarListener;
|
||||
import com.night.nullvalkyrie.commands.*;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Snowball;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -17,12 +24,22 @@ import org.bukkit.event.block.Action;
|
|||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public final class Main extends JavaPlugin implements Listener {
|
||||
private BossBar bossbar;
|
||||
private RankManager rankManager;
|
||||
private NameTagManager nameTagManager;
|
||||
|
||||
public RankManager getRankManager() {
|
||||
return rankManager;
|
||||
}
|
||||
public NameTagManager getNameTagManager() { return nameTagManager; }
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
|
@ -34,6 +51,7 @@ public final class Main extends JavaPlugin implements Listener {
|
|||
getCommand("gun").setExecutor(new GunCommand());
|
||||
getCommand("msg").setExecutor(new MessageCommand());
|
||||
getCommand("menu").setExecutor(new MenuCommand());
|
||||
getCommand("rank").setExecutor(new RankCommand(this));
|
||||
bossbar = Bukkit.createBossBar(
|
||||
ChatColor.GOLD + "Kuudra",
|
||||
BarColor.RED,
|
||||
|
@ -41,6 +59,25 @@ public final class Main extends JavaPlugin implements Listener {
|
|||
);
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
Bukkit.getPluginManager().registerEvents(new MenuListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new RankListener(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new SideBarListener(this), this);
|
||||
rankManager = new RankManager(this);
|
||||
nameTagManager = new NameTagManager(this);
|
||||
|
||||
ItemStack widow_sword = new ItemStack(Material.STICK);
|
||||
widow_sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20);
|
||||
widow_sword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 10);
|
||||
widow_sword.addUnsafeEnchantment(Enchantment.LUCK, 10);
|
||||
widow_sword.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
|
||||
ItemMeta wsMeta = widow_sword.getItemMeta();
|
||||
wsMeta.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Fabled Widow Sword");
|
||||
wsMeta.setUnbreakable(true);
|
||||
widow_sword.setItemMeta(wsMeta);
|
||||
ShapedRecipe wither_sword_recipe = new ShapedRecipe(new NamespacedKey(this, "widow_sword"), widow_sword);
|
||||
wither_sword_recipe.shape(" A ", " A "," B ");
|
||||
wither_sword_recipe.setIngredient('A', Material.IRON_INGOT);
|
||||
wither_sword_recipe.setIngredient('B', Material.STICK);
|
||||
Bukkit.addRecipe(wither_sword_recipe);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -59,7 +96,7 @@ public final class Main extends JavaPlugin implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
e.setJoinMessage(ChatColor.RED+"[ADMIN] " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!");
|
||||
e.setJoinMessage(rankManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!");
|
||||
|
||||
e.getPlayer().sendTitle(ChatColor.RED +"Welcome to Operation Valkyrie!", ChatColor.GREEN + "LOL", 20, 100, 20);
|
||||
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§1NOT ENOUGH MANNER"));
|
||||
|
@ -83,7 +120,7 @@ public final class Main extends JavaPlugin implements Listener {
|
|||
@EventHandler
|
||||
public void onPing(ServerListPingEvent e) {
|
||||
e.setMaxPlayers(8964);
|
||||
String s = centerText("Operation Valkyrie [1.18.1 & 1.8.9]\n", 45);
|
||||
String s = centerText("Operation Valkyrie\n", 45);
|
||||
String s2 = centerText("Support 1.18 & 1.8.9",45);
|
||||
e.setMotd(ChatColor.AQUA.toString() + ChatColor.BOLD + s + ChatColor.GOLD + ChatColor.BOLD + s2);
|
||||
try {
|
||||
|
@ -93,4 +130,6 @@ public final class Main extends JavaPlugin implements Listener {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package com.night.nullvalkyrie.NameTag;
|
||||
|
||||
import com.night.nullvalkyrie.Main;
|
||||
import com.night.nullvalkyrie.RankSys.Rank;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
public class NameTagManager {
|
||||
private Main main;
|
||||
|
||||
public NameTagManager(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
public void setNametags(Player player) {
|
||||
Scoreboard newScoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
Objective obj = newScoreboard.registerNewObjective("TabList", "dummy");
|
||||
obj.setDisplaySlot(DisplaySlot.PLAYER_LIST);
|
||||
player.setScoreboard(obj.getScoreboard());
|
||||
for (Rank rank : Rank.values()) {
|
||||
Team team = player.getScoreboard().registerNewTeam(rank.name());
|
||||
team.setPrefix(rank.getDisplay() + " ");
|
||||
}
|
||||
for (Player target : Bukkit.getOnlinePlayers()) {
|
||||
if (player.getUniqueId() != target.getUniqueId()) {
|
||||
Rank rank = main.getRankManager().getRank(target.getUniqueId());
|
||||
player.getScoreboard().getTeam(rank.name()).addEntry(target.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
public void newTag(Player player) {
|
||||
Rank rank = main.getRankManager().getRank(player.getUniqueId());
|
||||
for(Player target : Bukkit.getOnlinePlayers()) {
|
||||
target.getScoreboard().getTeam(rank.name()).addEntry(player.getName());
|
||||
}
|
||||
}
|
||||
public void removeTag(Player player) {
|
||||
Rank rank = main.getRankManager().getRank(player.getUniqueId());
|
||||
for(Player target : Bukkit.getOnlinePlayers()) {
|
||||
target.getScoreboard().getEntryTeam(player.getName()).removeEntry(player.getName());
|
||||
}
|
||||
}
|
||||
}
|
20
src/main/java/com/night/nullvalkyrie/RankSys/Rank.java
Normal file
20
src/main/java/com/night/nullvalkyrie/RankSys/Rank.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package com.night.nullvalkyrie.RankSys;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public enum Rank {
|
||||
OWNER(ChatColor.DARK_RED + "{OWNER}"),
|
||||
ADMIN(ChatColor.RED + "{ADMIN}"),
|
||||
SPECIAL(ChatColor.GOLD + "{SPECIAL}"),
|
||||
ROOKIE(ChatColor.DARK_GREEN + "{ROOKIE}");
|
||||
|
||||
private String display;
|
||||
|
||||
Rank(String display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public String getDisplay() {
|
||||
return display;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.night.nullvalkyrie.RankSys;
|
||||
|
||||
import com.night.nullvalkyrie.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class RankListener implements Listener {
|
||||
|
||||
private Main main;
|
||||
public RankListener(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
if(!player.hasPlayedBefore()) {
|
||||
main.getRankManager().setRank(player.getUniqueId(), Rank.ROOKIE);
|
||||
}
|
||||
main.getNameTagManager().setNametags(player);
|
||||
main.getNameTagManager().newTag(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
e.setQuitMessage(ChatColor.RED + "bozo " + e.getPlayer().getName() + " has left.");
|
||||
main.getNameTagManager().removeTag(e.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
e.setCancelled(true);
|
||||
Player player = e.getPlayer();
|
||||
Bukkit.broadcastMessage(main.getRankManager().getRank(player.getUniqueId()).getDisplay() + " " + player.getName() + ChatColor.WHITE + ": " + e.getMessage());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.night.nullvalkyrie.RankSys;
|
||||
|
||||
import com.night.nullvalkyrie.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RankManager {
|
||||
private File file;
|
||||
private YamlConfiguration config;
|
||||
|
||||
private Main main;
|
||||
|
||||
public RankManager(Main main) {
|
||||
this.main = main;
|
||||
if(!main.getDataFolder().exists()) {
|
||||
main.getDataFolder().mkdir();
|
||||
}
|
||||
file = new File(main.getDataFolder(), "ranks.yml");
|
||||
if(!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
public void setRank(UUID uuid, Rank rank) {
|
||||
config.set(uuid.toString(), rank.name());
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
main.getNameTagManager().removeTag(player);
|
||||
main.getNameTagManager().newTag(player);
|
||||
}
|
||||
}
|
||||
public Rank getRank(UUID uuid) {
|
||||
return Rank.valueOf(config.getString(uuid.toString()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.night.nullvalkyrie.SideBar;
|
||||
|
||||
import com.night.nullvalkyrie.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scoreboard.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SideBarListener implements Listener {
|
||||
private Main main;
|
||||
public SideBarListener(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
private HashMap<UUID, Integer> deaths = new HashMap<>();
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
Objective obj = board.registerNewObjective("Pluto", "dummy");
|
||||
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
obj.setDisplayName(ChatColor.AQUA.toString() + ChatColor.BOLD + "Pluto");
|
||||
Score website = obj.getScore(ChatColor.YELLOW + "cath.js.org");
|
||||
website.setScore(1);
|
||||
Score space1 = obj.getScore(" ");
|
||||
space1.setScore(2);
|
||||
Score name = obj.getScore(ChatColor.BLUE + "Player Name: " + player.getName());
|
||||
name.setScore(4);
|
||||
Team playersOnline = board.registerNewTeam("deathsTotal");
|
||||
playersOnline.addEntry(ChatColor.BOLD.toString());
|
||||
playersOnline.setPrefix(ChatColor.BLUE + "Deaths: ");
|
||||
playersOnline.setSuffix(ChatColor.YELLOW + "0");
|
||||
obj.getScore(ChatColor.BOLD.toString()).setScore(3);
|
||||
player.setScoreboard(board);
|
||||
deaths.put(player.getUniqueId(), 0);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDeath(PlayerDeathEvent e) {
|
||||
Player player = e.getEntity().getPlayer();
|
||||
int amount = deaths.get(player.getUniqueId());
|
||||
amount++;
|
||||
deaths.put(player.getUniqueId(), amount);
|
||||
player.getScoreboard().getTeam("deathsTotal").setSuffix(ChatColor.YELLOW.toString() + amount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.night.nullvalkyrie.commands;
|
||||
|
||||
import com.night.nullvalkyrie.Main;
|
||||
import com.night.nullvalkyrie.RankSys.Rank;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
//92.0.69.141:25565
|
||||
public class RankCommand implements CommandExecutor {
|
||||
private Main main;
|
||||
public RankCommand(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if(player.isOp()) {
|
||||
if(args.length == 2) {
|
||||
if(Bukkit.getOfflinePlayer(args[0]).hasPlayedBefore()) {
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
|
||||
for(Rank rank : Rank.values()) {
|
||||
if(rank.name().equalsIgnoreCase(args[1])) {
|
||||
main.getRankManager().setRank(target.getUniqueId(), rank);
|
||||
player.sendMessage(ChatColor.GREEN + "You changed " + target.getName() + "'s rank to " + rank.getDisplay());
|
||||
if(target.isOnline()) {
|
||||
target.getPlayer().sendMessage(ChatColor.GREEN + player.getName() + " set your rank to " + rank.getDisplay());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
player.sendMessage(ChatColor.RED + "Invalid Rank, please specify a valid rank, ROOKIE, SPECIAL, ADMIN, OWNER");
|
||||
} else {
|
||||
player.sendMessage("This player has never played in this server before!");
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Invalid parameter, use /rank <Player> <Rank>");
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "You must be server operator to use this command");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -18,3 +18,5 @@ commands:
|
|||
description: "Send message to someone"
|
||||
menu:
|
||||
description: "Open the menu"
|
||||
rank:
|
||||
description: "Set rank of players"
|
Loading…
Reference in a new issue