From b047d0197a2a40f59c8185a1ca911cb0805d21f9 Mon Sep 17 00:00:00 2001 From: Gary Tierney Date: Sun, 1 Jan 2017 08:13:09 +0000 Subject: [PATCH] Add a plugin which allows creating mixins for Mobs Adds a mob-extension plugin, which allows creating modules as mixins to be monkey-patched into the Mob class. Having a standard method of doing this prevents confusing problems with mixin name conflicts, by allowing the plugin to raise an error that 2 mixins with the same name exist. --- .../plugins/entity/mob/extension/extension.rb | 20 +++++++++++++++++++ data/plugins/entity/mob/extension/plugin.xml | 15 ++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 data/plugins/entity/mob/extension/extension.rb create mode 100644 data/plugins/entity/mob/extension/plugin.xml diff --git a/data/plugins/entity/mob/extension/extension.rb b/data/plugins/entity/mob/extension/extension.rb new file mode 100644 index 00000000..11e20c0d --- /dev/null +++ b/data/plugins/entity/mob/extension/extension.rb @@ -0,0 +1,20 @@ +require 'java' + +java_import 'org.apollo.game.model.entity.Mob' + +module MobExtension + MOB_EXTENSIONS = [] + + def self.register(extension) + fail 'Provided extension object is not a module' unless extension.is_a?(Module) + + new_mixins = extension.public_instance_methods + current_mixins = MOB_EXTENSIONS.map { |e| {e.to_s => e.public_instance_methods} } + + current_mixins.each do |ext, methods| + methods.each {|m| fail "Extension #{ext} already provides method #{m}" if new_mixins.include?(m) } + end + + Mob.include(extension) + end +end \ No newline at end of file diff --git a/data/plugins/entity/mob/extension/plugin.xml b/data/plugins/entity/mob/extension/plugin.xml new file mode 100644 index 00000000..e2c7d250 --- /dev/null +++ b/data/plugins/entity/mob/extension/plugin.xml @@ -0,0 +1,15 @@ + + + mob-extension + 0.1 + Mob Extensions + Adds support for extending Mobs with new functionality + + Gary Tierney + + + + + + + \ No newline at end of file