Skip to content

Commit

Permalink
use a slow warning for player name usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 1, 2019
1 parent 07cc549 commit 6bf0d82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
16 changes: 0 additions & 16 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -129,22 +129,6 @@ public static dEntity valueOf(String string) {
return valueOf(string, null);
}

/**
* Gets a dEntity Object from a string form. </br>
* </br>
* Unique dEntities: </br>
* n@13 will return the entity object of NPC 13 </br>
* e@5884 will return the entity object for the entity with the entityid of 5884 </br>
* e@jimmys_pet will return the saved entity object for the id 'jimmys pet' </br>
* p@aufdemrand will return the entity object for aufdemrand </br>
* </br>
* New dEntities: </br>
* zombie will return an unspawned Zombie dEntity </br>
* super_creeper will return an unspawned custom 'Super_Creeper' dEntity </br>
*
* @param string the string or dScript argument String
* @return a dEntity, or null
*/
@Fetchable("e")
public static dEntity valueOf(String string, TagContext context) {
if (string == null) {
Expand Down
20 changes: 14 additions & 6 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -18,6 +18,7 @@
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.aufdemrand.denizencore.utilities.debugging.SlowWarning;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.*;
Expand Down Expand Up @@ -92,9 +93,8 @@ public static Map<String, UUID> getAllPlayers() {
// @group Object Fetcher System
// @description
// p@ refers to the 'object identifier' of a dPlayer. The 'p@' is notation for Denizen's Object
// Fetcher. The only valid constructor for a dPlayer is the name of the player the object should be
// associated with. For example, to reference the player named 'mythan', use p@mythan. Player names
// are case insensitive.
// Fetcher. The only valid constructor for a dPlayer is the UUID of the player the object should be
// associated with.
// -->


Expand All @@ -104,14 +104,20 @@ public static dPlayer valueOf(String string) {

@Fetchable("p")
public static dPlayer valueOf(String string, TagContext context) {
return valueOfInternal(string, context == null || context.debug);
return valueOfInternal(string, context, true);
}

public static SlowWarning playerByNameWarning = new SlowWarning("");

static dPlayer valueOfInternal(String string, boolean announce) {
public static dPlayer valueOfInternal(String string, boolean announce) {
return valueOfInternal(string, null, announce);
}

public static dPlayer valueOfInternal(String string, TagContext context, boolean defaultAnnounce) {
if (string == null) {
return null;
}
boolean announce = context == null ? defaultAnnounce : context.debug;

string = string.replace("p@", "").replace("P@", "");

Expand All @@ -136,7 +142,9 @@ static dPlayer valueOfInternal(String string, boolean announce) {
if (playerNames.containsKey(CoreUtilities.toLowerCase(string))) {
OfflinePlayer player = Bukkit.getOfflinePlayer(playerNames.get(CoreUtilities.toLowerCase(string)));
if (announce) {
dB.echoError("Warning: loading player by name - use the UUID instead (or use tag server.match_player)! Player named '" + player.getName() + "' has UUID: " + player.getUniqueId());
playerByNameWarning.message = "Warning: loading player by name - use the UUID instead" +
" (or use tag server.match_player)! Player named '" + player.getName() + "' has UUID: " + player.getUniqueId();
playerByNameWarning.warn(context == null ? null : context.entry);
}
return new dPlayer(player);
}
Expand Down

0 comments on commit 6bf0d82

Please sign in to comment.