Finish adding the jailrecord command, this closes #12.
This commit is contained in:
parent
9f9ede433a
commit
2ec69c5650
@ -10,6 +10,7 @@ Beta 1 Changes
|
|||||||
- MySQL storage is now a valid option for storage ([#18](https://github.com/graywolf336/Jail/issues/18))
|
- MySQL storage is now a valid option for storage ([#18](https://github.com/graywolf336/Jail/issues/18))
|
||||||
- MySQL data validation, basically if a cell or prisoner reference a jail which no longer exists they are removed
|
- MySQL data validation, basically if a cell or prisoner reference a jail which no longer exists they are removed
|
||||||
- Fix a bug with not being able to unjail someone forcefully if they were in a cell ([#17](https://github.com/graywolf336/Jail/issues/17))
|
- Fix a bug with not being able to unjail someone forcefully if they were in a cell ([#17](https://github.com/graywolf336/Jail/issues/17))
|
||||||
|
- Add the record keeping system ([#12](https://github.com/graywolf336/Jail/issues/12))
|
||||||
|
|
||||||
Changes
|
Changes
|
||||||
===
|
===
|
||||||
@ -21,7 +22,6 @@ Changes
|
|||||||
|
|
||||||
ToDo
|
ToDo
|
||||||
===
|
===
|
||||||
- Prisoner profiles
|
|
||||||
- Guards
|
- Guards
|
||||||
|
|
||||||
Done
|
Done
|
||||||
|
@ -9,6 +9,7 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -33,7 +34,7 @@ import com.graywolf336.jail.enums.LangString;
|
|||||||
*/
|
*/
|
||||||
public class JailIO {
|
public class JailIO {
|
||||||
private JailMain pl;
|
private JailMain pl;
|
||||||
private FileConfiguration flat, lang;
|
private FileConfiguration flat, lang, records;
|
||||||
private Connection con;
|
private Connection con;
|
||||||
private int storage; //0 = flatfile, 1 = sqlite, 2 = mysql
|
private int storage; //0 = flatfile, 1 = sqlite, 2 = mysql
|
||||||
private String prefix;
|
private String prefix;
|
||||||
@ -169,6 +170,7 @@ public class JailIO {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
flat = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "data.yml"));
|
flat = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "data.yml"));
|
||||||
|
records = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "records.yml"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,15 +305,15 @@ public class JailIO {
|
|||||||
//pl.debug(prisCreateCmd);
|
//pl.debug(prisCreateCmd);
|
||||||
st.executeUpdate(prisCreateCmd);
|
st.executeUpdate(prisCreateCmd);
|
||||||
|
|
||||||
String proCreateCmd = "CREATE TABLE IF NOT EXISTS `" + prefix + "profiles` ("
|
String proCreateCmd = "CREATE TABLE IF NOT EXISTS `" + prefix + "records` ("
|
||||||
+ "`profileid` INT NOT NULL AUTO_INCREMENT COMMENT 'Auto generated number for the profiles database.',"
|
+ "`recordid` INT NOT NULL AUTO_INCREMENT COMMENT 'Auto generated number for the records database.',"
|
||||||
+ "`username` VARCHAR(16) NOT NULL COMMENT 'The username of the prisoner.',"
|
+ "`username` VARCHAR(16) NOT NULL COMMENT 'The username of the prisoner.',"
|
||||||
+ "`jailer` VARCHAR(250) NOT NULL COMMENT 'The name of the person who jailed the prisoner.',"
|
+ "`jailer` VARCHAR(250) NOT NULL COMMENT 'The name of the person who jailed the prisoner.',"
|
||||||
+ "`date` VARCHAR(32) NOT NULL COMMENT 'A string of the date.',"
|
+ "`date` VARCHAR(32) NOT NULL COMMENT 'A string of the date.',"
|
||||||
+ "`time` INT NOT NULL COMMENT 'The milliseconds they were jailed for.',"
|
+ "`time` INT NOT NULL COMMENT 'The milliseconds they were jailed for.',"
|
||||||
+ "`reason` VARCHAR(250) NOT NULL COMMENT 'The reason they were jailed for.',"
|
+ "`reason` VARCHAR(250) NOT NULL COMMENT 'The reason they were jailed for.',"
|
||||||
+ "PRIMARY KEY (`profileid`),"
|
+ "PRIMARY KEY (`recordid`),"
|
||||||
+ "UNIQUE INDEX `profileid_UNIQUE` (`profileid` ASC))"
|
+ "UNIQUE INDEX `recordid_UNIQUE` (`recordid` ASC))"
|
||||||
+ "COMMENT = 'Holds a history of all the times prisoners have been jailed.'";
|
+ "COMMENT = 'Holds a history of all the times prisoners have been jailed.'";
|
||||||
|
|
||||||
//pl.debug(proCreateCmd);
|
//pl.debug(proCreateCmd);
|
||||||
@ -1073,13 +1075,13 @@ public class JailIO {
|
|||||||
* @param time of the player's sentence
|
* @param time of the player's sentence
|
||||||
* @param reason the player is jailed
|
* @param reason the player is jailed
|
||||||
*/
|
*/
|
||||||
public void addProfileEntry(String username, String jailer, String date, long time, String reason) {
|
public void addRecordEntry(String username, String jailer, String date, long time, String reason) {
|
||||||
switch(storage) {
|
switch(storage) {
|
||||||
case 1:
|
case 1:
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
try {
|
try {
|
||||||
PreparedStatement p = con.prepareStatement("insert into `" + prefix + "profiles` (`username`, `jailer`, `date`, `time`, `reason`) VALUES (?,?,?,?,?);");
|
PreparedStatement p = con.prepareStatement("insert into `" + prefix + "records` (`username`, `jailer`, `date`, `time`, `reason`) VALUES (?,?,?,?,?);");
|
||||||
p.setString(1, username);
|
p.setString(1, username);
|
||||||
p.setString(2, jailer);
|
p.setString(2, jailer);
|
||||||
p.setString(3, date);
|
p.setString(3, date);
|
||||||
@ -1091,11 +1093,66 @@ public class JailIO {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||||
pl.getLogger().severe("Error while adding a profile entry for '" + username + "', please check the error and fix what is wrong.");
|
pl.getLogger().severe("Error while adding a record entry for '" + username + "', please check the error and fix what is wrong.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if(records == null) records = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "records.yml"));
|
||||||
|
|
||||||
|
List<String> previous = records.getStringList("username");
|
||||||
|
previous.add(this.getLanguageString(LangString.RECORDENTRY, new String[] { date, username, jailer, String.valueOf(time), reason }));
|
||||||
|
|
||||||
|
records.set(username, previous);
|
||||||
|
|
||||||
|
try {
|
||||||
|
records.save(new File(pl.getDataFolder(), "records.yml"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||||
|
pl.getLogger().severe("Saving the records.yml file failed while putting an entry in for '" + username + "'.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all the record entries for the given player.
|
||||||
|
*
|
||||||
|
* @param username of the prisoner to get.
|
||||||
|
* @return A List of strings containing the record entries.
|
||||||
|
*/
|
||||||
|
public List<String> getRecordEntries(String username) {
|
||||||
|
List<String> entries = new ArrayList<String>();
|
||||||
|
|
||||||
|
switch(storage) {
|
||||||
|
case 1:
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
try {
|
||||||
|
PreparedStatement ps = con.prepareStatement("SELECT * FROM " + prefix + "records where username = ?");
|
||||||
|
ps.setString(1, username);
|
||||||
|
ResultSet set = ps.executeQuery();
|
||||||
|
|
||||||
|
while(set.next()) {
|
||||||
|
entries.add(this.getLanguageString(LangString.RECORDENTRY,
|
||||||
|
new String[] { set.getString("date"), username, set.getString("jailer"), String.valueOf(set.getLong("time")), set.getString("reason") }));
|
||||||
|
}
|
||||||
|
|
||||||
|
set.close();
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||||
|
pl.getLogger().severe("Error while getting all the record entries for '" + username + "', please check the error and fix what is wrong.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if(records == null) records = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "records.yml"));
|
||||||
|
|
||||||
|
entries = records.getStringList(username);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import com.graywolf336.jail.command.subcommands.JailDeleteCommand;
|
|||||||
import com.graywolf336.jail.command.subcommands.JailListCellsCommand;
|
import com.graywolf336.jail.command.subcommands.JailListCellsCommand;
|
||||||
import com.graywolf336.jail.command.subcommands.JailListCommand;
|
import com.graywolf336.jail.command.subcommands.JailListCommand;
|
||||||
import com.graywolf336.jail.command.subcommands.JailMuteCommand;
|
import com.graywolf336.jail.command.subcommands.JailMuteCommand;
|
||||||
|
import com.graywolf336.jail.command.subcommands.JailRecordCommand;
|
||||||
import com.graywolf336.jail.command.subcommands.JailReloadCommand;
|
import com.graywolf336.jail.command.subcommands.JailReloadCommand;
|
||||||
import com.graywolf336.jail.command.subcommands.JailStatusCommand;
|
import com.graywolf336.jail.command.subcommands.JailStatusCommand;
|
||||||
import com.graywolf336.jail.command.subcommands.JailStopCommand;
|
import com.graywolf336.jail.command.subcommands.JailStopCommand;
|
||||||
@ -181,6 +182,7 @@ public class JailHandler {
|
|||||||
load(JailListCellsCommand.class);
|
load(JailListCellsCommand.class);
|
||||||
load(JailListCommand.class);
|
load(JailListCommand.class);
|
||||||
load(JailMuteCommand.class);
|
load(JailMuteCommand.class);
|
||||||
|
load(JailRecordCommand.class);
|
||||||
load(JailReloadCommand.class);
|
load(JailReloadCommand.class);
|
||||||
load(JailStatusCommand.class);
|
load(JailStatusCommand.class);
|
||||||
load(JailStopCommand.class);
|
load(JailStopCommand.class);
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.graywolf336.jail.command.subcommands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.JailManager;
|
||||||
|
import com.graywolf336.jail.command.Command;
|
||||||
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
|
import com.graywolf336.jail.enums.LangString;
|
||||||
|
|
||||||
|
@CommandInfo(
|
||||||
|
maxArgs = 2,
|
||||||
|
minimumArgs = 1,
|
||||||
|
needsPlayer = false,
|
||||||
|
pattern = "reload|r",
|
||||||
|
permission = "jail.command.jailrecord",
|
||||||
|
usage = "/jail record"
|
||||||
|
)
|
||||||
|
public class JailRecordCommand implements Command {
|
||||||
|
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||||
|
if(args.length == 2) {
|
||||||
|
// /jail record <username>
|
||||||
|
List<String> entries = jm.getPlugin().getJailIO().getRecordEntries(args[1]);
|
||||||
|
|
||||||
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.RECORDTIMESJAILED, new String[] { args[1], String.valueOf(entries.size()) }));
|
||||||
|
}else if(args.length == 3) {
|
||||||
|
// /jail record <username> something
|
||||||
|
List<String> entries = jm.getPlugin().getJailIO().getRecordEntries(args[1]);
|
||||||
|
|
||||||
|
//Send all the record entries
|
||||||
|
for(String s : entries) {
|
||||||
|
sender.sendMessage(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.RECORDTIMESJAILED, new String[] { args[1], String.valueOf(entries.size()) }));
|
||||||
|
}else {
|
||||||
|
//They didn't do the command right
|
||||||
|
//send them back to get the usage
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -144,6 +144,12 @@ public enum LangString {
|
|||||||
PLUGINRELOADED ("general"),
|
PLUGINRELOADED ("general"),
|
||||||
/** The message sent whenever the prisoners are cleared from jail(s). */
|
/** The message sent whenever the prisoners are cleared from jail(s). */
|
||||||
PRISONERSCLEARED ("general"),
|
PRISONERSCLEARED ("general"),
|
||||||
|
/** The format we should use when entering a record into flatfile or showing it. */
|
||||||
|
RECORDENTRY ("general"),
|
||||||
|
/** The message format sent saying how many times a user has been jailed.*/
|
||||||
|
RECORDTIMESJAILED ("general"),
|
||||||
|
/** The format of the time entry we should use for the record entries. */
|
||||||
|
TIMEFORMAT ("general"),
|
||||||
/** The simple word transferring to be put in other parts. */
|
/** The simple word transferring to be put in other parts. */
|
||||||
TRANSFERRING ("general"),
|
TRANSFERRING ("general"),
|
||||||
/** The message sent whenever someone does a command we don't know. */
|
/** The message sent whenever someone does a command we don't know. */
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import com.graywolf336.jail.JailMain;
|
import com.graywolf336.jail.JailMain;
|
||||||
|
import com.graywolf336.jail.enums.LangString;
|
||||||
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
|
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
|
||||||
|
|
||||||
public class JailingListener implements Listener {
|
public class JailingListener implements Listener {
|
||||||
@ -16,13 +17,13 @@ public class JailingListener implements Listener {
|
|||||||
|
|
||||||
public JailingListener(JailMain plugin) {
|
public JailingListener(JailMain plugin) {
|
||||||
this.pl = plugin;
|
this.pl = plugin;
|
||||||
this.dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
this.dateFormat = new SimpleDateFormat(pl.getJailIO().getLanguageString(LangString.TIMEFORMAT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled=true)
|
@EventHandler(ignoreCancelled=true)
|
||||||
public void preJailingListener(PrePrisonerJailedEvent event) {
|
public void preJailingListener(PrePrisonerJailedEvent event) {
|
||||||
pl.getJailIO().addProfileEntry(event.getPrisoner().getName(),
|
pl.getJailIO().addRecordEntry(event.getPrisoner().getName(),
|
||||||
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
|
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
|
||||||
event.getPrisoner().getRemainingTime(), event.getPrisoner().getReason());
|
event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,9 @@ language:
|
|||||||
playernotonline: '&cThat player is not online!'
|
playernotonline: '&cThat player is not online!'
|
||||||
pluginreloaded: '&9Jail data successfully reloaded.'
|
pluginreloaded: '&9Jail data successfully reloaded.'
|
||||||
prisonerscleared: '&cAll the prisoners from %0% have been cleared.'
|
prisonerscleared: '&cAll the prisoners from %0% have been cleared.'
|
||||||
|
recordentry: '&7[%0%]: &9%1% &fjailed by &9%2% &ffor &9%3% &fminutes with a reason of &9%4%&f.'
|
||||||
|
recordtimesjailed: '&c%0% has been jailed &a%1% &ctimes.'
|
||||||
|
timeformat: "MM/dd/yyyy HH:mm:ss"
|
||||||
transferring: '&9transferring'
|
transferring: '&9transferring'
|
||||||
unknowncommand: '&cNo commands registered by the name of %0%.'
|
unknowncommand: '&cNo commands registered by the name of %0%.'
|
||||||
jailing:
|
jailing:
|
||||||
|
Loading…
Reference in New Issue
Block a user