From bb87385d83be8053d652d9d96c8b21c3bf5e7c01 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 25 Aug 2019 03:36:30 +0200 Subject: [PATCH] Converted components and almost finished Towny-Factions --- plugin.yml | 32 +-- pom.xml | 191 ++++++++++-------- .../Factions/2.14.0/Factions-2.14.0.pom | 10 + .../Factions/maven-metadata-local.xml | 12 ++ .../MassiveCore/2.14.0/MassiveCore-2.14.0.pom | 10 + .../MassiveCore/maven-metadata-local.xml | 12 ++ .../presents/ButtonPresents.java | 21 +- .../buttondevteam/presents/StaticMain.java | 20 +- .../presents/architecture/Component.java | 76 ------- .../chunkarchive/ChunkArchiveComponent.java | 17 +- .../components/dungeon/DungeonComponent.java | 22 +- .../components/magic/MagicComponent.java | 48 ++--- .../research/ResearchComponent.java | 22 +- .../dictionary/DictionaryComponent.java | 71 +++---- .../components/spawn/SpawnComponent.java | 17 +- .../townyfactions/TownyFactionsComponent.java | 89 ++++++++ target/classes/plugin.yml | 32 +-- 17 files changed, 406 insertions(+), 296 deletions(-) create mode 100644 repo/com/massivecraft/Factions/2.14.0/Factions-2.14.0.pom create mode 100644 repo/com/massivecraft/Factions/maven-metadata-local.xml create mode 100644 repo/com/massivecraft/MassiveCore/2.14.0/MassiveCore-2.14.0.pom create mode 100644 repo/com/massivecraft/MassiveCore/maven-metadata-local.xml delete mode 100644 src/main/java/buttondevteam/presents/architecture/Component.java create mode 100644 src/main/java/buttondevteam/presents/components/townyfactions/TownyFactionsComponent.java diff --git a/plugin.yml b/plugin.yml index 77ab901..d2e613f 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,15 +1,17 @@ -main: buttondevteam.presents.ButtonPresents -name: ButtonPresents -version: 0.0.1 - -commands: - dictionary: - description: A set of Hello World commands and listeners, type in /hello to see subcommands - rtp: - description: A command that allows players to randomly teleport across the map - spawn: - description: A set of commands designed to be used in spawn - magic: - description: A set of fun commands designed for cheaty stuff - research: - description: A set of commands designed for R and D \ No newline at end of file +main: buttondevteam.presents.ButtonPresents +name: ButtonPresents +version: 0.0.1 + +commands: + dictionary: + description: A set of Hello World commands and listeners, type in /hello to see subcommands + rtp: + description: A command that allows players to randomly teleport across the map + spawn: + description: A set of commands designed to be used in spawn + magic: + description: A set of fun commands designed for cheaty stuff + research: + description: A set of commands designed for R and D + +softdepend: [Factions] diff --git a/pom.xml b/pom.xml index 04e47c4..aa3ffa1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,86 +1,105 @@ - - 4.0.0 - - com.github.tbmcplugins - ButtonPresents - 0.0.1-SNAPSHOT - jar - - ButtonPresents - http://maven.apache.org - - - UTF-8 - - - - - src - - **/*.java - - - - . - - *.yml - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.0 - - 1.8 - 1.8 - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - jcenter - http://jcenter.bintray.com - - - jitpack.io - https://jitpack.io - - - - - - org.apache.commons - commons-lang3 - 3.5 - - - org.spigotmc - spigot - 1.12.2-R0.1-SNAPSHOT - - - com.github.TBMCPlugins.ButtonCore - ButtonCore - master-SNAPSHOT - - - com.github.tbmcplugins - ButtonWebsiteModule - master-SNAPSHOT - - - junit - junit - 3.8.1 - test - - - + + 4.0.0 + + com.github.tbmcplugins + ButtonPresents + 0.0.1-SNAPSHOT + jar + + ButtonPresents + http://maven.apache.org + + + UTF-8 + + + + + src + + **/*.java + + + + . + + *.yml + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.8 + 1.8 + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + jcenter + http://jcenter.bintray.com + + + jitpack.io + https://jitpack.io + + + repo + file://${basedir}/repo + + + + + + org.apache.commons + commons-lang3 + 3.5 + + + org.spigotmc + spigot + 1.12.2-R0.1-SNAPSHOT + + + com.github.TBMCPlugins.ButtonCore + ButtonCore + master-SNAPSHOT + + + com.github.tbmcplugins + ButtonWebsiteModule + master-SNAPSHOT + + + com.massivecraft + Factions + 2.14.0 + + + com.massivecraft + MassiveCore + 2.14.0 + + + com.github.TBMCPlugins.ButtonCore + Towny + master-SNAPSHOT + + + junit + junit + 3.8.1 + test + + + diff --git a/repo/com/massivecraft/Factions/2.14.0/Factions-2.14.0.pom b/repo/com/massivecraft/Factions/2.14.0/Factions-2.14.0.pom new file mode 100644 index 0000000..51f1166 --- /dev/null +++ b/repo/com/massivecraft/Factions/2.14.0/Factions-2.14.0.pom @@ -0,0 +1,10 @@ + + + 4.0.0 + com.massivecraft + Factions + 2.14.0 + POM was created from install:install-file + diff --git a/repo/com/massivecraft/Factions/maven-metadata-local.xml b/repo/com/massivecraft/Factions/maven-metadata-local.xml new file mode 100644 index 0000000..4379776 --- /dev/null +++ b/repo/com/massivecraft/Factions/maven-metadata-local.xml @@ -0,0 +1,12 @@ + + + com.massivecraft + Factions + + 2.14.0 + + 2.14.0 + + 20190824204629 + + diff --git a/repo/com/massivecraft/MassiveCore/2.14.0/MassiveCore-2.14.0.pom b/repo/com/massivecraft/MassiveCore/2.14.0/MassiveCore-2.14.0.pom new file mode 100644 index 0000000..e79c625 --- /dev/null +++ b/repo/com/massivecraft/MassiveCore/2.14.0/MassiveCore-2.14.0.pom @@ -0,0 +1,10 @@ + + + 4.0.0 + com.massivecraft + MassiveCore + 2.14.0 + POM was created from install:install-file + diff --git a/repo/com/massivecraft/MassiveCore/maven-metadata-local.xml b/repo/com/massivecraft/MassiveCore/maven-metadata-local.xml new file mode 100644 index 0000000..4d6cf23 --- /dev/null +++ b/repo/com/massivecraft/MassiveCore/maven-metadata-local.xml @@ -0,0 +1,12 @@ + + + com.massivecraft + MassiveCore + + 2.14.0 + + 2.14.0 + + 20190824204534 + + diff --git a/src/main/java/buttondevteam/presents/ButtonPresents.java b/src/main/java/buttondevteam/presents/ButtonPresents.java index 65be054..e6451ef 100644 --- a/src/main/java/buttondevteam/presents/ButtonPresents.java +++ b/src/main/java/buttondevteam/presents/ButtonPresents.java @@ -1,10 +1,12 @@ package buttondevteam.presents; +import buttondevteam.lib.architecture.Component; import buttondevteam.presents.components.chunkarchive.ChunkArchiveComponent; import buttondevteam.presents.components.magic.MagicComponent; import buttondevteam.presents.components.research.ResearchComponent; import buttondevteam.presents.components.research.dictionary.DictionaryComponent; import buttondevteam.presents.components.spawn.SpawnComponent; +import buttondevteam.presents.components.townyfactions.TownyFactionsComponent; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; @@ -17,13 +19,18 @@ public class ButtonPresents extends JavaPlugin{ Logger logger = getLogger(); logger.info(pdfFile.getName() + " has been started (V." + pdfFile.getVersion()+ ")."); - - - new DictionaryComponent().register(this); - new SpawnComponent().register(this); - new MagicComponent().register(this); - new ResearchComponent().register(this); - new ChunkArchiveComponent().register(this); + + + Component.registerComponent(this, new DictionaryComponent()); + Component.registerComponent(this, new SpawnComponent()); + Component.registerComponent(this, new MagicComponent()); + Component.registerComponent(this, new ResearchComponent()); + try { + Component.registerComponent(this, new ChunkArchiveComponent()); + } catch (NoClassDefFoundError e) { + getLogger().warning("ChunkArchive compatibility error, not registering it."); + } + Component.registerComponent(this, new TownyFactionsComponent()); logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ")."); } diff --git a/src/main/java/buttondevteam/presents/StaticMain.java b/src/main/java/buttondevteam/presents/StaticMain.java index 2b8d7b3..4c589f2 100644 --- a/src/main/java/buttondevteam/presents/StaticMain.java +++ b/src/main/java/buttondevteam/presents/StaticMain.java @@ -1,14 +1,24 @@ package buttondevteam.presents; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - public class StaticMain { public static void main(String[] args){ - GsonBuilder builder = new GsonBuilder(); + /*GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create(); - System.out.println(gson.toJson(new output())); + System.out.println(gson.toJson(new output()));*/ + + int distance = 5; + for (int i = -distance; i <= distance; i++) { + for (int j = -distance; j <= distance; j++) { + //if(i*i+j*j<=distance*distance) { + double dist = Math.sqrt(Math.pow((double) (i), 2.0D) + Math.pow((double) (j), 2.0D)); + if (dist < distance) { + System.out.print("X"); + } else + System.out.print("-"); + } + System.out.println(); + } } static class output{ public String ali = "pls"; diff --git a/src/main/java/buttondevteam/presents/architecture/Component.java b/src/main/java/buttondevteam/presents/architecture/Component.java deleted file mode 100644 index 9d6d055..0000000 --- a/src/main/java/buttondevteam/presents/architecture/Component.java +++ /dev/null @@ -1,76 +0,0 @@ -package buttondevteam.presents.architecture; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.event.Listener; -import org.bukkit.plugin.java.JavaPlugin; - -import buttondevteam.lib.TBMCCoreAPI; -import buttondevteam.lib.chat.TBMCChatAPI; -import buttondevteam.lib.chat.TBMCCommandBase; -import buttondevteam.website.ButtonWebsiteModule; -import buttondevteam.website.page.Page; - -/** - * A Module class allows the compacting of projects into one single package. - * - * Each feature can have its commands and listeners coded into the Module class, - * as well as any other pointers to memory units, or other classes in the package. - * - * This package can then be moved from eclipse project to eclipse project smoothly, - * as long as the destination project has the Module abstract class, and as long as all dependencies are either - * contained in the moved package, or moved along with it. - * @author Alisolarflare - * - */ -public abstract class Component{ - /** - * Registers the module, when called by the JavaPlugin class. Call - * registerCommand() and registerListener() within this method. - * - * @param plugin Plugin class called to register commands and listeners - */ - public abstract void register(JavaPlugin plugin); - /** - * Registers a TBMCCommand to the plugin - * @param plugin Main plugin responsible for stuff - * @param label Name of the command in plugin.yml - * @param commandExecutor Custom coded CommandExecutor class - */ - protected void registerCommand(JavaPlugin plugin, TBMCCommandBase commandBase){ - TBMCChatAPI.AddCommand(plugin, commandBase); - //plugin.getCommand(commandBase.getClass().getSimpleName().toString()).setExecutor(commandBase); - } - /** - * Registers a Listener to this plugin - * @param plugin Main plugin responsible for stuff - * @param label Name of the command in plugin.yml - * @param commandExecutor Custom coded CommandExecutor class - */ - protected Listener registerListener(JavaPlugin plugin, Listener listener){ - TBMCCoreAPI.RegisterEventsForExceptions(listener, plugin); - return listener; - } - protected Page addPage(JavaPlugin plugin, Page page){ - ButtonWebsiteModule.addPage(page); - return page; - } - - public void saveData(FileConfiguration config, String pathToData, Object data){ - config.set("moduledata." + this.getClassName() + "." + pathToData, data); - } - public Object getData(FileConfiguration config, String pathToData, Object data){ - return config.get("moduledata." + this.getClassName() + "." + pathToData, data); - } - - public String getClassName(){ - Class enclosingClass = getClass().getEnclosingClass(); - String className = "nullModule"; - if (enclosingClass != null) { - className = (enclosingClass.getName()); - } else { - className = (getClass().getName()); - } - return className; - } - -} diff --git a/src/main/java/buttondevteam/presents/components/chunkarchive/ChunkArchiveComponent.java b/src/main/java/buttondevteam/presents/components/chunkarchive/ChunkArchiveComponent.java index 19cdff7..63fcd63 100644 --- a/src/main/java/buttondevteam/presents/components/chunkarchive/ChunkArchiveComponent.java +++ b/src/main/java/buttondevteam/presents/components/chunkarchive/ChunkArchiveComponent.java @@ -1,7 +1,8 @@ package buttondevteam.presents.components.chunkarchive; import buttondevteam.lib.TBMCCoreAPI; -import buttondevteam.presents.architecture.Component; +import buttondevteam.lib.architecture.Component; +import buttondevteam.presents.ButtonPresents; import net.minecraft.server.v1_12_R1.ChunkRegionLoader; import net.minecraft.server.v1_12_R1.ExceptionWorldConflict; import org.bukkit.Bukkit; @@ -11,22 +12,21 @@ import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.world.ChunkPopulateEvent; -import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.io.IOException; import java.util.logging.Logger; // @formatter:off -public class ChunkArchiveComponent extends Component implements Listener { +public class ChunkArchiveComponent extends Component implements Listener { private final File dataFolder = new File("plugins", "ChunkArchive"); @Override - public void register(JavaPlugin plugin) { + public void enable() { try { - this.registerListener(plugin, this); + this.registerListener(this); File testFolder = new File(dataFolder, "test"); testFolder.mkdirs(); - Logger logger = plugin.getLogger(); + Logger logger = getPlugin().getLogger(); logger.info("Starting chunk save test..."); ChunkRegionLoader testcrl = new ChunkRegionLoader(testFolder, ((CraftServer) Bukkit.getServer()).getServer().dataConverterManager); @@ -39,6 +39,11 @@ public class ChunkArchiveComponent extends Component implements Listener { TBMCCoreAPI.SendException("ChunkArchive loading/testing failed!", e); } } + + @Override + protected void disable() { + + } /*------------------------------------------------------------*/ private final ChunkRegionLoader chunkRegionLoader = diff --git a/src/main/java/buttondevteam/presents/components/dungeon/DungeonComponent.java b/src/main/java/buttondevteam/presents/components/dungeon/DungeonComponent.java index 88c5502..295df29 100644 --- a/src/main/java/buttondevteam/presents/components/dungeon/DungeonComponent.java +++ b/src/main/java/buttondevteam/presents/components/dungeon/DungeonComponent.java @@ -1,16 +1,20 @@ package buttondevteam.presents.components.dungeon; -import org.bukkit.plugin.java.JavaPlugin; +import buttondevteam.lib.architecture.Component; +import buttondevteam.presents.ButtonPresents; -import buttondevteam.presents.architecture.Component; - -public class DungeonComponent extends Component{ +public class DungeonComponent extends Component { @Override - public void register(JavaPlugin plugin) { - this.registerCommand(plugin, new DungeonCreate()); - this.registerCommand(plugin, new DungeonDelete()); - + public void enable() { + this.registerCommand(new DungeonCreate()); + this.registerCommand(new DungeonDelete()); + } - + + @Override + protected void disable() { + + } + } diff --git a/src/main/java/buttondevteam/presents/components/magic/MagicComponent.java b/src/main/java/buttondevteam/presents/components/magic/MagicComponent.java index 64c17e3..923cf96 100644 --- a/src/main/java/buttondevteam/presents/components/magic/MagicComponent.java +++ b/src/main/java/buttondevteam/presents/components/magic/MagicComponent.java @@ -1,23 +1,25 @@ -package buttondevteam.presents.components.magic; - -import org.bukkit.plugin.java.JavaPlugin; - -import buttondevteam.presents.architecture.Component; -import buttondevteam.presents.components.magic.tricks.AliArrowListener; -import buttondevteam.presents.components.magic.tricks.BoomBowDeathListener; -import buttondevteam.presents.components.magic.tricks.BoomBowListener; -import buttondevteam.presents.components.magic.tricks.CannonBowListener; -import buttondevteam.presents.components.magic.tricks.CannonBowSettings; - - -public class MagicComponent extends Component{ - - @Override - public void register(JavaPlugin plugin) { - registerCommand(plugin, new CannonBowSettings()); - registerListener(plugin, new AliArrowListener(plugin)); - registerListener(plugin, new BoomBowDeathListener()); - registerListener(plugin, new BoomBowListener(plugin)); - registerListener(plugin, new CannonBowListener(plugin)); - } -} +package buttondevteam.presents.components.magic; + +import buttondevteam.lib.architecture.Component; +import buttondevteam.presents.ButtonPresents; +import buttondevteam.presents.components.magic.tricks.*; +import org.bukkit.plugin.java.JavaPlugin; + + +public class MagicComponent extends Component { + + @Override + public void enable() { + JavaPlugin plugin = getPlugin(); + registerCommand(new CannonBowSettings()); + registerListener(new AliArrowListener(plugin)); + registerListener(new BoomBowDeathListener()); + registerListener(new BoomBowListener(plugin)); + registerListener(new CannonBowListener(plugin)); + } + + @Override + protected void disable() { + + } +} diff --git a/src/main/java/buttondevteam/presents/components/research/ResearchComponent.java b/src/main/java/buttondevteam/presents/components/research/ResearchComponent.java index 08a1d28..0a2ab37 100644 --- a/src/main/java/buttondevteam/presents/components/research/ResearchComponent.java +++ b/src/main/java/buttondevteam/presents/components/research/ResearchComponent.java @@ -1,22 +1,26 @@ package buttondevteam.presents.components.research; -import org.bukkit.plugin.java.JavaPlugin; - -import buttondevteam.presents.architecture.Component; +import buttondevteam.lib.architecture.Component; +import buttondevteam.presents.ButtonPresents; import buttondevteam.presents.components.research.questions.OverflowCrash; import buttondevteam.presents.components.research.questions.OverwhelmCrash; import buttondevteam.presents.components.research.questions.PluginConfigInfo; import buttondevteam.presents.components.research.questions.PluginDataFolderInfo; -public class ResearchComponent extends Component { +public class ResearchComponent extends Component { @Override - public void register(JavaPlugin plugin) { + public void enable() { // TODO Auto-generated method stub - this.registerCommand(plugin, new PluginConfigInfo()); - this.registerCommand(plugin, new PluginDataFolderInfo()); - this.registerCommand(plugin, new OverwhelmCrash()); - this.registerCommand(plugin, new OverflowCrash()); + this.registerCommand(new PluginConfigInfo()); + this.registerCommand(new PluginDataFolderInfo()); + this.registerCommand(new OverwhelmCrash()); + this.registerCommand(new OverflowCrash()); + + } + + @Override + protected void disable() { } diff --git a/src/main/java/buttondevteam/presents/components/research/dictionary/DictionaryComponent.java b/src/main/java/buttondevteam/presents/components/research/dictionary/DictionaryComponent.java index 0fb7a16..14df597 100644 --- a/src/main/java/buttondevteam/presents/components/research/dictionary/DictionaryComponent.java +++ b/src/main/java/buttondevteam/presents/components/research/dictionary/DictionaryComponent.java @@ -1,51 +1,46 @@ package buttondevteam.presents.components.research.dictionary; -import org.bukkit.plugin.java.JavaPlugin; - -import buttondevteam.presents.architecture.Component; +import buttondevteam.lib.architecture.Component; +import buttondevteam.presents.ButtonPresents; import buttondevteam.presents.components.research.dictionary.commands.SendJSON; import buttondevteam.presents.components.research.dictionary.commands.SendMessage; import buttondevteam.presents.components.research.dictionary.config.LoadConfig; import buttondevteam.presents.components.research.dictionary.config.SaveConfig; import buttondevteam.presents.components.research.dictionary.config.TimePersistence; import buttondevteam.presents.components.research.dictionary.effects.Bedsplode; -import buttondevteam.presents.components.research.dictionary.pages.DataPage; -import buttondevteam.presents.components.research.dictionary.pages.HelloPage; -import buttondevteam.presents.components.research.dictionary.pages.JSONPage; -import buttondevteam.presents.components.research.dictionary.pages.LocationPage; -import buttondevteam.presents.components.research.dictionary.pages.POSTPage; -import buttondevteam.presents.components.research.dictionary.pages.PlayersOnlinePage; -import buttondevteam.presents.components.research.dictionary.spawning.PlaySound; -import buttondevteam.presents.components.research.dictionary.spawning.SetBlock; -import buttondevteam.presents.components.research.dictionary.spawning.SpawnCow; -import buttondevteam.presents.components.research.dictionary.spawning.SpawnItem; -import buttondevteam.presents.components.research.dictionary.spawning.SpawnMagicPotato; -import buttondevteam.presents.components.research.dictionary.spawning.SpawnParticle; +import buttondevteam.presents.components.research.dictionary.spawning.*; +import org.bukkit.plugin.java.JavaPlugin; -public class DictionaryComponent extends Component{ +public class DictionaryComponent extends Component { @Override - public void register(JavaPlugin plugin) { - - this.registerCommand(plugin, new SendMessage()); - this.registerCommand(plugin, new SendJSON()); - this.registerCommand(plugin, new SaveConfig()); - this.registerCommand(plugin, new LoadConfig()); - this.registerCommand(plugin, new TimePersistence()); - - this.registerListener(plugin, new Bedsplode()); - this.registerCommand(plugin, new SpawnCow()); - this.registerCommand(plugin, new SpawnItem()); - this.registerCommand(plugin, new SpawnMagicPotato()); - this.registerCommand(plugin, new SetBlock()); - this.registerCommand(plugin, new SpawnParticle()); - this.registerCommand(plugin, new PlaySound()); - - this.addPage(plugin, new HelloPage()); - this.addPage(plugin, new DataPage()); - this.addPage(plugin, new PlayersOnlinePage(plugin)); - this.addPage(plugin, new LocationPage(plugin)); - this.addPage(plugin, new POSTPage(plugin)); - this.addPage(plugin, new JSONPage()); + public void enable() { + JavaPlugin plugin = getPlugin(); + + this.registerCommand(new SendMessage()); + this.registerCommand(new SendJSON()); + this.registerCommand(new SaveConfig()); + this.registerCommand(new LoadConfig()); + this.registerCommand(new TimePersistence()); + + this.registerListener(new Bedsplode()); + this.registerCommand(new SpawnCow()); + this.registerCommand(new SpawnItem()); + this.registerCommand(new SpawnMagicPotato()); + this.registerCommand(new SetBlock()); + this.registerCommand(new SpawnParticle()); + this.registerCommand(new PlaySound()); + + /*ButtonWebsiteModule.addPage(new HelloPage()); + ButtonWebsiteModule.addPage(new DataPage()); + ButtonWebsiteModule.addPage(new PlayersOnlinePage(plugin)); + ButtonWebsiteModule.addPage(new LocationPage(plugin)); + ButtonWebsiteModule.addPage(new POSTPage(plugin)); + ButtonWebsiteModule.addPage(new JSONPage());*/ + } + + @Override + protected void disable() { + } } diff --git a/src/main/java/buttondevteam/presents/components/spawn/SpawnComponent.java b/src/main/java/buttondevteam/presents/components/spawn/SpawnComponent.java index 69793bd..d4273b2 100644 --- a/src/main/java/buttondevteam/presents/components/spawn/SpawnComponent.java +++ b/src/main/java/buttondevteam/presents/components/spawn/SpawnComponent.java @@ -1,15 +1,18 @@ package buttondevteam.presents.components.spawn; -import org.bukkit.plugin.java.JavaPlugin; +import buttondevteam.lib.architecture.Component; +import buttondevteam.presents.ButtonPresents; -import buttondevteam.presents.architecture.Component; - -public class SpawnComponent extends Component{ +public class SpawnComponent extends Component { @Override - public void register(JavaPlugin plugin) { - this.registerCommand(plugin, new ChooseColor()); - + public void enable() { + this.registerCommand(new ChooseColor()); + } + + @Override + protected void disable() { + } } diff --git a/src/main/java/buttondevteam/presents/components/townyfactions/TownyFactionsComponent.java b/src/main/java/buttondevteam/presents/components/townyfactions/TownyFactionsComponent.java new file mode 100644 index 0000000..f09e221 --- /dev/null +++ b/src/main/java/buttondevteam/presents/components/townyfactions/TownyFactionsComponent.java @@ -0,0 +1,89 @@ +package buttondevteam.presents.components.townyfactions; + +import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.architecture.ConfigData; +import buttondevteam.presents.ButtonPresents; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.event.EventFactionsChunksChange; +import com.massivecraft.massivecore.ps.PS; +import com.palmergames.bukkit.towny.event.TownPreClaimEvent; +import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; +import com.palmergames.bukkit.towny.object.Coord; +import com.palmergames.bukkit.towny.object.TownyUniverse; +import com.palmergames.bukkit.towny.object.WorldCoord; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class TownyFactionsComponent extends Component implements Listener { + @Override + public void enable() { + registerListener(this); + } + + @Override + protected void disable() { + + } + + /** + * Defines how many chunks should be between towns and factions + */ + private ConfigData distance() { + return getConfig().getData("distance", 5); + } + + @EventHandler + public void onFactionsClaim(EventFactionsChunksChange event) throws NotRegisteredException { + if (event.getNewFaction().isNone()) + return; //Allow unclaiming + for (PS chunk : event.getChunks()) { + int x = chunk.getChunkX() * 16; + int z = chunk.getChunkZ() * 16; + int size = Coord.getCellSize(); + int amount = size / 16; + World world = chunk.asBukkitWorld(); + int max = 0; + for (int i = 0; i < amount; i++) { + for (int j = 0; j < amount; j++) { + Coord coord = Coord.parseCoord(new Location(world, x + i * size, 64, z + j * size)); + int dist = TownyUniverse.getDataSource().getWorld(world.getName()) + .getMinDistanceFromOtherTownsPlots(coord); + if (dist > max) max = dist; + } + } + int distance = max * amount; + if (distance().get() >= distance) { + event.setCancelled(true); + event.getSender().sendMessage("§cYou are too close to a town!"); + } + } + } + + @EventHandler + public void onTownyClaim(TownPreClaimEvent event) { + PS chunkCoord = PS.valueOf(getLocation(event.getTownBlock().getWorldCoord())).getChunkCoords(true); + int distance = distance().get(); + for (int i = -distance; i <= distance; i++) { + for (int j = -distance; j <= distance; j++) { + if (i * i + j * j <= distance * distance) { + PS chunk = PS.valueOf(chunkCoord.getChunkX() + i, chunkCoord.getChunkZ() + j) + .withWorld(chunkCoord.getWorld()); //TODO: Doesn't have the world for some reason + if (!BoardColl.get().getFactionAt(chunk).isNone()) { + event.setCancelled(true); + } + } + } + } + } + + //https://github.com/TownyAdvanced/Towny/blob/master/src/com/palmergames/bukkit/towny/tasks/DrawSmokeTask.java + + private Location getLocation(WorldCoord coord) { //Based on parseCoord() - needfix would be always false because the remainder is 0 + int cellSize = Coord.getCellSize(); + int xresult = coord.getX() * cellSize; + int zresult = coord.getZ() * cellSize; + return new Location(coord.getBukkitWorld(), xresult, 64, zresult); + } +} diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml index 77ab901..d2e613f 100644 --- a/target/classes/plugin.yml +++ b/target/classes/plugin.yml @@ -1,15 +1,17 @@ -main: buttondevteam.presents.ButtonPresents -name: ButtonPresents -version: 0.0.1 - -commands: - dictionary: - description: A set of Hello World commands and listeners, type in /hello to see subcommands - rtp: - description: A command that allows players to randomly teleport across the map - spawn: - description: A set of commands designed to be used in spawn - magic: - description: A set of fun commands designed for cheaty stuff - research: - description: A set of commands designed for R and D \ No newline at end of file +main: buttondevteam.presents.ButtonPresents +name: ButtonPresents +version: 0.0.1 + +commands: + dictionary: + description: A set of Hello World commands and listeners, type in /hello to see subcommands + rtp: + description: A command that allows players to randomly teleport across the map + spawn: + description: A set of commands designed to be used in spawn + magic: + description: A set of fun commands designed for cheaty stuff + research: + description: A set of commands designed for R and D + +softdepend: [Factions]