SHOW:
|
|
- or go back to the newest paste.
1 | package de.De24.hublobby; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.Arrays; | |
5 | import java.util.List; | |
6 | ||
7 | import org.bukkit.Bukkit; | |
8 | import org.bukkit.ChatColor; | |
9 | import org.bukkit.GameMode; | |
10 | import org.bukkit.Location; | |
11 | import org.bukkit.Material; | |
12 | import org.bukkit.command.Command; | |
13 | import org.bukkit.command.CommandSender; | |
14 | import org.bukkit.configuration.ConfigurationSection; | |
15 | import org.bukkit.configuration.file.FileConfiguration; | |
16 | import org.bukkit.entity.Player; | |
17 | import org.bukkit.event.Event.Result; | |
18 | import org.bukkit.event.EventHandler; | |
19 | import org.bukkit.event.Listener; | |
20 | import org.bukkit.event.block.Action; | |
21 | import org.bukkit.event.entity.EntityDamageEvent; | |
22 | import org.bukkit.event.inventory.InventoryClickEvent; | |
23 | import org.bukkit.event.inventory.InventoryOpenEvent; | |
24 | import org.bukkit.event.player.AsyncPlayerChatEvent; | |
25 | import org.bukkit.event.player.PlayerDropItemEvent; | |
26 | import org.bukkit.event.player.PlayerInteractEvent; | |
27 | import org.bukkit.event.player.PlayerJoinEvent; | |
28 | import org.bukkit.event.player.PlayerQuitEvent; | |
29 | import org.bukkit.inventory.Inventory; | |
30 | import org.bukkit.inventory.ItemStack; | |
31 | import org.bukkit.inventory.meta.ItemMeta; | |
32 | import org.bukkit.permissions.Permission; | |
33 | import org.bukkit.plugin.java.JavaPlugin; | |
34 | import org.bukkit.potion.PotionEffect; | |
35 | ||
36 | public class HubLobby extends JavaPlugin implements Listener { | |
37 | ||
38 | public static final ItemStack EMPTY_ITEM; | |
39 | public static final ItemStack CUBETOWN_ITEM; | |
40 | public static final ItemStack MINIGAMES_ITEM; | |
41 | public static final ItemStack HUNGERGAMES_ITEM; | |
42 | public static final ItemStack PAINTBALL_ITEM; | |
43 | public static final ItemStack GOLDMINE_ITEM; | |
44 | ||
45 | public static final ItemStack[] MENU_ITEMS; | |
46 | - | public static final List<String> games = Arrays.asList(new String[] {"hg", "sg", "ipaint", "tict"}); |
46 | + | |
47 | public static final List<String> games = Arrays.asList(new String[] {"hg", "sg", "ipaint", "tict", "goldmine"}); | |
48 | ||
49 | static { | |
50 | EMPTY_ITEM = new ItemStack(Material.AIR); | |
51 | ||
52 | ItemMeta meta; | |
53 | ArrayList<String> lore; | |
54 | ||
55 | { | |
56 | CUBETOWN_ITEM = new ItemStack(Material.EMERALD); | |
57 | meta = CUBETOWN_ITEM.getItemMeta(); | |
58 | meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Coming Soon!"); | |
59 | lore = new ArrayList<String>(); | |
60 | lore.add("§8Coming Soon. Very Soon!"); | |
61 | meta.setLore(lore); | |
62 | CUBETOWN_ITEM.setItemMeta(meta); | |
63 | } | |
64 | ||
65 | { | |
66 | MINIGAMES_ITEM = new ItemStack(Material.IRON_SWORD); | |
67 | meta = MINIGAMES_ITEM.getItemMeta(); | |
68 | meta.setDisplayName(ChatColor.AQUA + "Mini Games"); | |
69 | lore = new ArrayList<String>(); | |
70 | lore.add("§8Klicke, um §3zu den MiniGames zu kommen!"); | |
71 | meta.setLore(lore); | |
72 | MINIGAMES_ITEM.setItemMeta(meta); | |
73 | } | |
74 | ||
75 | { | |
76 | HUNGERGAMES_ITEM = new ItemStack(Material.BOW); | |
77 | meta = HUNGERGAMES_ITEM.getItemMeta(); | |
78 | meta.setDisplayName(ChatColor.GOLD + "Kit HungerGames"); | |
79 | lore = new ArrayList<String>(); | |
80 | lore.add("§8Klicke, um §3zu den HungerGames Servern zu kommen!"); | |
81 | meta.setLore(lore); | |
82 | HUNGERGAMES_ITEM.setItemMeta(meta); | |
83 | } | |
84 | ||
85 | { | |
86 | PAINTBALL_ITEM = new ItemStack(Material.SNOW_BALL); | |
87 | meta = PAINTBALL_ITEM.getItemMeta(); | |
88 | meta.setDisplayName(ChatColor.GREEN + "Paintball"); | |
89 | lore = new ArrayList<String>(); | |
90 | lore.add("§8Klicke, um §3zum Paintball Server zu kommen!"); | |
91 | meta.setLore(lore); | |
92 | PAINTBALL_ITEM.setItemMeta(meta); | |
93 | } | |
94 | - | MENU_ITEMS = new ItemStack[] { EMPTY_ITEM, HUNGERGAMES_ITEM, EMPTY_ITEM, PAINTBALL_ITEM, EMPTY_ITEM, MINIGAMES_ITEM, EMPTY_ITEM, CUBETOWN_ITEM, EMPTY_ITEM}; |
94 | + | |
95 | { | |
96 | GOLDMINE_ITEM = new ItemStack(Material.GOLD_NUGGET); | |
97 | meta = GOLDMINE_ITEM.getItemMeta(); | |
98 | meta.setDisplayName(ChatColor.MAGENTA + "Gold Mine"); | |
99 | lore = new ArrayList<String>(); | |
100 | lore.add("§8Klicke, um §3mine for gold!"); | |
101 | meta.setLore(lore); | |
102 | GOLDMINE_ITEM.setItemMeta(meta); | |
103 | } | |
104 | ||
105 | MENU_ITEMS = new ItemStack[] { HUNGERGAMES_ITEM, EMPTY_ITEM, PAINTBALL_ITEM, EMPTY_ITEM, MINIGAMES_ITEM, EMPTY_ITEM, CUBETOWN_ITEM, EMPTY_ITEM, GOLDMINE_ITEM }; | |
106 | } | |
107 | ||
108 | public Permission permChat; | |
109 | public Permission permHubset; | |
110 | ||
111 | public void onEnable() { | |
112 | Bukkit.getPluginManager().registerEvents(this, this); | |
113 | loadDefaults(); | |
114 | permChat = getServer().getPluginManager().getPermission("hub.chat"); | |
115 | permHubset = getServer().getPluginManager().getPermission("hub.setloc"); | |
116 | ||
117 | saveConfig(); | |
118 | } | |
119 | ||
120 | public void onDisable() { | |
121 | saveConfig(); | |
122 | } | |
123 | ||
124 | private void loadDefaults() { | |
125 | FileConfiguration config = getConfig(); | |
126 | config.options().header("HubLobby // TheMineTV by fkfabian & De24"); | |
127 | ConfigurationSection hg = getConfig().getConfigurationSection("hg"); | |
128 | if (hg == null) { | |
129 | hg = getConfig().createSection("hg"); | |
130 | } | |
131 | hg.addDefault("enabled", false); | |
132 | ConfigurationSection ipaint = getConfig().getConfigurationSection("ipaint"); | |
133 | if (ipaint == null) { | |
134 | ipaint = getConfig().createSection("ipaint"); | |
135 | } | |
136 | ipaint.addDefault("enabled", false); | |
137 | ConfigurationSection sg = getConfig().getConfigurationSection("sg"); | |
138 | if (sg == null) { | |
139 | sg = getConfig().createSection("sg"); | |
140 | } | |
141 | sg.addDefault("enabled", false); | |
142 | ConfigurationSection tict = getConfig().getConfigurationSection("tict"); | |
143 | if (tict == null) { | |
144 | tict = getConfig().createSection("tict"); | |
145 | } | |
146 | tict.addDefault("enabled", false); | |
147 | ConfigurationSection goldmine = getConfig().getConfigurationSection("goldmine"); | |
148 | if (goldmine == null) { | |
149 | goldmine = getConfig().createSection("goldmine"); | |
150 | } | |
151 | goldmine.addDefault("enabled", false); | |
152 | } | |
153 | ||
154 | public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) { | |
155 | if (cmd.getName().equalsIgnoreCase("hubset")) { | |
156 | if (!sender.hasPermission(permHubset)) { | |
157 | return false; | |
158 | } else if (args.length == 0) { | |
159 | return false; | |
160 | } else if (args[0].equals("clear")) { | |
161 | // Clear a certain hub destination | |
162 | if (args.length == 1) { | |
163 | return false; | |
164 | } | |
165 | String game = args[1]; | |
166 | if (games.contains(game)) { | |
167 | ConfigurationSection config = getConfig().getConfigurationSection(game); | |
168 | config.set("enabled", false); | |
169 | sender.sendMessage("§2[HubLobby]§f Disabled " + game); | |
170 | return true; | |
171 | } else { | |
172 | sender.sendMessage("§2[HubLobby]§a Unknown game " + game + ". Did you spell it wrong?"); | |
173 | return false; | |
174 | } | |
175 | } else { | |
176 | // Set a certain hub destination | |
177 | String game = args[0]; | |
178 | if (!games.contains(game)) { | |
179 | sender.sendMessage("§2[HubLobby]§a Unknown game " + game + ". Did you spell it wrong?"); | |
180 | return false; | |
181 | } | |
182 | Player p; | |
183 | if (args.length == 2) { | |
184 | p = getServer().getPlayer(args[1]); | |
185 | if (p == null) { | |
186 | sender.sendMessage("§2[HubLobby]§a Could not find player " + args[1]); | |
187 | return false; | |
188 | } | |
189 | } else if (sender instanceof Player) { | |
190 | p = (Player) sender; | |
191 | } else { | |
192 | sender.sendMessage("§2[HubLobby]§a A player is required when run from console"); | |
193 | return false; | |
194 | } | |
195 | return processLocationSet(p, game); | |
196 | } | |
197 | } | |
198 | return false; | |
199 | } | |
200 | ||
201 | private boolean processLocationSet(Player p, String game) { | |
202 | ConfigurationSection section = getConfig().getConfigurationSection(game); | |
203 | Location loc = p.getLocation(); | |
204 | section.set("X", loc.getX()); | |
205 | section.set("Y", loc.getY()); | |
206 | section.set("Z", loc.getZ()); | |
207 | section.set("yaw", loc.getYaw()); | |
208 | section.set("pitch", loc.getPitch()); | |
209 | section.set("world", loc.getWorld().getName()); | |
210 | section.set("enabled", true); | |
211 | saveConfig(); | |
212 | p.sendMessage("§2[HubLobby]§f Set location for " + game); | |
213 | return true; | |
214 | } | |
215 | ||
216 | @EventHandler | |
217 | public void onInvOpen(InventoryOpenEvent e) { | |
218 | if (e.getInventory().getSize() != 9) { | |
219 | // This is not our menu inventory - disallow | |
220 | e.setCancelled(true); | |
221 | } | |
222 | } | |
223 | ||
224 | @EventHandler | |
225 | public void onClick(InventoryClickEvent e) { | |
226 | if (e.getInventory().getSize() != 9) { | |
227 | // This is not our menu inventory - ignore | |
228 | return; | |
229 | } | |
230 | if (!(e.getWhoClicked() instanceof Player)) { | |
231 | // This isn't a player? ignore. | |
232 | return; | |
233 | } | |
234 | // Don't want default behavior at all | |
235 | e.setResult(Result.DENY); | |
236 | Player p = (Player) e.getWhoClicked(); | |
237 | ItemStack clicked = e.getCurrentItem(); | |
238 | if (clicked == CUBETOWN_ITEM) { | |
239 | p.closeInventory(); | |
240 | sendPlayer(p, "tict"); | |
241 | } else if (clicked == MINIGAMES_ITEM) { | |
242 | p.closeInventory(); | |
243 | sendPlayer(p, "sg"); | |
244 | } else if (clicked == HUNGERGAMES_ITEM) { | |
245 | p.closeInventory(); | |
246 | sendPlayer(p, "hg"); | |
247 | } else if (clicked == PAINTBALL_ITEM) { | |
248 | p.closeInventory(); | |
249 | sendPlayer(p, "ipaint"); | |
250 | } else if (clicked == GOLDMINE_ITEM) { | |
251 | p.closeInventory(); | |
252 | sendPlayer(p, "goldmine"); | |
253 | } | |
254 | } | |
255 | ||
256 | private void sendPlayer(Player p, String game) { | |
257 | ConfigurationSection config = getConfig().getConfigurationSection(game); | |
258 | if (config.getBoolean("enabled")) { | |
259 | 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")); | |
260 | p.teleport(dest); | |
261 | } else { | |
262 | p.sendMessage("§2[HubLobby]§f Uh oh! That game is disabled. :("); | |
263 | } | |
264 | } | |
265 | ||
266 | @EventHandler | |
267 | public void test(AsyncPlayerChatEvent e) { | |
268 | if (!(e.getPlayer().hasPermission("hub.chat"))) { | |
269 | e.setCancelled(true); | |
270 | e.getPlayer().sendMessage("§eLobby-Chat is disabled for non-premium!"); | |
271 | } | |
272 | } | |
273 | ||
274 | ||
275 | @EventHandler | |
276 | public void onPlayerDrop(PlayerDropItemEvent event) { | |
277 | event.setCancelled(true); | |
278 | } | |
279 | ||
280 | ||
281 | @EventHandler | |
282 | public void onEntityDamage(EntityDamageEvent e) { | |
283 | if ((e.getEntity() instanceof Player)) { | |
284 | e.getCause(); | |
285 | if (e.getCause() == EntityDamageEvent.DamageCause.VOID) { | |
286 | e.getEntity().teleport(e.getEntity().getWorld().getSpawnLocation()); | |
287 | } | |
288 | e.setCancelled(true); | |
289 | e.getEntity().setFireTicks(0); | |
290 | } | |
291 | } | |
292 | ||
293 | ||
294 | @EventHandler | |
295 | public void onQuit(PlayerQuitEvent e) { | |
296 | // Suppress quit message | |
297 | e.setQuitMessage(""); | |
298 | } | |
299 | ||
300 | @EventHandler | |
301 | public void onJoin(PlayerJoinEvent e) { | |
302 | // Adventure mode | |
303 | e.setJoinMessage(""); | |
304 | e.getPlayer().setGameMode(GameMode.ADVENTURE); | |
305 | // Give compass item | |
306 | ItemStack co = new ItemStack(Material.COMPASS); | |
307 | ItemMeta cometa = co.getItemMeta(); | |
308 | cometa.setDisplayName("§6§lTeleporter"); | |
309 | co.setItemMeta(cometa); | |
310 | Player p = e.getPlayer(); | |
311 | p.getInventory().clear(); | |
312 | p.getInventory().addItem(co); | |
313 | } | |
314 | ||
315 | @EventHandler | |
316 | public void onRightClick(PlayerInteractEvent event) { | |
317 | Player p = event.getPlayer(); | |
318 | if (((event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getAction() == Action.RIGHT_CLICK_BLOCK) && event.getPlayer().getItemInHand().getTypeId() == 345)) { | |
319 | Inventory inv = getServer().createInventory(p, 9, "§8TheMineTV Hub"); | |
320 | inv.setContents(MENU_ITEMS); | |
321 | p.openInventory(inv); | |
322 | } | |
323 | } | |
324 | ||
325 | @EventHandler | |
326 | public void onPlayerJoin(PlayerJoinEvent e) { | |
327 | if (!(e.getPlayer().hasPermission("clank.sichtbar"))) { | |
328 | Player p = (Player) e.getPlayer(); | |
329 | for (Player players : Bukkit.getOnlinePlayers()) { | |
330 | //players.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 500000, 2 )); | |
331 | for (PotionEffect effect : players.getActivePotionEffects()) | |
332 | players.removePotionEffect(effect.getType()); | |
333 | p.hidePlayer(players); | |
334 | players.hidePlayer(p); | |
335 | } | |
336 | } | |
337 | } | |
338 | } |