Created
September 17, 2011 16:17
-
-
Save ericpauley/1224091 to your computer and use it in GitHub Desktop.
Ebean stuff
This file contains hidden or 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
package zonedabone.battlelog; | |
import java.util.ArrayList; | |
import java.util.List; | |
import javax.persistence.PersistenceException; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import org.bukkit.plugin.Plugin; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import zonedabone.battlelog.runners.BaseRunner; | |
import com.nijiko.permissions.PermissionHandler; | |
import com.nijikokun.bukkit.Permissions.Permissions; | |
public class BattleLog extends JavaPlugin { | |
//public Logger logger = this.getServer().getLogger(); | |
public static PermissionHandler permissionHandler; | |
public static BattleLog plugin; | |
@Override | |
public void onDisable() { | |
this.getDatabase().endTransaction(); | |
} | |
@Override | |
public void onEnable() { | |
System.out.println("BattleLog enabling..."); | |
plugin = this; | |
setupDatabase(); | |
setupPermissions(); | |
this.getCommand("bl").setExecutor(new BaseRunner()); | |
System.out.println("BattleLog enabled."); | |
} | |
@Override | |
public List<Class<?>> getDatabaseClasses() { | |
List<Class<?>> list = new ArrayList<Class<?>>(); | |
list.add(LogRecord.class); | |
return list; | |
} | |
private void setupDatabase() { | |
try { | |
getDatabase().find(LogRecord.class).findRowCount(); | |
} catch (PersistenceException ex) { | |
System.out.println("Installing database for " + getDescription().getName() + " due to first time usage"); | |
installDDL(); | |
} | |
} | |
public static boolean has(CommandSender sender, String perm){ | |
if(sender instanceof Player){ | |
return permissionHandler.has((Player)sender, perm); | |
}else{ | |
return true; | |
} | |
} | |
private void setupPermissions() { | |
if (permissionHandler != null) { | |
return; | |
} | |
Plugin permissionsPlugin = this.getServer().getPluginManager() | |
.getPlugin("Permissions"); | |
if (permissionsPlugin == null) { | |
System.out.println("Permission system not detected, defaulting to OP"); | |
return; | |
} | |
permissionHandler = ((Permissions) permissionsPlugin).getHandler(); | |
System.out.println("Found and will use plugin " | |
+ ((Permissions) permissionsPlugin).getDescription() | |
.getFullName()); | |
} | |
} |
This file contains hidden or 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
package zonedabone.battlelog.runners; | |
import org.bukkit.command.CommandSender; | |
import zonedabone.battlelog.BattleLog; | |
import zonedabone.battlelog.LogRecord; | |
import com.iConomy.iConomy; | |
import com.iConomy.system.Account; | |
public class Custom { | |
public static void custom(CommandSender sender, String[] args){ | |
if(!iConomy.hasAccount(args[1])){ | |
sender.sendMessage("That player doesn't exist!"); | |
return; | |
} | |
Account acc = iConomy.getAccount(args[1]); | |
String msg = args[2]; | |
for(int i = 3;i<args.length;i++){ | |
msg = msg+" "+args[i]; | |
} | |
LogRecord lr = new LogRecord(); | |
lr.setData(acc.getName(), LogRecord.LogType.CUSTOM, msg); | |
lr.setSubmitter(sender); | |
BattleLog.plugin.getDatabase().save(lr); | |
sender.sendMessage("Log record added!"); | |
return; | |
} | |
} |
This file contains hidden or 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
package zonedabone.battlelog; | |
import java.util.Date; | |
import javax.persistence.Entity; | |
import javax.persistence.Id; | |
import javax.persistence.Table; | |
import org.bukkit.ChatColor; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import com.avaje.ebean.annotation.EnumValue; | |
import com.avaje.ebean.validation.NotNull; | |
@Entity | |
@Table(name="bl_records") | |
public class LogRecord { | |
@Id | |
private int id; | |
@NotNull | |
private Date recordDate; | |
@NotNull | |
private String player = ""; | |
@NotNull | |
private LogType type = LogType.CUSTOM; | |
@NotNull() | |
private String stringArg = ""; | |
@NotNull() | |
private int intArg = 0; | |
@NotNull() | |
private String reason = ""; | |
@NotNull() | |
private String submitter; | |
public LogRecord(){ | |
this.recordDate = new Date(); | |
} | |
public void setData(String player, LogType type, String reason, String stringArg, int intArg){ | |
this.setPlayer(player); | |
this.setType(type); | |
this.setReason(reason); | |
this.setStringArg(stringArg); | |
this.setIntArg(intArg); | |
} | |
public void setData(String player, LogType type, String reason, String stringArg){ | |
setData(player,type,reason,stringArg,0); | |
} | |
public void setData(String player, LogType type, String reason, int intArg){ | |
setData(player,type,reason,"",intArg); | |
} | |
public void setData(String player, LogType type, String reason){ | |
setData(player,type,reason,"",0); | |
} | |
//Getters and setters | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getPlayer() { | |
return player; | |
} | |
public void setPlayer(String player) { | |
this.player = player; | |
} | |
public String getStringArg() { | |
return stringArg; | |
} | |
public void setStringArg(String stringArg) { | |
this.stringArg = stringArg; | |
} | |
public int getIntArg() { | |
return intArg; | |
} | |
public void setIntArg(int intArg) { | |
this.intArg = intArg; | |
} | |
public LogType getType() { | |
return type; | |
} | |
public void setType(LogType type) { | |
this.type = type; | |
} | |
public String getSubmitter() { | |
return submitter; | |
} | |
public void setSubmitter(String submitter) { | |
this.submitter = submitter; | |
} | |
public void setSubmitter(CommandSender sender){ | |
if(sender instanceof Player){ | |
String name = ((Player)sender).getName(); | |
if(name.length()>4){ | |
name = name.substring(0, 4); | |
} | |
setSubmitter(name); | |
}else{ | |
setSubmitter("Cons"); | |
} | |
} | |
public String getReason() { | |
return reason; | |
} | |
public void setReason(String reason) { | |
this.reason = reason; | |
} | |
public Date getRecordDate() { | |
return recordDate; | |
} | |
public void setRecordDate(Date recordDate) { | |
this.recordDate = recordDate; | |
} | |
@SuppressWarnings("deprecation") | |
public String getFormat(){ | |
String date = recordDate.toLocaleString(); | |
String prefix = type.color+"["+date+"-"+type.name+"-"+submitter+"]"+ChatColor.WHITE; | |
String body = ""; | |
switch (type){ | |
case STRIKE: body = player+" recieved "+intArg+" strikes."+"("+reason+")"; break; | |
} | |
return prefix+body; | |
} | |
public enum LogType{ | |
@EnumValue("STRIKE") | |
STRIKE("Strike",ChatColor.RED), | |
@EnumValue("UNSTRIKE") | |
UNSTRIKE("Remove Strike",ChatColor.GREEN), | |
@EnumValue("BAN") | |
BAN("Ban",ChatColor.GOLD), | |
@EnumValue("UNBAN") | |
UNBAN("Unban",ChatColor.GOLD), | |
@EnumValue("SHOPADD") | |
SHOPADD("Add Shop",ChatColor.LIGHT_PURPLE), | |
@EnumValue("SHOPREMOVE") | |
SHOPREMOVE("Remove Shop",ChatColor.LIGHT_PURPLE), | |
@EnumValue("VIPBENEFIT") | |
VIPBENEFIT("VIP Benefit",ChatColor.BLUE), | |
@EnumValue("CUSTOM") | |
CUSTOM("Custom",ChatColor.GRAY); | |
public String name; | |
public ChatColor color; | |
LogType(String str,ChatColor color){ | |
name = str; | |
this.color = color; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment