Advertisement
Guest User

code

a guest
May 27th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.90 KB | None | 0 0
  1. package com.gmail.JyckoSianjaya.LastHolo;
  2.  
  3. import java.util.HashMap;
  4. import java.util.UUID;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.OfflinePlayer;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.command.ConsoleCommandSender;
  11. import org.bukkit.configuration.file.FileConfiguration;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.event.player.AsyncPlayerChatEvent;
  16. import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
  17. import org.bukkit.event.player.PlayerChatEvent;
  18. import org.bukkit.event.player.PlayerJoinEvent;
  19. import org.bukkit.event.player.PlayerQuitEvent;
  20. import org.bukkit.plugin.Plugin;
  21. import org.bukkit.plugin.java.JavaPlugin;
  22. import org.bukkit.scheduler.BukkitRunnable;
  23.  
  24. import com.gmail.filoghost.holographicdisplays.api.Hologram;
  25. import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
  26. import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
  27.  
  28. public class kaain extends JavaPlugin implements Listener {
  29.  
  30. HashMap<String,Hologram> cache = new HashMap<>();
  31. HashMap<String,Integer> live = new HashMap<>();
  32. HashMap<Player,Boolean> toggle = new HashMap<>();
  33. double offset = 3.0;
  34. double firstoffset = 1.5;
  35. int livetick = 95;
  36. int maxlength = 20;
  37. boolean enablelength = true;
  38.  
  39. /*
  40.  
  41.  
  42. */
  43.  
  44. public Boolean shouldEnable(){
  45. return getServer().getPluginManager().isPluginEnabled("HolographicDisplays");
  46. }
  47. public void reloadConfig2() {
  48. offset = this.getConfig().getDouble("holo-offset");
  49. firstoffset = this.getConfig().getDouble("holo-firstoffset");
  50. livetick = this.getConfig().getInt("holo-livetick");
  51. enablelength = this.getConfig().getBoolean("enable-max-length");
  52. maxlength = this.getConfig().getInt("max-length");
  53. }
  54. public void sendConsole(String msg){
  55. ConsoleCommandSender cs = Bukkit.getServer().getConsoleSender();
  56. cs.sendMessage(org.bukkit.ChatColor.translateAlternateColorCodes('&',msg));
  57. }
  58. public void sendmsg(Player player, String msg) {
  59. player.sendMessage(org.bukkit.ChatColor.translateAlternateColorCodes('&', msg));
  60. }
  61. @Override
  62. public void onEnable() {
  63. if (!shouldEnable()) {
  64. sendConsole("&cHolographicDisplays not found! Disabling plugin!");
  65. getServer().getPluginManager().disablePlugin(this);
  66. this.setEnabled(false);
  67. return;
  68. }
  69. sendConsole("&aenabled Holographic Chat plugin succesfully!");
  70. getServer().getPluginManager().registerEvents(this, this);
  71. getConfig().options().copyDefaults(true);
  72. FileConfiguration config = this.getConfig();
  73. offset = config.getDouble("holo-offset");
  74. firstoffset = config.getDouble("holo-firstoffset");
  75. livetick = config.getInt("holo-livetick");
  76. saveConfig();
  77. new BukkitRunnable() {
  78. @Override
  79. public void run() {
  80. for (String name : cache.keySet()) {
  81. Player p = Bukkit.getPlayer(name);
  82. Hologram holo = cache.get(name);
  83. int clive = live.get(name);
  84. if (clive < 1) {
  85. cache.remove(name);
  86. live.remove(name);
  87. holo.delete();
  88. }
  89. else {
  90. live.put(name, clive - 1);
  91. holo.teleport(p.getLocation().add(0.0, offset, 0.0));
  92. }
  93. }
  94. }
  95. }.runTaskTimer(this, 1L, 1L);
  96. }
  97. @EventHandler
  98. public void OnQuit(PlayerQuitEvent quita) {
  99. Player p = quita.getPlayer();
  100. String thename = p.getName();
  101. if (cache.containsKey(thename)) {
  102. Hologram holo = cache.get(thename);
  103. holo.delete();
  104. cache.remove(thename);
  105. live.remove(thename);
  106. }
  107. }
  108. @Override
  109. public void onDisable() {
  110. // TODO : Make more things
  111. sendConsole("LastHolo disabled");
  112. }
  113.  
  114. @SuppressWarnings("deprecation")
  115. @EventHandler
  116. public void playerchat(PlayerChatEvent e) {
  117.  
  118.  
  119. // nah ini
  120. // SINI
  121. // SINI
  122. // baca sini
  123. // iya
  124. // nama var nya diganti anjer :'v
  125. // kan indah
  126.  
  127. // ada yang mau gw ubah , biar lebih efisien dan ga makan memory
  128. // liat hashmap diatas
  129. // dah
  130.  
  131. Player p = e.getPlayer();
  132. String name = p.getName();
  133. String msg = e.getMessage();
  134. if (p.hasPermission("holo.chat")) {
  135. if (toggle.get(p) == null) {
  136. toggle.put(p, true);
  137. }
  138. if (toggle.get(p) == true) {
  139. int g = msg.length();
  140. if (enablelength == true) {
  141. if (g >= maxlength) {
  142. msg = msg.substring(0, maxlength) + "..";
  143. }
  144. }
  145. if (p.hasPermission("holo.color")) {
  146. msg = org.bukkit.ChatColor.translateAlternateColorCodes('&', msg);
  147. }
  148. Hologram holo = cache.getOrDefault(name, HologramsAPI.createHologram(this, p.getLocation().add(0.0, firstoffset, 0.0)));
  149. if(holo.size() > 0) {
  150. TextLine tl = (TextLine)holo.getLine(0);
  151. tl.setText(msg);
  152. }else {
  153. holo.appendTextLine(msg);
  154. }
  155. cache.put(name, holo);
  156. live.put(name, livetick);
  157. }
  158. }
  159. }
  160. @SuppressWarnings("unlikely-arg-type")
  161. @Override
  162. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  163. Player player = null;
  164. if(sender instanceof Player){
  165. player = (Player) sender;
  166. }
  167. if (cmd.getName().equalsIgnoreCase("lastholo")) {
  168. int length = args.length;
  169. if (length == 0) {
  170. sendmsg(player, "&e&m------------------------");
  171. sendmsg(player, " &b&lLast&3&lHolo ");
  172. sendmsg(player, "&f>> &7/lh reload");
  173. sendmsg(player, "&F>> &7/lh toggle");
  174. sendmsg(player, "&e&m------------------------");
  175. return true;
  176. }
  177.  
  178. if(length > 0){
  179. if(args[0].equalsIgnoreCase("reload")){
  180. if(!player.hasPermission("holo.reload")){
  181. sendmsg(player,"No Permission, too handsome.");
  182. return true;
  183. }
  184. else{
  185. sendmsg(player,"Config Reloaded");
  186. }
  187. }else{
  188. sendConsole("Config Reloaded");
  189. }
  190. // keatas
  191. //
  192. reloadConfig();
  193. reloadConfig2();
  194. }
  195. if(args[0].equalsIgnoreCase("toggle")) {
  196. if (!player.hasPermission("holo.toggle")) {
  197. sendmsg(player,"&c&lHey! &cCan't do that without permission!");
  198. return true;
  199. }
  200. if (toggle.get(player) == null) {
  201. toggle.put(player, true);
  202. sendmsg(player, "&8[&f&l!&8] &7You're chat will now pop up. (&aON&7)");
  203. return true;
  204. }
  205. if (toggle.get(player) == false) {
  206. toggle.put(player, true);
  207. sendmsg(player, "&8[&f&l!&8] &7You're chat will now pop up. (&aON&7)");
  208. return true;
  209. }
  210. if (toggle.get(player) == true) {
  211. toggle.put(player, false);
  212. sendmsg(player, "&8[&f&l!&8] &7You're chat won't pop up anymore. (&cOFF&7)");
  213. return true;
  214. }
  215.  
  216. }
  217. }
  218. return true;
  219.  
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement