Skip to content

Commit

Permalink
0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Dec 29, 2024
1 parent ea1e938 commit 0c9d850
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Provide bugfixes, optimizations and utilities for Forge+Bukkit server environmen
- Skip firing event if no listeners registered.
- Disable Timings for less performance overhead.
- Compatibility first, shouldn't break any mods/plugins.
- Built Bukkit plugin in the mod, offers utilities to server owners.

Configuration file is under `${minecraftDir}/config/hybridfix.cfg`

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ generate_javadocs_jar = false

# Mod Information
# HIGHLY RECOMMEND complying with SemVer for mod_version: https://semver.org/
mod_version = 0.0.2
mod_version = 0.0.3
root_package = io.wdsj
mod_id = hybridfix
mod_name = HybridFix
Expand Down Expand Up @@ -101,7 +101,7 @@ mixin_booter_version = 10.2
# You should change package root once they are generated
generate_mixins_json = true
# Delimit configs with spaces. Should only put configs name instead of full file name
mixin_configs = fix.capability bridge.explosion bridge.explosion.mohist bridge.permission fix.capability.mohist perf.eventbus perf.timings.v1 misc.command
mixin_configs = fix.capability bridge.explosion bridge.explosion.mohist bridge.permission fix.capability.mohist perf.eventbus perf.timings.v1 misc.command bukkit.plugin
# A refmap is a json that denotes mapping conversions, this json is generated automatically, with the name `mixins.mod_id.refmap.json`
# Use the property `mixin_refmap` if you want it to use a different name, only one name is accepted
mixin_refmap = mixins.${mod_id}.refmap.json
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wdsj/hybridfix/HybridFixPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class HybridFixPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader {
put("mixins.perf.timings.v1.json", () -> Settings.disableTimings);
}
put("mixins.misc.command.json", () -> Settings.registerHybridFixCommands);
put("mixins.bukkit.plugin.json", () -> Settings.bukkitPluginConfig.enable);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
case "version":
sender.sendMessage("This server is running HybridFix version " + HybridFix.VERSION);
break;
default:
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}

