2016-06-02 20:14:09 +02:00
|
|
|
/*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2013-07-01 15:11:04 +02:00
|
|
|
package fr.neatmonster.nocheatplus.compat.blocks.init;
|
|
|
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
|
2018-08-18 22:23:21 +02:00
|
|
|
import fr.neatmonster.nocheatplus.compat.BridgeMaterial;
|
2016-06-21 09:31:21 +02:00
|
|
|
import fr.neatmonster.nocheatplus.utilities.map.BlockFlags;
|
|
|
|
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
|
2013-07-01 15:11:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Auxiliary methods for block initialization.
|
2018-08-18 22:23:21 +02:00
|
|
|
* @author asofold
|
2013-07-01 15:11:04 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class BlockInit {
|
|
|
|
|
2014-10-26 16:38:35 +01:00
|
|
|
// TODO: Change to assert names only?, would be better with being able to feed MC names or map them as well, though.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for Material existence, throw RuntimeException if not.
|
|
|
|
* @param id
|
|
|
|
*/
|
2017-12-06 06:37:51 +01:00
|
|
|
public static void assertMaterialExists(String id) {
|
2014-10-26 16:38:35 +01:00
|
|
|
if (BlockProperties.getMaterial(id) == null) {
|
|
|
|
throw new RuntimeException("Material " + id + " does not exist.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[BLEEDING][BREAKING][INSTABLE] Swiftly throw in permission caching.
Benefits:
* Improves performance, where permission lookup has major impact, with
timeout based lookup, static permissions (skip permission check
entirely), and world/offline based invalidation. (Once fully
implemented.)
* Hopefully more efficient: use Bukkit Permission for faster defaults.
* (Allows control over how which permission is to be
updated/invalidated, which is useful per se.)
Risks:
* Complex changes yield bugs.
* Other plugins depending on NCP might break.
* Cache incoherence might happen (permissions are changed dynamically +-
unintended malconfiguration, or in case of bugs).
* (Endless loops certainly have all been fixed.)
Breaking:
* Lots of more or less internal API has been changed or removed: Check,
CheckType, CheckUtils, TickTask, ...
* Permission checking behavior has been altered.
Rough points:
* Implement a permission cache within PlayerData.
* Remove the player tasks and permission updates in favour of handling
those within DataManager and PlayerData.
* Adjust everything else to it (partly TBD).
* Updating sets of permissions (e.g. for CHAT) is done more lazily now,
i.e. one per 10 ticks). An actual permission check would still yield an
update next tick (asynchronous).
* Fixed/extended random spots (DualCollection, MiniListener registration
support, StringUtil).
Missing:
* Basic implementation
* Cleanup after logout (stages: 1. non-essential like permissions,
2. unrecoverable like set-back location, 3. complete data removal).
* Coverage
* Might have missed spots.
* NoCheatPlus.nameSetPerms should be replaced by caching + default
config for world-wise updating.
* Command permissions are always checked. At least for players,
cache based lookup should get implemented.
* More unit tests.
* Extended configurability: Per-world settings/policies.
* Efficiency
* Not all parts of the implementation are 100%/optimal yet.
2018-01-28 18:52:51 +01:00
|
|
|
public static Material getMaterial(String name) {
|
|
|
|
try {
|
|
|
|
return Material.matchMaterial(name.toUpperCase());
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-18 22:23:21 +02:00
|
|
|
/**
|
|
|
|
* Set the block breaking properties of newMat to the same as are present
|
|
|
|
* for mat.
|
|
|
|
*
|
|
|
|
* @param newMat
|
|
|
|
* @param mat
|
|
|
|
*/
|
|
|
|
public static void setPropsAs(Material newMat, Material mat) {
|
|
|
|
BlockProperties.setBlockProps(newMat, BlockProperties.getBlockProps(mat));
|
|
|
|
}
|
|
|
|
|
2014-10-26 16:38:35 +01:00
|
|
|
/**
|
|
|
|
* Set block breaking properties same as the block of the given material.
|
|
|
|
* @param newId
|
|
|
|
* @param mat
|
|
|
|
*/
|
2017-12-06 06:37:51 +01:00
|
|
|
public static void setPropsAs(String newId, Material mat) {
|
2014-10-26 16:38:35 +01:00
|
|
|
BlockProperties.setBlockProps(newId, BlockProperties.getBlockProps(mat));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set block breaking properties same as the block of the given id.
|
|
|
|
* @param newId
|
2017-12-06 06:37:51 +01:00
|
|
|
* @param otherId
|
2014-10-26 16:38:35 +01:00
|
|
|
*/
|
2017-12-06 06:37:51 +01:00
|
|
|
public static void setPropsAs(String newId, String otherId) {
|
2014-10-26 16:38:35 +01:00
|
|
|
BlockProperties.setBlockProps(newId, BlockProperties.getBlockProps(otherId));
|
|
|
|
}
|
|
|
|
|
2018-08-18 22:23:21 +02:00
|
|
|
public static void setAs(Material newMat, Material mat) {
|
|
|
|
BlockFlags.setFlagsAs(newMat, mat);
|
|
|
|
setPropsAs(newMat, mat);
|
|
|
|
}
|
|
|
|
|
2014-10-26 16:38:35 +01:00
|
|
|
/**
|
|
|
|
* Set block breaking and shape properties same as the block of the given material.
|
|
|
|
* @param newId
|
|
|
|
* @param mat
|
|
|
|
*/
|
2017-12-06 06:37:51 +01:00
|
|
|
public static void setAs(String newId, Material mat) {
|
2014-10-26 16:38:35 +01:00
|
|
|
BlockFlags.setFlagsAs(newId, mat);
|
|
|
|
setPropsAs(newId, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set block breaking and shape properties same as the block of the given id.
|
|
|
|
* @param newId
|
2017-12-06 06:37:51 +01:00
|
|
|
* @param otherId
|
2014-10-26 16:38:35 +01:00
|
|
|
*/
|
2017-12-06 06:37:51 +01:00
|
|
|
public static void setAs(String newId, String otherId) {
|
2014-10-26 16:38:35 +01:00
|
|
|
BlockFlags.setFlagsAs(newId, otherId);
|
|
|
|
setPropsAs(newId, otherId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set like air, plus instantly breakable.
|
|
|
|
* @param newId
|
|
|
|
*/
|
2017-12-06 06:37:51 +01:00
|
|
|
public static void setInstantAir(String newId) {
|
2014-10-26 16:38:35 +01:00
|
|
|
BlockFlags.setFlagsAs(newId, Material.AIR);
|
|
|
|
BlockProperties.setBlockProps(newId, BlockProperties.instantType);
|
|
|
|
}
|
2013-07-01 15:11:04 +02:00
|
|
|
|
2018-08-18 22:23:21 +02:00
|
|
|
/**
|
|
|
|
* Set like air, plus instantly breakable.
|
|
|
|
* @param newId
|
|
|
|
*/
|
|
|
|
public static void setInstantAir(Material newId) {
|
|
|
|
BlockFlags.setFlagsAs(newId, Material.AIR);
|
|
|
|
BlockProperties.setBlockProps(newId, BlockProperties.instantType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setAsIfExists(String newName, Material mat) {
|
|
|
|
if (BridgeMaterial.has(newName)) {
|
|
|
|
setAs(newName, mat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setAsIfExists(String newName, String otherName) {
|
|
|
|
if (BridgeMaterial.has(newName)) {
|
|
|
|
setAs(newName, otherName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-01 15:11:04 +02:00
|
|
|
}
|