Skip to content

Commit 60278a6

Browse files
author
TheProgramSrc
committed
Change log:
• Added LogsFilter • Added Translations • Added PreCreated GUIs
1 parent f8864f5 commit 60278a6

File tree

7 files changed

+178
-3
lines changed

7 files changed

+178
-3
lines changed

SuperCoreAPI.iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@
4747
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
4848
<orderEntry type="library" scope="PROVIDED" name="Maven: com.zaxxer:HikariCP:3.3.1" level="project" />
4949
<orderEntry type="library" scope="PROVIDED" name="Maven: org.xerial:sqlite-jdbc:3.25.2" level="project" />
50+
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-core:2.5" level="project" />
51+
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-api:2.5" level="project" />
5052
</component>
5153
</module>

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>xyz.theprogramsrc</groupId>
88
<artifactId>SuperCoreAPI</artifactId>
9-
<version>3.3.0</version>
9+
<version>3.3.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SuperCoreAPI</name>
@@ -158,5 +158,12 @@
158158
<version>3.25.2</version>
159159
<scope>provided</scope>
160160
</dependency>
161+
<!-- Logs Filter -->
162+
<dependency>
163+
<groupId>org.apache.logging.log4j</groupId>
164+
<artifactId>log4j-core</artifactId>
165+
<version>2.5</version>
166+
<scope>provided</scope>
167+
</dependency>
161168
</dependencies>
162169
</project>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package xyz.theprogramsrc.supercoreapi.global;
2+
3+
import org.apache.logging.log4j.Level;
4+
import org.apache.logging.log4j.Marker;
5+
import org.apache.logging.log4j.core.LogEvent;
6+
import org.apache.logging.log4j.core.Logger;
7+
import org.apache.logging.log4j.core.filter.AbstractFilter;
8+
import org.apache.logging.log4j.message.Message;
9+
10+
import java.util.Arrays;
11+
12+
public class LogsFilter extends AbstractFilter{
13+
14+
private final FilterResult result;
15+
private final String[] filteredStrings;
16+
17+
/**
18+
* Constructor of a log filter
19+
* @param result the default result for the filtered words
20+
* @param filteredStrings the strings to filter
21+
*/
22+
public LogsFilter(FilterResult result, String... filteredStrings){
23+
this.result = result;
24+
this.filteredStrings = filteredStrings;
25+
}
26+
27+
private Result process(String message){
28+
if(message != null){
29+
String msg = message.toLowerCase();
30+
if(Arrays.stream(this.filteredStrings).anyMatch(s-> msg.contains(s.toLowerCase()))){
31+
return Result.toResult(this.result.name(), Result.NEUTRAL);
32+
}
33+
}
34+
35+
return Result.NEUTRAL;
36+
}
37+
38+
@Override
39+
public Result filter(LogEvent event) {
40+
return this.process(event.getMessage().getFormattedMessage());
41+
}
42+
43+
@Override
44+
public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
45+
return this.process(msg.getFormattedMessage());
46+
}
47+
48+
@Override
49+
public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) {
50+
return this.process(msg.toString());
51+
}
52+
53+
@Override
54+
public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) {
55+
return this.process(msg);
56+
}
57+
58+
public static enum FilterResult{
59+
DENY,
60+
NEUTRAL,
61+
NONE
62+
}
63+
64+
}

src/main/java/xyz/theprogramsrc/supercoreapi/global/storage/MySQLDataBase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.zaxxer.hikari.HikariConfig;
44
import com.zaxxer.hikari.HikariDataSource;
55
import xyz.theprogramsrc.supercoreapi.SuperPlugin;
6+
import xyz.theprogramsrc.supercoreapi.global.LogsFilter;
67

78
import java.sql.Connection;
89

