Started work on profiling when prisoners get jailed #12.
This only works for the sql right now, next commit will handle flatfile.
This commit is contained in:
parent
ac6a5b23cb
commit
5f6807fc24
@ -1059,4 +1059,39 @@ public class JailIO {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an entry to the database/file for the user, logging when they was jailed.
|
||||
*
|
||||
* @param username of the player
|
||||
* @param jailer who jailed them
|
||||
* @param date string of when they are jailed
|
||||
* @param time of the player's sentence
|
||||
* @param reason the player is jailed
|
||||
*/
|
||||
public void addProfileEntry(String username, String jailer, String date, long time, String reason) {
|
||||
switch(storage) {
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
try {
|
||||
PreparedStatement p = con.prepareStatement("insert into `" + prefix + "profiles` (`username`, `jailer`, `date`, `time`, `reason`) VALUES (?,?,?,?,?);");
|
||||
p.setString(1, username);
|
||||
p.setString(2, jailer);
|
||||
p.setString(3, date);
|
||||
p.setLong(4, time);
|
||||
p.setString(5, reason);
|
||||
|
||||
p.executeUpdate();
|
||||
p.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
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.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.listeners.BlockListener;
|
||||
import com.graywolf336.jail.listeners.EntityListener;
|
||||
import com.graywolf336.jail.listeners.HandCuffListener;
|
||||
import com.graywolf336.jail.listeners.JailingListener;
|
||||
import com.graywolf336.jail.listeners.MoveProtectionListener;
|
||||
import com.graywolf336.jail.listeners.PlayerListener;
|
||||
import com.graywolf336.jail.listeners.ProtectionListener;
|
||||
@ -61,6 +62,7 @@ public class JailMain extends JavaPlugin {
|
||||
plm.registerEvents(new BlockListener(this), this);
|
||||
plm.registerEvents(new EntityListener(this), this);
|
||||
plm.registerEvents(new HandCuffListener(this), this);
|
||||
plm.registerEvents(new JailingListener(this), this);
|
||||
plm.registerEvents(new PlayerListener(this), this);
|
||||
plm.registerEvents(new ProtectionListener(this), this);
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
|
||||
|
||||
public class JailingListener implements Listener {
|
||||
private JailMain pl;
|
||||
private DateFormat dateFormat;
|
||||
|
||||
public JailingListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void preJailingListener(PrePrisonerJailedEvent event) {
|
||||
pl.getJailIO().addProfileEntry(event.getPrisoner().getName(),
|
||||
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
|
||||
event.getPrisoner().getRemainingTime(), event.getPrisoner().getReason());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user