List of usage examples for com.mongodb BasicDBList BasicDBList
BasicDBList
From source file:net.cogz.chat.ChatManager.java
License:Open Source License
@TCommand(name = "censor", description = "Command for managing censored words.", permission = "gearz.censor", usage = "/censor [list|remove|add] [message (required if applicable)]", senders = { TCommandSender.Player, TCommandSender.Console }) @SuppressWarnings("unused") public TCommandStatus censors(CommandSender sender, TCommandSender type, TCommand meta, Command command, String[] args) {//from w ww .ja v a 2s . c o m if (args.length < 1) return TCommandStatus.HELP; String cmd = args[0]; Object[] censoredWords1 = GearzChat.getInstance().getCensoredWords(); if (cmd.equalsIgnoreCase("list")) { sender.sendMessage(GearzChat.getInstance().getFormat("formats.header-censorlist", false)); int index = 0; for (Object o : censoredWords1) { index++; if (!(o instanceof String)) continue; String s = (String) o; sender.sendMessage(GearzChat.getInstance().getFormat("formats.list-motdlist", false, new String[] { "<index>", String.valueOf(index) }, new String[] { "<motd>", s })); } return TCommandStatus.SUCCESSFUL; } if (args.length < 2) return TCommandStatus.FEW_ARGS; List<String> strings = new ArrayList<>(); for (Object o : censoredWords1) { if (o instanceof String) strings.add((String) o); } if (cmd.equalsIgnoreCase("remove")) { Integer toRemove = Integer.parseInt(args[1]); if (toRemove < 1 || toRemove > censoredWords1.length) { sender.sendMessage(GearzChat.getInstance().getFormat("formats.index-out-of-range", false)); return TCommandStatus.SUCCESSFUL; } String s = strings.get(toRemove - 1); strings.remove(toRemove - 1); sender.sendMessage( GearzChat.getInstance().getFormat("formats.removed-motd", false, new String[] { "<motd>", s })); } else if (cmd.equalsIgnoreCase("add")) { StringBuilder build = new StringBuilder(); int index = 1; while (index < args.length) { build.append(args[index]).append(" "); index++; } String s = build.substring(0, build.length() - 1); strings.add(s); sender.sendMessage( GearzChat.getInstance().getFormat("formats.added-motd", false, new String[] { "<motd>", s })); } else { return TCommandStatus.INVALID_ARGS; } BasicDBList basicDBList = new BasicDBList(); basicDBList.addAll(strings); GearzChat.getInstance().setCensoredWords(basicDBList); GearzChat.getInstance().getChat().updateCensor(); return TCommandStatus.SUCCESSFUL; }
From source file:net.cogz.friends.GearzFriends.java
License:Open Source License
public void addFriend(String toUpdate, String toAdd, boolean primary) throws FriendRequestException { if (isFriend(toUpdate, toAdd)) throw new IllegalStateException("Already added"); DBObject playerDocument = getPlayerDocument(toUpdate); Object friendsObj = playerDocument.get("friends"); if (friendsObj == null || !(friendsObj instanceof BasicDBList)) { friendsObj = new BasicDBList(); }// www. j ava2 s.c om BasicDBList friendsList = (BasicDBList) friendsObj; if (!hasRequest(toUpdate, toAdd)) { throw new FriendRequestException("No request found"); } else { DBObject newFriend = new BasicDBObjectBuilder().add("name", getObjectId(getPlayerDocument(toAdd))) .add("added", new Date()).get(); friendsList.add(newFriend); if (primary) { addFriendRequest(toAdd, toUpdate); addFriend(toAdd, toUpdate, false); } denyFriendRequest(toUpdate, toAdd); } playerDocument.put("friends", friendsList); getCollection().save(playerDocument); }
From source file:net.cogz.friends.GearzFriends.java
License:Open Source License
public void addFriendRequest(String receiver, String from) { DBObject playerDocument = getPlayerDocument(receiver); Object friendsObj = playerDocument.get("friend_requests"); if (friendsObj == null || !(friendsObj instanceof BasicDBList)) { friendsObj = new BasicDBList(); }//from ww w. j a v a2s . c om BasicDBList friendsList = (BasicDBList) friendsObj; if (hasRequest(receiver, from)) { throw new IllegalStateException("Friend request exists for that player"); } else { DBObject newRequest = new BasicDBObjectBuilder().add("name", getObjectId(getPlayerDocument(from))) .add("sent", new Date()).get(); friendsList.add(newRequest); } playerDocument.put("friend_requests", friendsList); getCollection().save(playerDocument); }
From source file:net.cogz.friends.GearzFriends.java
License:Open Source License
public void denyFriendRequest(String player, String toDeny) { DBObject playerDocument = getPlayerDocument(player); Object friendsObj = playerDocument.get("friend_requests"); if (friendsObj == null || !(friendsObj instanceof BasicDBList)) { friendsObj = new BasicDBList(); }//w ww . j a v a 2s . c o m BasicDBList friendsList = (BasicDBList) friendsObj; if (hasRequest(player, toDeny)) { for (Object object : friendsList) { if (!(object instanceof BasicDBObject)) continue; BasicDBObject friend = (BasicDBObject) object; DBObject toRemoveDocument = getPlayerDocument(toDeny); ObjectId s = friend.getObjectId("name"); if (s.equals(getObjectId(toRemoveDocument))) { friendsList.remove(friend); playerDocument.put("friend_requests", friendsList); getCollection().save(playerDocument); return; } } } else { throw new IllegalStateException("No friend request from that player"); } playerDocument.put("friend_requests", friendsList); getCollection().save(playerDocument); }
From source file:net.handle.server.MongoDBHandleStorage.java
License:Open Source License
/** * ****************************************************************** * Creates the specified handle in the "database" with the specified * initial values/* w w w .j ava2 s .c o m*/ * <p/> * The document looks like this: * <p/> * handle:handle here: na\identifier * handles:[ * { * index: * type: * data: * ttl_type: * ttl: * timestamp: * refs: * admin_read: * admin_write: * pub_read: * pub_write: * } * , * { * index: * type: * data: * ttl_type: * ttl: * timestamp: * refs: * admin_read: * admin_write: * pub_read: * pub_write: * } * ] * ******************************************************************* */ public void createHandle(byte handle[], HandleValue values[]) throws HandleException { if (readOnly) throw new HandleException(HandleException.STORAGE_RDONLY, "Server is read-only"); final String handleStr = Util.decodeString(handle); // if the handle already exists, throw an exception if (handleExists(handle)) throw new HandleException(HandleException.HANDLE_ALREADY_EXISTS, handleStr); if (values == null) throw new HandleException(HandleException.INVALID_VALUE); BasicDBList handles = new BasicDBList(); for (HandleValue value : values) { // not the handle, // but index, type, data, ttl_type, ttl, timestamp, refs, // admin_read, admin_write, pub_read, pub_write BasicDBObject hv = setHandleValue(value); handles.add(hv); } BasicDBObject h = new BasicDBObject("handle", handleStr); h.put("handles", handles); final DBCollection collection = getCollection(handle); collection.insert(h); }
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
@Override public void addUser(String survey_id, SecureUserRecord user) throws DataStoreException, DuplicateKeyException { DBCollection col = getUsersCollection(survey_id); BasicDBList roles = new BasicDBList(); roles.addAll(user.roles);//from w ww.j a v a2 s . co m BasicDBList permissions = new BasicDBList(); permissions.addAll(user.permissions); BasicDBObject customFields = new BasicDBObject(); for (String k : user.customFields.keySet()) customFields.put(k, user.customFields.get(k)); try { col.insert( new BasicDBObject(FIELD_USERNAME, user.username).append(FIELD_PASSWORD, user.passwordHashBase64) .append(FIELD_SALT, user.passwordSaltBase64).append(FIELD_ROLES, roles) .append(FIELD_PERMISSIONS, permissions).append(FIELD_USERDATA, customFields)); } catch (DuplicateKey e) { throw new DuplicateKeyException(e); } catch (MongoException e) { throw new DataStoreException(e); } }
From source file:net.tbnr.commerce.items.CommerceItemManager.java
License:Open Source License
@Override public BasicDBList getPurchaseList(TBNRPlayer player) { DBObject playerDocument = player.getTPlayer().getPlayerDocument(); BasicDBList commerce_purchases;/*from ww w . j a va 2 s . c o m*/ try { commerce_purchases = (BasicDBList) playerDocument.get(CommerceItemManager.dbListKey); } catch (ClassCastException ex) { commerce_purchases = new BasicDBList(); } if (commerce_purchases == null) commerce_purchases = new BasicDBList(); return commerce_purchases; }
From source file:net.tbnr.commerce.items.CommerceItemManager.java
License:Open Source License
@Override public PurchaseResult purchaseTier(TBNRPlayer player, Tier tier) throws PurchaseException { if (!canPurchaseTier(player, tier)) throw new PurchaseException("You cannot purchase this tier!"); TPlayer tPlayer = player.getTPlayer(); DBObject playerDocument = tPlayer.getPlayerDocument(); BasicDBList tiers_purchased;/* w w w. j a v a2 s. co m*/ try { tiers_purchased = (BasicDBList) playerDocument.get("tiers_purchased"); } catch (ClassCastException ex) { tiers_purchased = new BasicDBList(); } if (tiers_purchased == null) tiers_purchased = new BasicDBList(); tiers_purchased.add(tier.toString()); playerDocument.put("tiers_purchased", tiers_purchased); tPlayer.save(); return new PurchaseResult(PurchaseMethod.Points, tier.getPoints(), true); }
From source file:net.tbnr.commerce.items.CommerceItemManager.java
License:Open Source License
@Override public boolean hasTier(TBNRPlayer player, Tier tier) { if (!tier.isMustBePurchased()) return true; TPlayer tPlayer = player.getTPlayer(); DBObject playerDocument = tPlayer.getPlayerDocument(); BasicDBList tiers_purchased;/* w ww . j a v a 2 s.com*/ try { tiers_purchased = (BasicDBList) playerDocument.get("tiers_purchased"); } catch (ClassCastException ex) { tiers_purchased = new BasicDBList(); } if (tiers_purchased == null) tiers_purchased = new BasicDBList(); return tiers_purchased.contains(tier.toString()); }
From source file:net.tbnr.gearz.activerecord.GModel.java
License:Open Source License
/** * * Processes a list into a {@link BasicDBList} * @param l The {@link List} object/* ww w. ja va 2 s. com*/ * @return The {@link BasicDBList} object. */ private BasicDBList processList(Field f, String dbKey, List l) { BasicDBList list = new BasicDBList(); for (Object o : l) { Object o1 = processField(o, f, dbKey); if (!isValidValue(o1)) continue; list.add(o1); } return list; }