Skip to content

Commit

Permalink
v2.0-Pre3
Browse files Browse the repository at this point in the history
  • Loading branch information
Moresteck committed Dec 2, 2018
1 parent 0f05f98 commit b1bca35
Show file tree
Hide file tree
Showing 57 changed files with 1,641 additions and 117 deletions.
Binary file added bin/bukkit/util/config/Configuration.class
Binary file not shown.
Binary file added bin/bukkit/util/config/ConfigurationException.class
Binary file not shown.
Binary file added bin/bukkit/util/config/ConfigurationNode.class
Binary file not shown.
Binary file not shown.
Binary file added bin/bukkit/util/config/EmptyNullRepresenter.class
Binary file not shown.
15 changes: 14 additions & 1 deletion bin/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
v2.0-Pre1:
- Initial release

v2.0-Pre2:
- Added '/mw create ...' command
- Added '/mw tp ...' command
Expand All @@ -9,4 +10,16 @@ v2.0-Pre2:
- Can hook into Permissions 2.5+
- Updates to BukkitVersion IE
- Fixed a compatibility issue
- Fixed custom worlds not loading after main ones
- Fixed custom worlds not loading after the main ones

v2.0-Pre3:
- Fixed applying world settings in create command
- Fixed MultiWorld not loading in Bukkit lower than b1.6.6
- Expanded compatibility
- Added '/mw import ...' command
- Added '/mw who ...' command
- Added '/mw save ...' command
- Added '/mw version' command
- Added '/mw unload ...' command
- Added '/mw list' command
- Added '/mw info ...' command
Binary file modified bin/pl/moresteck/bvnpe/BukkitVersion.class
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/MConfig.class
Binary file not shown.
Binary file added bin/pl/moresteck/multiworld/MultiWorld$1.class
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/MultiWorld.class
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/Perm.class
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/commands/MCommand.class
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/commands/MCreate.class
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/commands/MHelp.class
Binary file not shown.
Binary file not shown.
Binary file added bin/pl/moresteck/multiworld/commands/MInfo.class
Binary file not shown.
Binary file added bin/pl/moresteck/multiworld/commands/MList.class
Binary file not shown.
Binary file not shown.
Binary file added bin/pl/moresteck/multiworld/commands/MSave.class
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/commands/MTeleport.class
Binary file not shown.
Binary file not shown.
Binary file added bin/pl/moresteck/multiworld/commands/MWho.class
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/listeners/listener.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/listeners/worldlistener.class
Binary file not shown.
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/world/MWorld.class
Binary file not shown.
Binary file modified bin/pl/moresteck/multiworld/world/MWorldConfig.class
Binary file not shown.
4 changes: 2 additions & 2 deletions bin/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: MultiWorld
main: pl.moresteck.multiworld.MultiWorld
version: 2.0-Pre2
version: 2.0-Pre3
description: Provides multi-world support for Bukkit.
author: Moresteck
website: https://betacraft.ovh/
load: startup
load: postworld
softdepend: [BukkitVersion, Permissions]

commands:
Expand Down
Binary file modified lib/bukkit.jar
Binary file not shown.
231 changes: 231 additions & 0 deletions src/bukkit/util/config/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
package bukkit.util.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.nodes.CollectionNode;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.SequenceNode;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.reader.UnicodeReader;
import org.yaml.snakeyaml.representer.Represent;
import org.yaml.snakeyaml.representer.Representer;

