Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for utf-8 logging chat. #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<id>addstar-repo</id>
<url>http://maven.addstar.com.au/artifactory/ext-release-local</url>
</repository>
<repository>
<id>dynmap-repo</id>
<url>http://repo.mikeprimm.com/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -40,7 +44,13 @@
<artifactId>bukkit</artifactId>
<version>1.7.2-R0.1-SNAPSHOT</version>
</dependency>


<dependency>
<groupId>org.dynmap</groupId>
<artifactId>dynmap-api</artifactId>
<version>1.9</version>
</dependency>

<!-- CraftBukkit Dependency for experimental features
<dependency>
<groupId>org.bukkit</groupId>
Expand Down
11 changes: 11 additions & 0 deletions src/me/mcluke300/playerlogger/listeners/PListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.inventory.ItemStack;
import org.dynmap.DynmapWebChatEvent;

public class PListener implements Listener {
playerlogger plugin;
Expand Down Expand Up @@ -71,6 +72,16 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) {
}
}

// Player Web Chat
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerWebChat(final DynmapWebChatEvent event) {
if (getConfig.PlayerChat()) {
String msg = event.getMessage();
String playername = event.getName();
datadb.textadd(playername, "webchat", msg, null);
}
}

// Player Command
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerCmd(final PlayerCommandPreprocessEvent event) {
Expand Down
34 changes: 33 additions & 1 deletion src/me/mcluke300/playerlogger/mysql/addData.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean ConnectDB() {

// Attempt to make a connection
try {
con = DriverManager.getConnection("jdbc:mysql://" + getConfig.MySQLServer() + "/" + getConfig.MySQLDatabase(), getConfig.MySQLUser(), getConfig.MySQLPassword());
con = DriverManager.getConnection("jdbc:mysql://" + getConfig.MySQLServer() + "/" + getConfig.MySQLDatabase() + "?useUnicode=yes&characterEncoding=UTF-8", getConfig.MySQLUser(), getConfig.MySQLPassword());
con.setAutoCommit(false);
} catch (SQLException e) {
plugin.Log("ERROR: Unable to connect to database!");
Expand Down Expand Up @@ -113,6 +113,38 @@ public void add(Player player, String type, String data, World world) {
}
}

public void textadd(String player, String type, String data, String world) {
if (con == null) return;

int x = 0, y = 0, z = 0;

DataRec rec = new DataRec();

rec.playername = player;
if (world != null) {
rec.worldname = world;
} else {
rec.worldname = "";
}
rec.type = type;
rec.data = data;
rec.x = x;
rec.y = y;
rec.z = z;

// Add record to list
int count = 0;
synchronized (Records) {
Records.add(rec);
count = Records.size();
}

if (count > 50) {
plugin.DebugLog("Queue limit reached, forcing save.");
writeBuffer();
}
}

public void startWriterTask() {
Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
@Override
Expand Down