use of simplepets.brainsynder.pet.TypeManager in project SimplePets by brainsynder-Dev.
the class PetOwner method getOwnedPetList.
public List<PetDefault> getOwnedPetList() {
List<PetDefault> list = new ArrayList<>();
if (!ownedPets.isEmpty()) {
TypeManager manager = PetCore.get().getTypeManager();
ownedPets.forEach(o -> {
PetDefault type = manager.getType(String.valueOf(o));
if (type != null)
list.add(type);
});
}
return list;
}
use of simplepets.brainsynder.pet.TypeManager in project SimplePets by brainsynder-Dev.
the class PetCore method reload.
public void reload(int type) {
needsPermissions = configuration.getBoolean("Needs-Permission");
needsDataPermissions = configuration.getBoolean("Needs-Data-Permissions");
if ((type == 0) || (type == 2)) {
if (typeManager != null) {
typeManager.unLoad();
typeManager = null;
}
typeManager = new TypeManager(this);
}
if ((type == 1) || (type == 2)) {
if (getConfiguration().isSet("MySQL.Enabled")) {
if (!getConfiguration().getBoolean("MySQL.Enabled"))
return;
String host = getConfiguration().getString("MySQL.Host", false);
String port = getConfiguration().getString("MySQL.Port", false);
String databaseName = getConfiguration().getString("MySQL.DatabaseName", false);
String username = getConfiguration().getString("MySQL.Login.Username", false);
String password = getConfiguration().getString("MySQL.Login.Password", false);
mySQL = new MySQL(host, port, databaseName, username, password);
CompletableFuture.runAsync(() -> {
try (Connection connection = mySQL.getSource().getConnection()) {
connection.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS `SimplePets` (`UUID` TEXT,`name` TEXT,`UnlockedPets` MEDIUMTEXT,`PetName` TEXT,`NeedsRespawn` MEDIUMTEXT);");
if (!mySQL.hasColumn(connection, "SavedPets"))
mySQL.addColumn(connection, "SavedPets", "LONGTEXT");
} catch (Exception e) {
debug("Unable to create default SQL tables Error:");
e.printStackTrace();
}
});
}
}
}
use of simplepets.brainsynder.pet.TypeManager in project SimplePets by brainsynder-Dev.
the class List_SubCommand method run.
@Override
public void run(CommandSender sender) {
TypeManager manager = PetCore.get().getTypeManager();
Commands commands = PetCore.get().getCommands();
String list = commands.getString("List.List-Display").replace("%size%", String.valueOf(manager.getTypes().size()));
sender.sendMessage(list.substring(0, list.lastIndexOf("%list%")));
if (list.contains("%list%"))
fetchList(sender, commands, manager);
// Checks if anything is after the '%list%' placeholder
String after = list.substring(list.indexOf("%list%") + 6);
if (!after.trim().isEmpty())
sender.sendMessage(after);
}
use of simplepets.brainsynder.pet.TypeManager in project SimplePets by brainsynder-Dev.
the class PetCommand method run.
@Override
public void run(CommandSender sender, String[] args) {
if (args.length == 0) {
if (sender instanceof Player) {
Player p = (Player) sender;
if (args.length == 0) {
PetCore.get().getInvLoaders().SELECTION.open(PetOwner.getPetOwner(p));
} else {
TypeManager manager = PetCore.get().getTypeManager();
PetDefault type = manager.getType(args[0]);
if (type == null) {
sender.sendMessage(PetCore.get().getMessages().getString("Invalid-PetType", true));
return;
}
if (!type.isSupported()) {
sender.sendMessage(PetCore.get().getMessages().getString("Type-Not-Supported", true));
return;
}
if (!type.isEnabled()) {
sender.sendMessage(PetCore.get().getMessages().getString("Type-Not-Enabled", true));
return;
}
if (!type.hasPermission(p)) {
p.sendMessage(PetCore.get().getMessages().getString("No-Permission", true));
return;
}
PetCommandSummonEvent event = new PetCommandSummonEvent(type, p);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
p.sendMessage(PetCore.get().getMessages().getString("Select-Pet", true).replace("%pet%", type.getDisplayName()));
type.setPet(p);
}
} else {
sendHelp(sender, false);
}
}
}
use of simplepets.brainsynder.pet.TypeManager in project SimplePets by brainsynder-Dev.
the class PetCore method onEnable.
public void onEnable() {
Utilities.findDelay(getClass(), "startup", false);
instance = this;
if (!errorCheck()) {
setEnabled(false);
return;
}
Reflection.init();
Utilities.init();
// ALERT THE OPS !!!
if (!Bukkit.getOnlinePlayers().isEmpty()) {
reloaded = true;
Errors.RELOAD_DETECTED.print();
Bukkit.getOnlinePlayers().forEach(player -> {
if (player.isOp()) {
player.sendMessage("§6[§eSimplePets§6] §7SimplePets has detected a reload, If §c§lANY§7 issues arise then please restart the server.");
}
});
}
typeManager = new TypeManager(this);
loadConfig();
createPluginInstances();
new VersionNMS().registerPets();
registerEvents();
int v = ServerVersion.getVersion().getIntVersion();
if ((v < 18) || (ServerVersion.getVersion() == ServerVersion.UNKNOWN)) {
debug("This version is not supported, be sure you are between 1.11 and 1.14");
setEnabled(false);
return;
}
itemLoaders.initiate();
invLoaders.initiate();
// Lets run this later, just to make sure WorldEdit is loaded
new BukkitRunnable() {
@Override
public void run() {
linkRetriever.initiate();
WorldEditLink.init();
}
}.runTaskLater(this, 20 * 10);
reloadSpawner();
spawner.init();
if (getConfiguration().isSet("MySQL.Enabled"))
handleSQL();
debug("Took " + Utilities.findDelay(getClass(), "startup", false) + "ms to load");
}
Aggregations