Skip to content

Commit

Permalink
Added custom command option for trap breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
CeramicTitan committed Aug 30, 2014
1 parent f25e920 commit d118e56
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions co/proxa/founddiamonds/file/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Config {
public final static String kickOnTrapBreak = "Found Diamonds Configuration.Traps.Kick players on trap break";
public final static String kickMessage = "Found Diamonds Configuration.Traps.Kick message";
public final static String banOnTrapBreak = "Found Diamonds Configuration.Traps.Ban players on trap break";
public final static String commandOnTrapBreak = "Found Diamonds Configuration.Traps.Execute command on trap break";
public final static String ExecutecommandOnTrapBreak = "Found Diamonds Configuration.Traps.Command on trap break";

/*Awards.Items*/
public final static String awardAllItems = "Found Diamonds Configuration.Awards.Items.Award all players";
Expand Down
11 changes: 7 additions & 4 deletions co/proxa/founddiamonds/handlers/LoggingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LoggingHandler(FoundDiamonds fd) {
this.fd = fd;
}

public void handleLogging(Player player, Block block, boolean trapBlock, boolean kicked, boolean banned) {
public void handleLogging(Player player, Block block, boolean trapBlock, boolean kicked, boolean banned, boolean command) {
try {
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(fd.getFileHandler().getLogFile(), true)));
pw.print("[" + getFormattedDate() + "]");
Expand All @@ -36,12 +36,15 @@ public void handleLogging(Player player, Block block, boolean trapBlock, boolean
+ ") in " + player.getWorld().getName());
if (trapBlock) {
pw.print("[" + getFormattedDate() + "]" + " [ACTION TAKEN] ");
if (kicked && !banned) {
if (kicked && !banned && !command) {
pw.println(player.getName() + " was kicked from the sever per the configuration.");
} else if (banned && !kicked) {
} else if (banned && !kicked && !command) {
pw.println(player.getName() + " was banned from the sever per the configuration.");
} else if (banned && kicked) {
}else if(!banned && !kicked && command){
pw.println("Command was executed for "+player.getName()+" per the configuration");
} else if (banned && kicked && command) {
pw.println(player.getName() + " was kicked and banned from the sever per the configuration.");
pw.println("Command was executed for "+player.getName()+" per the configuration");
} else {
pw.println(player.getName() + " was neither kicked nor banned per the configuration.");
}
Expand Down
9 changes: 8 additions & 1 deletion co/proxa/founddiamonds/handlers/TrapHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.proxa.founddiamonds.handlers;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -212,6 +213,7 @@ public void handleTrapBlockBreak(BlockBreakEvent event) {
fd.getServer().getConsoleSender().sendMessage(Prefix.getLoggingPrefix() + trapMessage);
boolean banned = false;
boolean kicked = false;
boolean command = false;
if (fd.getConfig().getBoolean(Config.kickOnTrapBreak)) {
String kickMessage = fd.getConfig().getString(Config.kickMessage);
player.kickPlayer(kickMessage);
Expand All @@ -221,8 +223,13 @@ public void handleTrapBlockBreak(BlockBreakEvent event) {
player.setBanned(true);
banned = true;
}
if(fd.getConfig().getBoolean(Config.ExecutecommandOnTrapBreak)){
String commandString = fd.getConfig().getString(Config.commandOnTrapBreak).replaceAll("//@player@",player.getName());
Bukkit.getServer().dispatchCommand(player, commandString);
command = true;
}
if (fd.getConfig().getBoolean(Config.logTrapBreaks)) {
fd.getLoggingHandler().handleLogging(player, block, true, kicked, banned);
fd.getLoggingHandler().handleLogging(player, block, true, kicked, banned, command);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions co/proxa/founddiamonds/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Found Diamonds Configuration:
Traps:
Kick players on trap break: true
Ban players on trap break: false
Execute command on trap break: false
Kick message: "You triggered an X-RAY trap block"
Command on trap break: "jail @Player@ X-Ray Hacking!"
Awards:
Items:
Random items for finding diamonds: false
Expand Down

0 comments on commit d118e56

Please sign in to comment.