return true;
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/wdsj/hybridfix/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ public class Settings {
@Config.RequiresMcRestart
public static boolean registerHybridFixCommands = true;

@Config.Comment("Configuration for HybridFix built-in bukkit plugin.")
@Config.RequiresMcRestart
public static BukkitPluginSettings bukkitPluginConfig = new BukkitPluginSettings();

public static class BukkitPluginSettings {
@Config.Comment("Enable HybridFix built-in bukkit plugin.(All bukkit plugin features in this section won't work if you disabled this!)")
@Config.RequiresMcRestart
public boolean enable = false;

@Config.Comment("Enable HybridFix built-in AntiExplode.")
@Config.RequiresMcRestart
public boolean antiExplode = false;

@Config.Comment("Worlds that AntiExplode should protect.")
@Config.RequiresMcRestart
public String[] antiExplodeWorlds = new String[]{"world"};
}

static {
ConfigAnytime.register(Settings.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package io.wdsj.hybridfix.entry.bukkit;

import io.wdsj.hybridfix.HybridFix;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.PluginBase;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginLogger;
import org.bukkit.plugin.java.JavaPluginLoader;

import java.io.File;
import java.io.InputStream;
import java.util.List;

public class HybridFixInternalPlugin extends PluginBase {
private boolean enabled = true;
private PluginLoader loader;
private static final HybridFixInternalPlugin INSTANCE = new HybridFixInternalPlugin();
public static HybridFixInternalPlugin getInstance() {
return INSTANCE;
}
private final String pluginName;
private PluginDescriptionFile pdf;

public HybridFixInternalPlugin() {
this.pluginName = "HybridFix";
pdf = new PluginDescriptionFile(pluginName, HybridFix.VERSION, "hybridfix");
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

@Override
public File getDataFolder() {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public PluginDescriptionFile getDescription() {
return pdf;
}

@Override
public FileConfiguration getConfig() {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public InputStream getResource(String filename) {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public void saveConfig() {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public void saveDefaultConfig() {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public void saveResource(String resourcePath, boolean replace) {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public void reloadConfig() {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public PluginLogger getLogger() {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public PluginLoader getPluginLoader() {
if (loader == null) {
loader = new JavaPluginLoader(Bukkit.getServer());
}
return loader;
}

@Override
public Server getServer() {
return Bukkit.getServer();
}

@Override
public boolean isEnabled() {
return enabled;
}

@Override
public void onDisable() {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public void onLoad() {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public void onEnable() {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public boolean isNaggable() {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public void setNaggable(boolean canNag) {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
throw new UnsupportedOperationException("Not supported.");
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
throw new UnsupportedOperationException("Not supported.");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.wdsj.hybridfix.entry.bukkit.listener;

import io.wdsj.hybridfix.config.Settings;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.entity.EntityExplodeEvent;

public class ExplodeListener implements Listener {
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
String worldName = event.getEntity().getWorld().getName();
for (String s : Settings.bukkitPluginConfig.antiExplodeWorlds) {
if (s.equalsIgnoreCase(worldName)) {
event.setCancelled(true);
break;
}
}
}

@EventHandler
public void onBlockExplode(BlockExplodeEvent event) {
String worldName = event.getBlock().getWorld().getName();
for (String s : Settings.bukkitPluginConfig.antiExplodeWorlds) {
if (s.equalsIgnoreCase(worldName)) {
event.setCancelled(true);
break;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.wdsj.hybridfix.mixin.bukkit.plugin;

import io.wdsj.hybridfix.HybridFix;
import io.wdsj.hybridfix.entry.bukkit.HybridFixInternalPlugin;
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
import org.bukkit.event.HandlerList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(CraftServer.class)
public abstract class CraftServerMixin {

@Inject(
method = "disablePlugins",
at = @At(
value = "TAIL"
),
remap = false
)
public void onDisablePlugins(CallbackInfo ci) {
hybridFix$disableInternalPlugin();
}

@Unique
private void hybridFix$disableInternalPlugin() {
HybridFix.LOGGER.info("[HybridFix] Disabling HybridFix internal plugin v{}", HybridFix.VERSION);
HandlerList.unregisterAll(HybridFixInternalPlugin.getInstance());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.wdsj.hybridfix.mixin.bukkit.plugin;

import io.wdsj.hybridfix.HybridFix;
import io.wdsj.hybridfix.config.Settings;
import io.wdsj.hybridfix.entry.bukkit.HybridFixInternalPlugin;
import io.wdsj.hybridfix.entry.bukkit.listener.ExplodeListener;
import net.minecraft.server.dedicated.DedicatedServer;
import org.bukkit.Bukkit;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(DedicatedServer.class)
public abstract class DedicatedServerMixin {

@Inject(
method = "init",
at = @At(
value = "TAIL"
)
)
public void onInit(CallbackInfoReturnable<Boolean> cir) {
hybridFix$register();
}

@Unique
private void hybridFix$register() {
HybridFix.LOGGER.info("[HybridFix] Enabling HybridFix internal plugin v{}", HybridFix.VERSION);
if (Settings.bukkitPluginConfig.antiExplode) {
Bukkit.getServer().getPluginManager().registerEvents(new ExplodeListener(), HybridFixInternalPlugin.getInstance());
}
}
}
12 changes: 12 additions & 0 deletions src/main/resources/mixins.bukkit.plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"package": "io.wdsj.hybridfix.mixin.bukkit.plugin",
"required": true,
"refmap": "${mixin_refmap}",
"target": "@env(DEFAULT)",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"DedicatedServerMixin",
"CraftServerMixin"
]
}

0 comments on commit 0c9d850

Please sign in to comment.