Skip to content

Commit e6f179e

Browse files
authored
Merge pull request #4 from Dereku/reindevpatches
ReIndevPatches compatibility update
2 parents 83e16fa + a96f75f commit e6f179e

File tree

5 files changed

+10
-85
lines changed

5 files changed

+10
-85
lines changed

api/src/main/java/net/minecraft/server/command/Command.java

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,11 @@
33
// https://git.derekunavailable.direct/Dereku/ReIndevPatches
44
public abstract class Command {
55

6-
private final String commandLabel;
7-
private final String[] aliases;
8-
private IssuerRole canUseThisCommand = IssuerRole.BOTH;
9-
10-
public Command(final String name) {
11-
this.commandLabel = name;
12-
this.aliases = new String[0];
13-
}
14-
156
public Command(final String name, final String[] aliases) {
16-
this.commandLabel = name;
17-
this.aliases = aliases;
187
}
198

209
public abstract void execute(String commandLabel, String[] args, CommandSender commandSender);
2110

22-
public String getCommandLabel() {
23-
return commandLabel;
24-
}
25-
26-
public String[] getAliases() {
27-
return aliases;
28-
}
29-
3011
public boolean onlyForOperators() {
3112
return true;
3213
}
@@ -35,19 +16,7 @@ public boolean hideCommandArgs() {
3516
return false;
3617
}
3718

38-
public IssuerRole getRoleToUseThisCommand() {
39-
return canUseThisCommand;
40-
}
41-
19+
@SuppressWarnings({"unused", "SameParameterValue"})
4220
protected final void setIssuerRole(IssuerRole role) {
43-
this.canUseThisCommand = role;
44-
}
45-
46-
protected final int parseInt(String input, int value) {
47-
if (input.matches("-?[0-9]*")) {
48-
return Integer.parseInt(input);
49-
} else {
50-
return value;
51-
}
5221
}
5322
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package net.minecraft.server.command;
22

3-
import net.minecraft.server.plugin.JavaPlugin;
4-
53
public class CommandRegistry {
64
private static final CommandRegistry INSTANCE = new CommandRegistry();
75

@@ -11,7 +9,6 @@ public static CommandRegistry getInstance() {
119
return INSTANCE;
1210
}
1311

14-
public boolean registerCommand(JavaPlugin owner, Command command, boolean override) {
15-
return true;
12+
public void registerCommand(String label, Command command) {
1613
}
1714
}

api/src/main/java/net/minecraft/server/command/CommandSender.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ public boolean isPlayer() {
99

1010
public void sendMessage(String message) {}
1111

12-
/* public EntityPlayerMP getPlayer(); */
12+
// It's fine, I swear.
13+
public Object getPlayer() {
14+
return null;
15+
}
1316
}

api/src/main/java/net/minecraft/server/plugin/JavaPlugin.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

server/src/main/java/com/fox2code/foxloader/server/ServerCommandWrapper4ReIndevPatches.java

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,20 @@
44
import com.fox2code.foxloader.network.NetworkPlayer;
55
import com.fox2code.foxloader.registry.CommandCompat;
66
import net.minecraft.server.command.Command;
7+
import net.minecraft.server.command.CommandRegistry;
78
import net.minecraft.server.command.CommandSender;
89
import net.minecraft.server.command.IssuerRole;
9-
import net.minecraft.server.plugin.JavaPlugin;
10-
11-
import java.lang.reflect.Method;
1210

1311
/**
1412
* Compatibility class used in ReIndevPatches
1513
*/
1614
public class ServerCommandWrapper4ReIndevPatches extends Command {
17-
private static final Method getPlayer;
18-
static {
19-
Method getPlayerTmp;
20-
try {
21-
//noinspection JavaReflectionMemberAccess
22-
getPlayerTmp = CommandSender.class.getDeclaredMethod("getPlayer");
23-
} catch (NoSuchMethodException e) {
24-
try {
25-
//noinspection JavaReflectionMemberAccess
26-
getPlayerTmp = CommandSender.class.getDeclaredMethod("getCommandSender");
27-
} catch (NoSuchMethodException e2) {
28-
throw new RuntimeException("Not ReIndevPatches?", e);
29-
}
30-
}
31-
getPlayer = getPlayerTmp;
32-
}
3315

3416
private final CommandCompat commandCompat;
3517

3618
private ServerCommandWrapper4ReIndevPatches(CommandCompat commandCompat) {
3719
super(commandCompat.getName(), commandCompat.getAliases());
38-
this.setIssuerRole(IssuerRole.PLAYER); // We don't support console :(
20+
this.setIssuerRole(IssuerRole.PLAYER); // We don't support console :( // Sad to read :(
3921
this.commandCompat = commandCompat;
4022
}
4123

@@ -44,7 +26,7 @@ public void execute(String commandLabel, String[] args, CommandSender commandSen
4426
NetworkPlayer networkPlayer = null;
4527
if (commandSender.isPlayer()) {
4628
try {
47-
networkPlayer = (NetworkPlayer) getPlayer.invoke(commandSender);
29+
networkPlayer = (NetworkPlayer) commandSender.getPlayer();
4830
} catch (Exception ignored) {}
4931
}
5032
if (networkPlayer == null) {
@@ -67,21 +49,11 @@ public boolean hideCommandArgs() {
6749
return this.commandCompat.isHidden();
6850
}
6951

70-
private static final JavaPlugin foxLoaderJavaPlugin = new JavaPlugin() {
71-
@SuppressWarnings("deprecation")
72-
@Override
73-
public String getName() {
74-
return "FoxLoader";
75-
}
76-
};
77-
7852
public static void registerAllForReIndevPatches() {
7953
if (!ModLoader.areAllModsLoaded()) // Just a safeguard, just in case.
8054
throw new IllegalArgumentException("Not Loaded?");
8155
for (CommandCompat commandCompat : CommandCompat.commands.values()) {
82-
if (!foxLoaderJavaPlugin.registerCommand(new ServerCommandWrapper4ReIndevPatches(commandCompat), true)) {
83-
ModLoader.getModLoaderLogger().warning("Failed to register /" + commandCompat.getName() + " command");
84-
}
56+
CommandRegistry.getInstance().registerCommand(commandCompat.getName(), new ServerCommandWrapper4ReIndevPatches(commandCompat));
8557
}
8658
}
8759
}

0 commit comments

Comments
 (0)