/**
* YAML configuration loader. To use this class, construct it with path to
* a file and call its load() method. For specifying node paths in the
* various get*() methods, they support SK's path notation, allowing you to
* select child nodes by delimiting node names with periods.
*
* <p>
* For example, given the following configuration file:</p>
*
* <pre>members:
* - Hollie
* - Jason
* - Bobo
* - Aya
* - Tetsu
* worldguard:
* fire:
* spread: false
* blocks: [cloth, rock, glass]
* sturmeh:
* cool: false
* eats:
* babies: true</pre>
*
* <p>Calling code could access sturmeh's baby eating state by using
* <code>getBoolean("sturmeh.eats.babies", false)</code>. For lists, there are
* methods such as <code>getStringList</code> that will return a type safe list.
*
* <p>This class is currently incomplete. It is not yet possible to get a node.
* </p>
*
*/
// Compatibility for 1.1-R4+
public class Configuration extends ConfigurationNode {
private Yaml yaml;
private File file;
private String header = null;

public Configuration(File file) {
super(new HashMap<String, Object>());

DumperOptions options = new DumperOptions();

options.setIndent(4);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

yaml = new Yaml(new SafeConstructor(), new EmptyNullRepresenter(), options);

this.file = file;
}

/**
* Loads the configuration file. All errors are thrown away.
*/
public void load() {
FileInputStream stream = null;

try {
stream = new FileInputStream(file);
read(yaml.load(new UnicodeReader(stream)));
} catch (IOException e) {
root = new HashMap<String, Object>();
} catch (ConfigurationException e) {
root = new HashMap<String, Object>();
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException e) {}
}
}

/**
* Set the header for the file as a series of lines that are terminated
* by a new line sequence.
*
* @param headerLines header lines to prepend
*/
public void setHeader(String... headerLines) {
StringBuilder header = new StringBuilder();

for (String line : headerLines) {
if (header.length() > 0) {
header.append("\r\n");
}
header.append(line);
}

setHeader(header.toString());
}

/**
* Set the header for the file. A header can be provided to prepend the
* YAML data output on configuration save. The header is
* printed raw and so must be manually commented if used. A new line will
* be appended after the header, however, if a header is provided.
*
* @param header header to prepend
*/
public void setHeader(String header) {
this.header = header;
}

/**
* Return the set header.
*
* @return
*/
public String getHeader() {
return header;
}

/**
* Saves the configuration to disk. All errors are clobbered.
*
* @param header header to prepend
* @return true if it was successful
*/
public boolean save() {
FileOutputStream stream = null;

File parent = file.getParentFile();

if (parent != null) {
parent.mkdirs();
}

try {
stream = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
if (header != null) {
writer.append(header);
writer.append("\r\n");
}
yaml.dump(root, writer);
return true;
} catch (IOException e) {} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException e) {}
}

return false;
}

@SuppressWarnings("unchecked")
private void read(Object input) throws ConfigurationException {
try {
if (null == input) {
root = new HashMap<String, Object>();
} else {
root = (Map<String, Object>) input;
}
} catch (ClassCastException e) {
throw new ConfigurationException("Root document must be an key-value structure");
}
}

/**
* This method returns an empty ConfigurationNode for using as a
* default in methods that select a node from a node list.
* @return
*/
public static ConfigurationNode getEmptyNode() {
return new ConfigurationNode(new HashMap<String, Object>());
}
}

class EmptyNullRepresenter extends Representer {

public EmptyNullRepresenter() {
super();
this.nullRepresenter = new EmptyRepresentNull();
}

protected class EmptyRepresentNull implements Represent {
public Node representData(Object data) {
return representScalar(Tag.NULL, ""); // Changed "null" to "" so as to avoid writing nulls
}
}

// Code borrowed from snakeyaml (http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyaml/issues/issue60/SkipBeanTest.java)
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
NodeTuple tuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
Node valueNode = tuple.getValueNode();
if (valueNode instanceof CollectionNode) {
// Removed null check
if (Tag.SEQ.equals(valueNode.getTag())) {
SequenceNode seq = (SequenceNode) valueNode;
if (seq.getValue().isEmpty()) {
return null; // skip empty lists
}
}
if (Tag.MAP.equals(valueNode.getTag())) {
MappingNode seq = (MappingNode) valueNode;
if (seq.getValue().isEmpty()) {
return null; // skip empty maps
}
}
}
return tuple;
}
// End of borrowed code
}
18 changes: 18 additions & 0 deletions src/bukkit/util/config/ConfigurationException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package bukkit.util.config;

/**
* Configuration exception.
*
* @author sk89q
*/
public class ConfigurationException extends Exception {
private static final long serialVersionUID = -2442886939908724203L;

public ConfigurationException() {
super();
}

public ConfigurationException(String msg) {
super(msg);
}
}
Loading

0 comments on commit b1bca35

Please sign in to comment.