本文整理汇总了Java中org.spongepowered.api.service.user.UserStorageService类的典型用法代码示例。如果您正苦于以下问题:Java UserStorageService类的具体用法?Java UserStorageService怎么用?Java UserStorageService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserStorageService类属于org.spongepowered.api.service.user包,在下文中一共展示了UserStorageService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
@Override
public void execute(User user, CommandContext args, MessageChannel channel) {
String code = (String) args.getOne("code").get();
//link successful
if (this.bot.getCodes().containsKey(code)) {
org.spongepowered.api.entity.living.player.User spongeUser = Sponge.getServiceManager().provideUnchecked(UserStorageService.class)
.get(bot.getCodes().get(code)).get();
spongeUser.getSubjectData().setOption(SubjectData.GLOBAL_CONTEXT, "discord-user", user.getId());
AccountConfigData data = (AccountConfigData) this.phonon.getAllConfigs().get(AccountConfigData.class);
data.getAccounts().put(user.getId(), spongeUser.getUniqueId());
data.save();
channel.sendMessage("You have successfully linked " + user.getName() + "#" +user.getDiscriminator()
+ " to " + spongeUser.getName()).queue();
} else {
channel.sendMessage("That is not a valid code!").queue();
}
}
示例2: Defaults
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
public Defaults(EconomyService service, JavascriptManager manager, PlaceholderService s) {
if (service != null) {
eco = true;
this.service = service;
this.def = service.getDefaultCurrency();
service.getCurrencies().forEach(this::putCur);
} else {
eco = false;
}
this.manager = manager;
try {
manager.reloadScripts();
} catch (Exception e) {
}
server = PlaceholderAPIPlugin.getInstance().getGame().getServer();
this.s = s;
Optional<UserStorageService> o = Sponge.getServiceManager().provide(UserStorageService.class);
if (o.isPresent()) {
this.storage = o.get();
changed = true;
sync();
}
current = new Uptime();
current.start();
}
示例3: getAllAnnointedUsers
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
public static Stream<User> getAllAnnointedUsers() {
if (cachedService == null) {
Sponge.getServiceManager().provide(UserStorageService.class)
.ifPresent(x -> cachedService = x);
if (cachedService == null) {
// We can't tell who's annointed yet - no one is!
return Stream.empty();
}
}
if (cachedUserListInvalid.get() || ignoreCachedUserListAlways.get()) {
cachedAnnointedUsers.clear();
cachedAnnointedUsers.addAll(generateAnnointedUsersCollection());
cachedUserListInvalid.set(false);
}
return cachedAnnointedUsers.stream();
}
示例4: renderSubject
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
Text renderSubject(Subject subject) {
HoverAction<?> hover = null;
if (this.collection.getIdentifier().equals(PermissionService.SUBJECTS_USER)) {
try {
UUID uuid = UUID.fromString(subject.getIdentifier());
Optional<User> user = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(uuid);
if (user.isPresent()) {
hover = TextActions.showText(Text.of(user.get().getName()));
}
} catch (Exception e) {
}
}
return Text.builder(subject.getIdentifier())
.onHover(hover)
.onClick(ExtraUtils.clickAction(() -> {
this.tab.getSubjViewer().setActive(subject, true);
this.tab.setRoot(this.tab.getSubjViewer());
}, SubjectListPane.this.tab)).build();
}
示例5: getPlayer
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
@Override
public Optional<ICachedPlayer> getPlayer(String nameOrUuid) {
if (Util.isValidUUID(nameOrUuid)) {
return getPlayer(UUID.fromString(nameOrUuid));
}
Optional<CachedPlayer> player = players.values().stream().filter(p -> p.getName().equalsIgnoreCase(nameOrUuid)).findAny();
if (player.isPresent())
return player.flatMap(p -> getPlayer(p.getUUID()));
return WebAPI.runOnMain(() -> {
Optional<UserStorageService> optSrv = Sponge.getServiceManager().provide(UserStorageService.class);
if (!optSrv.isPresent())
return null;
Optional<User> optUser = optSrv.get().get(nameOrUuid);
return optUser.<ICachedPlayer>map(CachedPlayer::new).orElse(null);
});
}
示例6: getActiveVipInfo
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
/**Return player's vip info.<p>
* [0] = Duration, [1] = Vip Group, [2] = Player Group, [3] = Is Active, [4] = Player Nick
* @param puuid Player UUID as string or nickname.
* @return {@code String[5]}
*/
public String[] getActiveVipInfo(String playName){
User offp = null;
UserStorageService uss = Sponge.getGame().getServiceManager().provide(UserStorageService.class).get();
try{
UUID puuid = UUID.fromString(playName);
if (uss.get(puuid).isPresent()){
offp = uss.get(puuid).get();
}
} catch (IllegalArgumentException ex){
if (uss.get(playName).isPresent()){
offp = uss.get(playName).get();
}
}
if (offp != null){
for (String[] vips:getVipInfo(offp.getUniqueId().toString())){
if (vips[3].equals("true")){
return vips;
}
}
}
return new String[5];
}
示例7: getOrCreateUser
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
public static User getOrCreateUser(UUID uuid) {
if (uuid == null) {
return null;
}
if (uuid == WORLD_USER_UUID) {
return WORLD_USER;
}
// check the cache
Optional<User> player = Sponge.getGame().getServiceManager().provide(UserStorageService.class).get().get(uuid);
if (player.isPresent()) {
return player.get();
} else {
try {
GameProfile gameProfile = Sponge.getServer().getGameProfileManager().get(uuid).get();
return Sponge.getGame().getServiceManager().provide(UserStorageService.class).get().getOrCreate(gameProfile);
} catch (Exception e) {
return null;
}
}
}
示例8: getOwnerOfEntity
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
public static Optional<User> getOwnerOfEntity(net.minecraft.entity.Entity entity) {
NBTTagCompound nbt = new NBTTagCompound();
entity.writeToNBT(nbt);
if (nbt.hasKey(FORGE_DATA)) {
NBTTagCompound forgeNBT = nbt.getCompoundTag(FORGE_DATA);
if (forgeNBT.hasKey(SPONGE_DATA) && forgeNBT.getCompoundTag(SPONGE_DATA).hasKey(SPONGE_ENTITY_CREATOR)) {
NBTTagCompound creatorNBT = forgeNBT.getCompoundTag(SPONGE_DATA).getCompoundTag(SPONGE_ENTITY_CREATOR);
UUID uuid = new UUID(creatorNBT.getLong("uuid_most"), creatorNBT.getLong("uuid_least"));
// get player if online
EntityPlayer player = entity.world.getPlayerEntityByUUID(uuid);
if (player != null) {
return Optional.of((User) player);
}
// player is not online, get user from storage if one exists
return Sponge.getGame().getServiceManager().provide(UserStorageService.class).get().get(uuid);
}
}
return Optional.empty();
}
示例9: lookupPlayerName
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
public static String lookupPlayerName(UUID playerID) {
// parameter validation
if (playerID == null) {
return "somebody";
}
// check the cache
Optional<User> player = Sponge.getGame().getServiceManager().provide(UserStorageService.class).get().get(playerID);
if (player.isPresent()) {
return player.get().getName();
} else {
try {
return Sponge.getServer().getGameProfileManager().get(playerID).get().getName().get();
} catch (Exception e) {
return "someone";
}
}
}
示例10: LanternPlayer
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
public LanternPlayer(LanternGameProfile gameProfile, NetworkSession session) {
super((ProxyUser) Sponge.getServiceManager().provideUnchecked(UserStorageService.class).getOrCreate(gameProfile));
this.gameProfile = gameProfile;
this.interactionHandler = new PlayerInteractionHandler(this);
this.inventory = VanillaInventoryArchetypes.PLAYER.builder()
.withCarrier(this).build(Lantern.getMinecraftPlugin());
this.inventoryContainer = new PlayerInventoryContainer(this.inventory,
AbstractOrderedInventory.viewBuilder()
.title(this.inventory.getName())
.inventory(VanillaInventoryArchetypes.CRAFTING.builder()
.build(Lantern.getMinecraftPlugin()))
.inventory(this.inventory.getEquipment())
.inventory(this.inventory.getOffhand())
.shiftClickBehavior(PlayerInventoryShiftClickBehavior.INSTANCE)
.build(Lantern.getMinecraftPlugin()));
this.containerSession = new PlayerContainerSession(this);
this.session = session;
// Load the advancements
this.advancementsProgress.init();
resetIdleTimeoutCounter();
setBoundingBoxBase(BOUNDING_BOX_BASE);
// Attach this player to the proxy user and load player data
getProxyUser().setInternalUser(this);
}
示例11: sendAll
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
@Alias(value = "sendallmail")
@Command(desc = "Sends mails to all players.")
public void sendAll(CommandSource context, final @Greed(INFINITE) String message)
{
Collection<Player> users = Sponge.getServer().getOnlinePlayers();
final Set<UUID> alreadySend = new HashSet<>();
for (User user : users)
{
getMails(user).addMail(context, message);
alreadySend.add(user.getUniqueId());
}
taskManager.runAsynchronousTaskDelayed(MailModule.class, () ->
Sponge.getServiceManager().provideUnchecked(UserStorageService.class).getAll().stream()
.filter(p -> alreadySend.contains(p.getUniqueId()))
.forEach(p -> new PlayerMails(p.getUniqueId(), db).addMail(context, message)), 0);
i18n.send(context, POSITIVE, "Sent mail to everyone!");
}
示例12: save
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
@Override
public CompletableFuture<Boolean> save(CompletableFuture<Boolean> c)
{
return c.thenApply(changed -> {
if (changed)
{
cacheOptions();
cachePermissions();
cacheParents();
// Serialize Data
List<String> parents = serializeToList(this.parents);
Map<String, Boolean> permissions = serializeToMap(this.permissions);
Map<String, String> options = serializeToMap(this.options);
// Get User for Storage
UserStorageService storage = Sponge.getServiceManager().provide(UserStorageService.class).get();
User user = storage.get(uuid).get();
// Save Data in User
user.offer(new PermissionData(parents, permissions, options));
// actually save Data in Player til -> TODO remove once saving data on user is implemented
user.getPlayer().map(User.class::cast).orElse(user).offer(new PermissionData(parents, permissions, options));
}
return changed;
});
}
示例13: parse
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
@Override
public PlayerAccess parse(Class clazz, CommandInvocation invocation) throws ParserException
{
String token = invocation.currentToken();
boolean admin = token.startsWith("@");
boolean add = !token.startsWith("-");
token = admin || !add ? token.substring(1) : token;
User user = Sponge.getServer().getPlayer(token)
.map(User.class::cast)
.orElse(Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(token)
.orElse(null));
if (user == null)
{
throw new IllegalArgumentException("User not found");
}
invocation.consume(1);
return new PlayerAccess(user, admin, add);
}
示例14: notifyKeyUsage
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
public void notifyKeyUsage(Player user)
{
if (lastKeyNotify == null)
{
this.lastKeyNotify = new HashMap<>();
}
User owner = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(model.getValue(TABLE_LOCKS.OWNER_ID)).get();
if (owner.equals(user))
{
return;
}
Long last = this.lastKeyNotify.get(owner.getUniqueId());
if (last == null || TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - last) > 60) // 60 sec config ?
{
this.lastKeyNotify.put(owner.getUniqueId(), System.currentTimeMillis());
if (owner.isOnline())
{
i18n.send(owner.getPlayer().get(), NEUTRAL, "{user} used a KeyBook to access one of your protections!", user);
}
}
}
示例15: parseValue
import org.spongepowered.api.service.user.UserStorageService; //导入依赖的package包/类
@Nullable
@Override
public User parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
String player = args.next();
Optional<Player> t = Selector.one(source, player);
if (t.isPresent()) {
return t.get();
} else {
try {
UserStorageService service = Sponge.getServiceManager().provide(UserStorageService.class).get();
GameProfile profile = Sponge.getServer().getGameProfileManager().get(player).get();
return service.get(profile).get();
} catch (Exception ex) {
throw args.createError(Messages.getFormatted("core.playernotfound", "%player%", player));
}
}
}