Skip to content

Commit

Permalink
updata 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
a1640727878 committed Jan 10, 2020
1 parent 1df9d5e commit b04b285
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 55 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pluginGroup=sky_bai.bukkit
pluginVersion=0.1.1
pluginVersion=0.1.2
66 changes: 22 additions & 44 deletions src/main/java/sky_bai/bukkit/baiteam/BaiTeam.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package sky_bai.bukkit.baiteam;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand All @@ -14,21 +16,14 @@
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.EnumWrappers.Hand;
import com.comphenix.protocol.wrappers.MinecraftKey;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import net.minecraft.server.v1_12_R1.PacketDataSerializer;
import net.minecraft.server.v1_12_R1.EntityArrow.PickupStatus;
import sky_bai.bukkit.baiteam.config.BTConfig;
import sky_bai.bukkit.baiteam.config.DefaultConfig;
import sky_bai.bukkit.baiteam.config.MessageConfig;
Expand Down Expand Up @@ -75,40 +70,6 @@ public void run() {
}
}
}.runTaskTimerAsynchronously(this, 10, 10);

protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.CUSTOM_PAYLOAD) {
@Override
public void onPacketSending(PacketEvent event) {
System.out.println(event);
System.out.println(event.getPacket());
System.out.println(event.getPacket().getSpecificModifier(Object.class));
System.out.println(event.getPacket().getSpecificModifier(Object.class).getValues());
System.out.println(event.getPacket().getStrings());
System.out.println(event.getPacket().getStrings().getValues());
System.out.println(event.getPacket().getModifier().withType(ByteBuf.class));
System.out.println(event.getPacket().getModifier().withType(ByteBuf.class).getValues());
System.out.println(ByteBufUtil.hexDump((ByteBuf) event.getPacket().getModifier().withType(ByteBuf.class).getValues().get(0)));
}
});
}

public Object toObject(byte[] bytes) {
Object obj = null;
try {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bis);
obj = ois.readObject();
ois.close();
bis.close();
} catch (IOException | ClassNotFoundException ex) {
ex.printStackTrace();
}
return obj;
}

@Override
public void onDisable() {

}

public static BaiTeam getBaiTeam() {
Expand Down Expand Up @@ -157,7 +118,7 @@ private void openBookMinecraftVersion(Player player) {
if (version.compareTo(new MinecraftVersion("1.9")) >= 0 && version.compareTo(new MinecraftVersion("1.12.2")) == 0) {
openBookPacketContainer_V1_9(player);
return;
} else if (version.compareTo(new MinecraftVersion("1.13")) >= 0 && version.compareTo(new MinecraftVersion("1.13.2")) == 0 ) {
} else if (version.compareTo(new MinecraftVersion("1.13")) >= 0 && version.compareTo(new MinecraftVersion("1.13.2")) == 0) {
openBookPacketContainer_V1_13(player);
return;
} else if (version.compareTo(new MinecraftVersion("1.14")) >= 0) {
Expand All @@ -175,4 +136,21 @@ public void openBook(ItemStack book, Player player) {
openBookMinecraftVersion(player);
player.getInventory().setItem(slot, old);
}

public void copyInputStreamToFile(InputStream is, File file) {
file.getParentFile().mkdirs();
OutputStream os = null;
try {
file.createNewFile();
os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
is.close();
os.close();
} catch (IOException e) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.FileUtils;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

Expand All @@ -26,13 +25,14 @@ public DefaultConfig() {
}
}

@Override
public FileConfiguration getConfig() {
return defaultConfig;
}

private void reset() throws IOException {
InputStream a1 = BaiTeam.class.getResourceAsStream("/assets/config.yml");
FileUtils.copyInputStreamToFile(a1, configFile);
BaiTeam.getBaiTeam().copyInputStreamToFile(a1, configFile);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.FileUtils;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

Expand All @@ -25,12 +24,13 @@ public MessageConfig() {
}
}

@Override
public FileConfiguration getConfig() {
return messageConfig;
}

private void reset() throws IOException {
InputStream a1 = BaiTeam.class.getResourceAsStream("/assets/message.yml");
FileUtils.copyInputStreamToFile(a1, configFile);
BaiTeam.getBaiTeam().copyInputStreamToFile(a1, configFile);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/assets/message.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#一般情况下 &{0} 队伍名 &{1} 队长名 &{2} - &{x}其他字符
#一般情况下 &{0} 队伍名 &{1} 队长名 &{2} - &{x}其他字符
Team:
Create: 你成功的创建了队伍 [&{0}]
Leave_OnLeader_Member: "&{1}解散了队伍"
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: BaiTeam
main: sky_bai.bukkit.baiteam.BaiTeam
api-version: 1.13
version: '@version@'
name: "BaiTeam"
main: "sky_bai.bukkit.baiteam.BaiTeam"
api-version: "1.13"
version: "@version@"
prefix: BaiTeam
authors:
- sky_bai
depend:
- DungeonsXL
#- ProtocolLib
- ProtocolLib
softdepend:
- PlaceholderAPI

Expand Down

0 comments on commit b04b285

Please sign in to comment.