-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7519465
commit a773cc2
Showing
7 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/github/ravenlab/commander/platform/sponge/BungeeCommandMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.github.ravenlab.commander.platform.sponge; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
|
||
import net.md_5.bungee.api.plugin.Command; | ||
|
||
public class BungeeCommandMap { | ||
|
||
@SuppressWarnings("unchecked") | ||
public Map<String, Command> getMapIfExists(Object manager) { | ||
try { | ||
Field mapField = manager.getClass().getDeclaredField("commandMap"); | ||
mapField.setAccessible(true); | ||
return (Map<String, Command>) mapField.get(manager); | ||
} catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/github/ravenlab/commander/platform/sponge/SpongeCommandWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.github.ravenlab.commander.platform.sponge; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.spongepowered.api.command.CommandCallable; | ||
import org.spongepowered.api.command.CommandException; | ||
import org.spongepowered.api.command.CommandResult; | ||
import org.spongepowered.api.command.CommandSource; | ||
import org.spongepowered.api.text.Text; | ||
import org.spongepowered.api.world.Location; | ||
import org.spongepowered.api.world.World; | ||
|
||
import com.github.ravenlab.commander.command.CommanderCommand; | ||
import com.github.ravenlab.commander.command.CommanderExecutor; | ||
|
||
public class SpongeCommandWrapper implements CommandCallable { | ||
|
||
private CommanderExecutor<CommandSource> executor; | ||
|
||
public SpongeCommandWrapper(CommanderCommand<CommandSource> command) { | ||
this.executor = new CommanderExecutor<>(command, new SpongeTypeResolver()); | ||
} | ||
|
||
@Override | ||
public CommandResult process(CommandSource source, String arguments) throws CommandException { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) | ||
throws CommandException { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean testPermission(CommandSource source) { | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
@Override | ||
public Optional<Text> getShortDescription(CommandSource source) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public Optional<Text> getHelp(CommandSource source) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public Text getUsage(CommandSource source) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/github/ravenlab/commander/platform/sponge/SpongeCommander.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.github.ravenlab.commander.platform.sponge; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.spongepowered.api.command.CommandSource; | ||
import org.spongepowered.api.command.spec.CommandExecutor; | ||
import org.spongepowered.api.plugin.PluginContainer; | ||
|
||
import com.github.ravenlab.commander.Commander; | ||
import com.github.ravenlab.commander.command.CommandData; | ||
import com.github.ravenlab.commander.command.CommanderCommand; | ||
|
||
public class SpongeCommander extends Commander<PluginContainer, CommandExecutor, CommandSource>{ | ||
|
||
private Map<String, CommandExecutor> knownCommands; | ||
|
||
//Look at https://github.com/SpongePowered/SpongeCommon/blob/cd424add778a1059f036c052c3f685619305d001/src/main/java/org/spongepowered/common/command/SpongeCommandManager.java | ||
|
||
public SpongeCommander() { | ||
this.knownCommands = new BungeeCommandMap() | ||
.getMapIfExists(ProxyServer.getInstance().getPluginManager()); | ||
} | ||
|
||
@Override | ||
protected Optional<String> registerAlias(PluginContainer plugin, CommandExecutor command, String alias, boolean forceRegister) { | ||
String registeredAlias = alias; | ||
|
||
if(this.knownCommands.containsKey(alias) && !forceRegister) { | ||
registeredAlias = this.getPluginName(plugin).toLowerCase() + ":" + alias; | ||
} | ||
|
||
this.knownCommands.put(registeredAlias, command); | ||
return Optional.of(registeredAlias); | ||
} | ||
|
||
@Override | ||
protected boolean unregisterAlias(String command) { | ||
return this.knownCommands.remove(command) != null; | ||
} | ||
|
||
@Override | ||
protected CommandExecutor createCommandWrapper(CommandData data, CommanderCommand<CommandSource> command) { | ||
return new SpongeCommandWrapper(command); | ||
} | ||
|
||
@Override | ||
protected String getPluginName(PluginContainer plugin) { | ||
return plugin.getName(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/github/ravenlab/commander/platform/sponge/SpongeCommanderPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.github.ravenlab.commander.platform.sponge; | ||
|
||
import java.util.UUID; | ||
|
||
import org.spongepowered.api.entity.living.player.Player; | ||
import org.spongepowered.api.text.Text; | ||
|
||
import com.github.ravenlab.commander.player.CommanderPlayer; | ||
|
||
public class SpongeCommanderPlayer extends CommanderPlayer<Player> { | ||
|
||
public SpongeCommanderPlayer(Player player) { | ||
super(player); | ||
} | ||
|
||
@Override | ||
public UUID getUniqueId() { | ||
return this.getNative().getUniqueId(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return this.getNative().getName(); | ||
} | ||
|
||
@Override | ||
public boolean hasPermission(String permission) { | ||
return this.getNative().hasPermission(permission); | ||
} | ||
|
||
@Override | ||
public void sendMessage(String message) { | ||
this.getNative().sendMessage(Text.of(message)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/github/ravenlab/commander/platform/sponge/SpongeCommanderSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.ravenlab.commander.platform.sponge; | ||
|
||
import org.spongepowered.api.command.CommandSource; | ||
import org.spongepowered.api.text.Text; | ||
|
||
import com.github.ravenlab.commander.sender.CommanderSender; | ||
|
||
public class SpongeCommanderSender extends CommanderSender<CommandSource> { | ||
|
||
public SpongeCommanderSender(CommandSource sender) { | ||
super(sender); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return this.getNative().getName(); | ||
} | ||
|
||
@Override | ||
public boolean hasPermission(String permission) { | ||
return this.getNative().hasPermission(permission); | ||
} | ||
|
||
@Override | ||
public void sendMessage(String message) { | ||
this.getNative().sendMessages(Text.of(message)); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/github/ravenlab/commander/platform/sponge/SpongeTypeResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.github.ravenlab.commander.platform.sponge; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.spongepowered.api.Sponge; | ||
import org.spongepowered.api.entity.living.player.Player; | ||
import org.spongepowered.api.world.World; | ||
|
||
import com.github.ravenlab.commander.resolver.TypeResolver; | ||
import com.github.ravenlab.commander.sender.CommanderSender; | ||
|
||
public class SpongeTypeResolver implements TypeResolver<Player, World> { | ||
|
||
@Override | ||
public Optional<Player> getPlayer(String name) { | ||
return Sponge.getServer().getPlayer(name); | ||
} | ||
|
||
@Override | ||
public Optional<Player> getPlayer(UUID uuid) { | ||
return Sponge.getServer().getPlayer(uuid); | ||
} | ||
|
||
@Override | ||
public Optional<World> getWorld(String name) { | ||
return Sponge.getServer().getWorld(name); | ||
} | ||
|
||
@Override | ||
public CommanderSender<?> getSender(Object nativeSender) { | ||
if(nativeSender instanceof Player) { | ||
Player player = (Player) nativeSender; | ||
return new SpongeCommanderPlayer(player); | ||
} else { | ||
CommandSender commandSender = (CommandSender) nativeSender; | ||
return new SpongeCommanderSender(commandSender); | ||
} | ||
} | ||
|
||
@Override | ||
public Class<Player> getPlayerClass() { | ||
return Player.class; | ||
} | ||
|
||
@Override | ||
public Optional<Class<World>> getWorldClass() { | ||
return Optional.of(World.class); | ||
} | ||
} |