@EventHandler(ignoreCancelled = true) public void onAdminMenuClick(InventoryClickEvent event) { Inventory inv = event.getInventory(); String name = inv.getTitle(); if (name.equals("§4Admin Menu")) { event.setCancelled(true); int slot = event.getRawSlot(); if (slot < 54) { String option = getDisplay(inv, slot); if (slot == 53 && option.equals("Player Preferences")) { final Player p = (Player) event.getWhoClicked(); // close this gui and load the Player Prefs Menu plugin .getServer() .getScheduler() .scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { Inventory ppm = plugin.getServer().createInventory(p, 18, "§4Player Prefs Menu"); ppm.setContents( new TARDISPrefsMenuInventory(plugin, p.getUniqueId()).getMenu()); p.openInventory(ppm); } }, 1L); return; } if (!option.isEmpty()) { boolean bool = plugin.getConfig().getBoolean(option); plugin.getConfig().set(option, !bool); String lore = (bool) ? "false" : "true"; setLore(inv, slot, lore); plugin.saveConfig(); } } } }
/** Convert pre-TARDIS v2.3 controls to the new system. */ public void convertControls() { ResultSetTardis rs = new ResultSetTardis(plugin, null, "", true); if (rs.resultSet()) { int i = 0; ArrayList<HashMap<String, String>> data = rs.getData(); Statement del = null; PreparedStatement ps = null; try { service.testConnection(connection); // clear the controls table first - just incase they have reset `conversion_done` in the // config del = connection.createStatement(); del.executeUpdate("DELETE FROM controls"); // insert values from tardis table ps = connection.prepareStatement( "INSERT INTO controls (tardis_id, type, location) VALUES (?,?,?)"); for (HashMap<String, String> map : data) { int id = plugin.getUtils().parseInt(map.get("tardis_id")); String tmph; if (map.get("handbrake") == null || map.get("handbrake").isEmpty()) { tmph = estimateHandbrake(map.get("size"), map.get("chameleon")); plugin .getConsole() .sendMessage( plugin.getPluginName() + ChatColor.RED + "Handbrake location not found, making an educated guess..."); } else { tmph = map.get("handbrake"); } String tmpb; if (map.get("button") == null || map.get("button").isEmpty()) { tmpb = estimateButton(map.get("size"), map.get("chameleon")); plugin .getConsole() .sendMessage( plugin.getPluginName() + ChatColor.RED + "Button location not found, making an educated guess..."); } else { tmpb = map.get("button"); } String tmpa; if (map.get("artron_button") == null || map.get("artron_button").isEmpty()) { tmpa = estimateArtron(map.get("size"), map.get("chameleon")); plugin .getConsole() .sendMessage( plugin.getPluginName() + ChatColor.RED + "Artron Button location not found, making an educated guess..."); } else { tmpa = map.get("artron_button"); } String[] tmpr = new String[4]; if (map.get("repeater0") == null || map.get("repeater0").isEmpty()) { tmpr = estimateRepeaters(map.get("size"), map.get("chameleon")); plugin .getConsole() .sendMessage( plugin.getPluginName() + ChatColor.RED + "Repeater locations not found, making an educated guess..."); } else { tmpr[0] = map.get("repeater0"); tmpr[1] = map.get("repeater1"); tmpr[2] = map.get("repeater2"); tmpr[3] = map.get("repeater3"); } String hb = plugin.getUtils().makeLocationStr(tmph); String bn = plugin.getUtils().makeLocationStr(tmpb); String ab = plugin.getUtils().makeLocationStr(tmpa); ps.setInt(1, id); ps.setInt(2, 0); ps.setString(3, hb); ps.addBatch(); ps.setInt(1, id); ps.setInt(2, 1); ps.setString(3, bn); ps.addBatch(); ps.setInt(1, id); ps.setInt(2, 2); ps.setString(3, tmpr[0]); ps.addBatch(); ps.setInt(1, id); ps.setInt(2, 3); ps.setString(3, tmpr[1]); ps.addBatch(); ps.setInt(1, id); ps.setInt(2, 4); ps.setString(3, tmpr[2]); ps.addBatch(); ps.setInt(1, id); ps.setInt(2, 5); ps.setString(3, tmpr[3]); ps.addBatch(); ps.setInt(1, id); ps.setInt(2, 6); ps.setString(3, ab); ps.addBatch(); connection.setAutoCommit(false); ps.executeBatch(); connection.setAutoCommit(true); i++; } } catch (SQLException e) { plugin.debug("Control conversion error: " + e.getMessage()); } finally { if (del != null) { try { del.close(); } catch (SQLException e) { plugin.debug("Control delete statement close error: " + e.getMessage()); } } if (ps != null) { try { ps.close(); } catch (SQLException e) { plugin.debug("Control prepared statement close error: " + e.getMessage()); } } } if (i > 0) { plugin .getConsole() .sendMessage(plugin.getPluginName() + "Converted " + i + " control consoles"); plugin.getConfig().set("conversions.conversion_done", true); plugin.saveConfig(); } } }