Search in sources :

Example 1 with JavaPlugin

use of org.bukkit.plugin.java.JavaPlugin in project BKCommonLib by bergerhealer.

the class CommonMapController method handleMapShowEvent.

private synchronized void handleMapShowEvent(MapShowEvent event) {
    // Check if there are other map displays that should be shown to the player automatically
    // This uses the 'isGlobal()' property of the display
    MapDisplayInfo info = CommonMapController.this.getInfo(event.getMapUUID());
    boolean hasDisplay = false;
    if (info != null) {
        for (MapSession session : info.sessions) {
            if (session.display.isGlobal()) {
                session.display.addOwner(event.getPlayer());
                hasDisplay = true;
                break;
            }
        }
    }
    // When defined in the NBT of the item, construct the Map Display automatically
    CommonTagCompound tag = ItemUtil.getMetaTag(event.getMapItem(), false);
    if (tag != null && !hasDisplay) {
        String pluginName = tag.getValue("mapDisplayPlugin", String.class);
        String displayClassName = tag.getValue("mapDisplayClass", String.class);
        if (pluginName != null && displayClassName != null) {
            Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
            Class<?> displayClass = null;
            if (plugin != null) {
                try {
                    displayClass = plugin.getClass().getClassLoader().loadClass(displayClassName);
                    if (!MapDisplay.class.isAssignableFrom(displayClass)) {
                        displayClass = null;
                    }
                } catch (ClassNotFoundException e) {
                }
            }
            if (displayClass != null && !event.hasDisplay()) {
                try {
                    MapDisplay display = (MapDisplay) displayClass.newInstance();
                    event.setDisplay((JavaPlugin) plugin, display);
                    ;
                } catch (InstantiationException | IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    CommonUtil.callEvent(event);
}
Also used : MapDisplay(com.bergerkiller.bukkit.common.map.MapDisplay) CommonTagCompound(com.bergerkiller.bukkit.common.nbt.CommonTagCompound) MapSession(com.bergerkiller.bukkit.common.map.MapSession) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Example 2 with JavaPlugin

use of org.bukkit.plugin.java.JavaPlugin in project MyMaid2 by jaoafa.

the class Jail method SaveJailData.

/**
 * Jail情報をセーブする。
 * @return 実行できたかどうか
 * @author mine_book000
 * @throws Exception IOExceptionの発生時に発生
 */
@SuppressWarnings("unchecked")
public static boolean SaveJailData() throws Exception {
    JSONArray JailJSON = new JSONArray();
    for (String player : Jail) {
        JailJSON.add(player);
    }
    JSONObject BlockJSON = new JSONObject();
    for (Entry<String, Boolean> one : block.entrySet()) {
        BlockJSON.put(one.getKey(), one.getValue());
    }
    JSONObject AreaJSON = new JSONObject();
    for (Entry<String, Boolean> one : area.entrySet()) {
        AreaJSON.put(one.getKey(), one.getValue());
    }
    JSONObject LastTextJSON = new JSONObject();
    for (Entry<String, Boolean> one : lasttext.entrySet()) {
        LastTextJSON.put(one.getKey(), one.getValue());
    }
    JSONObject ALLJSON = new JSONObject();
    ALLJSON.put("Jail", JailJSON);
    ALLJSON.put("Block", BlockJSON);
    ALLJSON.put("Area", AreaJSON);
    ALLJSON.put("LastText", LastTextJSON);
    try {
        JavaPlugin plugin = JavaPlugin();
        File file = new File(plugin.getDataFolder(), "jail.json");
        FileWriter filewriter = new FileWriter(file);
        filewriter.write(ALLJSON.toJSONString());
        filewriter.close();
    } catch (IOException e) {
        BugReporter(e);
        throw new Exception("IOException");
    }
    return true;
}
Also used : JSONObject(org.json.simple.JSONObject) FileWriter(java.io.FileWriter) JSONArray(org.json.simple.JSONArray) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) IOException(java.io.IOException) File(java.io.File) SQLException(java.sql.SQLException) ParseException(org.json.simple.parser.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with JavaPlugin

use of org.bukkit.plugin.java.JavaPlugin in project MyMaid2 by jaoafa.

the class Cmd_DT method onTabComplete.

public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
    if (args.length == 1) {
        if (args[0].length() == 0) {
            // /dtまで
            Plugin dynmap = plugin.getServer().getPluginManager().getPlugin("dynmap");
            if (dynmap == null || !dynmap.isEnabled()) {
                SendMessage(sender, cmd, "Dynmapプラグインが停止中、もしくは存在しないため、このコマンドを利用できません。");
                return plugin.onTabComplete(sender, cmd, alias, args);
            }
            List<String> tablist = new ArrayList<>();
            tablist.add("add");
            tablist.add("del");
            tablist.add("list");
            DynmapAPI dynmapapi = (DynmapAPI) dynmap;
            MarkerAPI markerapi = dynmapapi.getMarkerAPI();
            for (MarkerSet markerset : markerapi.getMarkerSets()) {
                for (Marker marker : markerset.getMarkers()) {
                    tablist.add(marker.getLabel());
                }
            }
            return tablist;
        } else {
            Plugin dynmap = plugin.getServer().getPluginManager().getPlugin("dynmap");
            if (dynmap == null || !dynmap.isEnabled()) {
                SendMessage(sender, cmd, "Dynmapプラグインが停止中、もしくは存在しないため、このコマンドを利用できません。");
                return plugin.onTabComplete(sender, cmd, alias, args);
            }
            List<String> tablist = new ArrayList<>();
            tablist.add("add");
            tablist.add("del");
            tablist.add("list");
            DynmapAPI dynmapapi = (DynmapAPI) dynmap;
            MarkerAPI markerapi = dynmapapi.getMarkerAPI();
            for (MarkerSet markerset : markerapi.getMarkerSets()) {
                for (Marker marker : markerset.getMarkers()) {
                    tablist.add(marker.getLabel());
                }
            }
            List<String> tablistFor = new ArrayList<>();
            tablistFor.addAll(tablist);
            for (String tab : tablistFor) {
                if (!tab.toLowerCase().startsWith(args[0].toLowerCase())) {
                    tablist.remove(tab);
                }
            }
            if (tablist.size() == 0) {
                return plugin.onTabComplete(sender, cmd, alias, args);
            }
            return tablist;
        }
    } else if (args.length == 2) {
        if (args[1].length() == 0) {
            // /dt ~まで
            if (args[0].equalsIgnoreCase("del")) {
                Plugin dynmap = plugin.getServer().getPluginManager().getPlugin("dynmap");
                if (dynmap == null || !dynmap.isEnabled()) {
                    SendMessage(sender, cmd, "Dynmapプラグインが停止中、もしくは存在しないため、このコマンドを利用できません。");
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                List<String> tablist = new ArrayList<>();
                DynmapAPI dynmapapi = (DynmapAPI) dynmap;
                MarkerAPI markerapi = dynmapapi.getMarkerAPI();
                for (MarkerSet markerset : markerapi.getMarkerSets()) {
                    for (Marker marker : markerset.getMarkers()) {
                        tablist.add(marker.getLabel());
                    }
                }
                return tablist;
            } else {
                Plugin dynmap = plugin.getServer().getPluginManager().getPlugin("dynmap");
                if (dynmap == null || !dynmap.isEnabled()) {
                    SendMessage(sender, cmd, "Dynmapプラグインが停止中、もしくは存在しないため、このコマンドを利用できません。");
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                Player player = Bukkit.getPlayerExact(args[0]);
                if (player == null) {
                    SendMessage(sender, cmd, "入力されているプレイヤー「" + args[0] + "」は見つかりません。");
                    Player any_chance_player = Bukkit.getPlayer(args[0]);
                    if (any_chance_player != null) {
                        SendMessage(sender, cmd, "もしかして: " + any_chance_player.getName());
                    }
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                List<String> tablist = new ArrayList<>();
                DynmapAPI dynmapapi = (DynmapAPI) dynmap;
                MarkerAPI markerapi = dynmapapi.getMarkerAPI();
                for (MarkerSet markerset : markerapi.getMarkerSets()) {
                    for (Marker marker : markerset.getMarkers()) {
                        tablist.add(marker.getLabel());
                    }
                }
                List<String> tablistFor = new ArrayList<>();
                tablistFor.addAll(tablist);
                for (String tab : tablistFor) {
                    if (!tab.toLowerCase().startsWith(args[1].toLowerCase())) {
                        tablist.remove(tab);
                    }
                }
                if (tablist.size() == 0) {
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                return tablist;
            }
        } else {
            if (args[0].equalsIgnoreCase("del")) {
                Plugin dynmap = plugin.getServer().getPluginManager().getPlugin("dynmap");
                if (dynmap == null || !dynmap.isEnabled()) {
                    SendMessage(sender, cmd, "Dynmapプラグインが停止中、もしくは存在しないため、このコマンドを利用できません。");
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                List<String> tablist = new ArrayList<>();
                DynmapAPI dynmapapi = (DynmapAPI) dynmap;
                MarkerAPI markerapi = dynmapapi.getMarkerAPI();
                for (MarkerSet markerset : markerapi.getMarkerSets()) {
                    for (Marker marker : markerset.getMarkers()) {
                        tablist.add(marker.getLabel());
                    }
                }
                List<String> tablistFor = new ArrayList<>();
                tablistFor.addAll(tablist);
                for (String tab : tablistFor) {
                    if (!tab.startsWith(args[1])) {
                        tablist.remove(tab);
                    }
                }
                if (tablist.size() == 0) {
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                return tablist;
            } else {
                Plugin dynmap = plugin.getServer().getPluginManager().getPlugin("dynmap");
                if (dynmap == null || !dynmap.isEnabled()) {
                    SendMessage(sender, cmd, "Dynmapプラグインが停止中、もしくは存在しないため、このコマンドを利用できません。");
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                Player player = Bukkit.getPlayerExact(args[0]);
                if (player == null) {
                    SendMessage(sender, cmd, "入力されているプレイヤー「" + args[0] + "」は見つかりません。");
                    Player any_chance_player = Bukkit.getPlayer(args[0]);
                    if (any_chance_player != null) {
                        SendMessage(sender, cmd, "もしかして: " + any_chance_player.getName());
                    }
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                List<String> tablist = new ArrayList<>();
                DynmapAPI dynmapapi = (DynmapAPI) dynmap;
                MarkerAPI markerapi = dynmapapi.getMarkerAPI();
                for (MarkerSet markerset : markerapi.getMarkerSets()) {
                    for (Marker marker : markerset.getMarkers()) {
                        tablist.add(marker.getLabel());
                    }
                }
                List<String> tablistFor = new ArrayList<>();
                tablistFor.addAll(tablist);
                for (String tab : tablistFor) {
                    if (!tab.toLowerCase().startsWith(args[1].toLowerCase())) {
                        tablist.remove(tab);
                    }
                }
                if (tablist.size() == 0) {
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                return tablist;
            }
        }
    } else if (args.length == 3) {
        if (args[2].length() == 0) {
            // /dt ~ ~まで
            if (args[0].equalsIgnoreCase("add")) {
                // <MarkerType>を出す
                Plugin dynmap = plugin.getServer().getPluginManager().getPlugin("dynmap");
                if (dynmap == null || !dynmap.isEnabled()) {
                    SendMessage(sender, cmd, "Dynmapプラグインが停止中、もしくは存在しないため、このコマンドを利用できません。");
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                List<String> tablist = new ArrayList<>();
                DynmapAPI dynmapapi = (DynmapAPI) dynmap;
                MarkerAPI markerapi = dynmapapi.getMarkerAPI();
                for (MarkerSet markerset : markerapi.getMarkerSets()) {
                    tablist.add(markerset.getMarkerSetLabel());
                }
                return tablist;
            }
        } else {
            if (args[0].equalsIgnoreCase("add")) {
                Plugin dynmap = plugin.getServer().getPluginManager().getPlugin("dynmap");
                if (dynmap == null || !dynmap.isEnabled()) {
                    SendMessage(sender, cmd, "Dynmapプラグインが停止中、もしくは存在しないため、このコマンドを利用できません。");
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                List<String> tablist = new ArrayList<>();
                DynmapAPI dynmapapi = (DynmapAPI) dynmap;
                MarkerAPI markerapi = dynmapapi.getMarkerAPI();
                for (MarkerSet markerset : markerapi.getMarkerSets()) {
                    tablist.add(markerset.getMarkerSetLabel());
                }
                List<String> tablistFor = new ArrayList<>();
                tablistFor.addAll(tablist);
                for (String tab : tablistFor) {
                    if (!tab.toLowerCase().startsWith(args[2].toLowerCase())) {
                        tablist.remove(tab);
                    }
                }
                if (tablist.size() == 0) {
                    return plugin.onTabComplete(sender, cmd, alias, args);
                }
                return tablist;
            }
        }
    }
    // JavaPlugin#onTabComplete()を呼び出す
    return plugin.onTabComplete(sender, cmd, alias, args);
}
Also used : MarkerSet(org.dynmap.markers.MarkerSet) Player(org.bukkit.entity.Player) DynmapAPI(org.dynmap.DynmapAPI) ArrayList(java.util.ArrayList) MarkerAPI(org.dynmap.markers.MarkerAPI) ArrayList(java.util.ArrayList) List(java.util.List) Marker(org.dynmap.markers.Marker) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Example 4 with JavaPlugin

use of org.bukkit.plugin.java.JavaPlugin in project Karus-Commons by Pante.

the class PluginProcessor method process.

@Override
public void process(Class<? extends JavaPlugin> plugin, ConfigurationSection config) {
    Plugin annotation = plugin.getAnnotation(Plugin.class);
    processName(annotation, config);
    processMain(plugin, config);
    processVersion(annotation, config);
}
Also used : JavaPlugin(org.bukkit.plugin.java.JavaPlugin) Plugin(com.karuslabs.plugin.annotations.annotations.Plugin)

Example 5 with JavaPlugin

use of org.bukkit.plugin.java.JavaPlugin in project Karus-Commons by Pante.

the class Resolver method load.

protected Set<Class<? extends JavaPlugin>> load() {
    URL[] urls = elements.stream().map(element -> {
        try {
            return new File(element).toURI().toURL();
        } catch (MalformedURLException e) {
            throw new UncheckedIOException(e);
        }
    }).toArray(URL[]::new);
    Reflections reflections = new Reflections(URLClassLoader.newInstance(urls, getClass().getClassLoader()));
    return reflections.getSubTypesOf(JavaPlugin.class).stream().filter(type -> type.getAnnotation(Plugin.class) != null).collect(toSet());
}
Also used : JavaPlugin(org.bukkit.plugin.java.JavaPlugin) java.util(java.util) java.net(java.net) java.io(java.io) Plugin(com.karuslabs.plugin.annotations.annotations.Plugin) Reflections(org.reflections.Reflections) Collectors.toSet(java.util.stream.Collectors.toSet) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) Reflections(org.reflections.Reflections) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) Plugin(com.karuslabs.plugin.annotations.annotations.Plugin)

Aggregations

JavaPlugin (org.bukkit.plugin.java.JavaPlugin)11 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 Plugin (org.bukkit.plugin.Plugin)4 JSONArray (org.json.simple.JSONArray)4 ParseException (org.json.simple.parser.ParseException)4 MapDisplay (com.bergerkiller.bukkit.common.map.MapDisplay)2 MapSession (com.bergerkiller.bukkit.common.map.MapSession)2 Plugin (com.karuslabs.plugin.annotations.annotations.Plugin)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 FileWriter (java.io.FileWriter)2 Map (java.util.Map)2 Player (org.bukkit.entity.Player)2 JSONObject (org.json.simple.JSONObject)2 JSONParser (org.json.simple.parser.JSONParser)2 CommonPlugin (com.bergerkiller.bukkit.common.internal.CommonPlugin)1 LegacyContainerAnvilHook (com.bergerkiller.bukkit.common.internal.hooks.LegacyContainerAnvilHook)1 MapDisplayProperties (com.bergerkiller.bukkit.common.map.MapDisplayProperties)1