Skip to content

Commit

Permalink
Formatting/cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Aug 8, 2013
1 parent 56eee4f commit 924a3b5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 41 deletions.
23 changes: 12 additions & 11 deletions src/main/java/net/aufdemrand/denizen/objects/Duration.java
Expand Up @@ -11,25 +11,27 @@


/**
* Durations are a more convenient way to get a 'unit of time' within Denizen.
* Durations are a convenient way to get a 'unit of time' within Denizen.
*
* @version 1.0
* @author Jeremy Schroeder
*
*/

public class Duration implements dObject {

// Use regex pattern matching to easily determine if a string
// value is a valid Duration.
final static Pattern match =
Pattern.compile("(\\d+.\\d+|.\\d+|\\d+)(t|m|s|h|d|)(?:(?:-\\d+.\\d+|.\\d+|\\d+)(?:t|m|s|h|d|))?",
Pattern.compile("(\\d+.\\d+|.\\d+|\\d+)(t|m|s|h|d|)" +
// Optional 'high-range' for random durations.
"(?:(?:-\\d+.\\d+|.\\d+|\\d+)(?:t|m|s|h|d|))?",
Pattern.CASE_INSENSITIVE);


// Define a 'ZERO' Duration
final public static Duration ZERO = new Duration(0);




/**
* Gets a Duration Object from a dScript argument. Durations must be a positive
* number. Can specify the unit of time by using one of the following: T=ticks, M=minutes,
Expand Down Expand Up @@ -70,19 +72,19 @@ public static Duration valueOf(String string) {
// Standard Duration. Check the type and create new Duration object accordingly.
Matcher m = match.matcher(string);
if (m.matches()) {
if (m.group().toUpperCase().endsWith("T"))
if (m.group().toLowerCase().endsWith("t"))
// Matches TICKS, so 1 tick = .05 seconds
return new Duration(Double.valueOf(m.group(1)) * 0.05);

else if (m.group().toUpperCase().endsWith("D"))
else if (m.group().toLowerCase().endsWith("d"))
// Matches DAYS, so 1 day = 86400 seconds
return new Duration(Double.valueOf(m.group(1)) * 86400);

else if (m.group().toUpperCase().endsWith("M"))
else if (m.group().toLowerCase().endsWith("m"))
// Matches MINUTES, so 1 minute = 60 seconds
return new Duration(Double.valueOf(m.group(1)) * 60);

else if (m.group().toUpperCase().endsWith("H"))
else if (m.group().toLowerCase().endsWith("h"))
// Matches HOURS, so 1 hour = 3600 seconds
return new Duration(Double.valueOf(m.group(1)) * 3600);

Expand Down Expand Up @@ -344,8 +346,7 @@ public String getAttribute(Attribute attribute) {

// <--
// <d@duration.value> -> Element
// returns the value of the duration, in the best format
// possible.
// returns the value of the duration, in the best format possible.
// -->
if (attribute.startsWith("value")) {
if (seconds % 43200 == 0)
Expand Down
46 changes: 21 additions & 25 deletions src/main/java/net/aufdemrand/denizen/objects/dColor.java
Expand Up @@ -13,7 +13,7 @@
public class dColor implements dObject {

final static Pattern rgbPattern = Pattern.compile("(\\d+)[,:](\\d+)[,:](\\d+)");

//////////////////
// OBJECT FETCHER
////////////////
Expand All @@ -27,19 +27,23 @@ public class dColor implements dObject {
*/
@ObjectFetcher("co")
public static dColor valueOf(String string) {

if (string.toUpperCase().matches("RANDOM")) {

string = string.toUpperCase().replace("CO@", "");

if (string.matches("RANDOM")) {

// Get a color using random RGB values
return new dColor(Utilities.getRandom().nextInt(256), Utilities.getRandom().nextInt(256), Utilities.getRandom().nextInt(256));
return new dColor(Utilities.getRandom().nextInt(256),
Utilities.getRandom().nextInt(256),
Utilities.getRandom().nextInt(256));
}

Matcher m = rgbPattern.matcher(string);
if (m.matches()) {

return new dColor(aH.getIntegerFrom(m.group(1)), aH.getIntegerFrom(m.group(2)), aH.getIntegerFrom(m.group(3)));
}

if (m.matches())
return new dColor(aH.getIntegerFrom(m.group(1)),
aH.getIntegerFrom(m.group(2)),
aH.getIntegerFrom(m.group(3)));

Field colorField = null;

Expand All @@ -51,19 +55,17 @@ public static dColor valueOf(String string) {
dB.echoError("No such color field!");
}

if (colorField != null) {

if (colorField != null)
return new dColor(colorField);
}


// No match
return null;
}

/**
* Determine whether a string is a valid color.
* Determines whether a string is a valid color.
*
* @param string the string
* @param arg the string
* @return true if matched, otherwise false
*
*/
Expand All @@ -77,16 +79,10 @@ public static boolean matches(String arg) {
if (m.matches())
return true;

for (Field field : Color.class.getFields()) {

if (arg.toUpperCase().matches(field.getName())) {

return true;
}
}
for (Field field : Color.class.getFields())
if (arg.toUpperCase().matches(field.getName())) return true;

return false;

}


Expand Down Expand Up @@ -149,7 +145,7 @@ public String getType() {

@Override
public String identify() {
return "c@" + getColor().getRed() + "," + getColor().getGreen() + "," + getColor().getBlue();
return "co@" + getColor().getRed() + "," + getColor().getGreen() + "," + getColor().getBlue();
}

@Override
Expand Down
@@ -1,14 +1,9 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.aufdemrand.denizen.scripts.commands.entity;

import java.util.List;
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.npc.traits.NameplateTrait;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.aH;
Expand Down

0 comments on commit 924a3b5

Please sign in to comment.