Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.KaeFiverr.Tag;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Random;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.GameMode;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.boss.BarColor;
- import org.bukkit.boss.BarStyle;
- import org.bukkit.boss.BossBar;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.player.PlayerChangedWorldEvent;
- import org.bukkit.event.player.PlayerGameModeChangeEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- public class main extends JavaPlugin implements Listener {
- Map<String, Boolean> tagged = new HashMap<String, Boolean>();
- Map<String, Boolean> worlds = new HashMap<String, Boolean>();
- BossBar bar = Bukkit.createBossBar("", BarColor.BLUE, BarStyle.SOLID);
- public Inventory inv1;
- public Inventory inv2;
- public String tagworld;
- public String[] worldNames = new String[Bukkit.getServer().getWorlds().size()];
- FileConfiguration config = getConfig();
- public String prefix = (ChatColor.AQUA + config.getString("commandprefix"));
- @Override
- public void onEnable() { //Run when server starts
- this.getServer().getPluginManager().registerEvents(this, this); //Required for listeners
- this.saveDefaultConfig();
- createInv();
- config.addDefault("world", "''");
- config.addDefault("griefDisabled", true);
- config.addDefault("changegamemode", true);
- config.addDefault("speedboost", false);
- config.addDefault("commandprefix", "[Kaes Tag]");
- config.addDefault("taggedtitle", "You have been tagged!");
- config.addDefault("taggedsubtitle", "Run and tag someone else!");
- config.addDefault("jointagtitle", "You have joined tag!");
- config.options().copyDefaults(true);
- }
- @Override
- public void onDisable() {
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { //Listen for commands
- if (label.equalsIgnoreCase("tagsetup") && (sender.hasPermission("KaePlace.tag.admin"))) { //Tag Setup Command
- if(!(sender instanceof Player)) {
- sender.sendMessage("You cannot do this!");
- return true;
- }
- Player target = (Player) sender;
- // open the GUI
- target.openInventory(inv1);
- return true;
- }
- if (label.equalsIgnoreCase("tagreload") && (sender.hasPermission("KaePlace.tag.admin"))) { //Tag Reload Command
- this.reloadConfig();
- config = getConfig(); //this is necessary if you're like me and don't want to write "this.getConfig();" all the damn time.
- this.saveDefaultConfig();
- prefix = (ChatColor.AQUA + config.getString("commandprefix"));
- sender.sendMessage(prefix + ChatColor.WHITE + " Config reloaded!");
- }
- return false;
- }
- @EventHandler //Tag logic
- public void onHit(EntityDamageByEntityEvent event) {
- if (event.getEntity() instanceof Player && event.getDamager() instanceof Player && event.getEntity().getWorld().getName().equalsIgnoreCase((config.getString("world")))) {
- Player whoWasHit = (Player) event.getEntity();
- Player whoHit = (Player) event.getDamager();
- event.setCancelled(true);
- if (tagged.get(whoHit.getName()) == true) {
- TagPlayer(whoWasHit);
- if (config.getBoolean("speedboost")) {
- whoHit.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 3));
- }
- }
- }
- }
- @EventHandler(priority = EventPriority.HIGHEST) //Grief Prevention
- public void onInteract(PlayerInteractEvent event) {
- Player target = (Player) event.getPlayer();
- String worldname = target.getWorld().getName();
- List<String> allowedItems = Arrays.asList("OAK_DOOR", "SPRUCE_DOOR", "BIRCH_DOOR", "JUNGLE_DOOR", "ACACIA_DOOR", "DARK_OAK_DOOR");
- if (worldname.equalsIgnoreCase( (config.getString("world"))) && (!(allowedItems.contains(event.getClickedBlock().getBlockData().getMaterial().toString())))) {
- if (config.getBoolean("griefdisabled")) {
- event.setCancelled(true);
- return;
- }
- }
- return;
- }
- @EventHandler // Prevents all game mode changes from Multiverse or otherwise.
- public void player(PlayerGameModeChangeEvent event) {
- Player target = (Player) event.getPlayer();
- String worldname = target.getWorld().getName();
- GameMode gamemode = target.getGameMode();
- if (gamemode == GameMode.SURVIVAL && worldname.equalsIgnoreCase((config.getString("world"))) && config.getBoolean("changegamemode")) {
- event.setCancelled(true);
- return;
- }
- }
- @EventHandler () // Whenever players change their current worlds
- public void player(PlayerChangedWorldEvent event) {
- Player target = (Player) event.getPlayer();
- String worldname = target.getWorld().getName();
- if (worldname.equalsIgnoreCase((config.getString("world")))) {
- PlayerJoins(target);
- } else {
- PlayerLeaves(target);
- }
- }
- @EventHandler () // Removes players from game on Server Disconnect
- public void player(PlayerQuitEvent event) {
- Player target = (Player) event.getPlayer();
- PlayerLeaves(target);
- }
- @EventHandler() //Menus! Making it look a bit better. Java isnt my thing though
- public void onClick(InventoryClickEvent event) {
- if (event.getInventory().equals(inv1)) {
- if (event.getCurrentItem() == null) return;
- if (event.getCurrentItem().getItemMeta() == null) return;
- if (event.getCurrentItem().getItemMeta().getDisplayName() == null) return;
- event.setCancelled(true);
- Player target = (Player) event.getWhoClicked();
- config.set("world", (String.valueOf(worldNames[event.getSlot()])));
- this.saveConfig();
- target.closeInventory();
- target.openInventory(inv2);
- }
- if (event.getInventory().equals(inv2)) {
- if (event.getCurrentItem() == null) return;
- if (event.getCurrentItem().getItemMeta() == null) return;
- if (event.getCurrentItem().getItemMeta().getDisplayName() == null) return;
- event.setCancelled(true);
- Player target = (Player) event.getWhoClicked();
- switch (event.getSlot()) {
- case 0:
- config.set("griefdisabled", (!(config.getBoolean("griefdisabled"))));
- this.saveConfig();
- target.sendMessage("Grief prevention is now set to: " + (String.valueOf((config.getBoolean("griefdisabled")))));
- break;
- case 1:
- config.set("changegamemode", (!(config.getBoolean("changegamemode"))));
- this.saveConfig();
- target.sendMessage("Change Gamemode is now set to: " + (String.valueOf((config.getBoolean("changegamemode")))));
- break;
- case 2:
- config.set("speedboost", (!(config.getBoolean("speedboost"))));
- this.saveConfig();
- target.sendMessage("Speed boost is now set to: " + (String.valueOf((config.getBoolean("speedboost")))));
- break;
- case 8:
- target.closeInventory();
- this.saveConfig();
- target.sendMessage("Success! Configuration saved." + ChatColor.DARK_RED + " Have all players leave the world to prevent issues.");
- }
- }
- }
- public void createInv() { //Creates the GUI menus!
- inv1 = Bukkit.createInventory(null, 54, "Choose your world!"); //multiples of 9
- ItemStack item = new ItemStack(Material.BLUE_CONCRETE);
- ItemMeta meta = item.getItemMeta();
- int count = 0;
- for(World w : Bukkit.getServer().getWorlds()) {
- worldNames[count] = w.getName();
- count++;
- }
- count = 0;
- for(String s : worldNames){
- List<Material> givenList = Arrays.asList(Material.RED_WOOL, Material.ORANGE_WOOL, Material.YELLOW_WOOL, Material.GREEN_WOOL, Material.BLUE_WOOL, Material.PURPLE_WOOL);
- Random rand = new Random();
- Material randomMaterial = givenList.get(rand.nextInt(givenList.size()));
- getInventory(inv1, meta, randomMaterial, org.bukkit.ChatColor.AQUA, s, "Click to set tag on this world!", count);
- count++;
- }
- inv2 = Bukkit.createInventory(null, 9, "Final Settings"); //multiples of 9
- count = 0;
- for(int i = 0; i < 9; ++i) {
- List<Material> materialList = Arrays.asList(Material.DIRT, Material.PLAYER_HEAD, Material.POTION, Material.WHITE_STAINED_GLASS, Material.WHITE_STAINED_GLASS, Material.WHITE_STAINED_GLASS, Material.WHITE_STAINED_GLASS, Material.WHITE_STAINED_GLASS, Material.BARRIER);
- List<String> nameList = Arrays.asList("Toggle Grief Prevention", "Lock Gamemode To Survival", "Toggle Speed Boost", "", "", "", "", "", "Close Menu");
- List<String> loreList = Arrays.asList("This option will disable/enable the ability to break blocks.", "Prevents commands/plugins from changing gamemode", "Toggle speed boost when tagging someone", "", "", "", "", "", "Closes Menu");
- getInventory(inv2, meta, materialList.get(count), org.bukkit.ChatColor.AQUA, nameList.get(count), loreList.get(count), count);
- count++;
- }
- }
- public void PlayerJoins(Player target) {
- target.setGameMode(GameMode.SURVIVAL);
- target.getInventory().clear();
- bar.addPlayer(target);
- target.sendTitle(ChatColor.AQUA + config.getString("jointagtitle"), ChatColor.WHITE + "Current players: " + target.getWorld().getPlayers().size(), 10, 40, 10);
- tagged.put(target.getName(), false);
- if (!(tagged.isEmpty()) && ((!(tagged.containsValue(true))))) {
- AssignRandom();
- }
- return;
- }
- public void PlayerLeaves(Player target) {
- tagged.remove(target.getName());
- bar.removePlayer(target);
- if (!(tagged.isEmpty()) && ((!(tagged.containsValue(true))))) {
- AssignRandom();
- }
- return;
- }
- public void AssignRandom() {
- String[] keys = tagged.keySet().toArray(new String[tagged.size()]);
- String key = keys[new Random().nextInt(keys.length)];
- TagPlayer(getServer().getPlayer(key));
- return;
- }
- public void TagPlayer(Player target) {
- tagged.replaceAll((key, value) -> false);
- tagged.put(target.getName(), true);
- MessageTagWorld(target.getName() + " has been tagged!");
- bar.setTitle(target.getName() + " has been tagged!");
- bar.removeAll();
- for (Player on : Bukkit.getOnlinePlayers()) {
- if (on.getWorld().getName().equalsIgnoreCase((config.getString("world")))) {
- bar.addPlayer(on);
- }
- }
- target.sendTitle(ChatColor.DARK_RED + config.getString("taggedtitle"), ChatColor.WHITE + config.getString("taggedsubtitle"), 10, 40, 10);
- return;
- }
- public void MessageTagWorld(String message) {
- for (Player on : Bukkit.getOnlinePlayers()) {
- if (on.getWorld().getName().equalsIgnoreCase((config.getString("world")))) {
- on.sendMessage(prefix + " " + ChatColor.WHITE + message);
- }
- }
- return;
- }
- public static ItemStack getInventory(Inventory inventory, ItemMeta meta, Material material, org.bukkit.ChatColor cc, String string, String string2, int count) {
- ItemStack TempItem = new ItemStack(material);
- meta.setDisplayName(cc + string);
- List<String> lore = new ArrayList<String>();
- lore.add(string2);
- meta.setLore(lore);
- TempItem.setItemMeta(meta);
- inventory.setItem(count, TempItem);
- return TempItem;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment