added deprecation warnings, fixes #568
This commit is contained in:
1 parent
5615bddf9b
commit
2a403c36c8
7 files changed
+69
-5
No files matched your search
@@ -268,6 +268,12 @@ public class CarpetEventServer
|
|||||||
};
|
};
|
||||||
public static final Event NETHER_TICK = new Event("tick_nether", 0, true)
|
public static final Event NETHER_TICK = new Event("tick_nether", 0, true)
|
||||||
{
|
{
|
||||||
|
@Override
|
||||||
|
public boolean deprecated()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick()
|
public void onTick()
|
||||||
{
|
{
|
||||||
@@ -279,6 +285,11 @@ public class CarpetEventServer
|
|||||||
};
|
};
|
||||||
public static final Event ENDER_TICK = new Event("tick_ender", 0, true)
|
public static final Event ENDER_TICK = new Event("tick_ender", 0, true)
|
||||||
{
|
{
|
||||||
|
@Override
|
||||||
|
public boolean deprecated()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onTick()
|
public void onTick()
|
||||||
{
|
{
|
||||||
@@ -804,6 +815,7 @@ public class CarpetEventServer
|
|||||||
{
|
{
|
||||||
return handler.callList.size() > 0;
|
return handler.callList.size() > 0;
|
||||||
}
|
}
|
||||||
|
public boolean deprecated() {return false;}
|
||||||
//stubs for calls just to ease calls in vanilla code so they don't need to deal with scarpet value types
|
//stubs for calls just to ease calls in vanilla code so they don't need to deal with scarpet value types
|
||||||
public void onTick() { }
|
public void onTick() { }
|
||||||
public void onChunkGenerated(ServerWorld world, Chunk chunk) { }
|
public void onChunkGenerated(ServerWorld world, Chunk chunk) { }
|
||||||
@@ -900,10 +912,10 @@ public class CarpetEventServer
|
|||||||
|
|
||||||
private boolean canAddEvent(Event event, ScriptHost host)
|
private boolean canAddEvent(Event event, ScriptHost host)
|
||||||
{
|
{
|
||||||
|
if (event.deprecated()) host.issueDeprecation(event.name+" event");
|
||||||
return !(event.globalOnly && (host.perUser || host.parent != null));
|
return !(event.globalOnly && (host.perUser || host.parent != null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean removeEventFromCommand(ServerCommandSource source, String event, String funName)
|
public boolean removeEventFromCommand(ServerCommandSource source, String event, String funName)
|
||||||
{
|
{
|
||||||
Event ev = Event.getEvent(event, CarpetServer.scriptServer);
|
Event ev = Event.getEvent(event, CarpetServer.scriptServer);
|
||||||
|
|||||||
@@ -744,4 +744,15 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
{
|
{
|
||||||
return scriptServer;
|
return scriptServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean issueDeprecation(String feature)
|
||||||
|
{
|
||||||
|
if(super.issueDeprecation(feature))
|
||||||
|
{
|
||||||
|
Messenger.m(responsibleSource, "rb '"+feature+"' is deprecated and soon will be removed. Please consult the docs for their replacement");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -366,7 +366,28 @@ public class Expression
|
|||||||
|
|
||||||
public void alias(String copy, String original)
|
public void alias(String copy, String original)
|
||||||
{
|
{
|
||||||
functions.put(copy, functions.get(original));
|
ILazyFunction originalFunction = functions.get(original);
|
||||||
|
functions.put(copy, new ILazyFunction()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int getNumParams()
|
||||||
|
{
|
||||||
|
return originalFunction.getNumParams();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean numParamsVaries()
|
||||||
|
{
|
||||||
|
return originalFunction.numParamsVaries();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LazyValue lazyEval(Context c, Integer type, Expression expr, Tokenizer.Token token, List<LazyValue> lazyParams)
|
||||||
|
{
|
||||||
|
c.host.issueDeprecation(copy+"(...)");
|
||||||
|
return originalFunction.lazyEval(c, type, expr, token, lazyParams);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ import carpet.script.value.FunctionValue;
|
|||||||
import carpet.script.value.Value;
|
import carpet.script.value.Value;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -34,6 +36,8 @@ public abstract class ScriptHost
|
|||||||
private final Map<Value, Object> locks = new ConcurrentHashMap<>();
|
private final Map<Value, Object> locks = new ConcurrentHashMap<>();
|
||||||
protected boolean inTermination = false;
|
protected boolean inTermination = false;
|
||||||
|
|
||||||
|
private final Set<String> deprecations = new HashSet<>();
|
||||||
|
|
||||||
public Random getRandom(long aLong)
|
public Random getRandom(long aLong)
|
||||||
{
|
{
|
||||||
if (randomizers.size() > 1024)
|
if (randomizers.size() > 1024)
|
||||||
@@ -379,4 +383,14 @@ public abstract class ScriptHost
|
|||||||
{
|
{
|
||||||
errorSnooper=null;
|
errorSnooper=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Logger DEPRECATION_LOG = LogManager.getLogger("Scarpet Deprecation Warnings");
|
||||||
|
|
||||||
|
public boolean issueDeprecation(String feature)
|
||||||
|
{
|
||||||
|
if (deprecations.contains(feature)) return false;
|
||||||
|
deprecations.add(feature);
|
||||||
|
DEPRECATION_LOG.warn("'"+feature+"' is deprecated and soon will be removed. Please consult the docs for their replacement");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -577,6 +577,7 @@ public class Auxiliary {
|
|||||||
|
|
||||||
expression.addLazyFunction("seed", -1, (c, t, lv) -> {
|
expression.addLazyFunction("seed", -1, (c, t, lv) -> {
|
||||||
ServerCommandSource s = ((CarpetContext)c).s;
|
ServerCommandSource s = ((CarpetContext)c).s;
|
||||||
|
c.host.issueDeprecation("seed()");
|
||||||
Value ret = new NumericValue(s.getWorld().getSeed());
|
Value ret = new NumericValue(s.getWorld().getSeed());
|
||||||
return (cc, tt) -> ret;
|
return (cc, tt) -> ret;
|
||||||
});
|
});
|
||||||
@@ -785,6 +786,7 @@ public class Auxiliary {
|
|||||||
boolean shared = false;
|
boolean shared = false;
|
||||||
if (lv.size()>0)
|
if (lv.size()>0)
|
||||||
{
|
{
|
||||||
|
c.host.issueDeprecation("load_app_data(...) with arguments");
|
||||||
file = recognizeResource(lv.get(0).evalValue(c));
|
file = recognizeResource(lv.get(0).evalValue(c));
|
||||||
if (lv.size() > 1)
|
if (lv.size() > 1)
|
||||||
{
|
{
|
||||||
@@ -807,6 +809,7 @@ public class Auxiliary {
|
|||||||
boolean shared = false;
|
boolean shared = false;
|
||||||
if (lv.size()>1)
|
if (lv.size()>1)
|
||||||
{
|
{
|
||||||
|
c.host.issueDeprecation("store_app_data(...) with more than one argument");
|
||||||
file = recognizeResource(lv.get(1).evalValue(c));
|
file = recognizeResource(lv.get(1).evalValue(c));
|
||||||
if (lv.size() > 2)
|
if (lv.size() > 2)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -543,6 +543,7 @@ public class WorldAccess {
|
|||||||
// Deprecated, use loaded_status as more indicative
|
// Deprecated, use loaded_status as more indicative
|
||||||
expression.addLazyFunction("loaded_ep", -1, (c, t, lv) ->
|
expression.addLazyFunction("loaded_ep", -1, (c, t, lv) ->
|
||||||
{
|
{
|
||||||
|
c.host.issueDeprecation("loaded_ep(...)");
|
||||||
BlockPos pos = BlockArgument.findIn((CarpetContext)c, lv, 0).block.getPos();
|
BlockPos pos = BlockArgument.findIn((CarpetContext)c, lv, 0).block.getPos();
|
||||||
Value retval = ((CarpetContext)c).s.getWorld().getChunkManager().shouldTickChunk(new ChunkPos(pos))?Value.TRUE : Value.FALSE;
|
Value retval = ((CarpetContext)c).s.getWorld().getChunkManager().shouldTickChunk(new ChunkPos(pos))?Value.TRUE : Value.FALSE;
|
||||||
return (c_, t_) -> retval;
|
return (c_, t_) -> retval;
|
||||||
@@ -965,6 +966,7 @@ public class WorldAccess {
|
|||||||
// Deprecated for block_state()
|
// Deprecated for block_state()
|
||||||
expression.addLazyFunction("property", -1, (c, t, lv) ->
|
expression.addLazyFunction("property", -1, (c, t, lv) ->
|
||||||
{
|
{
|
||||||
|
c.host.issueDeprecation("property(...)");
|
||||||
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0);
|
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0);
|
||||||
BlockState state = locator.block.getBlockState();
|
BlockState state = locator.block.getBlockState();
|
||||||
if (lv.size() <= locator.offset)
|
if (lv.size() <= locator.offset)
|
||||||
@@ -981,6 +983,7 @@ public class WorldAccess {
|
|||||||
// Deprecated for block_state()
|
// Deprecated for block_state()
|
||||||
expression.addLazyFunction("block_properties", -1, (c, t, lv) ->
|
expression.addLazyFunction("block_properties", -1, (c, t, lv) ->
|
||||||
{
|
{
|
||||||
|
c.host.issueDeprecation("block_properties(...)");
|
||||||
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0);
|
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0);
|
||||||
BlockState state = locator.block.getBlockState();
|
BlockState state = locator.block.getBlockState();
|
||||||
StateManager<Block, BlockState> states = state.getBlock().getStateManager();
|
StateManager<Block, BlockState> states = state.getBlock().getStateManager();
|
||||||
|
|||||||
@@ -638,14 +638,14 @@ save_as(file) ->
|
|||||||
//otherwise mojang will interpret 0.0d as 0i and fail to insert
|
//otherwise mojang will interpret 0.0d as 0i and fail to insert
|
||||||
put(path_nbt:'points', point_nbt, _i);
|
put(path_nbt:'points', point_nbt, _i);
|
||||||
);
|
);
|
||||||
store_app_data(path_nbt, file);
|
write_file(file, 'nbt', path_nbt);
|
||||||
'stored path as '+file;
|
'stored path as '+file;
|
||||||
);
|
);
|
||||||
|
|
||||||
// loads path under the local file that
|
// loads path under the local file that
|
||||||
load(file) ->
|
load(file) ->
|
||||||
(
|
(
|
||||||
path_nbt = load_app_data(file);
|
path_nbt = read_file(file, 'nbt');
|
||||||
if (!path_nbt, exit('No path to load: '+file));
|
if (!path_nbt, exit('No path to load: '+file));
|
||||||
new_points = map(get(path_nbt, 'points[]'), l(_:'pos[]', _:'duration', _:'type'));
|
new_points = map(get(path_nbt, 'points[]'), l(_:'pos[]', _:'duration', _:'type'));
|
||||||
if (!new_points || first(new_points, length(_:0) != 5),
|
if (!new_points || first(new_points, length(_:0) != 5),
|
||||||
|
|||||||
Reference in new issue
Block a user