Skip to content

Commit

Permalink
Various improvements and rewrites
Browse files Browse the repository at this point in the history
  • Loading branch information
Pro4D committed May 22, 2024
1 parent 3e72466 commit 14bf22d
Show file tree
Hide file tree
Showing 25 changed files with 2,313 additions and 276 deletions.
17 changes: 14 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.pro4d</groupId>
<artifactId>quickmc-paper</artifactId>
<version>1.13.4-BETA</version>
<version>1.13.6-BETA</version>
<packaging>jar</packaging>

<name>QuickMC-Paper</name>
Expand Down Expand Up @@ -161,13 +161,17 @@
<id>eldonexus</id>
<url>https://eldonexus.de/repository/maven-releases/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19.3-R0.1-SNAPSHOT</version>
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -246,7 +250,7 @@
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.12.4</version>
<!-- <scope>compile</scope>-->
<scope>compile</scope>
</dependency>

<dependency>
Expand All @@ -255,6 +259,13 @@
<version>1.18.32</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
12 changes: 9 additions & 3 deletions src/main/java/com/pro4d/quickmc/QuickMC.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.pro4d.quickmc;

import com.pro4d.quickmc.attributes.AttributeManager;
import com.pro4d.quickmc.damage.ArmorTypes;
import com.pro4d.quickmc.damage.DamageManager;
import com.pro4d.quickmc.util.PlayerBorderManager;
import com.pro4d.quickmc.visuals.SpigotReflectionUtil;
import com.pro4d.quickmc.visuals.WrappedVisual;
import fr.skytasul.glowingentities.GlowingBlocks;
import fr.skytasul.glowingentities.GlowingEntities;
import lombok.Getter;
Expand All @@ -11,15 +14,14 @@
import org.bukkit.NamespacedKey;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.*;

public final class QuickMC {

public static NamespacedKey CANT_DESTROY, VOID_EVENT, NO_DROP, NO_REMOVE;
@Getter private static Set<Material> cantDestroy, voidEvent, noDrop, noRemove;

@Getter private static List<WrappedVisual> wrappedVisuals;
@Getter private static GlowingEntities glowingEntities;
@Getter private static GlowingBlocks glowingBlocks;
@Getter private static PlayerBorderManager playerBorderManager;
Expand All @@ -35,15 +37,19 @@ public static void init(JavaPlugin plugin) {

//if(REGISTERED.getAndSet(true)) throw new IllegalStateException("QuickLib is already registered");

SpigotReflectionUtil.init();

PAPI_LOADED = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;

wrappedVisuals = new ArrayList<>();
glowingEntities = new GlowingEntities(plugin);
glowingBlocks = new GlowingBlocks(plugin);
playerBorderManager = new PlayerBorderManager(plugin);

createKeys(plugin);
Bukkit.getPluginManager().registerEvents(new QuickListeners(plugin), plugin);
Bukkit.getPluginManager().registerEvents(new DamageManager(), plugin);
Bukkit.getPluginManager().registerEvents(new AttributeManager(), plugin);
}


Expand Down
24 changes: 15 additions & 9 deletions src/main/java/com/pro4d/quickmc/QuickUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.title.Title;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -293,11 +290,20 @@ public static List<BaseComponent[]> componentList(List<String> lore) {

public static Location stringToLocation(String s) {
String[] parts = s.split(",");
return new Location(Bukkit.getWorld(parts[0]),
format(stringToDouble(parts[1])),
format(stringToDouble(parts[2])),
format(stringToDouble(parts[3]))
);
World world = Bukkit.getWorld(parts[0]);
if(world == null) return null;

String x = parts[1];
if(!isDouble(x) && !isInt(x)) return null;

String y = parts[2];
if(!isDouble(y) && !isInt(y)) return null;

String z = parts[3];
if(!isDouble(z) && !isInt(z)) return null;

return new Location(world, format(stringToDouble(x)),
format(stringToDouble(y)), format(stringToDouble(z)));
}

public static String locationToString(Location loc) {
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/com/pro4d/quickmc/attributes/AbstractPacket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* 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 com.pro4d.quickmc.attributes;

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

@Getter
public abstract class AbstractPacket {
/**
* -- GETTER --
* Retrieve a handle to the raw packet data.
*
*/
// 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;
}

/**
* Constructs a new strongly typed wrapper for the given packet and initialize it with a default packet instance.
*
* @param type - the packet type.
*/
public AbstractPacket(PacketType type) {
this.handle = new PacketContainer(type);
this.handle.getModifier().writeDefaults();
}

/**
* 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) {
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, getHandle());
}

/**
* 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.
*/
public void receivePacket(Player sender) {
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender, getHandle());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AbstractPacket that = (AbstractPacket) o;

return java.util.Objects.equals(handle, that.handle);
}

@Override
public int hashCode() {
return handle != null ? handle.hashCode() : 0;
}
}
Loading

0 comments on commit 14bf22d

Please sign in to comment.