me.clip.placeholderapi.expansion.PlaceholderExpansion Java Examples

The following examples show how to use me.clip.placeholderapi.expansion.PlaceholderExpansion. 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: PlaceholderAPI.java    From PlaceholderAPI with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Unregister all expansions provided by PlaceholderAPI
 */
public static void unregisterAllProvidedExpansions() {
  if (placeholders.isEmpty()) {
    return;
  }
  
  getPlaceholders().forEach((key, value) -> {
    if (value instanceof PlaceholderExpansion) {
      PlaceholderExpansion ex = (PlaceholderExpansion) value;
      
      if (!ex.persist()) {
        unregisterExpansion(ex);
      }
    }
  });
}
 
Example #2
Source File: PlaceHolderVariables.java    From ScoreboardStats with MIT License 6 votes vote down vote up
@Override
public void register() {
    Set<String> variables = Sets.newHashSet();

    Collection<PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders().values();
    for (PlaceholderHook hook : hooks) {
        String variablePrefix = null;
        if (hook instanceof EZPlaceholderHook) {
            variablePrefix = ((EZPlaceholderHook) hook).getPlaceholderName();
        } else if (hook instanceof PlaceholderExpansion) {
            variablePrefix = ((PlaceholderExpansion) hook).getIdentifier();
        }

        if (variablePrefix != null) {
            variables.add(variablePrefix + "_*");
        }
    }

    for (String variable : variables) {
        register(variable).supply(player -> PlaceholderAPI.setPlaceholders(player, '%' + variable + '%'));
    }
}
 
Example #3
Source File: PlaceholderListener.java    From PlaceholderAPI with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPluginUnload(PluginDisableEvent e) {
  String n = e.getPlugin().getName();

  if (n == null) {
    return;
  }

  if (n.equals(plugin.getName())) {
    return;
  }

  Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders();

  for (Entry<String, PlaceholderHook> hook : hooks.entrySet()) {
    PlaceholderHook i = hook.getValue();

    if (i instanceof PlaceholderExpansion) {
      PlaceholderExpansion ex = (PlaceholderExpansion) i;

      if (ex.getRequiredPlugin() == null) {
        continue;
      }

      if (ex.getRequiredPlugin().equalsIgnoreCase(n)) {
        if (PlaceholderAPI.unregisterExpansion(ex)) {
          plugin.getLogger().info("Unregistered placeholder expansion: " + ex.getIdentifier());
        }
      }
    }
  }
}
 
Example #4
Source File: PlaceholderListener.java    From PlaceholderAPI with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onQuit(PlayerQuitEvent e) {
  Set<PlaceholderExpansion> expansions = PlaceholderAPI.getExpansions();

  if (expansions.isEmpty()) {
    return;
  }

  for (PlaceholderExpansion ex : expansions) {
    if (ex instanceof Cleanable) {
      ((Cleanable) ex).cleanup(e.getPlayer());
    }
  }
}
 
Example #5
Source File: PlaceholderAPIPlugin.java    From PlaceholderAPI with GNU General Public License v3.0 5 votes vote down vote up
private void setupMetrics() {
  Metrics m = new Metrics(this);
  m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud",
      () -> getExpansionCloud() != null ? "yes" : "no"));

  m.addCustomChart(
      new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));

  m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
    Map<String, Integer> map = new HashMap<>();
    Map<String, PlaceholderHook> p = PlaceholderAPI.getPlaceholders();

    if (!p.isEmpty()) {

      for (PlaceholderHook hook : p.values()) {
        if (hook instanceof PlaceholderExpansion) {
          PlaceholderExpansion ex = (PlaceholderExpansion) hook;
          map.put(ex.getRequiredPlugin() == null ? ex.getIdentifier()
              : ex.getRequiredPlugin(), 1);
        }
      }
    }
    return map;

  }));

}
 
Example #6
Source File: PlaceholderAPI.java    From PlaceholderAPI with GNU General Public License v3.0 5 votes vote down vote up
public static Set<PlaceholderExpansion> getExpansions() {
  Set<PlaceholderExpansion> set = getPlaceholders().values().stream()
          .filter(PlaceholderExpansion.class::isInstance).map(PlaceholderExpansion.class::cast)
          .collect(Collectors.toCollection(HashSet::new));
  
  return ImmutableSet.copyOf(set);
}
 
Example #7
Source File: PlaceholderAPI.java    From PlaceholderAPI with GNU General Public License v3.0 5 votes vote down vote up
public static boolean registerExpansion(PlaceholderExpansion ex) {
  ExpansionRegisterEvent ev = new ExpansionRegisterEvent(ex);
  Bukkit.getPluginManager().callEvent(ev);
  if (ev.isCancelled()) {
    return false;
  }
  
  return registerPlaceholderHook(ex.getIdentifier(), ex);
}
 
Example #8
Source File: PlaceholderAPI.java    From PlaceholderAPI with GNU General Public License v3.0 5 votes vote down vote up
public static boolean unregisterExpansion(PlaceholderExpansion ex) {
  if (unregisterPlaceholderHook(ex.getIdentifier())) {
    Bukkit.getPluginManager().callEvent(new ExpansionUnregisterEvent(ex));
    return true;
  }
  
  return false;
}
 
Example #9
Source File: BridgeImpl.java    From TabooLib with MIT License 5 votes vote down vote up
@Override
public void registerExpansion(Class pluginClass) {
    try {
        ((PlaceholderExpansion) pluginClass.newInstance()).register();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example #10
Source File: ExpansionRegisterEvent.java    From PlaceholderAPI with GNU General Public License v3.0 4 votes vote down vote up
public ExpansionRegisterEvent(PlaceholderExpansion expansion) {
  this.expansion = expansion;
}
 
Example #11
Source File: ExpansionRegisterEvent.java    From PlaceholderAPI with GNU General Public License v3.0 4 votes vote down vote up
public PlaceholderExpansion getExpansion() {
  return expansion;
}
 
Example #12
Source File: ExpansionUnregisterEvent.java    From PlaceholderAPI with GNU General Public License v3.0 4 votes vote down vote up
public ExpansionUnregisterEvent(PlaceholderExpansion expansion) {
  this.expansion = expansion;
}
 
Example #13
Source File: ExpansionUnregisterEvent.java    From PlaceholderAPI with GNU General Public License v3.0 4 votes vote down vote up
public PlaceholderExpansion getExpansion() {
  return expansion;
}
 
Example #14
Source File: BridgeImpl.java    From TabooLib with MIT License 4 votes vote down vote up
@Override
public boolean isPlaceholderExpansion(Class pluginClass) {
    return PlaceholderExpansion.class.isAssignableFrom(pluginClass);
}