Holograms

This commit is contained in:
night0721 2022-07-06 15:50:48 +01:00
parent 532bea2e0c
commit 0b464de40a
5 changed files with 59 additions and 5 deletions

View file

@ -21,6 +21,7 @@ import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.server.ServerListPingEvent;
@ -52,6 +53,7 @@ public final class Main extends JavaPlugin implements Listener {
getCommand("msg").setExecutor(new MessageCommand()); getCommand("msg").setExecutor(new MessageCommand());
getCommand("menu").setExecutor(new MenuCommand()); getCommand("menu").setExecutor(new MenuCommand());
getCommand("rank").setExecutor(new RankCommand(this)); getCommand("rank").setExecutor(new RankCommand(this));
getCommand("hologram").setExecutor(new HologramCommand());
bossbar = Bukkit.createBossBar( bossbar = Bukkit.createBossBar(
ChatColor.GOLD + "Kuudra", ChatColor.GOLD + "Kuudra",
BarColor.RED, BarColor.RED,
@ -130,6 +132,11 @@ public final class Main extends JavaPlugin implements Listener {
} }
} }
// For hologram clicks to change page
// @EventHandler
// public void onEntityInteract(EntityInteractEvent e) {
// System.out.println(e.getEntity().getLocation());
// e.getEntity().setCustomName(ChatColor.RED + "Changed name since you ust clicked lol");
// }
} }

View file

@ -7,9 +7,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scoreboard.*; import org.bukkit.scoreboard.*;
import java.util.HashMap; import java.util.HashMap;

View file

@ -0,0 +1,35 @@
package com.night.nullvalkyrie.commands;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
public class HologramCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player player = (Player) sender;
String[] ar = new String[]{
ChatColor.AQUA + "Hi",
ChatColor.DARK_PURPLE + "What",
ChatColor.GOLD + "Hello World"
};
Location location = player.getLocation();
for(String line: ar) {
ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(location.subtract(0,0.3,0), EntityType.ARMOR_STAND);
stand.setInvisible(true);
stand.setGravity(false);
stand.setInvulnerable(true);
stand.setCustomNameVisible(true);
stand.setCustomName(line);
}
}
return false;
}
}

View file

@ -1,5 +1,7 @@
package com.night.nullvalkyrie.commands; package com.night.nullvalkyrie.commands;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.night.nullvalkyrie.Main; import com.night.nullvalkyrie.Main;
import com.night.nullvalkyrie.RankSys.Rank; import com.night.nullvalkyrie.RankSys.Rank;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -9,17 +11,22 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
//92.0.69.141:25565 //92.0.69.141:25565
public class RankCommand implements CommandExecutor { public class RankCommand implements CommandExecutor {
private Main main; private Main main;
public RankCommand(Main main) { public RankCommand(Main main) {
this.main = main; this.main = main;
} }
private Cache<UUID, Long> cooldown = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.SECONDS).build();
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) { if(sender instanceof Player) {
Player player = (Player) sender; Player player = (Player) sender;
if(player.isOp()) { if(!cooldown.asMap().containsKey(player.getUniqueId())) {if(player.isOp()) {
if(args.length == 2) { if(args.length == 2) {
if(Bukkit.getOfflinePlayer(args[0]).hasPlayedBefore()) { if(Bukkit.getOfflinePlayer(args[0]).hasPlayedBefore()) {
OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
@ -43,6 +50,11 @@ public class RankCommand implements CommandExecutor {
} else { } else {
player.sendMessage(ChatColor.RED + "You must be server operator to use this command"); player.sendMessage(ChatColor.RED + "You must be server operator to use this command");
} }
cooldown.put(player.getUniqueId(), System.currentTimeMillis() + 5000);
} else {
long distance = cooldown.asMap().get(player.getUniqueId()) - System.currentTimeMillis();
player.sendMessage(ChatColor.RED + "You are on a " + TimeUnit.MILLISECONDS.toSeconds(distance) + " seconds cooldown to use the command again");
}
} }
return false; return false;
} }

View file

@ -19,4 +19,6 @@ commands:
menu: menu:
description: "Open the menu" description: "Open the menu"
rank: rank:
description: "Set rank of players" description: "Set rank of players"
hologram:
description: "Spawn a hologram"