-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extended counter datatypes support (needs testing)
entity slain counter
- Loading branch information
1 parent
eaf553d
commit 29fb0cf
Showing
10 changed files
with
503 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 98 additions & 81 deletions
179
src/main/java/com/github/crashdemons/lorekillcounter/Counter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,98 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/ . | ||
*/ | ||
package com.github.crashdemons.lorekillcounter; | ||
|
||
import org.bukkit.ChatColor; | ||
|
||
/** | ||
* | ||
* @author crashdemons (crashenator at gmail.com) | ||
*/ | ||
public class Counter { | ||
private int count=0; | ||
private CounterType type=CounterType.INVALID; | ||
|
||
public String toStringFormatted(){ | ||
return ChatColor.GREEN+getName()+": "+ChatColor.RED+getCount(); | ||
} | ||
|
||
public String toString(){ | ||
return getName()+": "+getCount(); | ||
} | ||
|
||
public String getName(){ | ||
return type.getDisplayName(); | ||
} | ||
|
||
public int getCount() { | ||
return count; | ||
} | ||
|
||
public void setCount(int count) { | ||
this.count = count; | ||
} | ||
|
||
public CounterType getType() { | ||
return type; | ||
} | ||
|
||
public void setType(CounterType type) { | ||
this.type = type; | ||
} | ||
public boolean isValid(){ return type!=CounterType.INVALID; } | ||
|
||
public Counter(CounterType type){ | ||
this.type=type; | ||
} | ||
public Counter(CounterType type, int count){ | ||
this.type=type; | ||
this.count=count; | ||
} | ||
|
||
public void increment(){ | ||
this.count++; | ||
} | ||
|
||
public static Counter fromLoreLine(String line){ | ||
line = ChatColor.stripColor(line); | ||
String[] pieces = line.split(": "); | ||
//System.out.println(pieces.length); | ||
//System.out.println(pieces[0]); | ||
if(pieces.length!=2) return null;//not the right number of colons | ||
|
||
//parse the string to get the name/count | ||
String name = pieces[0]; | ||
String str_count = pieces[1]; | ||
int count; | ||
try{ | ||
count = Integer.parseInt(str_count); | ||
}catch(NumberFormatException e){ | ||
//System.out.println("Invalid integer value "+str_count); | ||
return null;//invalid count string - can't be a counter | ||
} | ||
|
||
CounterType type = CounterType.fromDisplayName(name);//match display name | ||
if(type==null) return null; | ||
return new Counter(type,count); | ||
} | ||
} | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/ . | ||
*/ | ||
package com.github.crashdemons.lorekillcounter; | ||
|
||
import java.text.MessageFormat; | ||
import org.bukkit.ChatColor; | ||
|
||
/** | ||
* | ||
* @author crashdemons (crashenator at gmail.com) | ||
*/ | ||
public class Counter { | ||
private int count=0; | ||
//private CounterType type=CounterType.INVALID; | ||
private final CounterType type; | ||
|
||
public String toStringFormatted(){ | ||
return ChatColor.GREEN+getName()+": "+ChatColor.RED+getCount(); | ||
} | ||
|
||
public String toString(){ | ||
return getName()+": "+getCount(); | ||
} | ||
|
||
public String getName(){ | ||
return type.getDisplayName(); | ||
} | ||
|
||
public int getCount() { | ||
return count; | ||
} | ||
|
||
public void setCount(int count) { | ||
this.count = count; | ||
} | ||
|
||
public CounterType getType() { | ||
return type; | ||
} | ||
|
||
// public void setType(CounterType type) { | ||
// this.type = type; | ||
// } | ||
public boolean isValid(){ return type.baseType!=CounterBaseType.INVALID; } | ||
|
||
|
||
public Counter(CounterBaseType type){ | ||
this.type = new CounterType(type); | ||
} | ||
public Counter(CounterBaseType type, int count){ | ||
this.type = new CounterType(type); | ||
this.count=count; | ||
} | ||
|
||
public Counter(CounterType type){ | ||
this.type = type; | ||
} | ||
public Counter(CounterType type, int count){ | ||
this.type = type; | ||
this.count=count; | ||
} | ||
/*public Counter(CounterType type, String extendedData, int count){ | ||
this.type = new ExtendedCounterType(type, extendedData); | ||
this.count=count; | ||
}*/ | ||
|
||
public void increment(){ | ||
this.count++; | ||
} | ||
|
||
public static Counter fromLoreLine(String line){ | ||
line = ChatColor.stripColor(line); | ||
String[] pieces = line.split(": "); | ||
//System.out.println(pieces.length); | ||
//System.out.println(pieces[0]); | ||
if(pieces.length!=2) return null;//not the right number of colons | ||
|
||
//parse the string to get the name/count | ||
String name = pieces[0]; | ||
String str_count = pieces[1]; | ||
int count; | ||
try{ | ||
count = Integer.parseInt(str_count); | ||
}catch(NumberFormatException e){ | ||
//System.out.println("Invalid integer value "+str_count); | ||
return null;//invalid count string - can't be a counter | ||
} | ||
|
||
EntitySlainCounterType slainCounter = EntitySlainCounterType.fromDisplayName(name); | ||
if(slainCounter!=null) return new Counter(slainCounter, count); | ||
CounterType counterType = CounterType.fromDisplayName(name); | ||
if(counterType!=null) return new Counter(counterType, count); | ||
return null; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/com/github/crashdemons/lorekillcounter/CounterBaseType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/ . | ||
*/ | ||
package com.github.crashdemons.lorekillcounter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import org.bukkit.Material; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.ArmorStand; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.entity.Player; | ||
|
||
/** | ||
* | ||
* @author crashdemons (crashenator at gmail.com) | ||
*/ | ||
public enum CounterBaseType { | ||
INVALID("Invalid Counter"), | ||
PLAYER_KILLS("Player Kills", "pk","players","pvp"), | ||
MOB_KILLS("Mob Kills", "mk","mobs","pve"), | ||
|
||
PLAYER_HEADS("Players Beheaded","pheads","ph"), | ||
MOB_HEADS("Mobs Beheaded","mheads","mh"), | ||
|
||
|
||
ORES_MINED("Ores Mined","ores","om"), | ||
|
||
ENTITIES_SLAIN(true, "{0}s Slain", "entities","es","ek"), | ||
|
||
; | ||
|
||
|
||
private final String displayName; | ||
private final boolean extended;//whether the counter type requires extended information (like entity type) to be functional | ||
|
||
private static class Lookups { | ||
static final HashMap<String, CounterBaseType> shortNames = new HashMap<>(); | ||
} | ||
|
||
CounterBaseType(boolean isExtendedType, String displayName, String... shortNames){ | ||
this.displayName=displayName; | ||
this.extended = isExtendedType; | ||
for(String shortName : shortNames){ | ||
Lookups.shortNames.put(shortName.toUpperCase(), this); | ||
} | ||
} | ||
|
||
CounterBaseType(String displayName, String... shortNames){ | ||
this.displayName=displayName; | ||
this.extended = false; | ||
for(String shortName : shortNames){ | ||
Lookups.shortNames.put(shortName.toUpperCase(), this); | ||
} | ||
} | ||
|
||
public boolean isExtended(){ | ||
return extended; | ||
} | ||
|
||
public String getDisplayName(){ | ||
if(displayName==null) return this.name(); | ||
return displayName; | ||
} | ||
|
||
public static CounterBaseType fromDisplayName(String name){ | ||
//determine the type of counter on the item | ||
for(CounterBaseType type : CounterBaseType.values()) //check all counters for a matching name | ||
if(type.getDisplayName().equals(name)) //the name of the counter matches this item | ||
return type; | ||
return null; | ||
} | ||
|
||
public static CounterBaseType fromShortName(String name){ | ||
CounterBaseType result = Lookups.shortNames.get(name.toUpperCase()); | ||
if(result!=null) return result; | ||
try{ | ||
return CounterBaseType.valueOf(name.toUpperCase()); | ||
}catch(Exception e){ | ||
return null; | ||
} | ||
} | ||
|
||
public CounterType createType(){ | ||
return new CounterType(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.