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

Schematic choice #411

Closed
wants to merge 4 commits into from
Closed
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BentoBox
========

[![Build Status](https://ci.codemc.org/buildStatus/icon?job=BentoBoxWorld/bentobox)](https://ci.codemc.org/job/BentoBoxWorld/job/bentobox/)
[![Build Status](https://ci.codemc.org/buildStatus/icon?job=BentoBoxWorld/BentoBox)](https://ci.codemc.org/job/BentoBoxWorld/job/BentoBox/)
![Lines Of Code](https://sonarcloud.io/api/project_badges/measure?project=world.bentobox%3Abentobox%3Adevelop&metric=ncloc)
![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=world.bentobox%3Abentobox%3Adevelop&metric=sqale_rating)
![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=world.bentobox%3Abentobox%3Adevelop&metric=reliability_rating)
Expand Down Expand Up @@ -31,21 +31,21 @@ Hereby, **you** and **only you** are wrong when you :

Bugs and Feature requests
=========================
File bug and feature requests here: https://github.com/BentoBoxWorld/bentobox/issues. Make sure that your issue is following the guidelines, otherwise it will be declined.
File bug and feature requests here: https://github.com/BentoBoxWorld/BentoBox/issues. Make sure that your issue is following the guidelines, otherwise it will be declined.

Note for developers
===================
We consider Pull Requests from non-collaborators that contain actual code improvements or bug fixes. Do not submit PRs that only address code formatting because they will not be accepted.

Official Builds
===============
https://github.com/BentoBoxWorld/bentobox/releases
https://github.com/BentoBoxWorld/BentoBox/releases

Development Builds
==================
**These development builds are not eligible to any kind of support. Use them at your own discretion or only under our approval.** *Most of them are __untested__. In the worst cases, they can even __corrupt your worlds and/or your databases__.*

Jenkins: https://ci.codemc.org/job/BentoBoxWorld/job/bentobox/
Jenkins: https://ci.codemc.org/job/BentoBoxWorld/job/BentoBox/

API
===
Expand All @@ -68,4 +68,4 @@ Maven dependency:
</dependencies>
```

You can find the javadoc here: https://ci.codemc.org/job/BentoBoxWorld/job/bentobox/javadoc/
You can find the javadoc here: https://ci.codemc.org/job/BentoBoxWorld/job/BentoBox/javadoc/
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>0.18.0</version>
<version>0.19.0-SNAPSHOT</version>

<name>BentoBox</name>
<description>Expandable Minecraft Spigot plugin for island-type games like SkyBlock or AcidIsland.</description>
<url>https://github.com/BentoBoxWorld/BentoBox</url>
<inceptionYear>2017</inceptionYear>

<scm>
<connection>scm:git:https://github.com/BentoBoxWorld/bentobox.git</connection>
<developerConnection>scm:git:[email protected]:BentoBoxWorld/bentobox.git</developerConnection>
<connection>scm:git:https://github.com/BentoBoxWorld/BentoBox.git</connection>
<developerConnection>scm:git:[email protected]:BentoBoxWorld/BentoBox.git</developerConnection>
<url>https://github.com/BentoBoxWorld/BentoBox</url>
</scm>

<ciManagement>
<system>jenkins</system>
<url>http://ci.codemc.org/job/BentoBoxWorld/job/bentobox</url>
<url>http://ci.codemc.org/job/BentoBoxWorld/job/BentoBox</url>
</ciManagement>

<issueManagement>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/world/bentobox/bentobox/api/addons/Addon.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,9 @@ public InputStream getResource(String jarResource) {
/**
* Set the file that contains this addon
*
* @param f
* the file to set
* @param f the file to set
*/
public void setAddonFile(File f) {
public void setFile(File f) {
file = f;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.IOException;
import java.util.List;
import java.util.Set;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.managers.island.NewIsland;

Expand All @@ -27,6 +29,7 @@ public IslandCreateCommand(CompositeCommand islandCommand) {
public void setup() {
setPermission("island.create");
setOnlyPlayer(true);
setParametersHelp("commands.island.create.parameters");
setDescription("commands.island.create.description");
}

Expand All @@ -45,11 +48,30 @@ && getIslands().getIslandCount(getWorld()) >= getIWM().getMaxIslands(getWorld())
}

user.sendMessage("commands.island.create.creating-island");
// Default schem is 'island'
String name = "island";
if (!args.isEmpty()) {
name = args.get(0).toLowerCase(java.util.Locale.ENGLISH);
// Permission check
String permission = this.getPermissionPrefix() + "island.create." + name;
if (!user.isOp() && !user.hasPermission(permission)) {
user.sendMessage("general.errors.no-permission", TextVariables.PERMISSION, permission);
return false;
}
// Check the schem name exists
Set<String> validNames = getPlugin().getSchemsManager().get(getWorld()).keySet();
if (!validNames.contains(name)) {
user.sendMessage("commands.island.create.unknown-schem");
return false;
}

}
try {
NewIsland.builder()
.player(user)
.world(getWorld())
.reason(Reason.CREATE)
.name(name)
.build();
return true;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Set;

import org.bukkit.GameMode;
import org.bukkit.entity.Player;
Expand All @@ -24,6 +25,7 @@ public IslandResetCommand(CompositeCommand islandCommand) {
public void setup() {
setPermission("island.create");
setOnlyPlayer(true);
setParametersHelp("commands.island.reset.parameters");
setDescription("commands.island.reset.description");
}

Expand Down Expand Up @@ -56,17 +58,35 @@ public boolean execute(User user, String label, List<String> args) {
user.sendMessage("commands.island.reset.resets-left", TextVariables.NUMBER, String.valueOf(resetsLeft));
}
}
// Default schem is 'island'

String name = args.isEmpty() ? "island" : args.get(0).toLowerCase(java.util.Locale.ENGLISH);
if (!args.isEmpty()) {
// Permission check
String permission = this.getPermissionPrefix() + "island.create." + name;
if (!user.isOp() && !user.hasPermission(permission)) {
user.sendMessage("general.errors.no-permission", TextVariables.PERMISSION, permission);
return false;
}
// Check the schem name exists
Set<String> validNames = getPlugin().getSchemsManager().get(getWorld()).keySet();
if (!validNames.contains(name)) {
user.sendMessage("commands.island.create.unknown-schem");
return false;
}

}
// Request confirmation
if (getSettings().isResetConfirmation()) {
this.askConfirmation(user, () -> resetIsland(user));
this.askConfirmation(user, () -> resetIsland(user, name));
return true;
} else {
return resetIsland(user);
return resetIsland(user, name);
}

}

private boolean resetIsland(User user) {
private boolean resetIsland(User user, String name) {
// Reset the island
Player player = user.getPlayer();
player.setGameMode(GameMode.SPECTATOR);
Expand All @@ -92,6 +112,7 @@ private boolean resetIsland(User user) {
.player(user)
.reason(Reason.RESET)
.oldIsland(oldIsland)
.name(name)
.build();
} catch (IOException e) {
getPlugin().logError("Could not create island for player. " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ private void loadAddon(File f) {
addon = addonClassLoader.getAddon();
// Initialize some settings
addon.setDataFolder(new File(f.getParent(), addon.getDescription().getName()));
addon.setAddonFile(f);
addon.setFile(f);

File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + addon.getDescription().getName());
// Obtain any locale files and save them
for (String localeFile : listJarYamlFiles(jar, LOCALE_FOLDER)) {
for (String localeFile : listJarFiles(jar, LOCALE_FOLDER, ".yml")) {
addon.saveResource(localeFile, localeDir, false, true);
}
plugin.getLocalesManager().loadLocalesFromFile(addon.getDescription().getName());
Expand Down Expand Up @@ -206,12 +206,13 @@ public void setClass(final String name, final Class<?> clazz) {
}

/**
* Lists all the yml files found in the jar in the folder
* Lists files found in the jar in the folderPath with the suffix given
* @param jar - the jar file
* @param folderPath - the path within the jar
* @param suffix - the suffix required
* @return a list of files
*/
public List<String> listJarYamlFiles(JarFile jar, String folderPath) {
public List<String> listJarFiles(JarFile jar, String folderPath, String suffix) {
List<String> result = new ArrayList<>();

Enumeration<JarEntry> entries = jar.entries();
Expand All @@ -223,7 +224,7 @@ public List<String> listJarYamlFiles(JarFile jar, String folderPath) {
continue;
}

if (entry.getName().endsWith(".yml")) {
if (entry.getName().endsWith(suffix)) {
result.add(entry.getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public String get(User user, String reference) {
// No translation could be gotten from the player's locale, trying more generic solutions
return get(reference);
}

/**
* Gets the translated String corresponding to the reference from the locale file for this user.
* @param user the User
* @param reference a reference that can be found in a locale file
* @param default to return if the reference cannot be found anywhere
* @param defaultText to return if the reference cannot be found anywhere
* @return the translated String from the User's locale or from the server's locale or from the en-US locale, or null.
*/
public String getOrDefault(User user, String reference, String defaultText) {
Expand Down Expand Up @@ -88,12 +88,12 @@ public String get(String reference) {
}
return null;
}

/**
* Gets the translated String corresponding to the reference from the server's or the en-US locale file
* or if it cannot be found anywhere, use the default text supplied.
* @param reference a reference that can be found in a locale file
* @param default text to return if the reference cannot be found anywhere
* @param defaultText text to return if the reference cannot be found anywhere
* @return the translated String from the server's locale or from the en-US locale, or default.
*/
public String getOrDefault(String reference, String defaultText) {
Expand Down
Loading