Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SimpleChatFilter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DapperGoose
SimpleChatFilter
Commits
a3c95d4d
Verified
Commit
a3c95d4d
authored
Jul 25, 2023
by
TheJoeCoder
Browse files
Options
Downloads
Patches
Plain Diff
Add main features
Signed-off-by:
TheJoeCoder
<
joe@radialbog9.uk
>
parent
d1dac0c3
No related branches found
No related tags found
No related merge requests found
Pipeline
#40
canceled
Jul 25, 2023
Stage: build
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/net/dappergoose/simplechatfilter/SimpleChatFilter.java
+99
-3
99 additions, 3 deletions
...va/net/dappergoose/simplechatfilter/SimpleChatFilter.java
src/main/resources/config.yml
+12
-0
12 additions, 0 deletions
src/main/resources/config.yml
with
111 additions
and
3 deletions
src/main/java/net/dappergoose/simplechatfilter/SimpleChatFilter.java
+
99
−
3
View file @
a3c95d4d
package
net.dappergoose.simplechatfilter
;
import
net.md_5.bungee.api.ChatColor
;
import
net.md_5.bungee.api.chat.BaseComponent
;
import
net.md_5.bungee.api.chat.TextComponent
;
import
net.md_5.bungee.api.connection.ProxiedPlayer
;
import
net.md_5.bungee.api.event.ChatEvent
;
import
net.md_5.bungee.api.plugin.Listener
;
import
net.md_5.bungee.api.plugin.Plugin
;
import
net.md_5.bungee.config.Configuration
;
import
net.md_5.bungee.config.ConfigurationProvider
;
import
net.md_5.bungee.config.YamlConfiguration
;
import
net.md_5.bungee.event.EventHandler
;
public
final
class
SimpleChatFilter
extends
Plugin
{
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
public
final
class
SimpleChatFilter
extends
Plugin
implements
Listener
{
public
void
makeConfig
()
throws
IOException
{
// Create plugin config folder if it doesn't exist
if
(!
getDataFolder
().
exists
())
{
getLogger
().
info
(
"Created config folder: "
+
getDataFolder
().
mkdir
());
}
File
configFile
=
new
File
(
getDataFolder
(),
"config.yml"
);
// Copy default config if it doesn't exist
if
(!
configFile
.
exists
())
{
FileOutputStream
outputStream
=
new
FileOutputStream
(
configFile
);
// Throws IOException
InputStream
in
=
getResourceAsStream
(
"config.yml"
);
// This file must exist in the jar resources folder
in
.
transferTo
(
outputStream
);
// Throws IOException
}
}
private
Configuration
pluginConfig
;
@Override
public
void
onEnable
()
{
// Plugin startup logic
try
{
makeConfig
();
pluginConfig
=
ConfigurationProvider
.
getProvider
(
YamlConfiguration
.
class
)
.
load
(
new
File
(
getDataFolder
(),
"config.yml"
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
getProxy
().
getPluginManager
().
registerListener
(
this
,
this
);
}
@Override
public
void
onDisable
()
{
// Plugin shutdown logic
getProxy
().
getPluginManager
().
unregisterListener
(
this
);
}
@EventHandler
public
void
onChatEvent
(
ChatEvent
e
)
{
if
(!(
e
.
getSender
()
instanceof
ProxiedPlayer
))
return
;
ProxiedPlayer
p
=
(
ProxiedPlayer
)
e
.
getSender
();
if
(
e
.
isCommand
())
// TODO message commands
return
;
// ignore commands
String
message
=
e
.
getMessage
();
boolean
violated
=
false
;
String
matchedCategory
=
null
;
for
(
String
category
:
pluginConfig
.
getSection
(
"categories"
).
getKeys
())
{
if
(
p
.
hasPermission
(
"chatfilter.bypass."
+
category
))
continue
;
for
(
String
word
:
pluginConfig
.
getStringList
(
"categories."
+
category
+
".blocked"
))
{
if
(
message
.
contains
(
word
))
{
violated
=
true
;
matchedCategory
=
category
;
break
;
}
}
if
(
violated
)
break
;
}
if
(
violated
)
{
e
.
setCancelled
(
true
);
sendStaffMessage
(
new
TextComponent
(
ChatColor
.
translateAlternateColorCodes
(
'&'
,
pluginConfig
.
getString
(
"staff-message"
)
.
replace
(
"{player}"
,
p
.
getDisplayName
())
.
replace
(
"{category}"
,
matchedCategory
)
.
replace
(
"{message}"
,
message
)
.
replace
(
"{server}"
,
p
.
getServer
().
getInfo
().
getName
())
)
));
p
.
sendMessage
(
new
TextComponent
(
ChatColor
.
translateAlternateColorCodes
(
'&'
,
pluginConfig
.
getString
(
"categories."
+
matchedCategory
+
".message"
)
)
));
for
(
String
command
:
pluginConfig
.
getStringList
(
"categories."
+
matchedCategory
+
".commands"
))
{
getProxy
().
getPluginManager
().
dispatchCommand
(
getProxy
().
getConsole
(),
command
.
replace
(
"{player}"
,
p
.
getName
()));
}
}
}
private
void
sendStaffMessage
(
BaseComponent
component
)
{
for
(
ProxiedPlayer
p
:
getProxy
().
getPlayers
())
{
if
(
p
.
hasPermission
(
"chatfilter.staff"
))
{
p
.
sendMessage
(
component
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/resources/config.yml
0 → 100644
+
12
−
0
View file @
a3c95d4d
categories
:
# A list of categories - !! most severe first !!
advertising-pfcloud
:
blocked
:
-
a friendly bot designed to join servers
-
If you are searching for a good server hosting provider
-
https://shop.pfcloud.io
commands
:
-
ipban {username} Bot/Advertising -s
message
:
'
&cPlease
do
not
advertise!'
staff-message
:
'
&a[ChatFilter]
&c{username}
&7
broke
rule
&c{category}
&7on
server
&c{server}&7.'
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment