use of org.spongepowered.api.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class SpongeTimings method getPluginTaskTimings.
/**
* Gets a timer associated with a plugins tasks.
*
* @param task
* @param period
* @return
*/
public static Timing getPluginTaskTimings(Task task, long period) {
if (task.isAsynchronous()) {
return null;
}
PluginContainer plugin = task.getOwner();
String name = "Task: " + task.getName();
if (period > 0) {
name += " (interval:" + period + ")";
} else {
name += " (Single)";
}
return SpongeTimingsFactory.ofSafe(plugin, name);
}
use of org.spongepowered.api.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class SpongeAdvancementBuilder method build.
@Override
public Advancement build() {
checkState(this.id != null, "The id must be set");
final PluginContainer plugin = Sponge.getCauseStackManager().getCurrentCause().first(PluginContainer.class).get();
final Tuple<Map<String, Criterion>, String[][]> result = SpongeCriterionHelper.toVanillaCriteriaData(this.criterion);
final AdvancementRewards rewards = AdvancementRewards.EMPTY;
final ResourceLocation resourceLocation = new ResourceLocation(plugin.getId(), this.id);
final net.minecraft.advancements.DisplayInfo displayInfo = this.displayInfo == null ? null : // Create a copy
(net.minecraft.advancements.DisplayInfo) DisplayInfo.builder().from(this.displayInfo).build();
net.minecraft.advancements.Advancement parent = (net.minecraft.advancements.Advancement) this.parent;
if (parent == null) {
// Attach a dummy root until a tree is constructed
parent = DUMMY_ROOT_ADVANCEMENT;
}
final Advancement advancement = (Advancement) new net.minecraft.advancements.Advancement(resourceLocation, parent, displayInfo, rewards, result.getFirst(), result.getSecond());
((IMixinAdvancement) advancement).setCriterion(this.criterion);
if (StringUtils.isNotEmpty(this.name)) {
((IMixinAdvancement) advancement).setName(this.name);
}
return advancement;
}
use of org.spongepowered.api.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class MixinTraitInventory method getPlugin.
@Override
public PluginContainer getPlugin() {
if (this.plugin == null) {
Object base = this;
PluginContainer container;
if (base instanceof CarriedInventory) {
final Optional<?> carrier = ((CarriedInventory<?>) base).getCarrier();
if (carrier.isPresent()) {
base = carrier.get();
}
}
if (base instanceof TileEntity) {
final String id = ((TileEntity) base).getBlock().getType().getId();
final String pluginId = id.substring(0, id.indexOf(":"));
container = Sponge.getPluginManager().getPlugin(pluginId).orElseThrow(() -> new AssertionError("Missing plugin " + pluginId + " for block " + id));
} else if (base instanceof Entity) {
final String id = ((Entity) base).getType().getId();
final String pluginId = id.substring(0, id.indexOf(":"));
container = Sponge.getPluginManager().getPlugin(pluginId).orElseThrow(() -> new AssertionError("Missing plugin " + pluginId + " for entity " + id + " (" + this.getClass().getName() + ")"));
} else if (base instanceof SpongeUser) {
container = SpongeImpl.getMinecraftPlugin();
} else {
container = Sponge.getPluginManager().getPlugin(SpongeImplHooks.getModIdFromClass(this.getClass())).orElseGet(() -> {
SpongeImpl.getLogger().warn("Unknown plugin for " + this);
return SpongeImpl.getMinecraftPlugin();
});
}
this.plugin = container;
}
return this.plugin;
}
use of org.spongepowered.api.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class KeyRegistryModule method registerAdditionalCatalog.
@Override
public void registerAdditionalCatalog(Key<?> extraCatalog) {
checkState(!SpongeDataManager.areRegistrationsComplete(), "Cannot register new Keys after Data Registration has completed!");
checkNotNull(extraCatalog, "Key cannot be null!");
final PluginContainer parent = ((SpongeKey) extraCatalog).getParent();
final String pluginId = parent.getId().toLowerCase(Locale.ENGLISH);
final String id = extraCatalog.getId().toLowerCase(Locale.ENGLISH);
final String[] split = id.split(":");
checkArgument(split.length == 2, "Key id's have to be in two parts! The first part being the plugin id, the second part being the key's individual id. Currently you have: " + Arrays.toString(split));
checkArgument(split[0].equals(pluginId), "A plugin is trying to register custom keys under a different plugin id namespace! This is unsupported! The provided key: " + id);
this.keyMap.put(id, extraCatalog);
}
use of org.spongepowered.api.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class AITaskTypeModule method createAITaskType.
public AITaskType createAITaskType(Object plugin, String id, String name, Class<? extends AITask<? extends Agent>> aiClass) {
final Optional<PluginContainer> optPluginContainer = SpongeImpl.getGame().getPluginManager().fromInstance(plugin);
Preconditions.checkArgument(optPluginContainer.isPresent());
final PluginContainer pluginContainer = optPluginContainer.get();
final String combinedId = pluginContainer.getId().toLowerCase(Locale.ENGLISH) + ':' + id;
return createAITaskType(combinedId, name, aiClass);
}
Aggregations