me.clip.placeholderapi.PlaceholderAPIPlugin Java Examples

The following examples show how to use me.clip.placeholderapi.PlaceholderAPIPlugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Civs.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
private void setupDependencies() {
    if (Bukkit.getPluginManager().isPluginEnabled(Constants.PLACEHOLDER_API)) {
        new PlaceHook().register();
        placeholderAPI = (PlaceholderAPIPlugin) Bukkit.getPluginManager().getPlugin(Constants.PLACEHOLDER_API);
    }
    if (Bukkit.getPluginManager().isPluginEnabled("MMOItems")) {
        mmoItems = MMOItems.plugin;
    }
    if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) {
        discordSRV = DiscordSRV.getPlugin();
    }
    Bukkit.getPluginManager().registerEvents(new DynmapHook(), this);
    if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) {
        DynmapHook.dynmapCommonAPI = (DynmapCommonAPI) Bukkit.getPluginManager().getPlugin("dynmap");
        DynmapHook.initMarkerSet();
    }
}
 
Example #2
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPluginEnable(PluginEnableEvent event) {
    if ("dynmap".equalsIgnoreCase(event.getPlugin().getName())) {
        DynmapHook.dynmapCommonAPI = (DynmapCommonAPI) event.getPlugin();
        DynmapHook.initMarkerSet();
        return;
    }
    if (Constants.PLACEHOLDER_API.equals(event.getPlugin().getName()) &&
            Bukkit.getPluginManager().isPluginEnabled(Constants.PLACEHOLDER_API)) {
        new PlaceHook().register();
        Civs.placeholderAPI = (PlaceholderAPIPlugin) event.getPlugin();
        return;
    }
    if ("MMOItems".equals(event.getPlugin().getName()) &&
            Bukkit.getPluginManager().isPluginEnabled("MMOItems")) {
        Civs.mmoItems = MMOItems.plugin;
        return;
    }
    if ("DiscordSRV".equals(event.getPlugin().getName()) &&
            Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) {
        Civs.discordSRV = DiscordSRV.getPlugin();
        return;
    }
}
 
Example #3
Source File: PlanPlaceholderExtension.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public String onPlaceholderRequest(Player player, String params) {
    UUID uuid = player != null ? player.getUniqueId() : null;
    try {
        String value = placeholders.onPlaceholderRequest(uuid, params, Collections.emptyList());

        if ("true".equals(value)) { //hack
            value = PlaceholderAPIPlugin.booleanTrue();
        } else if ("false".equals(value)) {
            value = PlaceholderAPIPlugin.booleanFalse();
        }

        return value;
    } catch (Exception e) {
        errorLogger.log(L.WARN, e, ErrorContext.builder().whatToDo("Report this").related("Placeholder Request", params, uuid).build());
        return null;
    }
}
 
Example #4
Source File: Menu.java    From TrMenu with MIT License 5 votes vote down vote up
/**
 * 检测菜单需要的 PlaceholderAPI 依赖并自动下载
 *
 * @return 未安装的
 */
@Deprecated
private List<String> checkDepends() {
    List<String> unInstalled = Lists.newArrayList();

    if (PlaceholderAPIPlugin.getInstance().getExpansionCloud() == null) {
        return unInstalled;
    }
    try {
        if (dependExpansions != null && dependExpansions.size() > 0) {
            if (PlaceholderAPIPlugin.getInstance().getExpansionCloud().getCloudExpansions().isEmpty()) {
                PlaceholderAPIPlugin.getInstance().getExpansionCloud().fetch(false);
                return dependExpansions.stream().filter(d -> PlaceholderAPI.getExpansions().stream().noneMatch(e -> e.getName().equalsIgnoreCase(d))).collect(Collectors.toList());
            }
            unInstalled = dependExpansions.stream().filter(d -> PlaceholderAPI.getExpansions().stream().noneMatch(e -> e.getName().equalsIgnoreCase(d)) && PlaceholderAPIPlugin.getInstance().getExpansionCloud().getCloudExpansion(d) != null && !PlaceholderAPIPlugin.getInstance().getExpansionCloud().isDownloading(d)).collect(Collectors.toList());
            if (unInstalled.size() > 0) {
                unInstalled.forEach(ex -> {
                    CloudExpansion cloudExpansion = PlaceholderAPIPlugin.getInstance().getExpansionCloud().getCloudExpansion(ex);
                    PlaceholderAPIPlugin.getInstance().getExpansionCloud().downloadExpansion(null, cloudExpansion);
                });
                Bukkit.getScheduler().runTaskLater(TrMenu.getPlugin(), () -> PlaceholderAPIPlugin.getInstance().reloadConf(Bukkit.getConsoleSender()), 20 * 5);
            }
        }
    } catch (Throwable ignored) {
    }
    return unInstalled;
}
 
