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)
|
||||
{
|
||||
@Override
|
||||
public boolean deprecated()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
@@ -279,6 +285,11 @@ public class CarpetEventServer
|
||||
};
|
||||
public static final Event ENDER_TICK = new Event("tick_ender", 0, true)
|
||||
{
|
||||
@Override
|
||||
public boolean deprecated()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
@@ -804,6 +815,7 @@ public class CarpetEventServer
|
||||
{
|
||||
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
|
||||
public void onTick() { }
|
||||
public void onChunkGenerated(ServerWorld world, Chunk chunk) { }
|
||||
@@ -900,10 +912,10 @@ public class CarpetEventServer
|
||||
|
||||
private boolean canAddEvent(Event event, ScriptHost host)
|
||||
{
|
||||
if (event.deprecated()) host.issueDeprecation(event.name+" event");
|
||||
return !(event.globalOnly && (host.perUser || host.parent != null));
|
||||
}
|
||||
|
||||
|
||||
public boolean removeEventFromCommand(ServerCommandSource source, String event, String funName)
|
||||
{
|
||||
Event ev = Event.getEvent(event, CarpetServer.scriptServer);
|
||||
|
||||
@@ -744,4 +744,15 @@ public class CarpetScriptHost extends ScriptHost
|
||||
{
|
||||
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)
|
||||
{
|
||||
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 it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
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.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -34,6 +36,8 @@ public abstract class ScriptHost
|
||||
private final Map<Value, Object> locks = new ConcurrentHashMap<>();
|
||||
protected boolean inTermination = false;
|
||||
|
||||
private final Set<String> deprecations = new HashSet<>();
|
||||
|
||||
public Random getRandom(long aLong)
|
||||
{
|
||||
if (randomizers.size() > 1024)
|
||||
@@ -379,4 +383,14 @@ public abstract class ScriptHost
|
||||
{
|
||||
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) -> {
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
c.host.issueDeprecation("seed()");
|
||||
Value ret = new NumericValue(s.getWorld().getSeed());
|
||||
return (cc, tt) -> ret;
|
||||
});
|
||||
@@ -785,6 +786,7 @@ public class Auxiliary {
|
||||
boolean shared = false;
|
||||
if (lv.size()>0)
|
||||
{
|
||||
c.host.issueDeprecation("load_app_data(...) with arguments");
|
||||
file = recognizeResource(lv.get(0).evalValue(c));
|
||||
if (lv.size() > 1)
|
||||
{
|
||||
@@ -807,6 +809,7 @@ public class Auxiliary {
|
||||
boolean shared = false;
|
||||
if (lv.size()>1)
|
||||
{
|
||||
c.host.issueDeprecation("store_app_data(...) with more than one argument");
|
||||
file = recognizeResource(lv.get(1).evalValue(c));
|
||||
if (lv.size() > 2)
|
||||
{
|
||||
|
||||
@@ -543,6 +543,7 @@ public class WorldAccess {
|
||||
// Deprecated, use loaded_status as more indicative
|
||||
expression.addLazyFunction("loaded_ep", -1, (c, t, lv) ->
|
||||
{
|
||||
c.host.issueDeprecation("loaded_ep(...)");
|
||||
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;
|
||||
return (c_, t_) -> retval;
|
||||
@@ -965,6 +966,7 @@ public class WorldAccess {
|
||||
// Deprecated for block_state()
|
||||
expression.addLazyFunction("property", -1, (c, t, lv) ->
|
||||
{
|
||||
c.host.issueDeprecation("property(...)");
|
||||
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0);
|
||||
BlockState state = locator.block.getBlockState();
|
||||
if (lv.size() <= locator.offset)
|
||||
@@ -981,6 +983,7 @@ public class WorldAccess {
|
||||
// Deprecated for block_state()
|
||||
expression.addLazyFunction("block_properties", -1, (c, t, lv) ->
|
||||
{
|
||||
c.host.issueDeprecation("block_properties(...)");
|
||||
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0);
|
||||
BlockState state = locator.block.getBlockState();
|
||||
StateManager<Block, BlockState> states = state.getBlock().getStateManager();
|
||||
|
||||
Reference in new issue
Block a user