Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACF Command rework - Done! #210

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added lib/Multiverse-Core-5.0.0-ACF-BETA.jar
Binary file not shown.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.onarandombox.multiversenetherportals</groupId>
<artifactId>Multiverse-NetherPortals</artifactId>
<version>4.2.2-SNAPSHOT</version>
<version>5.0.0-ACF-BETA</version>
<name>Multiverse-NetherPortals</name>
<description>Multiverse Nether Portals module</description>
<properties>
Expand Down Expand Up @@ -155,9 +155,9 @@
<dependency>
<groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId>
<version>4.2.2</version>
<type>jar</type>
<scope>provided</scope>
<version>5.0.0-ACF-BETA</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Multiverse-Core-5.0.0-ACF-BETA.jar</systemPath>
</dependency>
<dependency>
<groupId>com.onarandombox.multiverseportals</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
package com.onarandombox.MultiverseNetherPortals;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;

import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVPlugin;
import com.onarandombox.MultiverseCore.commands.HelpCommand;
import com.onarandombox.MultiverseNetherPortals.commands.LinkCommand;
import com.onarandombox.MultiverseNetherPortals.commands.ShowLinkCommand;
import com.onarandombox.MultiverseNetherPortals.commands.UnlinkCommand;
import com.onarandombox.MultiverseNetherPortals.listeners.MVNPCoreListener;
import com.onarandombox.MultiverseNetherPortals.listeners.MVNPEntityListener;
import com.onarandombox.MultiverseNetherPortals.listeners.MVNPPlayerListener;
import com.onarandombox.MultiverseNetherPortals.listeners.MVNPPluginListener;
import com.onarandombox.MultiverseNetherPortals.utils.CommandTools;
import com.onarandombox.MultiversePortals.MultiversePortals;
import com.onarandombox.commandhandler.CommandHandler;
import org.bukkit.Location;
import org.bukkit.PortalType;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;

public class MultiverseNetherPortals extends JavaPlugin implements MVPlugin {

private static final String NETHER_PORTALS_CONFIG = "config.yml";
Expand All @@ -50,7 +42,6 @@ public class MultiverseNetherPortals extends JavaPlugin implements MVPlugin {
private String endSuffix = DEFAULT_END_SUFFIX;
private Map<String, String> linkMap;
private Map<String, String> endLinkMap;
protected CommandHandler commandHandler;
private final static int requiresProtocol = 24;
private MVNPEntityListener entityListener;

Expand Down Expand Up @@ -92,7 +83,9 @@ public void onEnable() {
pm.registerEvents(this.customListener, this);

loadConfig();
this.registerCommands();

// Setup commands
new CommandTools(this);

Logging.log(true, Level.INFO, " Enabled - By %s", getAuthors());
}
Expand Down Expand Up @@ -164,30 +157,6 @@ private void initMVNPConfig() {
}
}

/** Register commands to Multiverse's CommandHandler so we get a super sexy single menu */
private void registerCommands() {
this.commandHandler = this.core.getCommandHandler();
this.commandHandler.registerCommand(new LinkCommand(this));
this.commandHandler.registerCommand(new UnlinkCommand(this));
this.commandHandler.registerCommand(new ShowLinkCommand(this));
for (com.onarandombox.commandhandler.Command c : this.commandHandler.getAllCommands()) {
if (c instanceof HelpCommand) {
c.addKey("mvnp");
}
}
}

@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if (!this.isEnabled()) {
sender.sendMessage("This plugin is Disabled!");
return true;
}
ArrayList<String> allArgs = new ArrayList<String>(Arrays.asList(args));
allArgs.add(0, command.getName());
return this.commandHandler.locateAndRunCommand(sender, allArgs);
}

@Override
public void onDisable() {
Logging.info("- Disabled");
Expand Down Expand Up @@ -262,21 +231,20 @@ public boolean addWorldLink(String from, String to, PortalType type) {
}

this.MVNPConfiguration.set("worlds." + from + ".portalgoesto." + type, to);
this.saveMVNPConfig();
return true;
return this.saveMVNPConfig();
}

public void removeWorldLink(String from, String to, PortalType type) {
public boolean removeWorldLink(String from, String to, PortalType type) {
if (type == PortalType.NETHER) {
this.linkMap.remove(from);
} else if (type == PortalType.ENDER) {
this.endLinkMap.remove(from);
} else {
return;
return false;
}

this.MVNPConfiguration.set("worlds." + from + ".portalgoesto." + type, null);
this.saveMVNPConfig();
return this.saveMVNPConfig();
}

public boolean saveMVNPConfig() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,91 +1,71 @@
package com.onarandombox.MultiverseNetherPortals.commands;

import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals;
import com.onarandombox.acf.InvalidCommandArgument;
import com.onarandombox.acf.annotation.CommandAlias;
import com.onarandombox.acf.annotation.CommandCompletion;
import com.onarandombox.acf.annotation.CommandPermission;
import com.onarandombox.acf.annotation.Description;
import com.onarandombox.acf.annotation.Flags;
import com.onarandombox.acf.annotation.Optional;
import com.onarandombox.acf.annotation.Subcommand;
import com.onarandombox.acf.annotation.Syntax;
import org.bukkit.ChatColor;
import org.bukkit.PortalType;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;

import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@CommandAlias("mvnp")
public class LinkCommand extends NetherPortalCommand {
private MVWorldManager worldManager;

public LinkCommand(MultiverseNetherPortals plugin) {
super(plugin);
this.setName("Sets NP Destination");
this.setCommandUsage("/mvnp link " + ChatColor.GREEN + "{end|nether} " + ChatColor.GOLD + "[FROM_WORLD] " + ChatColor.GREEN + " {TO_WORLD}");
this.setArgRange(2, 3);
this.addKey("mvnp link");
this.addKey("mvnpl");
this.addKey("mvnplink");
this.addCommandExample("/mvnp link end world world_nether");
this.addCommandExample("/mvnp link end world_nether");
this.setPermission("multiverse.netherportals.link", "Sets which world to link to when a player enters a NetherPortal in this world.", PermissionDefault.OP);
this.worldManager = this.plugin.getCore().getMVWorldManager();
}

@Override
public void runCommand(CommandSender sender, List<String> args) {
if (!(sender instanceof Player) && args.size() == 2) {
sender.sendMessage("From the command line, FROM_WORLD is required");
sender.sendMessage("No changes were made...");
return;
}
@Subcommand("link")
@CommandPermission("multiverse.netherportals.link")
@Syntax("<nether|end> [fromWorld] <toWorld>")
@CommandCompletion("@linkTypes @MVWorlds @MVWorlds")
@Description("Sets which world to link to when a player enters a NetherPortal in this world.")
public void onLinkCommand(@NotNull CommandSender sender,
@Nullable @Optional MultiverseWorld playerWorld,

MultiverseWorld fromWorld;
MultiverseWorld toWorld;
String fromWorldString;
String toWorldString;
PortalType type;
Player p;
@Syntax("<nether|end>")
@Description("Portal type to link.")
@NotNull PortalType linkType,

if (args.get(0).equalsIgnoreCase("END")) {
type = PortalType.ENDER;
} else if (args.get(0).equalsIgnoreCase("NETHER")) {
type = PortalType.NETHER;
} else {
type = null;
}
@Syntax("[fromWorld]")
@Description("World the portals are at.")
@NotNull @Flags("other") MultiverseWorld fromWorld,

if (args.size() == 2) {
p = (Player) sender;
fromWorldString = p.getWorld().getName();
toWorldString = args.get(1);
} else {
fromWorldString = args.get(1);
toWorldString = args.get(2);
}
@Syntax("<toWorld>")
@Description("World the portals should teleport to.")
@Nullable @Optional @Flags("other") MultiverseWorld toWorld) {

if (type == null) {
sender.sendMessage("The type must either be 'end' or 'nether'");
return;
if (toWorld == null && playerWorld == null) {
throw new InvalidCommandArgument("You need to specify a toWorld.");
}

fromWorld = this.worldManager.getMVWorld(fromWorldString);
toWorld = this.worldManager.getMVWorld(toWorldString);

if (fromWorld == null) {
this.plugin.getCore().showNotMVWorldMessage(sender, fromWorldString);
return;
}
if (toWorld == null) {
this.plugin.getCore().showNotMVWorldMessage(sender, toWorldString);
return;
toWorld = fromWorld;
fromWorld = playerWorld;
}

if (!this.plugin.addWorldLink(fromWorld.getName(), toWorld.getName(), linkType)) {
throw new InvalidCommandArgument("There was an error creating the link! See console for more details.");
}

this.plugin.addWorldLink(fromWorld.getName(), toWorld.getName(), type);
String coloredFrom = fromWorld.getColoredWorldString();
String coloredTo = toWorld.getColoredWorldString();
if (fromWorld.getName().equals(toWorld.getName())) {
sender.sendMessage(ChatColor.RED + "NOTE: " + ChatColor.WHITE + "You have successfully disabled " + type.toString() + " Portals in " + coloredTo);
} else {
sender.sendMessage("The " + type + " portals in " + coloredFrom + ChatColor.WHITE + " are now linked to " + coloredTo);
}

}
sender.sendMessage((fromWorld.getName().equals(toWorld.getName()))

? String.format("%sNOTE: %sYou have %ssuccessfully disabled %s%s Portals in %s.",
ChatColor.RED, ChatColor.WHITE, ChatColor.GREEN, ChatColor.WHITE, linkType, coloredTo)

: String.format("The %s portals in %s%s are now linked to %s.",
linkType, coloredFrom, ChatColor.WHITE, coloredTo));
}
}
Loading