@@ -16,6 +17,7 @@ public abstract class MySQLDataBase implements DataBase{
1617
public MySQLDataBase(SuperPlugin<?> plugin){
1718
this.plugin = plugin;
1819
this.plugin.log("Connecting to '" + getDataBaseSettings().host() + ":" + getDataBaseSettings().port()+"'...");
20+
new LogsFilter(LogsFilter.FilterResult.DENY, "com.zaxxer.hikari");
1921
HikariConfig cfg = new HikariConfig();
2022
cfg.setJdbcUrl("jdbc:mysql://" + getDataBaseSettings().host() + ":" + getDataBaseSettings().port() + "/" + getDataBaseSettings().database() + "?useSSL=" + getDataBaseSettings().useSSL());
2123
cfg.setUsername(getDataBaseSettings().username());

src/main/java/xyz/theprogramsrc/supercoreapi/global/translations/Base.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
import java.util.stream.Collectors;
77

88
public enum Base implements TranslationPack{
9-
CONFIRM("Confirm"),
10-
DECLINE("Decline"),
9+
OK("Ok"),
10+
ADD("Add"),
11+
REMOVE("Remove"),
12+
DONE("Done"),
13+
COMPLETED("Completed"),
14+
CANCEL("Cancel"),
1115
LEFT_CLICK("Left Click"),
16+
SHIFT_CLICK("Shift Click"),
1217
MIDDLE_CLICK("Middle Click"),
1318
RIGHT_CLICK("Right Click"),
1419
LANGUAGES("Languages"),
@@ -19,6 +24,8 @@ public enum Base implements TranslationPack{
1924
PLAYER("Player"),
2025
PLAYERS("Players"),
2126
CONSOLE("Console"),
27+
CONFIRM("Confirm"),
28+
DECLINE("Decline"),
2229

2330
/* MESSAGES */
2431
NO_PERMISSION("&cYou dont have permission."),
@@ -60,6 +67,7 @@ public enum Base implements TranslationPack{
6067
MATERIAL_SELECTOR_ITEM_NAME("&a$1"),
6168
MATERIAL_SELECTOR_ITEM_DESCRIPTION("&7Click to select &a$1"),
6269

70+
/* Items */
6371
ITEM_BACK_NAME("&aBack"),
6472
ITEM_BACK_DESCRIPTION("&7Click to go Back."),
6573

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated;
2+
3+
import org.bukkit.entity.Player;
4+
import xyz.theprogramsrc.supercoreapi.global.translations.Base;
5+
import xyz.theprogramsrc.supercoreapi.spigot.SpigotPlugin;
6+
import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI;
7+
import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton;
8+
import xyz.theprogramsrc.supercoreapi.spigot.guis.action.ClickAction;
9+
import xyz.theprogramsrc.supercoreapi.spigot.guis.objects.GUIRows;
10+
import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem;
11+
import xyz.theprogramsrc.supercoreapi.spigot.utils.xseries.XMaterial;
12+
13+
public abstract class ConfirmationGUI extends GUI {
14+
15+
public ConfirmationGUI(SpigotPlugin plugin, Player player) {
16+
super(plugin, player);
17+
}
18+
19+
@Override
20+
protected GUIRows getRows() {
21+
return GUIRows.THREE;
22+
}
23+
24+
@Override
25+
protected GUIButton[] getButtons() {
26+
return new GUIButton[]{
27+
new GUIButton(12, new SimpleItem(XMaterial.EMERALD_BLOCK).setDisplayName(Base.CONFIRM.toString()), this::onConfirm),
28+
new GUIButton(14, new SimpleItem(XMaterial.REDSTONE_BLOCK).setDisplayName(Base.DECLINE.toString()), this::onDecline),
29+
new GUIButton(26, this.getPreloadedItems().getBackItem(), this::onBack)
30+
};
31+
}
32+
33+
public abstract void onConfirm(ClickAction clickAction);
34+
35+
public abstract void onDecline(ClickAction clickAction);
36+
37+
public abstract void onBack(ClickAction clickAction);
38+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.entity.Player;
5+
import org.bukkit.inventory.Inventory;
6+
import xyz.theprogramsrc.supercoreapi.global.translations.Base;
7+
import xyz.theprogramsrc.supercoreapi.spigot.SpigotPlugin;
8+
import xyz.theprogramsrc.supercoreapi.spigot.guis.BrowserGUI;
9+
import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton;
10+
import xyz.theprogramsrc.supercoreapi.spigot.guis.action.ClickAction;
11+
import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem;
12+
import xyz.theprogramsrc.supercoreapi.spigot.utils.xseries.XMaterial;
13+
14+
import java.util.Arrays;
15+
16+
public abstract class MaterialBrowser extends BrowserGUI<XMaterial> {
17+
18+
public MaterialBrowser(SpigotPlugin plugin, Player player) {
19+
super(plugin, player);
20+
}
21+
22+
@Override
23+
public XMaterial[] getObjects() {
24+
Inventory inventory = Bukkit.createInventory(null, 9);
25+
return Arrays.stream(XMaterial.itemsSupported()).filter(m->{
26+
inventory.setItem(4, m.parseItem());
27+
if(inventory.getItem(4) != null){
28+
inventory.clear();
29+
return true;
30+
}
31+
return false;
32+
}).toArray(XMaterial[]::new);
33+
}
34+
35+
@Override
36+
public GUIButton getButton(XMaterial xMaterial) {
37+
SimpleItem item = new SimpleItem(xMaterial)
38+
.setDisplayName(Base.MATERIAL_SELECTOR_ITEM_NAME.options().vars(xMaterial.getHumanName()).toString())
39+
.setLore(Base.MATERIAL_SELECTOR_ITEM_DESCRIPTION.options().vars(xMaterial.getHumanName()).toString());
40+
return new GUIButton(item).setAction(a-> this.onSelect(a, xMaterial));
41+
}
42+
43+
@Override
44+
public void onBack(ClickAction clickAction) {
45+
46+
}
47+
48+
@Override
49+
protected String getTitle() {
50+
return Base.MATERIAL_SELECTOR_TITLE.toString();
51+
}
52+
53+
public abstract void onSelect(ClickAction clickAction, XMaterial xMaterial);
54+
}

0 commit comments

Comments
 (0)