base project
This commit is contained in:
parent
7240f08f30
commit
f5e8c51ff7
55
.gitignore
vendored
Normal file
55
.gitignore
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
*.class
|
||||
*.log
|
||||
*.ctxt
|
||||
.mtj.tmp/
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
.idea/**/aws.xml
|
||||
.idea/**/contentModel.xml
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
cmake-build-*/
|
||||
.idea/**/mongoSettings.xml
|
||||
*.iws
|
||||
out/
|
||||
.idea_modules/
|
||||
atlassian-ide-plugin.xml
|
||||
.idea/replstate.xml
|
||||
.idea/sonarlint/
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
.idea/httpRequests
|
||||
.idea/caches/build_file_checksums.ser
|
||||
.gradle
|
||||
**/build/
|
||||
!src/**/build/
|
||||
gradle-app.setting
|
||||
!gradle-wrapper.jar
|
||||
!gradle-wrapper.properties
|
||||
.gradletasknamecache
|
||||
.project
|
||||
.classpath
|
||||
run
|
||||
gradle
|
||||
.idea
|
92
README.md
92
README.md
@ -1,92 +0,0 @@
|
||||
# WildAddons
|
||||
|
||||
|
||||
|
||||
## Getting started
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
|
||||
## Add your files
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://git.fascinated.cc/Fascinated/wildaddons.git
|
||||
git branch -M master
|
||||
git push -uf origin master
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
- [ ] [Set up project integrations](https://git.fascinated.cc/Fascinated/wildaddons/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
|
||||
## Test and Deploy
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
|
||||
***
|
||||
|
||||
# Editing this README
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
|
||||
## Suggestions for a good README
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
84
build.gradle
Normal file
84
build.gradle
Normal file
@ -0,0 +1,84 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '1.0-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
repositories {
|
||||
// Add repositories to retrieve artifacts from in here.
|
||||
// You should only use this when depending on other mods because
|
||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||
// for more information about repositories.
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// To change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
compileOnly("org.projectlombok:lombok:1.18.26")
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.26")
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
filteringCharset "UTF-8"
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
|
||||
def targetJavaVersion = 17
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
// If Javadoc is generated, this must be specified in that task too.
|
||||
it.options.encoding = "UTF-8"
|
||||
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||
it.options.release = targetJavaVersion
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||
if (JavaVersion.current() < javaVersion) {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||
}
|
||||
archivesBaseName = project.archives_base_name
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this line, sources will not be generated.
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
jar {
|
||||
from("LICENSE") {
|
||||
rename { "${it}_${project.archivesBaseName}"}
|
||||
}
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
|
||||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
|
||||
repositories {
|
||||
// Add repositories to publish to here.
|
||||
// Notice: This block does NOT have the same function as the block in the top level.
|
||||
// The repositories here will be used for publishing your artifact, not for
|
||||
// retrieving dependencies.
|
||||
}
|
||||
}
|
17
gradle.properties
Normal file
17
gradle.properties
Normal file
@ -0,0 +1,17 @@
|
||||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx4G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://modmuss50.me/fabric.html
|
||||
minecraft_version=1.19.3
|
||||
yarn_mappings=1.19.3+build.5
|
||||
loader_version=0.14.17
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0-SNAPSHOT
|
||||
maven_group = cc.fascinated
|
||||
archives_base_name = WildAddons
|
||||
|
||||
# Dependencies
|
||||
# check this on https://modmuss50.me/fabric.html
|
||||
fabric_version=0.75.1+1.19.3
|
9
settings.gradle
Normal file
9
settings.gradle
Normal file
@ -0,0 +1,9 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
23
src/main/java/cc/fascinated/wildaddons/WildAddons.java
Normal file
23
src/main/java/cc/fascinated/wildaddons/WildAddons.java
Normal file
@ -0,0 +1,23 @@
|
||||
package cc.fascinated.wildaddons;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class WildAddons implements ModInitializer {
|
||||
|
||||
public static final Logger LOGGER = LogManager.getLogger(WildAddons.class);
|
||||
@Getter private static final ExecutorService executorService = Executors.newCachedThreadPool();
|
||||
|
||||
/**
|
||||
* Runs the mod initializer.
|
||||
*/
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
||||
}
|
||||
}
|
50
src/main/java/cc/fascinated/wildaddons/addon/Addon.java
Normal file
50
src/main/java/cc/fascinated/wildaddons/addon/Addon.java
Normal file
@ -0,0 +1,50 @@
|
||||
package cc.fascinated.wildaddons.addon;
|
||||
|
||||
import cc.fascinated.wildaddons.event.EventListener;
|
||||
import cc.fascinated.wildaddons.event.EventManager;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public abstract class Addon implements EventListener {
|
||||
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final Category category;
|
||||
private boolean enabled;
|
||||
|
||||
public Addon(String name, String description, Category category) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.category = category;
|
||||
|
||||
EventManager.registerListener(this);
|
||||
onEnable();
|
||||
}
|
||||
|
||||
public enum Category {
|
||||
CHAT
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles this addon on or off.
|
||||
*/
|
||||
public void toggle() {
|
||||
this.enabled = !this.enabled;
|
||||
|
||||
if (this.enabled) {
|
||||
onDisable();
|
||||
} else {
|
||||
onEnable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this addon gets enabled.
|
||||
*/
|
||||
public void onEnable() {}
|
||||
|
||||
/**
|
||||
* Called when this addon gets disabled.
|
||||
*/
|
||||
public void onDisable() {}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package cc.fascinated.wildaddons.addon;
|
||||
|
||||
import cc.fascinated.wildaddons.addon.impl.chat.AutoWelcomer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class AddonManager {
|
||||
|
||||
public static final Set<Addon> ADDONS = new HashSet<>();
|
||||
|
||||
public AddonManager() {
|
||||
registerAddon(new AutoWelcomer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an addon.
|
||||
*
|
||||
* @param addon The addon to register
|
||||
*/
|
||||
public void registerAddon(Addon addon) {
|
||||
ADDONS.add(addon);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package cc.fascinated.wildaddons.addon.impl.chat;
|
||||
|
||||
import cc.fascinated.wildaddons.WildAddons;
|
||||
import cc.fascinated.wildaddons.addon.Addon;
|
||||
import cc.fascinated.wildaddons.listener.PlayerListener;
|
||||
import cc.fascinated.wildaddons.statistic.Statistic;
|
||||
import cc.fascinated.wildaddons.utils.PlayerUtils;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.gui.PlayerListGui;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class AutoWelcomer extends Addon {
|
||||
|
||||
public AutoWelcomer() {
|
||||
super("Auto Welcomer",
|
||||
"Automatically sends the welcome command when a new player joins.",
|
||||
Category.CHAT
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(String message, String messageStripped) {
|
||||
if (!PlayerListener.isMoving()) { // To prevent bans lol
|
||||
return;
|
||||
}
|
||||
if (!messageStripped.startsWith("WILDNETWORK » Welcome")) { // This is not the message we are looking for
|
||||
return;
|
||||
}
|
||||
String[] parts = messageStripped.split(" ");
|
||||
String name = parts[2];
|
||||
|
||||
// No need to welcome ourselves
|
||||
if (MinecraftClient.getInstance().player.getName().getString().equals(name)) {
|
||||
return;
|
||||
}
|
||||
WildAddons.getExecutorService().execute(() -> {
|
||||
try {
|
||||
// Sleep the thread for a randomized amount of time to make it look less suspicious
|
||||
Thread.sleep(ThreadLocalRandom.current().nextLong(600, 2000));
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
PlayerUtils.sendMessage("/wc"); // Send the command
|
||||
Statistic.PLAYERS_WELCOMED.increment(); // Increment the stat
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package cc.fascinated.wildaddons.client;
|
||||
|
||||
import cc.fascinated.wildaddons.addon.AddonManager;
|
||||
import cc.fascinated.wildaddons.event.EventManager;
|
||||
import cc.fascinated.wildaddons.listener.PlayerListener;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class WildAddonsClient implements ClientModInitializer {
|
||||
|
||||
/**
|
||||
* Runs the mod initializer on the client environment.
|
||||
*/
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
new AddonManager();
|
||||
|
||||
EventManager.registerListener(new PlayerListener());
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cc.fascinated.wildaddons.event;
|
||||
|
||||
public interface EventListener {
|
||||
|
||||
default void onTick() {}
|
||||
|
||||
/**
|
||||
* Gets called when a chat message is received
|
||||
*
|
||||
* @param message the message
|
||||
* @param messageStripped the message without colors
|
||||
*/
|
||||
default void onChat(String message, String messageStripped) {}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package cc.fascinated.wildaddons.event;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class EventManager {
|
||||
|
||||
/**
|
||||
* The list of listeners registered
|
||||
*/
|
||||
@Getter private static final Set<EventListener> listeners = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Registers the event listener.
|
||||
*
|
||||
* @param listener the listener to register
|
||||
*/
|
||||
public static void registerListener(EventListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package cc.fascinated.wildaddons.listener;
|
||||
|
||||
import cc.fascinated.wildaddons.event.EventListener;
|
||||
import cc.fascinated.wildaddons.utils.PlayerUtils;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
|
||||
public class PlayerListener implements EventListener {
|
||||
|
||||
/**
|
||||
* The last time the player moved.
|
||||
*/
|
||||
private static long lastMovement;
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
if (!PlayerUtils.isOnWild()) { // Ignore if the player isn't on Wild
|
||||
return;
|
||||
}
|
||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
if (player.getX() - player.prevX > 0 || player.getY() - player.prevY > 0 ||
|
||||
player.getZ() - player.prevZ > 0) { // Check if the player has moved
|
||||
lastMovement = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player has moved
|
||||
* in the last 10 seconds.
|
||||
*
|
||||
* @return true if they are moving, otherwise false
|
||||
*/
|
||||
public static boolean isMoving() {
|
||||
return (System.currentTimeMillis() - lastMovement) < 10_000L;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package cc.fascinated.wildaddons.mixin;
|
||||
|
||||
import cc.fascinated.wildaddons.event.EventListener;
|
||||
import cc.fascinated.wildaddons.event.EventManager;
|
||||
import cc.fascinated.wildaddons.utils.PlayerUtils;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class MinecraftClientMixin {
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
public void onTick(CallbackInfo ci) {
|
||||
if (!PlayerUtils.isOnWild()) { // Ignore if the player isn't on Wild
|
||||
return;
|
||||
}
|
||||
for (EventListener listener : EventManager.getListeners()) {
|
||||
listener.onTick();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package cc.fascinated.wildaddons.mixin;
|
||||
|
||||
import cc.fascinated.wildaddons.event.EventListener;
|
||||
import cc.fascinated.wildaddons.event.EventManager;
|
||||
import cc.fascinated.wildaddons.utils.PlayerUtils;
|
||||
import cc.fascinated.wildaddons.utils.TextUtils;
|
||||
import net.minecraft.client.gui.hud.ChatHud;
|
||||
import net.minecraft.client.gui.hud.MessageIndicator;
|
||||
import net.minecraft.network.message.MessageSignatureData;
|
||||
import net.minecraft.text.Text;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ChatHud.class)
|
||||
public class PlayerMixin {
|
||||
|
||||
@Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", at = @At("HEAD"))
|
||||
public void onChat(Text text, MessageSignatureData signature, int ticks, MessageIndicator indicator, boolean refresh, CallbackInfo ci) {
|
||||
if (!PlayerUtils.isOnWild()) { // Ignore if the player isn't on Wild
|
||||
return;
|
||||
}
|
||||
String message = text.getString();
|
||||
String stripped = TextUtils.stripColors(message); // Strip the text removing colors
|
||||
|
||||
for (EventListener listener : EventManager.getListeners()) {
|
||||
listener.onChat(message, stripped);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package cc.fascinated.wildaddons.statistic;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Getter @RequiredArgsConstructor
|
||||
public enum Statistic {
|
||||
|
||||
PLAYERS_WELCOMED("players-welcomed");
|
||||
|
||||
/**
|
||||
* The in memory storage for all statistics
|
||||
*/
|
||||
private final HashMap<Statistic, Integer> statistics = new HashMap<>();
|
||||
|
||||
/**
|
||||
* The key used in the storage
|
||||
*/
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* Increment this statistic.
|
||||
*/
|
||||
public void increment() {
|
||||
increment(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment this statistic.
|
||||
*
|
||||
* @param amount the amount to increment by
|
||||
*/
|
||||
public void increment(int amount) {
|
||||
int current = statistics.computeIfAbsent(this, (e) -> 0);
|
||||
current += amount;
|
||||
statistics.put(this, current);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package cc.fascinated.wildaddons.utils;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ServerInfo;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
private static final MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||
|
||||
/**
|
||||
* Sends a chat message as the player.
|
||||
*
|
||||
* @param message the message to send
|
||||
*/
|
||||
public static void sendMessage(String message) {
|
||||
minecraftClient.player.networkHandler.sendChatMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the given ip against the
|
||||
* currently connected servers ip.
|
||||
*
|
||||
* @param ips the server ips
|
||||
* @return true if same, otherwise false
|
||||
*/
|
||||
public static boolean onServer(String... ips) {
|
||||
ServerInfo currentServerEntry = minecraftClient.getCurrentServerEntry();
|
||||
if (currentServerEntry == null) {
|
||||
return false;
|
||||
}
|
||||
for (String ip : ips) {
|
||||
if (currentServerEntry.address.toLowerCase().contains(ip)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is currently on wild.
|
||||
*
|
||||
* @return true if on wild, otherwise false
|
||||
*/
|
||||
public static boolean isOnWild() {
|
||||
return onServer("wildprison.net", "wildnetwork.net");
|
||||
}
|
||||
}
|
14
src/main/java/cc/fascinated/wildaddons/utils/TextUtils.java
Normal file
14
src/main/java/cc/fascinated/wildaddons/utils/TextUtils.java
Normal file
@ -0,0 +1,14 @@
|
||||
package cc.fascinated.wildaddons.utils;
|
||||
|
||||
public class TextUtils {
|
||||
|
||||
/**
|
||||
* Strips all colors from the given string
|
||||
*
|
||||
* @param message the string to strip
|
||||
* @return the stripped string
|
||||
*/
|
||||
public static String stripColors(String message) {
|
||||
return message.replaceAll("(?i)§[0-9A-FK-OR]/g", "");
|
||||
}
|
||||
}
|
15
src/main/resources/WildAddons.mixins.json
Normal file
15
src/main/resources/WildAddons.mixins.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "cc.fascinated.wildaddons.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"PlayerMixin",
|
||||
"MinecraftClientMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
29
src/main/resources/fabric.mod.json
Normal file
29
src/main/resources/fabric.mod.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "wild-addons",
|
||||
"version": "${version}",
|
||||
"name": "WildAddons",
|
||||
"description": "",
|
||||
"authors": ["Fascinated#7668"],
|
||||
"contact": {
|
||||
"repo": "https://github.com/Liam/WildAddons"
|
||||
},
|
||||
"license": "All-Rights-Reserved",
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"cc.fascinated.wildaddons.client.WildAddonsClient"
|
||||
],
|
||||
"main": [
|
||||
"cc.fascinated.wildaddons.WildAddons"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"WildAddons.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.17",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.19.3"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user