How to get an offline player by UUID? - minecraft

How to get an offline player by UUID? I can get an online player by UUID by iterating through all online players and return when an UUID matches, but I don't know how to do this for offline players.

Beta build of CraftBukkit (1.7.9-R0.1) has the method you need in org.bukkit.Server interface:
/**
* Gets the player by the given UUID, regardless if they are offline or
* online.
* <p>
* This will return an object even if the player does not exist. To this
* method, all players will exist.
*
* #param id the UUID of the player to retrieve
* #return an offline player
*/
public OfflinePlayer getOfflinePlayer(UUID id);
JavaDoc
Related issue: BUKKIT-5501
Related commit: 4bc86be4

Related

How can I sort images by date or folder name from CameraRoll in React Native

I'm trying to make custom listView of camera roll in React Native.
And I see when I do ' CameraRoll.getPhotos(fetchParams) ', I can put some params. But there's no option for sorting or I can get the folders name.
Thanks in advance for the advice !
In CameraRoll.js below..
var getPhotosParamChecker = createStrictShapeTypeChecker({
/**
* The number of photos wanted in reverse order of the photo application
* (i.e. most recent first for SavedPhotos).
*/
first: ReactPropTypes.number.isRequired,
/**
* A cursor that matches `page_info { end_cursor }` returned from a previous
* call to `getPhotos`
*/
after: ReactPropTypes.string,
/**
* Specifies which group types to filter the results to.
*/
groupTypes: ReactPropTypes.oneOf(GROUP_TYPES_OPTIONS),
/**
* Specifies filter on group names, like 'Recent Photos' or custom album
* titles.
*/
groupName: ReactPropTypes.string,
/**
* Specifies filter on asset type
*/
assetType: ReactPropTypes.oneOf(ASSET_TYPE_OPTIONS),
/**
* Filter by mimetype (e.g. image/jpeg).
*/
mimeTypes: ReactPropTypes.arrayOf(ReactPropTypes.string),
});
It seems there is no way other then need to fix..
Or can I make a list of Image folders?
Please sort according to time stamp. Above attached picture is the output of CameraRoll

How do I obtain all documents referenced by a single document?

If I have a document Shop that has many Activities defined as ReferenceMany, is there a way I can directly query for the list of Activities for a Shop without hydrating a Shop instance?
For example:
{
"_id": fd390j09afj09dfj,
"activities": [
...
]
}
All I want is to be able to say "get me the array activities where _id is fd390j09afj09dfj, and hydrate them as Activity instances.
Here's the first solution I came up with:
/**
* Gets all activities configured for a shop.
*
* #param string $shopId
* #return \BikeShed\Domain\Activity[]|\Doctrine\Common\Collections\ArrayCollection
*/
public function findByShopId($shopId) {
/** #var \BikeShed\Domain\Repository\Shop $shopRepository */
$shopRepository = $this->dm->getRepository('BikeShed\Domain\Shop');
$shop = $shopRepository->findOneById($shopId);
return $shop->getActivities();
}
It's simply fetching the Shop and then getting all the Activities via the defined relation.
Here's a working example of how you would implement jmikola's last suggestion:
/**
* #param string $shopId
* #return ActivityModel[]
*/
public function findByShopId($shopId) {
$partialShopData = $this->dm->getRepository('BikeShed\Domain\Shop')->createQueryBuilder()
->hydrate(false)
->field('activities')
->getQuery()
->getSingleResult()
;
$activityIds = [];
if(!empty($partialShopData['activities']))
foreach($partialShopData['activities'] as $activity)
if(!empty($activity['$id']))
$activityIds[] = $activity['$id'];
return $this->createQueryBuilder()
->field('id')
->in($activityIds)
->getQuery()
->toArray()
;
}
You cannot directly query the Shop collection or (or ODM repository) and receive Activity instances; however, you can use the Query Builder API to specify a projection with select('activities'). The executed query will still return Shop instances, but the activities field should be the only thing hydrated (as a PersistentCollection of Activity instances). In this case, you shouldn't modify any of the non-hydrated Shop fields, as ODM will detect any non-null value as a change.
It should be trivial to add a convenience method on ShopRepository that issues the above query with its select() and returns the collection (or an array) of Activity documents instead of the Shop. Keeping the Shop inaccessible should also protect you from inadvertently modifying other non-hydrated fields within it.
The down-side with this method is that the Activities will be proxy objects and lazily loaded. You can mitigate this with reference priming. With priming, you'll end up doing two queries (one for the Shop and one for all referenced Activity documents).
Regarding your follow-up question about putting this method on the Activity repository, you do have another option. Firstly, I agree that ActivityRepository::findByShopId() is preferable to calling a method on ShopRepository that returns Activity objects.
Each repository has a reference to the document manager, which you can use to access other repositories via the getRepository() method. An ActivityRepository::findByShopId() could do the following:
Access the Shop repository through the document manager
Query for the Shop by its ID, projecting only the activities field and disabling hydration completely
Collect the identifiers from the activities array. Depending on whether the Activity references are simple or not, the elements in that array may be the raw _id values or DBRef objects.
Execute a query for all Activity objects (easy, since we're already in that repository) where the ID is $in the array of identifiers

zend framework 2 + doctrine: removing media with related Entity

I've setup ZF2 Skeleton Application with Doctrine2. My goal is to create simple News service with simple hierarchy.
Category -> News -> Media (file)
I've setup all required relations for Category, News and Media (i.e. If News is deleted all related media is deleted from DB).
The problem is that media points to some file (located in file storage). I've implemented simple function that deletes all media related to News and then News it self.
$news->deleteImg();
$this->getEntityManager()->remove($news);
$this->getEntityManager()->flush();
It feels that this is wrong approach.
Is there a way to bind delete file function to Media Entity that will be called automatically each time Media is removed directly or throught it's parents? (i.e. News or Category)
Found the solution.
It's pretty simple:
First add annotation before Media class
/**
* Media
*
* #ORM\Table(name="media")
* #ORM\Entity
* #ORM\HasLifecycleCallbacks <- Add this line
*/
class Media
Then you need to add 2 functions for the class on PreRemove and PostRemove
/**
* #ORM\PreRemove()
*/
public function storeFilenameForRemove()
{
$this->temp = realpath($this->path);
}
/**
* #ORM\PostRemove()
*/
public function removeImg()
{
if (isset($this->temp)) {
unlink($this->temp);
}
}
This functions will be fired: 1st before remove (to store file name) and second after Entity is removed from DB to remove related File.
You need also to define
private $temp;
That stores file name.
That's it. Now when you remove news or news category all related media files will be removed with the it's entity.

Symfony Doctrine : Use real tablename in request

I'm using doctrine in a symfony project and I have a little problem.
I have a "Character" entity, and a "Equipment" entity.
The character can only wear 5 equipment on him.
But he could buy some other equipment, to put in his inventory. This way, he can switch one of his equipment for another one in his inventory.
So, in my "Character" entity I have :
/**
* #ORM\ManyToMany(targetEntity="rs\WelcomeBundle\Entity\Equipment", cascade={"persist"})
* #ORM\JoinTable(name="InventoryCharacter")
*/
private $inventory;
/**
* #ORM\ManyToMany(targetEntity="rs\WelcomeBundle\Entity\Equipment", cascade={"persist"})
* #ORM\JoinTable(name="EquipmentWearCharacter")
*/
private $equipementsWear;
The problem is : I want to get the list of equipment that the character don't already buy.
In fact I want to get the list of equipment that are in the complete list (findAll in equipment) but NOT IN the list of character inventory.
I try to do a request but doctrine doesn't know the table "InventoryCharacter" because there is no corresponding entity class...
So I can't do "Select p from InventoryCharacter..."
How I can do ? I want to specify to search in the real database, not in the list of entity class...
The 'ManyToMany' relationship with Doctrine is very transparent. You can not do anything more than getting entity list for the one or the other.
If you ever find yourself needing to access the 'Relation' table, either to add extra data about the relation (e.g. time created) or to apply a filter (e.g. recently created), you need to create that relationship entity yourself. i.e. CharacterInventory. and set up OneToMany and ManyToOne relationships between the 3 entities.
Hope this help.
+++++++++++Edited+++++++++++
If you simply want to retrieve all equipments user can purchase (i.e. not purchased yet), you actually dont need to create the middle entity CharacterInventory:
/**
* Add this to the Equipment Entity
*
* #ORM\ManyToMany(targetEntity="rs\WelcomeBundle\Entity\Character", cascade={"persist"})
* #ORM\JoinTable(name="InventoryCharacter")
*/
private $characters;
Then you can use this to query what you want:
$dql = "SELECT s FROM rs\WelcomeBundle\Entity\Equipment s LEFT JOIN s.characters ct WHERE ct != :character";
$found = $em->createQuery($dql)
->setParameter('character', $characterEntityObject)
->getResult();

Sencha Touch 2 Beta 2 Store Sync Issues

In ST1.x I had no problem syncing an onlinestore to an offlinestore with the below method, now it seems that sync doesn't work in STB2. I can see the records being output on the console. Anyone else having this issue? I believe it may be a bug...
var remoteStore = Ext.getStore('UpdateConfig');
var localStore = Ext.getStore('UpdateLocalConfig');
remoteStore.each(function (record) {
localStore.add(record.data);
console.log(record.data);
});
localStore.sync();
same question + answer # Sencha Forum
...and same user??? XD
This was answered on the Sencha Touch 2 Forums by TommyMaintz, but I wanted to give the answer here as well.
"One thing I think I see which is wrong is that you are adding a record to the LocalStore using the record.data. In ST2 we now have a Model cache. This means that if you create two instances with the exact same model and id, the second time you create that instance it will just return the already existing instance. This means that if you sync your local store, it won't recognize that record as a 'phantom' record because it already has an id. What you would have to do in your case if you want to make a "copy" of your record by using all the data but removing the id. This will generate a new simple id for it and when you save it to your local storage it will generate a proper local id for it.
When I tried doing this I noticed the "copy" method on Model hasn't been updated to handle this. If you apply the following override you should be able to do localStore.add(record.copy()); localStore.sync()"
Ext.define('Ext.data.ModelCopyFix', {
override: 'Ext.data.Model',
/**
* Creates a copy (clone) of this Model instance.
*
* #param {String} id A new id. If you don't specify this a new id will be generated for you.
* To generate a phantom instance with a new id use:
*
* var rec = record.copy(); // clone the record with a new id
*
* #return {Ext.data.Model}
*/
copy: function(newId) {
var me = this,
idProperty = me.getIdProperty(),
raw = Ext.apply({}, me.raw),
data = Ext.apply({}, me.data);
delete raw[idProperty];
delete data[idProperty];
return new me.self(null, newId, raw, data);
}
});