Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gmail.JyckoSianjaya.LastHolo;
- import java.util.HashMap;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.command.ConsoleCommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- 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.AsyncPlayerPreLoginEvent;
- import org.bukkit.event.player.PlayerChatEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitRunnable;
- import com.gmail.filoghost.holographicdisplays.api.Hologram;
- import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
- import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
- public class kaain extends JavaPlugin implements Listener {
- HashMap<String,Hologram> cache = new HashMap<>();
- HashMap<String,Integer> live = new HashMap<>();
- HashMap<Player,Boolean> toggle = new HashMap<>();
- double offset = 3.0;
- double firstoffset = 1.5;
- int livetick = 95;
- int maxlength = 20;
- boolean enablelength = true;
- /*
- */
- public Boolean shouldEnable(){
- return getServer().getPluginManager().isPluginEnabled("HolographicDisplays");
- }
- public void reloadConfig2() {
- offset = this.getConfig().getDouble("holo-offset");
- firstoffset = this.getConfig().getDouble("holo-firstoffset");
- livetick = this.getConfig().getInt("holo-livetick");
- enablelength = this.getConfig().getBoolean("enable-max-length");
- maxlength = this.getConfig().getInt("max-length");
- }
- public void sendConsole(String msg){
- ConsoleCommandSender cs = Bukkit.getServer().getConsoleSender();
- cs.sendMessage(org.bukkit.ChatColor.translateAlternateColorCodes('&',msg));
- }
- public void sendmsg(Player player, String msg) {
- player.sendMessage(org.bukkit.ChatColor.translateAlternateColorCodes('&', msg));
- }
- @Override
- public void onEnable() {
- if (!shouldEnable()) {
- sendConsole("&cHolographicDisplays not found! Disabling plugin!");
- getServer().getPluginManager().disablePlugin(this);
- this.setEnabled(false);
- return;
- }
- sendConsole("&aenabled Holographic Chat plugin succesfully!");
- getServer().getPluginManager().registerEvents(this, this);
- getConfig().options().copyDefaults(true);
- FileConfiguration config = this.getConfig();
- offset = config.getDouble("holo-offset");
- firstoffset = config.getDouble("holo-firstoffset");
- livetick = config.getInt("holo-livetick");
- saveConfig();
- new BukkitRunnable() {
- @Override
- public void run() {
- for (String name : cache.keySet()) {
- Player p = Bukkit.getPlayer(name);
- Hologram holo = cache.get(name);
- int clive = live.get(name);
- if (clive < 1) {
- cache.remove(name);
- live.remove(name);
- holo.delete();
- }
- else {
- live.put(name, clive - 1);
- holo.teleport(p.getLocation().add(0.0, offset, 0.0));
- }
- }
- }
- }.runTaskTimer(this, 1L, 1L);
- }
- @EventHandler
- public void OnQuit(PlayerQuitEvent quita) {
- Player p = quita.getPlayer();
- String thename = p.getName();
- if (cache.containsKey(thename)) {
- Hologram holo = cache.get(thename);
- holo.delete();
- cache.remove(thename);
- live.remove(thename);
- }
- }
- @Override
- public void onDisable() {
- // TODO : Make more things
- sendConsole("LastHolo disabled");
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void playerchat(PlayerChatEvent e) {
- // nah ini
- // SINI
- // SINI
- // baca sini
- // iya
- // nama var nya diganti anjer :'v
- // kan indah
- // ada yang mau gw ubah , biar lebih efisien dan ga makan memory
- // liat hashmap diatas
- // dah
- Player p = e.getPlayer();
- String name = p.getName();
- String msg = e.getMessage();
- if (p.hasPermission("holo.chat")) {
- if (toggle.get(p) == null) {
- toggle.put(p, true);
- }
- if (toggle.get(p) == true) {
- int g = msg.length();
- if (enablelength == true) {
- if (g >= maxlength) {
- msg = msg.substring(0, maxlength) + "..";
- }
- }
- if (p.hasPermission("holo.color")) {
- msg = org.bukkit.ChatColor.translateAlternateColorCodes('&', msg);
- }
- Hologram holo = cache.getOrDefault(name, HologramsAPI.createHologram(this, p.getLocation().add(0.0, firstoffset, 0.0)));
- if(holo.size() > 0) {
- TextLine tl = (TextLine)holo.getLine(0);
- tl.setText(msg);
- }else {
- holo.appendTextLine(msg);
- }
- cache.put(name, holo);
- live.put(name, livetick);
- }
- }
- }
- @SuppressWarnings("unlikely-arg-type")
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- Player player = null;
- if(sender instanceof Player){
- player = (Player) sender;
- }
- if (cmd.getName().equalsIgnoreCase("lastholo")) {
- int length = args.length;
- if (length == 0) {
- sendmsg(player, "&e&m------------------------");
- sendmsg(player, " &b&lLast&3&lHolo ");
- sendmsg(player, "&f>> &7/lh reload");
- sendmsg(player, "&F>> &7/lh toggle");
- sendmsg(player, "&e&m------------------------");
- return true;
- }
- if(length > 0){
- if(args[0].equalsIgnoreCase("reload")){
- if(!player.hasPermission("holo.reload")){
- sendmsg(player,"No Permission, too handsome.");
- return true;
- }
- else{
- sendmsg(player,"Config Reloaded");
- }
- }else{
- sendConsole("Config Reloaded");
- }
- // keatas
- //
- reloadConfig();
- reloadConfig2();
- }
- if(args[0].equalsIgnoreCase("toggle")) {
- if (!player.hasPermission("holo.toggle")) {
- sendmsg(player,"&c&lHey! &cCan't do that without permission!");
- return true;
- }
- if (toggle.get(player) == null) {
- toggle.put(player, true);
- sendmsg(player, "&8[&f&l!&8] &7You're chat will now pop up. (&aON&7)");
- return true;
- }
- if (toggle.get(player) == false) {
- toggle.put(player, true);
- sendmsg(player, "&8[&f&l!&8] &7You're chat will now pop up. (&aON&7)");
- return true;
- }
- if (toggle.get(player) == true) {
- toggle.put(player, false);
- sendmsg(player, "&8[&f&l!&8] &7You're chat won't pop up anymore. (&cOFF&7)");
- return true;
- }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement