Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions src/main/java/org/cloudanarchy/queueplugin/EventCanceler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerAttemptPickupItemEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.raid.RaidTriggerEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.cloudanarchy.queueplugin.packets.PacketS2CUpdateTime;

import java.util.HashSet;
import java.util.Set;
Expand All @@ -38,34 +36,32 @@ public void onPacketReceiving(PacketEvent ev) {

@Override
public void onPacketSending(PacketEvent ev) {
// these are needed or a notchian client will not join
if (ev.getPacketType() == PacketType.Play.Server.KEEP_ALIVE) return;
if (ev.getPacketType() == PacketType.Play.Server.POSITION) return;
if (ev.getPacketType() == PacketType.Play.Server.LOGIN) return;
if (ev.getPacketType() == PacketType.Play.Server.CHAT) return;
ev.setCancelled(true);
}

@EventHandler
public void onEntitySpawn(EntitySpawnEvent ev) {
if (ev.getEntityType() == EntityType.PLAYER) return;
ev.setCancelled(true);
}
// if we dont send this, player has default skin lol
if (ev.getPacketType() == PacketType.Play.Server.PLAYER_INFO) return;

@EventHandler
public void onBlockPhysics(BlockPhysicsEvent ev) {
ev.setCancelled(true);
}

@EventHandler
public void onCommand(PlayerCommandPreprocessEvent ev) {
ev.setCancelled(true);
if (ev.getPacketType() == PacketType.Play.Server.UPDATE_TIME) {
PacketS2CUpdateTime p = new PacketS2CUpdateTime(ev.getPacket());
p.setAgeOfTheWorld(p.getAgeOfTheWorld() - 420);
p.sendPacket(ev.getPlayer());
}
}

@EventHandler
public void onPlayerAttemptPickupItem(PlayerAttemptPickupItemEvent ev) {
public void onEntitySpawn(EntitySpawnEvent ev) {
if (ev.getEntityType() == EntityType.PLAYER) return;
ev.setCancelled(true);
}

@EventHandler
public void onRaidTrigger(RaidTriggerEvent ev) {
public void onCommand(PlayerCommandPreprocessEvent ev) {
ev.setCancelled(true);
}

Expand Down
113 changes: 113 additions & 0 deletions src/main/java/org/cloudanarchy/queueplugin/packets/AbstractPacket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cloudanarchy.queueplugin.packets;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.google.common.base.Objects;
import org.bukkit.entity.Player;

import java.lang.reflect.InvocationTargetException;

public abstract class AbstractPacket {
// The packet we will be modifying
protected PacketContainer handle;

/**
* Constructs a new strongly typed wrapper for the given packet.
*
* @param handle - handle to the raw packet data.
* @param type - the packet type.
*/
protected AbstractPacket(PacketContainer handle, PacketType type) {
// Make sure we're given a valid packet
if (handle == null)
throw new IllegalArgumentException("Packet handle cannot be NULL.");
if (!Objects.equal(handle.getType(), type))
throw new IllegalArgumentException(handle.getHandle()
+ " is not a packet of type " + type);

this.handle = handle;
}

/**
* Retrieve a handle to the raw packet data.
*
* @return Raw packet data.
*/
public PacketContainer getHandle() {
return handle;
}

/**
* Send the current packet to the given receiver.
*
* @param receiver - the receiver.
* @throws RuntimeException If the packet cannot be sent.
*/
public void sendPacket(Player receiver) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
getHandle());
} catch (InvocationTargetException e) {
throw new RuntimeException("Cannot send packet.", e);
}
}

/**
* Send the current packet to all online players.
*/
public void broadcastPacket() {
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
}

/**
* Simulate receiving the current packet from the given sender.
*
* @param sender - the sender.
* @throws RuntimeException If the packet cannot be received.
* @deprecated Misspelled. recieve to receive
* @see #receivePacket(Player)
*/
@Deprecated
public void recievePacket(Player sender) {
try {
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
getHandle());
} catch (Exception e) {
throw new RuntimeException("Cannot recieve packet.", e);
}
}

/**
* Simulate receiving the current packet from the given sender.
*
* @param sender - the sender.
* @throws RuntimeException if the packet cannot be received.
*/
public void receivePacket(Player sender) {
try {
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
getHandle());
} catch (Exception e) {
throw new RuntimeException("Cannot receive packet.", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cloudanarchy.queueplugin.packets;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;

public class PacketS2CUpdateTime extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.UPDATE_TIME;

public PacketS2CUpdateTime() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}

public PacketS2CUpdateTime(PacketContainer packet) {
super(packet, TYPE);
}

/**
* Retrieve Age of the world.
* <p>
* Notes: in ticks; not changed by server commands
*
* @return The current Age of the world
*/
public long getAgeOfTheWorld() {
return handle.getLongs().read(0);
}

/**
* Set Age of the world.
*
* @param value - new value.
*/
public void setAgeOfTheWorld(long value) {
handle.getLongs().write(0, value);
}

/**
* Retrieve Time of day.
* <p>
* Notes: the world (or region) time, in ticks. If negative the sun will
* stop moving at the Math.abs of the time
*
* @return The current Time of day
*/
public long getTimeOfDay() {
return handle.getLongs().read(1);
}

/**
* Set Time of day.
*
* @param value - new value.
*/
public void setTimeOfDay(long value) {
handle.getLongs().write(1, value);
}

}