Example #5
Source File: ExpansionManager.java    From PlaceholderAPI with GNU General Public License v3.0 5 votes vote down vote up
public ExpansionManager(PlaceholderAPIPlugin instance) {
  plugin = instance;

  File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), "expansions");
  if (!f.exists()) {
    f.mkdirs();
  }
}
 
Example #6
Source File: ExpansionCloudManager.java    From PlaceholderAPI with GNU General Public License v3.0 5 votes vote down vote up
public ExpansionCloudManager(PlaceholderAPIPlugin plugin) {
    this.plugin = plugin;

    expansionsDir = new File(plugin.getDataFolder(), "expansions");

    final boolean result = expansionsDir.mkdirs();
    if (result) {
        plugin.getLogger().info("Created Expansions Directory");
    }

}
 
Example #7
Source File: FileUtil.java    From PlaceholderAPI with GNU General Public License v3.0 5 votes vote down vote up
public static List<Class<?>> getClasses(String folder, String fileName, Class<?> type) {
  List<Class<?>> list = new ArrayList<>();

  try {
    File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), folder);
    if (!f.exists()) {
      return list;
    }

    FilenameFilter fileNameFilter = (dir, name) -> {
      if (fileName != null) {
        return name.endsWith(".jar") && name.replace(".jar", "")
            .equalsIgnoreCase(fileName.replace(".jar", ""));
      }

      return name.endsWith(".jar");
    };

    File[] jars = f.listFiles(fileNameFilter);
    if (jars == null) {
      return list;
    }

    for (File file : jars) {
      list = gather(file.toURI().toURL(), list, type);
    }

    return list;
  } catch (Throwable t) {
  }

  return null;
}
 
Example #8
Source File: NametagHandler.java    From NametagEdit with GNU General Public License v3.0 5 votes vote down vote up
private void applyConfig() {
    this.debug = config.getBoolean("Debug");
    this.tabListEnabled = config.getBoolean("Tablist.Enabled");
    this.longNametagsEnabled = config.getBoolean("Tablist.LongTags");
    this.refreshTagOnWorldChange = config.getBoolean("RefreshTagOnWorldChange");
    DISABLE_PUSH_ALL_TAGS = config.getBoolean("DisablePush");

    if (config.getBoolean("MetricsEnabled")) {
        Metrics m = new Metrics(NametagEdit.getPlugin(NametagEdit.class));
        m.addCustomChart(new Metrics.SimplePie("using_spigot", () -> PlaceholderAPIPlugin.getServerVersion().isSpigot() ? "yes" : "no"));
    }

    clearEmptyTeamTask = createTask("ClearEmptyTeamsInterval", clearEmptyTeamTask, new Runnable() {
        @Override
        public void run() {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "nte teams clear");
        }
    });

    refreshNametagTask = createTask("RefreshInterval", refreshNametagTask, new Runnable() {
        @Override
        public void run() {
            nametagManager.reset();
            applyTags();
        }
    });
}
 
