-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f3584c
commit afd4159
Showing
14 changed files
with
1,028 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/x_tornado10/chat/filters/CustomFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.x_tornado10.chat.filters; | ||
|
||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.Marker; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.Logger; | ||
import org.apache.logging.log4j.core.filter.AbstractFilter; | ||
import org.apache.logging.log4j.message.Message; | ||
|
||
//https://github.com/4drian3d/LogFilter/blob/main/common/src/main/java/me/adrianed/logfilter/common/filter/CustomFilter.java | ||
public abstract class CustomFilter extends AbstractFilter { | ||
protected CustomFilter() {} | ||
|
||
@Override | ||
public Result filter(final LogEvent event){ | ||
return event == null ? Result.NEUTRAL : logResult(event.getMessage().getFormattedMessage()); | ||
} | ||
|
||
@Override | ||
public Result filter(final Logger logger, final Level level, final Marker marker, final Message msg, | ||
final Throwable t) { | ||
Result result = t != null ? logResult(t.getMessage()) : Result.NEUTRAL; | ||
if (msg != null) { | ||
if (result == Result.DENY) return result; | ||
return logResult(msg.getFormattedMessage()); | ||
} | ||
return Result.NEUTRAL; | ||
} | ||
|
||
@Override | ||
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, | ||
final Object... params) { | ||
return logResult(msg); | ||
} | ||
|
||
@Override | ||
public Result filter(final Logger logger, final Level level, final Marker marker, final Object msg, | ||
final Throwable t) { | ||
Result result = t != null ? logResult(t.getMessage()) : Result.NEUTRAL; | ||
if (msg != null) { | ||
if(result == Result.DENY) return result; | ||
return logResult(msg.toString()); | ||
} | ||
return Result.NEUTRAL; | ||
} | ||
|
||
protected abstract Result logResult(String string); | ||
|
||
public abstract String getName(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.x_tornado10.chat.filters; | ||
|
||
|
||
import com.x_tornado10.craftiservi; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.core.Logger; | ||
|
||
import java.util.List; | ||
|
||
public final class MsgFilter extends CustomFilter { | ||
|
||
private final craftiservi plugin = craftiservi.getInstance(); | ||
private final List<String> blockedStrings = plugin.getBlockedStrings(); | ||
|
||
public void registerFilter() { | ||
Logger rootLogger = (Logger) LogManager.getRootLogger(); | ||
rootLogger.addFilter(this); | ||
} | ||
|
||
@Override | ||
protected Result logResult(String string) { | ||
|
||
for (String str : blockedStrings) { | ||
|
||
if (string.contains(str)) { | ||
|
||
return Result.DENY; | ||
} | ||
|
||
} | ||
|
||
return Result.NEUTRAL; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
src/main/java/com/x_tornado10/commands/open_gui_command/OpenGUICommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package com.x_tornado10.commands.open_gui_command; | ||
|
||
import com.x_tornado10.craftiservi; | ||
import com.x_tornado10.logger.Logger; | ||
import com.x_tornado10.messages.PlayerMessages; | ||
import org.bukkit.Material; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
public class OpenGUICommand implements CommandExecutor { | ||
|
||
private final craftiservi plugin = craftiservi.getInstance(); | ||
private final Logger logger = plugin.getCustomLogger(); | ||
private final PlayerMessages plmsg = plugin.getPlayerMessages(); | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
|
||
if (!(sender instanceof Player)) { | ||
|
||
logger.info("Only Players can run this command!"); | ||
|
||
return true; | ||
} | ||
|
||
Player p = (Player) sender; | ||
|
||
if (args.length == 1) { | ||
|
||
String args0 = args[0]; | ||
String[] parts = args0.split("_"); | ||
|
||
if (parts.length != 2) { | ||
|
||
sendUsage(p); | ||
return true; | ||
|
||
} | ||
|
||
String key = parts[0].trim(); | ||
String sid = parts[1].trim(); | ||
|
||
switch (key) { | ||
case "GUI" -> { | ||
if (isStringInt(sid)) { | ||
|
||
int id = Integer.parseInt(sid); | ||
|
||
HashMap<Integer, Inventory> invs_review = plugin.getInvs_review(); | ||
|
||
if (!invs_review.containsKey(id)) { | ||
|
||
plmsg.msg(p, "Invalid GUI_ID! (GUI_" + id + ")"); | ||
break; | ||
|
||
} | ||
|
||
Inventory inv = invs_review.get(id); | ||
|
||
ItemStack approve = new ItemStack(Material.GREEN_CONCRETE); | ||
ItemStack deny = new ItemStack(Material.RED_CONCRETE); | ||
ItemStack gui_id = new ItemStack(Material.BOOK); | ||
|
||
ItemMeta approve_meta = approve.getItemMeta(); | ||
ItemMeta deny_meta = deny.getItemMeta(); | ||
ItemMeta gui_id_meta = gui_id.getItemMeta(); | ||
|
||
String approve_displayname = "§aApprove request"; | ||
String deny_displayname = "§cDeny request"; | ||
String gui_id_dispalyname = "§bGUI_ID"; | ||
|
||
List<String> approve_lore = new ArrayList<>(); | ||
List<String> deny_lore = new ArrayList<>(); | ||
List<String> gui_id_lore = new ArrayList<>(); | ||
|
||
approve_lore.add("§7Approve the request and close this inventory"); | ||
deny_lore.add("§7Deny the request and close this inventory"); | ||
gui_id_lore.add("§7ID: " + id); | ||
|
||
approve_meta.setDisplayName(approve_displayname); | ||
approve_meta.setLore(approve_lore); | ||
|
||
deny_meta.setDisplayName(deny_displayname); | ||
deny_meta.setLore(deny_lore); | ||
|
||
gui_id_meta.setDisplayName(gui_id_dispalyname); | ||
gui_id_meta.setLore(gui_id_lore); | ||
|
||
approve.setItemMeta(approve_meta); | ||
deny.setItemMeta(deny_meta); | ||
gui_id.setItemMeta(gui_id_meta); | ||
|
||
|
||
inv.setItem(53, deny); | ||
inv.setItem(52, approve); | ||
inv.setItem(51, gui_id); | ||
|
||
p.openInventory(inv); | ||
|
||
invs_review.remove(id); | ||
|
||
} else { | ||
|
||
sendUsage(p); | ||
|
||
} | ||
} | ||
case "Placeholder" -> {} | ||
default -> sendUsage(p); | ||
} | ||
|
||
} else { | ||
|
||
sendUsage(p); | ||
|
||
} | ||
|
||
return true; | ||
} | ||
|
||
private void sendUsage(Player p) { | ||
|
||
plmsg.msg(p,"Usage: /opengui GUI_ID"); | ||
|
||
} | ||
|
||
|
||
public boolean isStringInt(String s) | ||
{ | ||
try { | ||
|
||
Integer.parseInt(s); | ||
return true; | ||
|
||
} catch (NumberFormatException ex) { | ||
|
||
return false; | ||
|
||
} | ||
} | ||
|
||
} |
Oops, something went wrong.