Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/v3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythologyli committed Dec 3, 2023
2 parents 8bded43 + b181607 commit ca142c8
Show file tree
Hide file tree
Showing 146 changed files with 9,034 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ClientUpdateComponent extends Component {
private int hideifshadow;
private int hideifunder;
private boolean hideifsneaking;
private boolean hideifspectator;
private boolean hideifinvisiblepotion;
private boolean is_protected;
public static boolean usePlayerColors;
Expand All @@ -24,6 +25,7 @@ public ClientUpdateComponent(final DynmapCore core, ConfigurationNode configurat
hideifshadow = configuration.getInteger("hideifshadow", 15);
hideifunder = configuration.getInteger("hideifundercover", 15);
hideifsneaking = configuration.getBoolean("hideifsneaking", false);
hideifspectator = configuration.getBoolean("hideifspectator", false);
hideifinvisiblepotion = configuration.getBoolean("hide-if-invisiblity-potion", true);
is_protected = configuration.getBoolean("protected-player-info", false);
usePlayerColors = configuration.getBoolean("use-name-colors", false);
Expand Down Expand Up @@ -100,6 +102,9 @@ else if(pw.isNether() == false) { /* Not nether */
if((!hide) && hideifsneaking && p.isSneaking()) {
hide = true;
}
if((!hide) && hideifspectator && p.isSpectator()) {
hide = true;
}
if((!hide) && is_protected && (!see_all)) {
if(e.user != null) {
hide = !core.testIfPlayerVisibleToPlayer(e.user, p.getName());
Expand Down
20 changes: 12 additions & 8 deletions DynmapCore/src/main/java/org/dynmap/ConfigurationNode.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.dynmap;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -82,13 +86,13 @@ public boolean load() {
initparse();
// If no file to read, just return false
if (!f.canRead()) { return false; }
FileInputStream fis = null;
Reader fr = null;
try {
fis = new FileInputStream(f);
Object o = yaml.load(new UnicodeReader(fis));
fr = new UnicodeReader(new BufferedInputStream(new FileInputStream(f)));
Object o = yaml.load(fr);
if((o != null) && (o instanceof Map))
entries = (Map<String, Object>)o;
fis.close();
fr.close();
}
catch (YAMLException e) {
Log.severe("Error parsing " + f.getPath() + ". Use http://yamllint.com to debug the YAML syntax." );
Expand All @@ -97,8 +101,8 @@ public boolean load() {
Log.severe("Error reading " + f.getPath());
return false;
} finally {
if(fis != null) {
try { fis.close(); } catch (IOException x) {}
if(fr != null) {
try { fr.close(); } catch (IOException x) {}
}
}
return (entries != null);
Expand All @@ -111,7 +115,7 @@ public boolean save() {
public boolean save(File file) {
initparse();

FileOutputStream stream = null;
OutputStream stream = null;

File parent = file.getParentFile();

Expand All @@ -120,7 +124,7 @@ public boolean save(File file) {
}

try {
stream = new FileOutputStream(file);
stream = new BufferedOutputStream(new FileOutputStream(file));
OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
yaml.dump(entries, writer);
return true;
Expand Down
9 changes: 9 additions & 0 deletions DynmapCore/src/main/java/org/dynmap/DynmapCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public static abstract class EnableCoreCallbacks {
private File dataDirectory;
private File tilesDirectory;
private File exportDirectory;
private File importDirectory;
private String plugin_ver;
private MapStorage defaultStorage;

Expand Down Expand Up @@ -224,6 +225,9 @@ public final File getTilesFolder() {
public final File getExportFolder() {
return exportDirectory;
}
public final File getImportFolder() {
return importDirectory;
}
public void setMinecraftVersion(String mcver) {
this.platformVersion = mcver;
}
Expand Down Expand Up @@ -428,6 +432,11 @@ public boolean initConfiguration(EnableCoreCallbacks cb) {
if (!exportDirectory.isDirectory() && !exportDirectory.mkdirs()) {
Log.warning("Could not create directory for exports ('" + exportDirectory + "').");
}
// Prime the imports directory
importDirectory = getFile(configuration.getString("importpath", "import"));
if (!importDirectory.isDirectory() && !importDirectory.mkdirs()) {
Log.warning("Could not create directory for imports ('" + importDirectory + "').");
}
// Create default storage handler
String storetype = configuration.getString("storage/type", "filetree");
if (storetype.equals("filetree")) {
Expand Down
6 changes: 5 additions & 1 deletion DynmapCore/src/main/java/org/dynmap/DynmapMapCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private void initTabCompletions() {
mapSetArgs.put("boostzoom", emptySupplier);
mapSetArgs.put("tilescale", emptySupplier);
mapSetArgs.put("tileupdatedelay", emptySupplier);
mapSetArgs.put("readonly", booleanSupplier);

tabCompletions = new HashMap<>();
tabCompletions.put("worldaddlimit", worldAddLimitArgs);
Expand Down Expand Up @@ -696,7 +697,7 @@ private boolean handleMapList(DynmapCommandSender sender, String[] args, DynmapC
sb.append(", lighting=").append(hdmt.getLighting().getName()).append(", mapzoomin=").append(hdmt.getMapZoomIn()).append(", mapzoomout=").append(hdmt.getMapZoomOutLevels());
sb.append(", img-format=").append(hdmt.getImageFormatSetting()).append(", icon=").append(hdmt.getIcon());
sb.append(", append-to-world=").append(hdmt.getAppendToWorld()).append(", boostzoom=").append(hdmt.getBoostZoom());
sb.append(", protected=").append(hdmt.isProtected()).append(", tilescale=").append(hdmt.getTileScale());
sb.append(", protected=").append(hdmt.isProtected()).append(", tilescale=").append(hdmt.getTileScale()).append(", readonly=").append(hdmt.isReadOnly());
if(hdmt.tileupdatedelay > 0) {
sb.append(", tileupdatedelay=").append(hdmt.tileupdatedelay);
}
Expand Down Expand Up @@ -996,6 +997,9 @@ else if(tok[0].equalsIgnoreCase("append-to-world")) {
else if(tok[0].equalsIgnoreCase("protected")) {
did_update |= mt.setProtected(Boolean.parseBoolean(tok[1]));
}
else if(tok[0].equalsIgnoreCase("readonly")) {
did_update |= mt.setReadOnly(Boolean.parseBoolean(tok[1]));
}
}
if(did_update) {
if(core.updateWorldConfig(w)) {
Expand Down
22 changes: 18 additions & 4 deletions DynmapCore/src/main/java/org/dynmap/MapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,12 @@ else if(pausedforworld) {
renderedmaps.addAll(map.getMapsSharingRender(world));

/* Now, prime the render queue */
for (MapTile mt : map.getTiles(world, (int)loc.x, (int)loc.y, (int)loc.z)) {
if (!found.getFlag(mt.tileOrdinalX(), mt.tileOrdinalY())) {
found.setFlag(mt.tileOrdinalX(), mt.tileOrdinalY(), true);
renderQueue.add(mt);
if (map.isReadOnly() == false) {
for (MapTile mt : map.getTiles(world, (int)loc.x, (int)loc.y, (int)loc.z)) {
if (!found.getFlag(mt.tileOrdinalX(), mt.tileOrdinalY())) {
found.setFlag(mt.tileOrdinalX(), mt.tileOrdinalY(), true);
renderQueue.add(mt);
}
}
}
if(!updaterender) { /* Only add other seed points for fullrender */
Expand Down Expand Up @@ -1072,6 +1074,10 @@ private void addNextTilesToUpdate(int cnt) {
tiles.clear();
for(DynmapWorld w : worlds) {
for(MapTypeState mts : w.mapstate) {
if (mts.type.isReadOnly()) {
continue;
}

if(mts.getNextInvalidTileCoord(coord)) {
mts.type.addMapTiles(tiles, w, coord.x, coord.y);
mts.validateTile(coord.x, coord.y);
Expand Down Expand Up @@ -1903,6 +1909,10 @@ private void processTouchEvents() {
}
if(world == null) continue;
for (MapTypeState mts : world.mapstate) {
if (mts.type.isReadOnly()) {
continue;
}

List<TileFlags.TileCoord> tiles = mts.type.getTileCoords(world, evt.x, evt.y, evt.z);
invalidates += mts.invalidateTiles(tiles);
}
Expand Down Expand Up @@ -1935,6 +1945,10 @@ private void processTouchEvents() {
if(world == null) continue;
int invalidates = 0;
for (MapTypeState mts : world.mapstate) {
if (mts.type.isReadOnly()) {
continue;
}

List<TileFlags.TileCoord> tiles = mts.type.getTileCoords(world, evt.xmin, evt.ymin, evt.zmin, evt.xmax, evt.ymax, evt.zmax);
invalidates += mts.invalidateTiles(tiles);
}
Expand Down
24 changes: 24 additions & 0 deletions DynmapCore/src/main/java/org/dynmap/MapType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

public abstract class MapType {
private boolean is_protected;
/**
* Is the map type read-only? (i.e. should not be updated by renderer)
*/
private boolean is_readonly;
protected int tileupdatedelay;

public enum ImageVariant {
Expand Down Expand Up @@ -207,6 +211,26 @@ public boolean setProtected(boolean p) {
}
return false;
}
/**
* Is the map type read-only? (i.e. should not be updated by renderer)
* @return true if read-only
*/
public boolean isReadOnly() {
return is_readonly;
}

/**
* Set read-only state of map type
* @param r - true if read-only
* @return true if state changed
*/
public boolean setReadOnly(boolean r) {
if(is_readonly != r) {
is_readonly = r;
return true;
}
return false;
}
public abstract String getPrefix();

public int getTileUpdateDelay(DynmapWorld w) {
Expand Down
4 changes: 2 additions & 2 deletions DynmapCore/src/main/java/org/dynmap/WebAuthManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Properties;
import java.util.Random;
import java.util.Set;

import org.dynmap.common.DynmapCommandSender;
Expand All @@ -26,7 +26,7 @@ public class WebAuthManager {
public static final String WEBAUTHFILE = "webauth.txt";
private static final String HASHSALT = "$HASH_SALT$";
private static final String PWDHASH_PREFIX = "hash.";
private Random rnd = new Random();
private SecureRandom rnd = new SecureRandom();
private DynmapCore core;
private String publicRegistrationURL;

Expand Down
6 changes: 6 additions & 0 deletions DynmapCore/src/main/java/org/dynmap/common/DynmapPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public interface DynmapPlayer extends DynmapCommandSender {
* @return true if sneaking
*/
public boolean isSneaking();

/**
* get spectator gamemode
* @return true if gamemode spectator
*/
public boolean isSpectator();
/**
* Get health
* @return health points
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static class DataVersionMap {

}
};
// Mapping from https://minecraft.fandom.com/wiki/Data_version
// Mapping from https://minecraft.wiki/w/Data_version
final static DataVersionMap[] versionmap = {
new DataVersionMap(0, "unknown", 0x202020),
new DataVersionMap(1519, "1.13.0", 0xF9E79F),
Expand Down
3 changes: 2 additions & 1 deletion DynmapCore/src/main/java/org/dynmap/hdmap/HDBlockModels.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dynmap.hdmap;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -356,7 +357,7 @@ private static void loadModelFile(InputStream in, String fname, ConfigurationNod
int layerbits = 0;
int rownum = 0;
int scale = 0;
rdr = new LineNumberReader(new InputStreamReader(in));
rdr = new LineNumberReader(new BufferedReader(new InputStreamReader(in)));
while ((line = rdr.readLine()) != null) {
boolean skip = false;
int lineNum = rdr.getLineNumber();
Expand Down
2 changes: 2 additions & 0 deletions DynmapCore/src/main/java/org/dynmap/hdmap/HDMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public HDMap(DynmapCore core, ConfigurationNode configuration) {
this.append_to_world = configuration.getString("append_to_world", "");
setProtected(configuration.getBoolean("protected", false));
setTileUpdateDelay(configuration.getInteger("tileupdatedelay", -1));
setReadOnly(configuration.getBoolean("readonly", false));
}

public ConfigurationNode saveConfiguration() {
Expand Down Expand Up @@ -180,6 +181,7 @@ public ConfigurationNode saveConfiguration() {
cn.put("backgroundnight", bg_night_cfg);
cn.put("append_to_world", append_to_world);
cn.put("protected", isProtected());
cn.put("readonly", isReadOnly());
if(this.tileupdatedelay > 0) {
cn.put("tileupdatedelay", this.tileupdatedelay);
}
Expand Down
6 changes: 6 additions & 0 deletions DynmapCore/src/main/java/org/dynmap/hdmap/HDMapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ public HDShaderState[] getShaderStateForTile(HDMapTile tile, MapChunkCache cache
/* If limited to one map, and this isn't it, skip */
if((mapname != null) && (!hdmap.getName().equals(mapname)))
continue;

// Maps can be set to read-only, which means they don't get re-rendered
if (map.isReadOnly()) {
continue;
}

shaders.add(hdmap.getShader().getStateInstance(hdmap, cache, mapiter, scale));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ public boolean render(MapChunkCache cache, HDMapTile tile, String mapname) {
// Mark the tiles we're going to render as validated
for (int i = 0; i < numshaders; i++) {
MapTypeState mts = world.getMapState(shaderstate[i].getMap());
if (mts != null) {
if (mts != null && mts.type.isReadOnly() == false) {
mts.validateTile(tile.tx, tile.ty);
}
}
Expand Down
5 changes: 3 additions & 2 deletions DynmapCore/src/main/java/org/dynmap/hdmap/TexturePack.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dynmap.hdmap;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -1823,7 +1824,7 @@ private static void loadTileSetsFile(InputStream txtfile, String txtname, Config

try {
String line;
rdr = new LineNumberReader(new InputStreamReader(txtfile));
rdr = new LineNumberReader(new BufferedReader(new InputStreamReader(txtfile)));
while((line = rdr.readLine()) != null) {
if(line.startsWith("#")) {
}
Expand Down Expand Up @@ -1922,7 +1923,7 @@ private static void loadTextureFile(InputStream txtfile, String txtname, Configu
Map<DynmapBlockState, BitSet> bsprslt;
try {
String line;
rdr = new LineNumberReader(new InputStreamReader(txtfile));
rdr = new LineNumberReader(new BufferedReader(new InputStreamReader(txtfile)));
while((line = rdr.readLine()) != null) {
boolean skip = false;
int lineNum = rdr.getLineNumber();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dynmap.hdmap;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -61,21 +62,21 @@ public InputStream openModTPResource(String rname, String modname) {
if (zf != null) {
ZipEntry ze = zf.getEntry(rname);
if ((ze != null) && (!ze.isDirectory())) {
return zf.getInputStream(ze);
return new BufferedInputStream(zf.getInputStream(ze));
}
}
else if (tpdir != null) {
File f = new File(tpdir, rname);
if (f.isFile() && f.canRead()) {
return new FileInputStream(f);
return new BufferedInputStream(new FileInputStream(f));
}
}
} catch (IOException iox) {
}
// Fall through - load as resource from mod, if possible, or from jar
InputStream is = dsi.openResource(modname, rname);
if (is != null) {
return is;
return new BufferedInputStream(is);
}
if (modname != null) {
ModSource ms = src_by_mod.get(modname);
Expand Down Expand Up @@ -118,7 +119,7 @@ else if (ms.directory != null) {
Log.warning("Resource " + rname + " for mod " + modname + " not found");
}

return is;
return (is != null) ? new BufferedInputStream(is) : null;
}
public void close() {
if(zf != null) {
Expand Down
Loading

0 comments on commit ca142c8

Please sign in to comment.