mirror of
https://github.com/shansen/EggCatcher.git
synced 2024-11-28 21:15:44 +01:00
Add optional logging for captures (#11)
* Add optional logging for captures * Add file logging for captures.
This commit is contained in:
parent
19b269d425
commit
e3268ef46c
45
src/main/java/me/shansen/EggCatcher/EggCatcherLogger.java
Normal file
45
src/main/java/me/shansen/EggCatcher/EggCatcherLogger.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package me.shansen.EggCatcher;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
//Created 11/11/2016 2:21 AM
|
||||||
|
public class EggCatcherLogger{
|
||||||
|
private final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||||
|
private File file;
|
||||||
|
|
||||||
|
public EggCatcherLogger(File file){
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logToFile(String message){
|
||||||
|
if (!file.exists()){
|
||||||
|
try{
|
||||||
|
file.createNewFile();
|
||||||
|
}catch(IOException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PrintWriter pw = null;
|
||||||
|
try{
|
||||||
|
pw = new PrintWriter(new FileWriter(file, true));
|
||||||
|
}catch(IOException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
pw.println(dateFormat.format(System.currentTimeMillis()) + " " + message);
|
||||||
|
pw.flush();
|
||||||
|
pw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getFile(){
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFile(File file){
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
}
|
@ -19,10 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package me.shansen.EggCatcher.listeners;
|
package me.shansen.EggCatcher.listeners;
|
||||||
|
|
||||||
import me.shansen.EggCatcher.EggCatcher;
|
import me.shansen.EggCatcher.EggCatcher;
|
||||||
|
import me.shansen.EggCatcher.EggCatcherLogger;
|
||||||
import me.shansen.EggCatcher.EggType;
|
import me.shansen.EggCatcher.EggType;
|
||||||
import me.shansen.EggCatcher.events.EggCaptureEvent;
|
import me.shansen.EggCatcher.events.EggCaptureEvent;
|
||||||
|
|
||||||
import me.shansen.nbt.NbtReflection;
|
import me.shansen.nbt.NbtReflection;
|
||||||
|
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
@ -37,6 +39,8 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class EggCatcherEntityListener implements Listener {
|
public class EggCatcherEntityListener implements Listener {
|
||||||
|
|
||||||
private final boolean usePermissions;
|
private final boolean usePermissions;
|
||||||
@ -58,8 +62,12 @@ public class EggCatcherEntityListener implements Listener {
|
|||||||
private final boolean spawnChickenOnFail;
|
private final boolean spawnChickenOnFail;
|
||||||
private final boolean spawnChickenOnSuccess;
|
private final boolean spawnChickenOnSuccess;
|
||||||
private final boolean deleteVillagerInventoryOnCatch;
|
private final boolean deleteVillagerInventoryOnCatch;
|
||||||
|
private final boolean logCaptures;
|
||||||
FileConfiguration config;
|
FileConfiguration config;
|
||||||
JavaPlugin plugin;
|
JavaPlugin plugin;
|
||||||
|
private final File captureLogFile;
|
||||||
|
private final EggCatcherLogger captureLogger;
|
||||||
|
|
||||||
|
|
||||||
public EggCatcherEntityListener(JavaPlugin plugin) {
|
public EggCatcherEntityListener(JavaPlugin plugin) {
|
||||||
this.config = plugin.getConfig();
|
this.config = plugin.getConfig();
|
||||||
@ -83,7 +91,10 @@ public class EggCatcherEntityListener implements Listener {
|
|||||||
this.spawnChickenOnSuccess = this.config.getBoolean("SpawnChickenOnSuccess", false);
|
this.spawnChickenOnSuccess = this.config.getBoolean("SpawnChickenOnSuccess", false);
|
||||||
this.vaultTargetBankAccount = this.config.getString("VaultTargetBankAccount", "");
|
this.vaultTargetBankAccount = this.config.getString("VaultTargetBankAccount", "");
|
||||||
this.deleteVillagerInventoryOnCatch = this.config.getBoolean("DeleteVillagerInventoryOnCatch", false);
|
this.deleteVillagerInventoryOnCatch = this.config.getBoolean("DeleteVillagerInventoryOnCatch", false);
|
||||||
}
|
this.logCaptures = this.config.getBoolean("LogEggCaptures", false);
|
||||||
|
this.captureLogFile = new File(plugin.getDataFolder(), "captures.txt");
|
||||||
|
this.captureLogger = new EggCatcherLogger(captureLogFile);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onEntityHitByEgg(EntityDamageEvent event) {
|
public void onEntityHitByEgg(EntityDamageEvent event) {
|
||||||
@ -300,5 +311,9 @@ public class EggCatcherEntityListener implements Listener {
|
|||||||
EggCatcher.eggs.add(egg);
|
EggCatcher.eggs.add(egg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.logCaptures){
|
||||||
|
captureLogger.logToFile("Player " + ((Player) egg.getShooter()).getName() + " caught " + entity.getType() + " at X" + Math.round(entity.getLocation().getX()) + ",Y" + Math.round(entity.getLocation().getY()) + ",Z" + Math.round(entity.getLocation().getZ()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ SpawnChickenOnSuccess: false
|
|||||||
SpawnChickenOnFail: true
|
SpawnChickenOnFail: true
|
||||||
VaultTargetBankAccount: ""
|
VaultTargetBankAccount: ""
|
||||||
DeleteVillagerInventoryOnCatch: false
|
DeleteVillagerInventoryOnCatch: false
|
||||||
|
LogEggCaptures: false
|
||||||
CatchChance:
|
CatchChance:
|
||||||
Bat: 100.0
|
Bat: 100.0
|
||||||
Blaze: 100.0
|
Blaze: 100.0
|
||||||
|
Loading…
Reference in New Issue
Block a user