Skip to content

Commit

Permalink
Updates to 1.16.2+
Browse files Browse the repository at this point in the history
Removes tps based events
Adds player count to hub menu
  • Loading branch information
ShakeforProtein committed Sep 11, 2020
1 parent 986273c commit a961f9c
Show file tree
Hide file tree
Showing 13 changed files with 531 additions and 35 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.ShakeforProtein</groupId>
<artifactId>TreeboTeleport</artifactId>
<version>1.0.1 - SpMc1.16.1</version>
<version>1.1.0 - SpMc1.16.2</version>
<packaging>jar</packaging>

<name>TreeboTeleport</name>
Expand Down Expand Up @@ -82,13 +82,13 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<version>1.16.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<version>1.16.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.IOException;

import static me.shakeforprotein.treeboteleport.TreeboTeleport.fullPlayerList;
import static me.shakeforprotein.treeboteleport.TreeboTeleport.playerCounts;

public class BungeeRecieve implements PluginMessageListener {

Expand All @@ -35,13 +36,15 @@ public void onPluginMessageReceived(String channel, Player player, byte[] messag
String subchannel = in.readUTF();
//System.out.println("Recieved message on 'subchannel' :" + subchannel);
if (subchannel.startsWith(pl.getName() + "Channel-")) {
//Bukkit.broadcastMessage("Channel started with Channel-");
Short len = in.readShort();
byte[] msgbytes = new byte[len];
in.readFully(msgbytes);

DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
try {
String msgData = msgin.readUTF(); // Read the data in the same way you wrote it
//Bukkit.broadcastMessage(msgData);
if (subchannel.endsWith("CrossServerTeleport")) {
for (Player targetPlayer : Bukkit.getOnlinePlayers()) {
if (targetPlayer.getName().equalsIgnoreCase(msgData.split(",")[1])) {
Expand Down Expand Up @@ -86,6 +89,45 @@ public void run() {
}
}
}
else if (subchannel.contains("perWorldPlayersList")) {
String[] str = msgData.split("\\|");
int totalPlayers = 0;
if(str.length > 0) {
if (str[0].equalsIgnoreCase("Sky")) {
int sb, ai, cb, ob;
sb = 0;
ai = 0;
cb = 0;
ob = 0;
for (int i = 1; i < str.length; i++) {
if (!str[0].equalsIgnoreCase("")) {
if (str[i].toLowerCase().startsWith("sky")){
sb++;
} else if (str[i].toLowerCase().startsWith("one")){
ob++;
} else if (str[i].toLowerCase().startsWith("cave")){
cb++;
} else if (str[i].toLowerCase().startsWith("acid")){
ai++;
}
}
}
playerCounts.put("Sky", (sb+ob+cb+ai)-1);
playerCounts.put("SkyBlock", (sb)-1);
playerCounts.put("OneBlock", (ob)-1);
playerCounts.put("CaveBlock", (cb)-1);
playerCounts.put("AcidIsland", (ai)-1);

} else {
for (int i = 1; i < str.length; i++) {
if (!str[i].equalsIgnoreCase("")) {
totalPlayers++;
}
}
playerCounts.put(str[0].trim(), totalPlayers);
}
}
}
else if (subchannel.endsWith("Jsaw")) {
Bukkit.getScheduler().runTaskLater(pl, new Runnable() {
@Override
Expand All @@ -94,7 +136,6 @@ public void run() {
}
},40L);
}

else if(subchannel.equals("GetServers")) {
String[] serverList = in.readUTF().split(", ");
for(String servers : serverList) {
Expand All @@ -108,11 +149,17 @@ else if(subchannel.equals("GetServers")) {
else if(subchannel.contains("PlayerList")){
String server = in.readUTF();
String[] playerList = in.readUTF().split(", ");
fullPlayerList.clear();
for(String playa : playerList){
if(playa != null) {
fullPlayerList.add(playa);
if(server.equalsIgnoreCase("ALL")) {
fullPlayerList.clear();
for (String playa : playerList) {
if (playa != null) {
fullPlayerList.add(playa);
}
}
} else {
if(!playerList[0].equalsIgnoreCase("")) {
pl.playerCounts.put(server, playerList.length);
} else {pl.playerCounts.put(server, 0);}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void sendPluginMessage(String type, String server, String cmd){
DataOutputStream msgout = new DataOutputStream(msgbytes);
try {
String message = "";
if(type.equalsIgnoreCase("CrossServerTeleport") || type.equalsIgnoreCase("CrossServerTPAHere") || type.equalsIgnoreCase("CrossServerTPA") || type.equalsIgnoreCase("Jsaw")){
if(type.equalsIgnoreCase("CrossServerTeleport") || type.equalsIgnoreCase("CrossServerTPAHere") || type.equalsIgnoreCase("CrossServerTPA") || type.equalsIgnoreCase("perWorldPlayersList") || type.equalsIgnoreCase("Jsaw")){
message = cmd;
}
msgout.writeUTF(message);
Expand All @@ -49,6 +49,36 @@ public void sendPluginMessage(String type, String server, String cmd){
player.sendPluginMessage(pl, "BungeeCord", out.toByteArray());
}

public void consoleSendPluginMessage(String type, String server, String cmd){
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Forward"); //Type of message
out.writeUTF(server); // Server to send to
out.writeUTF(pl.getName() + "Channel-" + type); //Receiver Channel

// If you don't care about the player
// Player player = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
// Else, specify them
// Player player = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);

ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
DataOutputStream msgout = new DataOutputStream(msgbytes);
try {
String message = "";
if(type.equalsIgnoreCase("CrossServerTeleport") || type.equalsIgnoreCase("CrossServerTPAHere") || type.equalsIgnoreCase("CrossServerTPA") || type.equalsIgnoreCase("perWorldPlayersList") || type.equalsIgnoreCase("Jsaw")){
message = cmd;
}
msgout.writeUTF(message);
} catch (IOException exception){
exception.printStackTrace();
}

out.writeShort(msgbytes.toByteArray().length);
out.write(msgbytes.toByteArray());


Bukkit.getServer().sendPluginMessage(pl, "BungeeCord", out.toByteArray());
}

public void sendConnectOther(String server, String playerName){
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("ConnectOther"); //Type of message
Expand Down Expand Up @@ -76,6 +106,13 @@ public void getPlayerList(String server){
}
}

public void sendPerWorldPlayerList(String list){
if(Bukkit.getOnlinePlayers().size() > 0) {
consoleSendPluginMessage("perWorldPlayersList", "ALL", list);
}
}


public void getServers(){
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("GetServers"); //Type of message
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package me.shakeforprotein.treeboteleport.Commands;

import me.shakeforprotein.treeboteleport.TreeboTeleport;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class SetPersonalWarp {

private TreeboTeleport pl;

public SetPersonalWarp(TreeboTeleport main) {
this.pl = main;
}

public boolean register(String command) {
if (!pl.getConfig().getBoolean("disabledCommands." + command)) {
BukkitCommand item2 = new BukkitCommand(command.toLowerCase()) {
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
this.setDescription("Creates a personal warp point with given name, that is accessible to all other players in this gamemode");
this.setUsage("/SetPWarp <warp name> - requires tbteleport.player.warps.setpersonalwarp");
this.setPermission("tbteleport.player.warps.setpersonalwarp");
if (sender.hasPermission(this.getPermission())) {

File warpsYml = new File(pl.getDataFolder(), File.separator + "warps.yml");
if (!warpsYml.exists()) {
sender.sendMessage(pl.err + "Warps data not found. Attempting to recover.");
try {
warpsYml.createNewFile();
FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml);
try {
warps.options().copyDefaults();
warps.save(warpsYml);
} catch (FileNotFoundException e) {
pl.makeLog(e);
}
} catch (IOException e) {
pl.makeLog(e);
sender.sendMessage(pl.err + "Creating warps file failed");
}
}
FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml);
Player p = (Player) sender;
Location loc = p.getLocation();
String world = loc.getWorld().getName();
double x = loc.getX();
double y = loc.getY();
double z = loc.getZ();
float pitch = loc.getPitch();
float yaw = loc.getYaw();
if (args.length == 0) {
p.sendMessage(pl.err + "You must provide a name for your new warp");
} else if (args.length > 2) {
p.sendMessage(pl.err + "Too many arguments");
} else {
String name = args[0];
args[0] = args[0].toLowerCase();
warps.set("playerWarps." + p.getUniqueId().toString() + ".name", name);
warps.set("playerWarps." + p.getUniqueId().toString() + ".world", world);
warps.set("playerWarps." + p.getUniqueId().toString() + ".x", x);
warps.set("playerWarps." + p.getUniqueId().toString() + ".y", y);
warps.set("playerWarps." + p.getUniqueId().toString() + ".z", z);
warps.set("playerWarps." + p.getUniqueId().toString() + ".pitch", pitch);
warps.set("playerWarps." + p.getUniqueId().toString() + ".yaw", yaw);

try {
warps.save(warpsYml);
p.sendMessage(pl.badge + "Player Warp with name: " + ChatColor.GOLD + args[0] + ChatColor.RESET + " has been saved.");
p.sendMessage("If you choose to set a new PWarp, this warp will be overwritten.");
} catch (IOException e) {
pl.makeLog(e);
p.sendMessage(pl.err + "Saving warps file Unsuccessful");
}
}
} else {
sender.sendMessage(ChatColor.RED + "You do not have access to this command. You require permission node " + ChatColor.GOLD + this.getPermission());
}
return true;
}
};
pl.registerNewCommand(pl.getDescription().getName(), item2);
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.shakeforprotein.treeboteleport.Listeners;

import me.shakeforprotein.treeboteleport.Bungee.BungeeSend;
import me.shakeforprotein.treeboteleport.TreeboTeleport;
import me.shakeforprotein.treeboteleport.UpdateChecker.UpdateChecker;
import org.bukkit.Bukkit;
Expand All @@ -12,6 +13,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

Expand All @@ -22,10 +24,12 @@ public class PlayerJoinListener implements Listener {

private TreeboTeleport pl;
private UpdateChecker uc;
private BungeeSend bungeeSend;

public PlayerJoinListener(TreeboTeleport main) {
this.pl = main;
this.uc = new UpdateChecker(main);
this.bungeeSend = new BungeeSend(pl);
}

@EventHandler
Expand Down Expand Up @@ -96,4 +100,5 @@ public boolean onPlayerChangeWorld(PlayerChangedWorldEvent e) {
}
return true;
}

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,71 @@
package me.shakeforprotein.treeboteleport.Listeners;

import me.shakeforprotein.treeboteleport.Bungee.BungeeSend;
import me.shakeforprotein.treeboteleport.TreeboTeleport;
import net.minecraft.server.v1_16_R2.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

public class PlayerMoveListener implements Listener {

public TreeboTeleport pl;
private HashMap<Player, Long> afkHash = new HashMap<>();
private HashMap<Player, Location> locationHash = new HashMap<>();
private BungeeSend bungeeSend;

public PlayerMoveListener(TreeboTeleport main){
this.pl = main;
bungeeSend = new BungeeSend(pl);
}

@EventHandler
public void onPlayerMove(PlayerMoveEvent e){
if(pl.lockMove.containsKey(e.getPlayer().getUniqueId())){
e.setTo(e.getFrom());
}

if(pl.getConfig().getBoolean("doAfkKick")){
if(afkHash == null || !afkHash.containsKey(e.getPlayer())){
afkHash.put(e.getPlayer(), System.currentTimeMillis());
locationHash.put(e.getPlayer(), e.getTo());
} else if(e.getPlayer().getWorld() != locationHash.get(e.getPlayer()).getWorld()){
afkHash.replace(e.getPlayer(), System.currentTimeMillis());
locationHash.replace(e.getPlayer(), e.getTo());
}
else{
Double x, z, x1, x2, z1, z2;
x1 = Math.floor(locationHash.get(e.getPlayer()).getX());
x2 = Math.floor(e.getTo().getX());
z1 = Math.floor(locationHash.get(e.getPlayer()).getZ());
z2 = Math.floor(e.getTo().getZ());
x = x2 - x1;
z = z1 - z2;
if(Math.abs(x*z) > 1000){
afkHash.replace(e.getPlayer(), System.currentTimeMillis());
locationHash.replace(e.getPlayer(), e.getTo());
}
}
}
}

@EventHandler
public void playerDisconnect(PlayerQuitEvent e){
if(afkHash.containsKey(e.getPlayer())){afkHash.remove(e.getPlayer());
locationHash.remove(e.getPlayer());}
}

@EventHandler
public void playerChangeWorld(PlayerChangedWorldEvent e){
afkHash.put(e.getPlayer(), System.currentTimeMillis());
locationHash.put(e.getPlayer(), e.getPlayer().getLocation());
}
}
Loading

0 comments on commit a961f9c

Please sign in to comment.