Advertisement
Guest User

Code #1

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.83 KB | None | 0 0
  1. package me.ashten.levelingplugin;
  2.  
  3. import java.util.HashMap;
  4. import java.util.UUID;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.command.ConsoleCommandSender;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.permissions.Permission;
  13. import org.bukkit.permissions.PermissionAttachment;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15. import org.bukkit.scoreboard.Scoreboard;
  16. import org.bukkit.scoreboard.Team;
  17.  
  18. public class Main extends JavaPlugin {
  19.  
  20. public HashMap<UUID, PermissionAttachment> playerPermissions = new HashMap<>();
  21.  
  22. // LuckPermsApi api = LuckPerms.getApi();
  23.  
  24. @Override
  25. public void onEnable() {
  26. getLogger().info(ChatColor.GREEN + "Plugin succesfully started!");
  27.  
  28. getServer().getPluginManager().registerEvents(new Events(this), this);
  29. loadConfig();
  30.  
  31. // BukkitScheduler scheduler = this.getServer().getScheduler();
  32. // scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
  33. // @Override
  34. // public void run() {
  35. // fixStuff();
  36. // }
  37. // }, 0L, 40L);
  38.  
  39. }
  40.  
  41. public void addPermission(Player p, String permission) {
  42. String pname = p.getName();
  43.  
  44. ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
  45. String command = "lp user " + pname + " permission set " + permission;
  46. Bukkit.dispatchCommand(console, command);
  47. }
  48.  
  49. public void removePermission(Player p, String permission) {
  50. String pname = p.getName();
  51.  
  52. ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
  53. String command = "lp user " + pname + " permission unset " + permission;
  54. Bukkit.dispatchCommand(console, command);
  55. }
  56.  
  57. public void setupPermissions(Player player) {
  58. PermissionAttachment attachment = player.addAttachment(this);
  59. this.playerPermissions.put(player.getUniqueId(), attachment);
  60. playerSet(player.getUniqueId(), new Permission("ash.testperm"), true);
  61. }
  62.  
  63. public void playerSet(UUID uuid, Permission perm, boolean b) {
  64. PermissionAttachment attachment = this.playerPermissions.get(uuid);
  65. attachment.setPermission(perm, b);
  66. }
  67.  
  68. @SuppressWarnings("deprecation")
  69. public void onNameTag(Player p, String xp) {
  70. Scoreboard score = Bukkit.getScoreboardManager().getMainScoreboard();
  71. Team t = score.getTeam(xp);
  72.  
  73. if (t == null) {
  74. t = score.registerNewTeam(xp);
  75. }
  76.  
  77. t.setPrefix(xp);
  78. t.addPlayer(p);
  79.  
  80. for (Player all : Bukkit.getOnlinePlayers()) {
  81. all.setScoreboard(score);
  82. }
  83. }
  84.  
  85. private HashMap<String, Integer> map = new HashMap<String, Integer>();
  86.  
  87. Scoreboard s;
  88.  
  89. @Override
  90. public void onDisable() {
  91. getLogger().info(ChatColor.RED + "Plugin succesfully stopped!");
  92. saveConfig();
  93.  
  94. playerPermissions.clear();
  95. }
  96.  
  97. public void loadConfig() {
  98. getConfig().options().copyDefaults(true);
  99. saveConfig();
  100. }
  101.  
  102. public void fixStuff(Player p, Integer level) {
  103. if (!(level == null)) {
  104.  
  105. } else {
  106. level = 0;
  107. }
  108.  
  109. if (level < 0) {
  110. level = 0;
  111. }
  112.  
  113. if (level > 200) {
  114. level = 200;
  115. }
  116.  
  117. if (level < 10) {
  118. removePermission(p, "ash.10");
  119. removePermission(p, "ash.20");
  120. removePermission(p, "ash.30");
  121. removePermission(p, "ash.40");
  122. removePermission(p, "ash.50");
  123. removePermission(p, "ash.60");
  124. }
  125. if (level > 9 && level < 20 && p.hasPermission("magicspells.rank.chuunin")) {
  126. addPermission(p, "ash.10");
  127. }
  128.  
  129. if (level > 19 && level < 30 && p.hasPermission("magicspells.rank.chuunin")) {
  130. removePermission(p, "ash.10");
  131. addPermission(p, "ash.20");
  132. }
  133. if (level > 29 && level < 40 && p.hasPermission("magicspells.rank.jounin")) {
  134. removePermission(p, "ash.20");
  135. addPermission(p, "ash.30");
  136. }
  137. if (level >= 40 && level < 50 && p.hasPermission("magicspells.rank.jounin")) {
  138. removePermission(p, "ash.30");
  139. addPermission(p, "ash.40");
  140. }
  141. if (level >= 50 && level < 60 && p.hasPermission("magicspells.rank.jounin")) {
  142. removePermission(p, "ash.40");
  143. addPermission(p, "ash.50");
  144. }
  145. if (level >= 60 && level < 70 && p.hasPermission("magicspells.rank.jounin")) {
  146. removePermission(p, "ash.50");
  147. addPermission(p, "ash.60");
  148. }
  149. if (level >= 70 && level < 80 && p.hasPermission("magicspells.rank.jounin")) {
  150. removePermission(p, "ash.60");
  151. addPermission(p, "ash.70");
  152. }
  153. if (level >= 80 && level < 90 && p.hasPermission("magicspells.rank.jounin")) {
  154. removePermission(p, "ash.70");
  155. addPermission(p, "ash.80");
  156. }
  157. if (level >= 90 && level < 100 && p.hasPermission("magicspells.rank.jounin")) {
  158. removePermission(p, "ash.80");
  159. addPermission(p, "ash.90");
  160. }
  161. if (level >= 100 && level < 110 && p.hasPermission("magicspells.rank.jounin")) {
  162. removePermission(p, "ash.90");
  163. addPermission(p, "ash.100");
  164. }
  165. if (level >= 110 && level < 120 && p.hasPermission("magicspells.rank.jounin")) {
  166. removePermission(p, "ash.100");
  167. addPermission(p, "ash.110");
  168. }
  169. if (level >= 120 && level < 130 && p.hasPermission("magicspells.rank.jounin")) {
  170. removePermission(p, "ash.110");
  171. addPermission(p, "ash.120");
  172. }
  173. if (level >= 130 && level < 140 && p.hasPermission("magicspells.rank.jounin")) {
  174. removePermission(p, "ash.120");
  175. addPermission(p, "ash.130");
  176. }
  177. if (level >= 140 && level < 150 && p.hasPermission("magicspells.rank.jounin")) {
  178. removePermission(p, "ash.130");
  179. addPermission(p, "ash.140");
  180. }
  181. if (level >= 150 && level < 160 && p.hasPermission("magicspells.rank.jounin")) {
  182. removePermission(p, "ash.140");
  183. addPermission(p, "ash.150");
  184. }
  185. if (level >= 160 && level < 170 && p.hasPermission("magicspells.rank.jounin")) {
  186. removePermission(p, "ash.150");
  187. addPermission(p, "ash.160");
  188. }
  189. if (level >= 170 && level < 180 && p.hasPermission("magicspells.rank.jounin")) {
  190. removePermission(p, "ash.160");
  191. addPermission(p, "ash.170");
  192. }
  193. if (level >= 180 && level < 190 && p.hasPermission("magicspells.rank.jounin")) {
  194. removePermission(p, "ash.170");
  195. addPermission(p, "ash.180");
  196. }
  197. if (level >= 190 && level < 200 && p.hasPermission("magicspells.rank.jounin")) {
  198. removePermission(p, "ash.180");
  199. addPermission(p, "ash.190");
  200. }
  201. if (level >= 200 && p.hasPermission("magicspells.rank.jounin")) {
  202. removePermission(p, "ash.190");
  203. addPermission(p, "ash.200");
  204. }
  205.  
  206. if (level > 9 && !p.hasPermission("magicspells.rank.chuunin")) {
  207. level = 9;
  208. }
  209.  
  210. if (level > 29 && !p.hasPermission("magicspells.rank.jounin")) {
  211. level = 29;
  212. }
  213.  
  214. if (level > 200) {
  215. level = 200;
  216. }
  217.  
  218.  
  219. onNameTag(p, ChatColor.DARK_GRAY + "LVL:" + ChatColor.AQUA + " " + (Integer) this.getConfig().get("LVL."+p.getName()) + " " + ChatColor.WHITE);
  220. }
  221.  
  222. @SuppressWarnings("deprecation")
  223. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  224. if (sender instanceof Player) {
  225. // Credits command
  226. if (cmd.getName().equalsIgnoreCase("credits")) {
  227. sender.sendMessage(ChatColor.BOLD+""+ChatColor.GOLD + "This plugin is made by " + ChatColor.AQUA + "AshTen_ "
  228. + ChatColor.GOLD + "(" + ChatColor.RED + "Rosa#8710" + ChatColor.GOLD + ")");
  229. return true;
  230. }
  231. //
  232. // // set XP command
  233. // if (cmd.getName().equalsIgnoreCase("setxp")) {
  234. // if (args[0] != null) {
  235. // if (Integer.parseInt(args[0].replaceAll("[\\D]", "")) >= 0
  236. // && Integer.parseInt(args[0].replaceAll("[\\D]", "")) < 100000000) {
  237. // map.put(sender.getName(), Integer.parseInt(args[0].replaceAll("[\\D]", "")));
  238. // sender.sendMessage(ChatColor.GREEN + "Your XP has been set!");
  239. // this.getConfig().set("XP." + sender.getName(),
  240. // Integer.parseInt(args[0].replaceAll("[\\D]", "")));
  241. // this.saveConfig();
  242. // return true;
  243. // } else {
  244. // sender.sendMessage(ChatColor.RED + "Unknown error, please contact the
  245. // developer");
  246. // return true;
  247. // }
  248. // } else {
  249. // sender.sendMessage(ChatColor.RED + "This command needs an argument
  250. // (Number)");
  251. // return true;
  252. // }
  253. // }
  254.  
  255. // see XP command
  256. if (cmd.getName().equalsIgnoreCase("level")) {
  257. if (sender.hasPermission("ash.level")) {
  258.  
  259. if (this.getConfig().get("XP." + sender.getName()) != null) {
  260. Integer xp = (Integer) this.getConfig().get("XP." + sender.getName());
  261. Integer lvl = (Integer) this.getConfig().get("LVL." + sender.getName());
  262. Integer needed = (Integer) this.getConfig().get("NE." + sender.getName());
  263. sender.sendMessage(ChatColor.GOLD + "( ---" + ChatColor.RED + " Ninja Status "
  264. + ChatColor.GOLD + "--- ) \n" + ChatColor.GOLD + "Level: " + ChatColor.AQUA
  265. + lvl + ChatColor.GOLD + "\nExp: " + ChatColor.AQUA + xp + "/" + needed);
  266. return true;
  267. } else {
  268. this.getConfig().set("XP." + sender.getName(), 0);
  269. this.getConfig().set("LVL." + sender.getName(), 0);
  270.  
  271. this.getConfig().get("XP." + sender.getName());
  272. this.getConfig().get("LVL." + sender.getName());
  273. this.getConfig().get("NE." + sender.getName());
  274. sender.sendMessage(ChatColor.GOLD + "( ---" + ChatColor.RED + "Ninja Status"
  275. + ChatColor.GOLD + "--- ) \n" + ChatColor.GOLD + "Level:" + ChatColor.AQUA
  276. + " 0\n" + ChatColor.GOLD + "Exp: " + ChatColor.AQUA + "0/100");
  277.  
  278. return true;
  279. }
  280.  
  281. } else {
  282. sender.sendMessage(ChatColor.DARK_RED + "NO PERMISSIONS");
  283. return true;
  284. }
  285. }
  286.  
  287. // add XP command
  288. if (cmd.getName().equalsIgnoreCase("addxp")) {
  289. if (sender.hasPermission("ash.addxp")) {
  290. if (args.length > 1) {
  291.  
  292. Player target = getServer().getPlayer(args[0]);
  293.  
  294. if (args[0] != null) {
  295. Integer cxp = (Integer) this.getConfig().get("XP." + target.getName());
  296. Integer adx = Integer.parseInt(args[1].replaceAll("[\\D]", ""));
  297. Integer newxp = cxp + adx;
  298. target.sendMessage(ChatColor.AQUA + "You now have " + newxp + " XP!");
  299. map.put(sender.getName(), newxp);
  300. this.getConfig().set("XP." + target.getName(), newxp);
  301. this.getConfig().get("LVL." + target.getName());
  302. this.saveConfig();
  303.  
  304. Integer lvl = (Integer) this.getConfig().get("LVL." + target.getName());
  305. if (lvl == null) {
  306. lvl = 0;
  307. this.getConfig().set("LVL." + target.getName(), 0);
  308. }
  309.  
  310. Integer xp = (Integer) this.getConfig().get("XP." + target.getName());
  311. if (xp == null) {
  312. xp = 0;
  313. }
  314.  
  315. Integer needed = (Integer) this.getConfig().get("NE." + target.getName());
  316.  
  317. if (needed == null) {
  318. needed = 100;
  319. this.getConfig().set("NE." + target.getName(), 100);
  320. }
  321.  
  322. Integer newlvl = lvl + 1;
  323.  
  324. if (xp >= needed) {
  325. lvl = newlvl;
  326.  
  327. if (lvl > 9 && !target.hasPermission("magicspells.rank.chuunin")) {
  328. newlvl = 9;
  329. }
  330.  
  331. if (lvl > 29 && !target.hasPermission("magicspells.rank.jounin")) {
  332. newlvl = 29;
  333. }
  334.  
  335. if (lvl > 200) {
  336. newlvl = 200;
  337. }
  338.  
  339. Integer remaining = xp - needed;
  340. needed = needed + 100;
  341. xp = 0;
  342. this.getConfig().set("XP." + target.getName(), remaining);
  343.  
  344. this.getConfig().set("LVL." + target.getName(), newlvl);
  345. this.getConfig().set("NE." + target.getName(), needed);
  346. target.sendMessage(ChatColor.GREEN + "You just ranked up to level " + ChatColor.AQUA
  347. + newlvl + ChatColor.GREEN + "!");
  348.  
  349. } else {
  350.  
  351. }
  352.  
  353. fixStuff(target, newlvl);
  354.  
  355. return true;
  356. } else {
  357. sender.sendMessage(ChatColor.RED + "Unknown error");
  358. return true;
  359. }
  360. } else {
  361. sender.sendMessage(ChatColor.RED + "This command needs two arguments! (player, amount)");
  362. }
  363.  
  364. } else {
  365. sender.sendMessage(
  366. ChatColor.DARK_AQUA + "You do not have the permission " + ChatColor.RED + "ash.addxp");
  367. }
  368.  
  369. }
  370.  
  371. // reset XP command
  372. if (cmd.getName().equalsIgnoreCase("resetxp")) {
  373. if (sender.hasPermission("ash.resetxp")) {
  374.  
  375. if (args.length > 0) {
  376. Player target = getServer().getPlayer(args[0]);
  377.  
  378. this.getConfig().set("XP." + target.getName(), 0);
  379. this.getConfig().set("LVL." + target.getName(), 0);
  380. this.getConfig().set("NE." + target.getName(), 100);
  381.  
  382. target.sendMessage(ChatColor.RED + "Your XP has been reset!");
  383. sender.sendMessage(ChatColor.GREEN + "Success!");
  384. fixStuff((Player) sender, 0);
  385.  
  386. return true;
  387. } else {
  388. sender.sendMessage(ChatColor.RED + "This command needs an argument! (player)");
  389. return true;
  390. }
  391. } else {
  392. sender.sendMessage(
  393. ChatColor.DARK_AQUA + "You do not have the permission " + ChatColor.RED + "ash.resetxp");
  394. }
  395.  
  396. }
  397.  
  398. }
  399. return false;
  400. }
  401.  
  402. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement