Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.De24.hublobby;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.GameMode;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Event.Result;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.entity.EntityDamageEvent;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.inventory.InventoryOpenEvent;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.event.player.PlayerDropItemEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- 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.permissions.Permission;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.potion.PotionEffect;
- public class HubLobby extends JavaPlugin implements Listener {
- public static final ItemStack EMPTY_ITEM;
- public static final ItemStack CUBETOWN_ITEM;
- public static final ItemStack MINIGAMES_ITEM;
- public static final ItemStack HUNGERGAMES_ITEM;
- public static final ItemStack PAINTBALL_ITEM;
- public static final ItemStack GOLDMINE_ITEM;
- public static final ItemStack[] MENU_ITEMS;
- public static final List<String> games = Arrays.asList(new String[] {"hg", "sg", "ipaint", "tict", "goldmine"});
- static {
- EMPTY_ITEM = new ItemStack(Material.AIR);
- ItemMeta meta;
- ArrayList<String> lore;
- {
- CUBETOWN_ITEM = new ItemStack(Material.EMERALD);
- meta = CUBETOWN_ITEM.getItemMeta();
- meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Coming Soon!");
- lore = new ArrayList<String>();
- lore.add("§8Coming Soon. Very Soon!");
- meta.setLore(lore);
- CUBETOWN_ITEM.setItemMeta(meta);
- }
- {
- MINIGAMES_ITEM = new ItemStack(Material.IRON_SWORD);
- meta = MINIGAMES_ITEM.getItemMeta();
- meta.setDisplayName(ChatColor.AQUA + "Mini Games");
- lore = new ArrayList<String>();
- lore.add("§8Klicke, um §3zu den MiniGames zu kommen!");
- meta.setLore(lore);
- MINIGAMES_ITEM.setItemMeta(meta);
- }
- {
- HUNGERGAMES_ITEM = new ItemStack(Material.BOW);
- meta = HUNGERGAMES_ITEM.getItemMeta();
- meta.setDisplayName(ChatColor.GOLD + "Kit HungerGames");
- lore = new ArrayList<String>();
- lore.add("§8Klicke, um §3zu den HungerGames Servern zu kommen!");
- meta.setLore(lore);
- HUNGERGAMES_ITEM.setItemMeta(meta);
- }
- {
- PAINTBALL_ITEM = new ItemStack(Material.SNOW_BALL);
- meta = PAINTBALL_ITEM.getItemMeta();
- meta.setDisplayName(ChatColor.GREEN + "Paintball");
- lore = new ArrayList<String>();
- lore.add("§8Klicke, um §3zum Paintball Server zu kommen!");
- meta.setLore(lore);
- PAINTBALL_ITEM.setItemMeta(meta);
- }
- {
- GOLDMINE_ITEM = new ItemStack(Material.GOLD_NUGGET);
- meta = GOLDMINE_ITEM.getItemMeta();
- meta.setDisplayName(ChatColor.MAGENTA + "Gold Mine");
- lore = new ArrayList<String>();
- lore.add("§8Klicke, um §3mine for gold!");
- meta.setLore(lore);
- GOLDMINE_ITEM.setItemMeta(meta);
- }
- MENU_ITEMS = new ItemStack[] { HUNGERGAMES_ITEM, EMPTY_ITEM, PAINTBALL_ITEM, EMPTY_ITEM, MINIGAMES_ITEM, EMPTY_ITEM, CUBETOWN_ITEM, EMPTY_ITEM, GOLDMINE_ITEM };
- }
- public Permission permChat;
- public Permission permHubset;
- public void onEnable() {
- Bukkit.getPluginManager().registerEvents(this, this);
- loadDefaults();
- permChat = getServer().getPluginManager().getPermission("hub.chat");
- permHubset = getServer().getPluginManager().getPermission("hub.setloc");
- saveConfig();
- }
- public void onDisable() {
- saveConfig();
- }
- private void loadDefaults() {
- FileConfiguration config = getConfig();
- config.options().header("HubLobby // TheMineTV by fkfabian & De24");
- ConfigurationSection hg = getConfig().getConfigurationSection("hg");
- if (hg == null) {
- hg = getConfig().createSection("hg");
- }
- hg.addDefault("enabled", false);
- ConfigurationSection ipaint = getConfig().getConfigurationSection("ipaint");
- if (ipaint == null) {
- ipaint = getConfig().createSection("ipaint");
- }
- ipaint.addDefault("enabled", false);
- ConfigurationSection sg = getConfig().getConfigurationSection("sg");
- if (sg == null) {
- sg = getConfig().createSection("sg");
- }
- sg.addDefault("enabled", false);
- ConfigurationSection tict = getConfig().getConfigurationSection("tict");
- if (tict == null) {
- tict = getConfig().createSection("tict");
- }
- tict.addDefault("enabled", false);
- ConfigurationSection goldmine = getConfig().getConfigurationSection("goldmine");
- if (goldmine == null) {
- goldmine = getConfig().createSection("goldmine");
- }
- goldmine.addDefault("enabled", false);
- }
- public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
- if (cmd.getName().equalsIgnoreCase("hubset")) {
- if (!sender.hasPermission(permHubset)) {
- return false;
- } else if (args.length == 0) {
- return false;
- } else if (args[0].equals("clear")) {
- // Clear a certain hub destination
- if (args.length == 1) {
- return false;
- }
- String game = args[1];
- if (games.contains(game)) {
- ConfigurationSection config = getConfig().getConfigurationSection(game);
- config.set("enabled", false);
- sender.sendMessage("§2[HubLobby]§f Disabled " + game);
- return true;
- } else {
- sender.sendMessage("§2[HubLobby]§a Unknown game " + game + ". Did you spell it wrong?");
- return false;
- }
- } else {
- // Set a certain hub destination
- String game = args[0];
- if (!games.contains(game)) {
- sender.sendMessage("§2[HubLobby]§a Unknown game " + game + ". Did you spell it wrong?");
- return false;
- }
- Player p;
- if (args.length == 2) {
- p = getServer().getPlayer(args[1]);
- if (p == null) {
- sender.sendMessage("§2[HubLobby]§a Could not find player " + args[1]);
- return false;
- }
- } else if (sender instanceof Player) {
- p = (Player) sender;
- } else {
- sender.sendMessage("§2[HubLobby]§a A player is required when run from console");
- return false;
- }
- return processLocationSet(p, game);
- }
- }
- return false;
- }
- private boolean processLocationSet(Player p, String game) {
- ConfigurationSection section = getConfig().getConfigurationSection(game);
- Location loc = p.getLocation();
- section.set("X", loc.getX());
- section.set("Y", loc.getY());
- section.set("Z", loc.getZ());
- section.set("yaw", loc.getYaw());
- section.set("pitch", loc.getPitch());
- section.set("world", loc.getWorld().getName());
- section.set("enabled", true);
- saveConfig();
- p.sendMessage("§2[HubLobby]§f Set location for " + game);
- return true;
- }
- @EventHandler
- public void onInvOpen(InventoryOpenEvent e) {
- if (e.getInventory().getSize() != 9) {
- // This is not our menu inventory - disallow
- e.setCancelled(true);
- }
- }
- @EventHandler
- public void onClick(InventoryClickEvent e) {
- if (e.getInventory().getSize() != 9) {
- // This is not our menu inventory - ignore
- return;
- }
- if (!(e.getWhoClicked() instanceof Player)) {
- // This isn't a player? ignore.
- return;
- }
- // Don't want default behavior at all
- e.setResult(Result.DENY);
- Player p = (Player) e.getWhoClicked();
- ItemStack clicked = e.getCurrentItem();
- if (clicked == CUBETOWN_ITEM) {
- p.closeInventory();
- sendPlayer(p, "tict");
- } else if (clicked == MINIGAMES_ITEM) {
- p.closeInventory();
- sendPlayer(p, "sg");
- } else if (clicked == HUNGERGAMES_ITEM) {
- p.closeInventory();
- sendPlayer(p, "hg");
- } else if (clicked == PAINTBALL_ITEM) {
- p.closeInventory();
- sendPlayer(p, "ipaint");
- } else if (clicked == GOLDMINE_ITEM) {
- p.closeInventory();
- sendPlayer(p, "goldmine");
- }
- }
- private void sendPlayer(Player p, String game) {
- ConfigurationSection config = getConfig().getConfigurationSection(game);
- if (config.getBoolean("enabled")) {
- Location dest = new Location(Bukkit.getWorld(config.getString("world")), config.getDouble("X"), config.getDouble("Y"), config.getDouble("Z"), (float)config.getDouble("yaw"), (float)config.getDouble("pitch"));
- p.teleport(dest);
- } else {
- p.sendMessage("§2[HubLobby]§f Uh oh! That game is disabled. :(");
- }
- }
- @EventHandler
- public void test(AsyncPlayerChatEvent e) {
- if (!(e.getPlayer().hasPermission("hub.chat"))) {
- e.setCancelled(true);
- e.getPlayer().sendMessage("§eLobby-Chat is disabled for non-premium!");
- }
- }
- @EventHandler
- public void onPlayerDrop(PlayerDropItemEvent event) {
- event.setCancelled(true);
- }
- @EventHandler
- public void onEntityDamage(EntityDamageEvent e) {
- if ((e.getEntity() instanceof Player)) {
- e.getCause();
- if (e.getCause() == EntityDamageEvent.DamageCause.VOID) {
- e.getEntity().teleport(e.getEntity().getWorld().getSpawnLocation());
- }
- e.setCancelled(true);
- e.getEntity().setFireTicks(0);
- }
- }
- @EventHandler
- public void onQuit(PlayerQuitEvent e) {
- // Suppress quit message
- e.setQuitMessage("");
- }
- @EventHandler
- public void onJoin(PlayerJoinEvent e) {
- // Adventure mode
- e.setJoinMessage("");
- e.getPlayer().setGameMode(GameMode.ADVENTURE);
- // Give compass item
- ItemStack co = new ItemStack(Material.COMPASS);
- ItemMeta cometa = co.getItemMeta();
- cometa.setDisplayName("§6§lTeleporter");
- co.setItemMeta(cometa);
- Player p = e.getPlayer();
- p.getInventory().clear();
- p.getInventory().addItem(co);
- }
- @EventHandler
- public void onRightClick(PlayerInteractEvent event) {
- Player p = event.getPlayer();
- if (((event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getAction() == Action.RIGHT_CLICK_BLOCK) && event.getPlayer().getItemInHand().getTypeId() == 345)) {
- Inventory inv = getServer().createInventory(p, 9, "§8TheMineTV Hub");
- inv.setContents(MENU_ITEMS);
- p.openInventory(inv);
- }
- }
- @EventHandler
- public void onPlayerJoin(PlayerJoinEvent e) {
- if (!(e.getPlayer().hasPermission("clank.sichtbar"))) {
- Player p = (Player) e.getPlayer();
- for (Player players : Bukkit.getOnlinePlayers()) {
- //players.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 500000, 2 ));
- for (PotionEffect effect : players.getActivePotionEffects())
- players.removePotionEffect(effect.getType());
- p.hidePlayer(players);
- players.hidePlayer(p);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement