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

MV5 #514

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

MV5 #514

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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.onarandombox.multiverseinventories;

import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.MVWorld;
import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.multiverseinventories.profile.GlobalProfile;
Expand Down Expand Up @@ -389,7 +389,7 @@ private void handleRespawn(PlayerRespawnEvent event, EventPriority priority) {
if (group.getSpawnPriority().equals(priority)) {
String spawnWorldName = group.getSpawnWorld();
if (spawnWorldName != null) {
MultiverseWorld mvWorld = this.inventories.getCore()
MVWorld mvWorld = this.inventories.getCore()
.getMVWorldManager().getMVWorld(spawnWorldName);
if (mvWorld != null) {
this.spawnLoc = mvWorld.getSpawnLocation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
package com.onarandombox.multiverseinventories;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Locale;

import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVCore;
import com.onarandombox.MultiverseCore.api.MVPlugin;
import com.onarandombox.MultiverseCore.commands.HelpCommand;
import com.onarandombox.commandhandler.CommandHandler;
import com.onarandombox.multiverseinventories.locale.Message;
import com.onarandombox.multiverseinventories.locale.Messager;
import com.onarandombox.multiverseinventories.locale.Messaging;
import com.onarandombox.multiverseinventories.migration.ImportManager;
import com.onarandombox.multiverseinventories.profile.ProfileDataSource;
import com.onarandombox.multiverseinventories.profile.WorldGroupManager;
import com.onarandombox.multiverseinventories.profile.container.ContainerType;
import com.onarandombox.multiverseinventories.profile.container.ProfileContainerStore;
import com.onarandombox.multiverseinventories.share.Sharables;
import com.onarandombox.multiverseinventories.command.AddSharesCommand;
import com.onarandombox.multiverseinventories.command.AddWorldCommand;
import com.onarandombox.multiverseinventories.command.CreateGroupCommand;
import com.onarandombox.multiverseinventories.command.DeleteGroupCommand;
import com.onarandombox.multiverseinventories.command.GroupCommand;
import com.onarandombox.multiverseinventories.command.ImportCommand;
import com.onarandombox.multiverseinventories.command.InfoCommand;
import com.onarandombox.multiverseinventories.command.ListCommand;
import com.onarandombox.multiverseinventories.command.MigrateCommand;
import com.onarandombox.multiverseinventories.command.ReloadCommand;
import com.onarandombox.multiverseinventories.command.RemoveSharesCommand;
import com.onarandombox.multiverseinventories.command.RemoveWorldCommand;
import com.onarandombox.multiverseinventories.command.SpawnCommand;
import com.onarandombox.multiverseinventories.command.ToggleCommand;
import com.onarandombox.multiverseinventories.locale.Message;
import com.onarandombox.multiverseinventories.locale.Messager;
import com.onarandombox.multiverseinventories.locale.Messaging;
import com.onarandombox.multiverseinventories.migration.ImportManager;
import com.onarandombox.multiverseinventories.util.Perm;
import me.drayshak.WorldInventories.WorldInventories;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
Expand All @@ -41,25 +28,19 @@
import org.bukkit.plugin.java.JavaPluginLoader;
import uk.co.tggl.pluckerpluck.multiinv.MultiInv;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.logging.Level;

/**
* Multiverse-Inventories plugin main class.
*/
public class MultiverseInventories extends JavaPlugin implements MVPlugin, Messaging {

private static final int PROTOCOL = 50;

private static MultiverseInventories inventoriesPlugin;

public static MultiverseInventories getPlugin() {
return inventoriesPlugin;
}

private final int requiresProtocol = 22;
private final InventoriesListener inventoriesListener = new InventoriesListener(this);
private final AdventureListener adventureListener = new AdventureListener(this);

Expand All @@ -69,8 +50,7 @@ public static MultiverseInventories getPlugin() {
private ProfileContainerStore groupProfileContainerStore = null;
private ImportManager importManager = new ImportManager(this);

private CommandHandler commandHandler = null;
private MultiverseCore core = null;
private MVCore core = null;
private InventoriesConfig config = null;
private FlatFileProfileDataSource data = null;

Expand Down Expand Up @@ -101,49 +81,43 @@ public MultiverseInventories(JavaPluginLoader loader, PluginDescriptionFile desc
* {@inheritDoc}
*/
@Override
public void onDisable() {
for (final Player player : getServer().getOnlinePlayers()) {
final String world = player.getWorld().getName();
//getData().updateLastWorld(player.getName(), world);
if (getMVIConfig().usingLoggingSaveLoad()) {
ShareHandlingUpdater.updateProfile(this, player, new DefaultPersistingProfile(Sharables.allOf(),
getWorldProfileContainerStore().getContainer(world).getPlayerData(player)));
getData().setLoadOnLogin(player.getName(), true);
}
}

this.dupingPatch.disable();

Logging.shutdown();
public void onLoad() {
Logging.init(this);
this.getDataFolder().mkdirs();
}

/**
* {@inheritDoc}
*/
@Override
public void onEnable() {
Logging.init(this);
Perm.register(this);

MultiverseCore mvCore;
mvCore = (MultiverseCore) this.getServer().getPluginManager().getPlugin("Multiverse-Core");
// Test if the Core was found, if not we'll disable this plugin.
if (mvCore == null) {
Logging.severe("Multiverse-Core not found, disabling...");
public final void onEnable() {
this.core = (MVCore) this.getServer().getPluginManager().getPlugin("Multiverse-Core");
if (this.core == null) {
Logging.severe("Core not found! You must have Multiverse-Core installed to use this plugin!");
Logging.severe("Grab a copy at: ");
Logging.severe("https://dev.bukkit.org/projects/multiverse-core");
Logging.severe("Disabling!");
this.getServer().getPluginManager().disablePlugin(this);
return;
}
this.setCore(mvCore);

if (this.getCore().getProtocolVersion() < this.getRequiredProtocol()) {
if (this.core.getProtocolVersion() < this.getProtocolVersion()) {
Logging.severe("Your Multiverse-Core is OUT OF DATE");
Logging.severe("This version of Multiverse-Inventories requires Protocol Level: " + this.getRequiredProtocol());
Logging.severe("Your of Core Protocol Level is: " + this.getCore().getProtocolVersion());
Logging.severe("This version of " + this.getDescription().getName() + " requires Protocol Level: " + this.getProtocolVersion());
Logging.severe("Your of Core Protocol Level is: " + this.core.getProtocolVersion());
Logging.severe("Grab an updated copy at: ");
Logging.severe("http://bukkit.onarandombox.com/?dir=multiverse-core");
Logging.severe("https://dev.bukkit.org/projects/multiverse-core");
Logging.severe("Disabling!");
this.getServer().getPluginManager().disablePlugin(this);
return;
}
Logging.setDebugLevel(core.getMVConfig().getGlobalDebug());
this.core.incrementPluginCount();
this.onMVPluginEnable();
Logging.config("Version %s (API v%s) Enabled - By %s", this.getDescription().getVersion(), getProtocolVersion(), getAuthors());
}

private void onMVPluginEnable() {
Perm.register(this);

this.reloadConfig();

Expand All @@ -158,15 +132,12 @@ public void onEnable() {
// Initialize data class
//this.getWorldProfileContainerStore().setWorldProfiles(this.getData().getWorldProfiles());

Logging.setDebugLevel(getCore().getMVConfig().getGlobalDebug());

this.getCore().incrementPluginCount();

// Register Events
Bukkit.getPluginManager().registerEvents(inventoriesListener, this);
if (Bukkit.getPluginManager().getPlugin("Multiverse-Adventure") != null) {
Bukkit.getPluginManager().registerEvents(adventureListener, this);
}

if (getCore().getProtocolVersion() >= 24) {
new CoreDebugListener(this);
}
Expand All @@ -180,32 +151,31 @@ public void onEnable() {
Sharables.init(this);

this.dupingPatch = InventoriesDupingPatch.enableDupingPatch(this);

// Display enable message/version info
Logging.log(true, Level.INFO, "enabled.");
}

private void registerCommands() {
this.commandHandler = this.getCore().getCommandHandler();
this.getCommandHandler().registerCommand(new InfoCommand(this));
this.getCommandHandler().registerCommand(new ImportCommand(this));
this.getCommandHandler().registerCommand(new ListCommand(this));
this.getCommandHandler().registerCommand(new ReloadCommand(this));
this.getCommandHandler().registerCommand(new AddWorldCommand(this));
this.getCommandHandler().registerCommand(new RemoveWorldCommand(this));
this.getCommandHandler().registerCommand(new AddSharesCommand(this));
this.getCommandHandler().registerCommand(new RemoveSharesCommand(this));
this.getCommandHandler().registerCommand(new CreateGroupCommand(this));
this.getCommandHandler().registerCommand(new DeleteGroupCommand(this));
this.getCommandHandler().registerCommand(new SpawnCommand(this));
this.getCommandHandler().registerCommand(new GroupCommand(this));
this.getCommandHandler().registerCommand(new ToggleCommand(this));
this.getCommandHandler().registerCommand(new MigrateCommand(this));
for (com.onarandombox.commandhandler.Command c : this.commandHandler.getAllCommands()) {
if (c instanceof HelpCommand) {
c.addKey("mvinv");
/**
* {@inheritDoc}
*/
@Override
public void onDisable() {
for (final Player player : getServer().getOnlinePlayers()) {
final String world = player.getWorld().getName();
//getData().updateLastWorld(player.getName(), world);
if (getMVIConfig().usingLoggingSaveLoad()) {
ShareHandlingUpdater.updateProfile(this, player, new DefaultPersistingProfile(Sharables.allOf(),
getWorldProfileContainerStore().getContainer(world).getPlayerData(player)));
getData().setLoadOnLogin(player.getName(), true);
}
}

this.dupingPatch.disable();

this.core.decrementPluginCount();
Logging.shutdown();
}

private void registerCommands() {

}

private void hookImportables() {
Expand All @@ -231,71 +201,40 @@ public ImportManager getImportManager() {
* {@inheritDoc}
*/
@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.getCommandHandler().locateAndRunCommand(sender, allArgs);
}

private CommandHandler getCommandHandler() {
return this.commandHandler;
}

/**
* {@inheritDoc}
*/
@Override
public void log(Level level, String msg) {
Logging.log(level, msg);
}

/**
* {@inheritDoc}
*/
@Override
public MultiverseCore getCore() {
public MVCore getCore() {
return this.core;
}

/**
* {@inheritDoc}
*/
@Override
public void setCore(MultiverseCore core) {
this.core = core;
}

/**
* {@inheritDoc}
*/
@Override
public int getProtocolVersion() {
return 1;
return PROTOCOL;
}

/**
* {@inheritDoc}
*/
@Override
public String dumpVersionInfo(String buffer) {
buffer += logAndAddToPasteBinBuffer("=== Settings ===");
buffer += logAndAddToPasteBinBuffer("First Run: " + this.getMVIConfig().isFirstRun());
buffer += logAndAddToPasteBinBuffer("Using Bypass: " + this.getMVIConfig().isUsingBypass());
buffer += logAndAddToPasteBinBuffer("Default Ungrouped Worlds: " + this.getMVIConfig().isDefaultingUngroupedWorlds());
buffer += logAndAddToPasteBinBuffer("Save and Load on Log In and Out: " + this.getMVIConfig().usingLoggingSaveLoad());
buffer += logAndAddToPasteBinBuffer("Using GameMode Profiles: " + this.getMVIConfig().isUsingGameModeProfiles());
buffer += logAndAddToPasteBinBuffer("=== Shares ===");
buffer += logAndAddToPasteBinBuffer("Optionals for Ungrouped Worlds: " + this.getMVIConfig().usingOptionalsForUngrouped());
buffer += logAndAddToPasteBinBuffer("Enabled Optionals: " + this.getMVIConfig().getOptionalShares());
buffer += logAndAddToPasteBinBuffer("=== Groups ===");
for (WorldGroup group : this.getGroupManager().getGroups()) {
buffer += logAndAddToPasteBinBuffer(group.toString());
public String getAuthors() {
List<String> authorsList = this.getDescription().getAuthors();
if (authorsList.size() == 0) {
return "";
}

StringBuilder authors = new StringBuilder();
authors.append(authorsList.get(0));

for (int i = 1; i < authorsList.size(); i++) {
if (i == authorsList.size() - 1) {
authors.append(" and ").append(authorsList.get(i));
} else {
authors.append(", ").append(authorsList.get(i));
}
}
return buffer;

return authors.toString();
}

/**
Expand Down Expand Up @@ -413,13 +352,6 @@ public void setMessager(Messager messager) {
this.messager = messager;
}

/**
* @return The required protocol version of core.
*/
public int getRequiredProtocol() {
return this.requiresProtocol;
}

/**
* @return The World Group manager for this plugin.
*/
Expand Down
Loading
Loading