Example #9
Source File: PlaceholderAPIBridge.java    From ChestCommands with GNU General Public License v3.0 5 votes vote down vote up
public static boolean setupPlugin() {
	Plugin placeholderPlugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");

	if (placeholderPlugin == null) {
		return false;
	}

	placeholderAPI = (PlaceholderAPIPlugin) placeholderPlugin;
	return true;
}
 
Example #10
Source File: UpdateChecker.java    From PlaceholderAPI with GNU General Public License v3.0 4 votes vote down vote up
public UpdateChecker(PlaceholderAPIPlugin i) {
  plugin = i;
  pluginVersion = i.getDescription().getVersion();
}
 
Example #11
Source File: ExpansionCloudCommands.java    From PlaceholderAPI with GNU General Public License v3.0 4 votes vote down vote up
public ExpansionCloudCommands(PlaceholderAPIPlugin instance) {
  plugin = instance;
}
 
Example #12
Source File: PlaceholderAPICommands.java    From PlaceholderAPI with GNU General Public License v3.0 4 votes vote down vote up
public PlaceholderAPICommands(PlaceholderAPIPlugin i) {
  plugin = i;
  eCloud = new ExpansionCloudCommands(i);
}
 
Example #13
Source File: ExpansionManager.java    From PlaceholderAPI with GNU General Public License v3.0 4 votes vote down vote up
public boolean registerExpansion(PlaceholderExpansion expansion) {
  if (expansion == null || expansion.getIdentifier() == null) {
    return false;
  }

  if (expansion instanceof Configurable) {
    Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
    String pre = "expansions." + expansion.getIdentifier() + ".";
    FileConfiguration cfg = plugin.getConfig();
    boolean save = false;

    if (defaults != null) {
      for (Entry<String, Object> entries : defaults.entrySet()) {
        if (entries.getKey() == null || entries.getKey().isEmpty()) {
          continue;
        }

        if (entries.getValue() == null) {
          if (cfg.contains(pre + entries.getKey())) {
            save = true;
            cfg.set(pre + entries.getKey(), null);
          }
        } else {
          if (!cfg.contains(pre + entries.getKey())) {
            save = true;
            cfg.set(pre + entries.getKey(), entries.getValue());
          }
        }
      }
    }

    if (save) {
      plugin.saveConfig();
      plugin.reloadConfig();
    }
  }

  if (expansion instanceof VersionSpecific) {
    VersionSpecific nms = (VersionSpecific) expansion;
    if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) {
      plugin.getLogger()
          .info(
              "Your server version is not compatible with expansion: " + expansion.getIdentifier()
                  + " version: " + expansion.getVersion());
      return false;
    }
  }

  if (!expansion.canRegister()) {
    return false;
  }

  if (!expansion.register()) {
    return false;
  }

  if (expansion instanceof Listener) {
    Listener l = (Listener) expansion;
    Bukkit.getPluginManager().registerEvents(l, plugin);
  }

  plugin.getLogger().info("Successfully registered expansion: " + expansion.getIdentifier());

  if (expansion instanceof Taskable) {
    ((Taskable) expansion).start();
  }

  if (plugin.getExpansionCloud() != null) {
    CloudExpansion ce = plugin.getExpansionCloud().getCloudExpansion(expansion.getIdentifier());

    if (ce != null) {
      ce.setHasExpansion(true);
      if (!ce.getLatestVersion().equals(expansion.getVersion())) {
        ce.setShouldUpdate(true);
      }
    }
  }

  return true;
}
 
Example #14
Source File: PlaceholderAPIConfig.java    From PlaceholderAPI with GNU General Public License v3.0 4 votes vote down vote up
public PlaceholderAPIConfig(PlaceholderAPIPlugin i) {
  plugin = i;
}
 
Example #15
Source File: PlaceholderExpansion.java    From PlaceholderAPI with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Quick getter for the {@link PlaceholderAPIPlugin} instance
 *
 * @return {@link PlaceholderAPIPlugin} instance
 */
public PlaceholderAPIPlugin getPlaceholderAPI() {
  return PlaceholderAPIPlugin.getInstance();
}