Skip to content

Commit 9814693

Browse files
author
Matthew
committed
Published to GitHub
This is version 1.1.
0 parents  commit 9814693

11 files changed

Lines changed: 516 additions & 0 deletions

File tree

.gitattributes

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
*.sln merge=union
7+
*.csproj merge=union
8+
*.vbproj merge=union
9+
*.fsproj merge=union
10+
*.dbproj merge=union
11+
12+
# Standard to msysgit
13+
*.doc diff=astextplain
14+
*.DOC diff=astextplain
15+
*.docx diff=astextplain
16+
*.DOCX diff=astextplain
17+
*.dot diff=astextplain
18+
*.DOT diff=astextplain
19+
*.pdf diff=astextplain
20+
*.PDF diff=astextplain
21+
*.rtf diff=astextplain
22+
*.RTF diff=astextplain

.gitignore

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#################
2+
## Eclipse
3+
#################
4+
5+
*.pydevproject
6+
.project
7+
.metadata
8+
bin/
9+
tmp/
10+
*.tmp
11+
*.bak
12+
*.swp
13+
*~.nib
14+
local.properties
15+
.classpath
16+
.settings/
17+
.loadpath
18+
19+
# External tool builders
20+
.externalToolBuilders/
21+
22+
# Locally stored "Eclipse launch configurations"
23+
*.launch
24+
25+
# CDT-specific
26+
.cproject
27+
28+
# PDT-specific
29+
.buildpath
30+
31+
32+
#################
33+
## Visual Studio
34+
#################
35+
36+
## Ignore Visual Studio temporary files, build results, and
37+
## files generated by popular Visual Studio add-ons.
38+
39+
# User-specific files
40+
*.suo
41+
*.user
42+
*.sln.docstates
43+
44+
# Build results
45+
46+
[Dd]ebug/
47+
[Rr]elease/
48+
x64/
49+
build/
50+
[Bb]in/
51+
[Oo]bj/
52+
53+
# MSTest test Results
54+
[Tt]est[Rr]esult*/
55+
[Bb]uild[Ll]og.*
56+
57+
*_i.c
58+
*_p.c
59+
*.ilk
60+
*.meta
61+
*.obj
62+
*.pch
63+
*.pdb
64+
*.pgc
65+
*.pgd
66+
*.rsp
67+
*.sbr
68+
*.tlb
69+
*.tli
70+
*.tlh
71+
*.tmp
72+
*.tmp_proj
73+
*.log
74+
*.vspscc
75+
*.vssscc
76+
.builds
77+
*.pidb
78+
*.log
79+
*.scc
80+
81+
# Visual C++ cache files
82+
ipch/
83+
*.aps
84+
*.ncb
85+
*.opensdf
86+
*.sdf
87+
*.cachefile
88+
89+
# Visual Studio profiler
90+
*.psess
91+
*.vsp
92+
*.vspx
93+
94+
# Guidance Automation Toolkit
95+
*.gpState
96+
97+
# ReSharper is a .NET coding add-in
98+
_ReSharper*/
99+
*.[Rr]e[Ss]harper
100+
101+
# TeamCity is a build add-in
102+
_TeamCity*
103+
104+
# DotCover is a Code Coverage Tool
105+
*.dotCover
106+
107+
# NCrunch
108+
*.ncrunch*
109+
.*crunch*.local.xml
110+
111+
# Installshield output folder
112+
[Ee]xpress/
113+
114+
# DocProject is a documentation generator add-in
115+
DocProject/buildhelp/
116+
DocProject/Help/*.HxT
117+
DocProject/Help/*.HxC
118+
DocProject/Help/*.hhc
119+
DocProject/Help/*.hhk
120+
DocProject/Help/*.hhp
121+
DocProject/Help/Html2
122+
DocProject/Help/html
123+
124+
# Click-Once directory
125+
publish/
126+
127+
# Publish Web Output
128+
*.Publish.xml
129+
*.pubxml
130+
131+
# NuGet Packages Directory
132+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133+
#packages/
134+
135+
# Windows Azure Build Output
136+
csx
137+
*.build.csdef
138+
139+
# Windows Store app package directory
140+
AppPackages/
141+
142+
# Others
143+
sql/
144+
*.Cache
145+
ClientBin/
146+
[Ss]tyle[Cc]op.*
147+
~$*
148+
*~
149+
*.dbmdl
150+
*.[Pp]ublish.xml
151+
*.pfx
152+
*.publishsettings
153+
154+
# RIA/Silverlight projects
155+
Generated_Code/
156+
157+
# Backup & report files from converting an old project file to a newer
158+
# Visual Studio version. Backup files are not needed, because we have git ;-)
159+
_UpgradeReport_Files/
160+
Backup*/
161+
UpgradeLog*.XML
162+
UpgradeLog*.htm
163+
164+
# SQL Server files
165+
App_Data/*.mdf
166+
App_Data/*.ldf
167+
168+
#############
169+
## Windows detritus
170+
#############
171+
172+
# Windows image file caches
173+
Thumbs.db
174+
ehthumbs.db
175+
176+
# Folder config file
177+
Desktop.ini
178+
179+
# Recycle Bin used on file shares
180+
$RECYCLE.BIN/
181+
182+
# Mac crap
183+
.DS_Store
184+
185+
186+
#############
187+
## Python
188+
#############
189+
190+
*.py[co]
191+
192+
# Packages
193+
*.egg
194+
*.egg-info
195+
dist/
196+
build/
197+
eggs/
198+
parts/
199+
var/
200+
sdist/
201+
develop-eggs/
202+
.installed.cfg
203+
204+
# Installer logs
205+
pip-log.txt
206+
207+
# Unit test / coverage reports
208+
.coverage
209+
.tox
210+
211+
#Translations
212+
*.mo
213+
214+
#Mr Developer
215+
.mr.developer.cfg
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.fuzzoland.CommandSyncBukkit;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.DataOutputStream;
5+
import java.io.IOException;
6+
import java.util.logging.Level;
7+
8+
import org.bukkit.Bukkit;
9+
import org.bukkit.ChatColor;
10+
import org.bukkit.command.Command;
11+
import org.bukkit.command.CommandExecutor;
12+
import org.bukkit.command.CommandSender;
13+
14+
public class CommandSync implements CommandExecutor{
15+
16+
private Main plugin;
17+
18+
public CommandSync(Main plugin){
19+
this.plugin = plugin;
20+
}
21+
22+
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
23+
if(sender.hasPermission("CommandSync.use")){
24+
if(args.length == 0){
25+
sender.sendMessage(ChatColor.BLUE + "CommandSync v" + plugin.getDescription().getVersion() + " by YoFuzzy3");
26+
sender.sendMessage(ChatColor.GREEN + "/Sync console <server-name/all> </your-command_args>");
27+
sender.sendMessage(ChatColor.GREEN + "/Sync player <player-name/all> </your-command_args>");
28+
sender.sendMessage(ChatColor.BLUE + "Visit www.spigotmc.org/resources/commandsync.115 for help.");
29+
}else if(args.length == 3){
30+
try{
31+
ByteArrayOutputStream b = new ByteArrayOutputStream();
32+
DataOutputStream out = new DataOutputStream(b);
33+
String command = args[2].replaceAll("_", " ");
34+
if(args[0].equalsIgnoreCase("console")){
35+
out.writeUTF("Console");
36+
if(args[1].equalsIgnoreCase("all")){
37+
out.writeUTF("All");
38+
out.writeUTF(command.replaceFirst("/", ""));
39+
sender.sendMessage(ChatColor.GREEN + "Successfully ran command " + command + " for all servers.");
40+
}else{
41+
out.writeUTF("Single");
42+
out.writeUTF(args[1]);
43+
out.writeUTF(command.replaceFirst("/", ""));
44+
sender.sendMessage(ChatColor.GREEN + "Successfully ran command " + command + " for server " + args[1] + ".");
45+
}
46+
Bukkit.getScheduler().runTaskAsynchronously(plugin, new PluginMessageTask(plugin, "CommandSync", b));
47+
plugin.logger.log(Level.INFO, "[CommandSync] Sent data to BungeeCord.");
48+
}else if(args[0].equalsIgnoreCase("player")){
49+
out.writeUTF("Player");
50+
if(args[1].equalsIgnoreCase("all")){
51+
out.writeUTF("All");
52+
out.writeUTF(command);
53+
sender.sendMessage(ChatColor.GREEN + "Successfully ran command " + command + " for all players.");
54+
}else{
55+
out.writeUTF("Single");
56+
out.writeUTF(args[1]);
57+
out.writeUTF(command);
58+
sender.sendMessage(ChatColor.GREEN + "Successfully ran command " + command + " for player " + args[1] + ".");
59+
}
60+
Bukkit.getScheduler().runTaskAsynchronously(plugin, new PluginMessageTask(plugin, "CommandSync", b));
61+
plugin.logger.log(Level.INFO, "[CommandSync] Sent command " + command + " to BungeeCord.");
62+
}else{
63+
sender.sendMessage(ChatColor.RED + "Type /Sync for help!");
64+
}
65+
b.close();
66+
out.close();
67+
}catch(IOException e){
68+
e.printStackTrace();
69+
sender.sendMessage(ChatColor.RED + "An error occurred, check the console.");
70+
}
71+
}else{
72+
sender.sendMessage(ChatColor.RED + "Type /Sync for help!");
73+
}
74+
}else{
75+
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command.");
76+
}
77+
return true;
78+
}
79+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.fuzzoland.CommandSyncBukkit;
2+
3+
import java.util.logging.Logger;
4+
5+
import org.bukkit.Bukkit;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
8+
public class Main extends JavaPlugin{
9+
10+
public Logger logger = Bukkit.getLogger();
11+
12+
public void onEnable(){
13+
getServer().getMessenger().registerIncomingPluginChannel(this, "CommandSync", new MessageListener(this));
14+
getServer().getMessenger().registerOutgoingPluginChannel(this, "CommandSync");
15+
getCommand("Sync").setExecutor(new CommandSync(this));
16+
}
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.fuzzoland.CommandSyncBukkit;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.DataInputStream;
5+
import java.io.IOException;
6+
import java.util.logging.Level;
7+
8+
import org.bukkit.Bukkit;
9+
import org.bukkit.entity.Player;
10+
import org.bukkit.plugin.messaging.PluginMessageListener;
11+
12+
public class MessageListener implements PluginMessageListener{
13+
14+
private Main plugin;
15+
16+
public MessageListener(Main plugin){
17+
this.plugin = plugin;
18+
}
19+
20+
public void onPluginMessageReceived(String channel, Player player, byte[] data){
21+
DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
22+
try{
23+
String command = in.readUTF();
24+
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
25+
plugin.logger.log(Level.INFO, "[CommandSync] Ran command: " + command);
26+
}catch(IOException e){
27+
e.printStackTrace();
28+
}
29+
}
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fuzzoland.CommandSyncBukkit;
2+
3+
import java.io.ByteArrayOutputStream;
4+
5+
import org.bukkit.Bukkit;
6+
7+
public class PluginMessageTask implements Runnable{
8+
9+
private Main plugin;
10+
private String channel = null;
11+
private ByteArrayOutputStream bytes = null;
12+
13+
public PluginMessageTask(Main plugin, String channel, ByteArrayOutputStream bytes){
14+
this.plugin = plugin;
15+
this.channel = channel;
16+
this.bytes = bytes;
17+
}
18+
19+
public void run(){
20+
Bukkit.getServer().sendPluginMessage(plugin, channel, bytes.toByteArray());
21+
}
22+
}

0 commit comments

Comments
 (0)