forked from iTXTech/SynapseAPI
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
built-in transfer command #6
Open
Chlorine17
wants to merge
2
commits into
CloudburstMC:master
Choose a base branch
from
Chlorine17:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,126 @@ | ||
package org.itxtech.synapseapi; | ||
|
||
import cn.nukkit.Server; | ||
import cn.nukkit.network.RakNetInterface; | ||
import cn.nukkit.network.SourceInterface; | ||
import cn.nukkit.network.protocol.DataPacket; | ||
import cn.nukkit.network.protocol.ProtocolInfo; | ||
import cn.nukkit.plugin.PluginBase; | ||
import cn.nukkit.utils.ConfigSection; | ||
import org.itxtech.synapseapi.messaging.Messenger; | ||
import org.itxtech.synapseapi.messaging.StandardMessenger; | ||
import org.itxtech.synapseapi.network.protocol.mcpe.SetHealthPacket; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* @author boybook | ||
*/ | ||
public class SynapseAPI extends PluginBase { | ||
|
||
public static boolean enable = true; | ||
private static SynapseAPI instance; | ||
private boolean autoConnect = true; | ||
private Map<String, SynapseEntry> synapseEntries = new HashMap<>(); | ||
private Messenger messenger; | ||
|
||
public static SynapseAPI getInstance() { | ||
return instance; | ||
} | ||
|
||
public boolean isAutoConnect() { | ||
return autoConnect; | ||
} | ||
|
||
@Override | ||
public void onLoad() { | ||
instance = this; | ||
} | ||
|
||
@Override | ||
public void onEnable() { | ||
this.getServer().getNetwork().registerPacket(ProtocolInfo.SET_HEALTH_PACKET, SetHealthPacket.class); | ||
this.messenger = new StandardMessenger(); | ||
loadEntries(); | ||
} | ||
|
||
public Map<String, SynapseEntry> getSynapseEntries() { | ||
return synapseEntries; | ||
} | ||
|
||
public void addSynapseAPI(SynapseEntry entry) { | ||
this.synapseEntries.put(entry.getHash(), entry); | ||
} | ||
|
||
public SynapseEntry getSynapseEntry(String hash) { | ||
return this.synapseEntries.get(hash); | ||
} | ||
|
||
public void shutdownAll() { | ||
for (SynapseEntry entry : new ArrayList<>(this.synapseEntries.values())) { | ||
entry.shutdown(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
this.shutdownAll(); | ||
} | ||
|
||
public DataPacket getPacket(byte[] buffer) { | ||
byte pid = buffer[0] == (byte) 0xfe ? (byte) 0xff : buffer[0]; | ||
|
||
byte start = 1; | ||
DataPacket data; | ||
data = this.getServer().getNetwork().getPacket(pid); | ||
|
||
if (data == null) { | ||
Server.getInstance().getLogger().notice("C => S 未找到匹配数据包"); | ||
return null; | ||
} | ||
data.setBuffer(buffer, start); | ||
return data; | ||
} | ||
|
||
private void loadEntries() { | ||
this.saveDefaultConfig(); | ||
enable = this.getConfig().getBoolean("enable", true); | ||
|
||
if (!enable) { | ||
this.getLogger().warning("The SynapseAPI is not be enabled!"); | ||
} else { | ||
if (this.getConfig().getBoolean("disable-rak")) { | ||
for (SourceInterface sourceInterface : this.getServer().getNetwork().getInterfaces()) { | ||
if (sourceInterface instanceof RakNetInterface) { | ||
sourceInterface.shutdown(); | ||
} | ||
} | ||
} | ||
|
||
List entries = this.getConfig().getList("entries"); | ||
|
||
for (Object entry : entries) { | ||
@SuppressWarnings("unchecked") | ||
ConfigSection section = new ConfigSection((LinkedHashMap) entry); | ||
String serverIp = section.getString("server-ip", "127.0.0.1"); | ||
int port = section.getInt("server-port", 10305); | ||
boolean isMainServer = section.getBoolean("isMainServer"); | ||
boolean isLobbyServer = section.getBoolean("isLobbyServer"); | ||
boolean transfer = section.getBoolean("transferOnShutdown", true); | ||
String password = section.getString("password"); | ||
String serverDescription = section.getString("description"); | ||
this.autoConnect = section.getBoolean("autoConnect", true); | ||
if (this.autoConnect) { | ||
this.addSynapseAPI(new SynapseEntry(this, serverIp, port, isMainServer, isLobbyServer, transfer, password, serverDescription)); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
public Messenger getMessenger() { | ||
return messenger; | ||
} | ||
} | ||
package org.itxtech.synapseapi; | ||
|
||
import cn.nukkit.Server; | ||
import cn.nukkit.network.RakNetInterface; | ||
import cn.nukkit.network.SourceInterface; | ||
import cn.nukkit.network.protocol.DataPacket; | ||
import cn.nukkit.network.protocol.ProtocolInfo; | ||
import cn.nukkit.plugin.PluginBase; | ||
import cn.nukkit.utils.ConfigSection; | ||
import org.itxtech.synapseapi.command.TransferCommand; | ||
import org.itxtech.synapseapi.messaging.Messenger; | ||
import org.itxtech.synapseapi.messaging.StandardMessenger; | ||
import org.itxtech.synapseapi.network.protocol.mcpe.SetHealthPacket; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* @author boybook | ||
*/ | ||
public class SynapseAPI extends PluginBase { | ||
|
||
public static boolean enable = true; | ||
private static SynapseAPI instance; | ||
private boolean autoConnect = true; | ||
private Map<String, SynapseEntry> synapseEntries = new HashMap<>(); | ||
private Messenger messenger; | ||
|
||
public static SynapseAPI getInstance() { | ||
return instance; | ||
} | ||
|
||
public boolean isAutoConnect() { | ||
return autoConnect; | ||
} | ||
|
||
@Override | ||
public void onLoad() { | ||
instance = this; | ||
} | ||
|
||
@Override | ||
public void onEnable() { | ||
this.getServer().getNetwork().registerPacket(ProtocolInfo.SET_HEALTH_PACKET, SetHealthPacket.class); | ||
this.getServer().getCommandMap().register("transfer", new TransferCommand("transfer")); | ||
this.messenger = new StandardMessenger(); | ||
loadEntries(); | ||
} | ||
|
||
public Map<String, SynapseEntry> getSynapseEntries() { | ||
return synapseEntries; | ||
} | ||
|
||
public void addSynapseAPI(SynapseEntry entry) { | ||
this.synapseEntries.put(entry.getHash(), entry); | ||
} | ||
|
||
public SynapseEntry getSynapseEntry(String hash) { | ||
return this.synapseEntries.get(hash); | ||
} | ||
|
||
public void shutdownAll() { | ||
for (SynapseEntry entry : new ArrayList<>(this.synapseEntries.values())) { | ||
entry.shutdown(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
this.shutdownAll(); | ||
} | ||
|
||
public DataPacket getPacket(byte[] buffer) { | ||
byte pid = buffer[0] == (byte) 0xfe ? (byte) 0xff : buffer[0]; | ||
|
||
byte start = 1; | ||
DataPacket data; | ||
data = this.getServer().getNetwork().getPacket(pid); | ||
|
||
if (data == null) { | ||
Server.getInstance().getLogger().notice("C => S 未找到匹配数据包"); | ||
return null; | ||
} | ||
data.setBuffer(buffer, start); | ||
return data; | ||
} | ||
|
||
private void loadEntries() { | ||
this.saveDefaultConfig(); | ||
enable = this.getConfig().getBoolean("enable", true); | ||
|
||
if (!enable) { | ||
this.getLogger().warning("The SynapseAPI is not be enabled!"); | ||
} else { | ||
if (this.getConfig().getBoolean("disable-rak")) { | ||
for (SourceInterface sourceInterface : this.getServer().getNetwork().getInterfaces()) { | ||
if (sourceInterface instanceof RakNetInterface) { | ||
sourceInterface.shutdown(); | ||
} | ||
} | ||
} | ||
|
||
List entries = this.getConfig().getList("entries"); | ||
|
||
for (Object entry : entries) { | ||
@SuppressWarnings("unchecked") | ||
ConfigSection section = new ConfigSection((LinkedHashMap) entry); | ||
String serverIp = section.getString("server-ip", "127.0.0.1"); | ||
int port = section.getInt("server-port", 10305); | ||
boolean isMainServer = section.getBoolean("isMainServer"); | ||
boolean isLobbyServer = section.getBoolean("isLobbyServer"); | ||
boolean transfer = section.getBoolean("transferOnShutdown", true); | ||
String password = section.getString("password"); | ||
String serverDescription = section.getString("description"); | ||
this.autoConnect = section.getBoolean("autoConnect", true); | ||
if (this.autoConnect) { | ||
this.addSynapseAPI(new SynapseEntry(this, serverIp, port, isMainServer, isLobbyServer, transfer, password, serverDescription)); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
public Messenger getMessenger() { | ||
return messenger; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/itxtech/synapseapi/command/TransferCommand.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,31 @@ | ||
package org.itxtech.synapseapi.command; | ||
|
||
import cn.nukkit.command.Command; | ||
import cn.nukkit.command.CommandSender; | ||
import cn.nukkit.utils.TextFormat; | ||
import org.itxtech.synapseapi.SynapsePlayer; | ||
|
||
public class TransferCommand extends Command { | ||
|
||
public TransferCommand(String name) { | ||
super(name); | ||
this.setDescription("Transfer server to another server"); | ||
this.setUsage("/transfer <description>"); | ||
this.setPermission("synapseapi.command.transfer"); | ||
this.setAliases(new String[] {"transfer", "stransfer", "synapsetransfer", "proxy"}); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String s, String[] args) { | ||
if (sender instanceof SynapsePlayer){ | ||
if (args.length > 0){ | ||
((SynapsePlayer) sender).transferByDescription(args[0]); | ||
return true; | ||
} | ||
sender.sendMessage(TextFormat.RED + this.getUsage()); | ||
return false; | ||
} | ||
sender.sendMessage(TextFormat.RED + "[SynapseAPI] This command only available for player!"); | ||
return false; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why only players?
make it for console too. it's just checks :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wkwkwk