Added local method invocation annotation
This commit is contained in:
@@ -24,6 +24,7 @@ import static io.anuke.mindustry.Vars.playerGroup;
|
|||||||
public class Invoke {
|
public class Invoke {
|
||||||
private static ObjectMap<Class, ObjectMap<String, Method>> methods = new ObjectMap<>();
|
private static ObjectMap<Class, ObjectMap<String, Method>> methods = new ObjectMap<>();
|
||||||
private static ObjectMap<String, Class> classes = new ObjectMap<>();
|
private static ObjectMap<String, Class> classes = new ObjectMap<>();
|
||||||
|
private static ObjectMap<Method, Boolean> methodLocal = new ObjectMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes a method remotely (on all clients) and locally.
|
* Invokes a method remotely (on all clients) and locally.
|
||||||
@@ -34,7 +35,9 @@ public class Invoke {
|
|||||||
public static void on(Class<?> type, String methodName, Object... args){
|
public static void on(Class<?> type, String methodName, Object... args){
|
||||||
try {
|
try {
|
||||||
Method method = getMethod(type, methodName);
|
Method method = getMethod(type, methodName);
|
||||||
|
if(methodLocal.get(method)){
|
||||||
method.invoke(null, args);
|
method.invoke(null, args);
|
||||||
|
}
|
||||||
InvokePacket packet = new InvokePacket();
|
InvokePacket packet = new InvokePacket();
|
||||||
packet.args = args;
|
packet.args = args;
|
||||||
packet.type = type;
|
packet.type = type;
|
||||||
@@ -55,10 +58,6 @@ public class Invoke {
|
|||||||
on(NetEvents.class, methodName, args);
|
on(NetEvents.class, methodName, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void eventRemote(String methodName, Object... args){
|
|
||||||
on(NetEvents.class, methodName, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO refactor to serializer map!
|
//TODO refactor to serializer map!
|
||||||
static void writeObjects(ByteBuffer buffer, Object[] objects){
|
static void writeObjects(ByteBuffer buffer, Object[] objects){
|
||||||
for(Object o : objects){
|
for(Object o : objects){
|
||||||
@@ -162,6 +161,7 @@ public class Invoke {
|
|||||||
if(method.getDeclaredAnnotation(Remote.class) == null){
|
if(method.getDeclaredAnnotation(Remote.class) == null){
|
||||||
throw new RuntimeException("Attempt to invoke method '" + methodname + "', which is not Invokable!");
|
throw new RuntimeException("Attempt to invoke method '" + methodname + "', which is not Invokable!");
|
||||||
}
|
}
|
||||||
|
methodLocal.put(method, method.getDeclaredAnnotation(Local.class) != null);
|
||||||
map.put(methodname, method);
|
map.put(methodname, method);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -170,9 +170,12 @@ public class Invoke {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Marks a method as invokable remotely with {@link Invoke#on(Class, String, Object...)}*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@interface Remote{
|
@interface Remote{}
|
||||||
|
|
||||||
}
|
/**Marks a method to be locally invoked as well as remotely invoked.*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@interface Local{}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import io.anuke.mindustry.entities.Player;
|
|||||||
import io.anuke.mindustry.entities.SyncEntity;
|
import io.anuke.mindustry.entities.SyncEntity;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.Unit;
|
||||||
|
import io.anuke.mindustry.net.Invoke.Local;
|
||||||
|
import io.anuke.mindustry.net.Invoke.Remote;
|
||||||
import io.anuke.mindustry.net.Net.SendMode;
|
import io.anuke.mindustry.net.Net.SendMode;
|
||||||
import io.anuke.mindustry.net.Packets.*;
|
import io.anuke.mindustry.net.Packets.*;
|
||||||
import io.anuke.mindustry.resource.Weapon;
|
import io.anuke.mindustry.resource.Weapon;
|
||||||
@@ -114,12 +116,10 @@ public class NetEvents {
|
|||||||
Net.send(packet, SendMode.tcp);
|
Net.send(packet, SendMode.tcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remote
|
||||||
|
@Local
|
||||||
public static void adminSet(Player player, boolean admin){
|
public static void adminSet(Player player, boolean admin){
|
||||||
player.isAdmin = admin;
|
player.isAdmin = admin;
|
||||||
|
|
||||||
if(Net.client()){
|
|
||||||
ui.listfrag.rebuild();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleAdministerRequest(Player target, AdminAction action){
|
public static void handleAdministerRequest(Player target, AdminAction action){
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.anuke.mindustry.ui.fragments;
|
package io.anuke.mindustry.ui.fragments;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
@@ -28,7 +29,7 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
public class PlayerListFragment implements Fragment{
|
public class PlayerListFragment implements Fragment{
|
||||||
public boolean visible = false;
|
public boolean visible = false;
|
||||||
Table content = new Table();
|
Table content = new Table();
|
||||||
int last = 0;
|
ObjectMap<Player, Boolean> checkmap = new ObjectMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(){
|
public void build(){
|
||||||
@@ -72,10 +73,14 @@ public class PlayerListFragment implements Fragment{
|
|||||||
if(!(Net.active() && !state.is(State.menu))){
|
if(!(Net.active() && !state.is(State.menu))){
|
||||||
visible = false;
|
visible = false;
|
||||||
}
|
}
|
||||||
if(playerGroup.size() != last){
|
boolean rebuild = false;
|
||||||
rebuild();
|
for(Player player : playerGroup.all()){
|
||||||
last = playerGroup.size();
|
if(!checkmap.containsKey(player) || checkmap.get(player, false) != player.isAdmin){
|
||||||
|
rebuild = true;
|
||||||
}
|
}
|
||||||
|
checkmap.put(player, player.isAdmin);
|
||||||
|
}
|
||||||
|
if(rebuild) rebuild();
|
||||||
});
|
});
|
||||||
|
|
||||||
visible(() -> visible);
|
visible(() -> visible);
|
||||||
|
|||||||
Reference in New Issue
Block a user