Skip to content

Instantly share code, notes, and snippets.

View hamza-cskn's full-sized avatar
🎯
Focusing

Hamza Coşkun hamza-cskn

🎯
Focusing
  • Türkiye/Kocaeli
  • 05:25 (UTC +03:00)
View GitHub Profile
@hamza-cskn
hamza-cskn / ItemBuilder
Last active July 31, 2021 16:11
My Simple ItemBuilder
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@hamza-cskn
hamza-cskn / Gradient.java
Last active May 23, 2023 02:43
Gradient Colored Text Animation API
import net.md_5.bungee.api.ChatColor;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Gradient {
List<String> gradient;
@hamza-cskn
hamza-cskn / MessageUtils
Last active June 26, 2022 14:01
MessageUtils for plugin configs.
package mc.obliviate.masterduels.utils;
import mc.obliviate.masterduels.utils.placeholder.InternalPlaceholder;
import mc.obliviate.masterduels.utils.placeholder.PlaceholderUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@hamza-cskn
hamza-cskn / Convert location list to cuboid
Created September 26, 2021 08:49
Creates a cuboid that is includes all locations of a locations list.
//to get main cuboid class: https://www.spigotmc.org/threads/region-cuboid.329859/
public static Cuboid convertCuboid(final List<Location> locations) {
int firstPosX = Integer.MIN_VALUE;
int firstPosY = Integer.MIN_VALUE;
int firstPosZ = Integer.MIN_VALUE;
int secondPosX = Integer.MAX_VALUE;
int secondPosY = Integer.MAX_VALUE;
private int getSnakeSlot(int slot) {
final int horizontalLength = 2;
final int verticalLength = 5;
final int patternLength = 2 * (horizontalLength + verticalLength);
final int patternNo = slot / (patternLength + 1); // 10 -> 1, 8/10 -> 1, 12/10 -> 2
int slotNoInPattern = slot % (patternLength + 1); // 8/10 -> 8, 12/10 -> 2
final boolean isInReversedPattern = slotNoInPattern > patternLength / 2;
package mc.obliviate.masterduels.utils.placeholder;
public class InternalPlaceholder {
private final String placeholder;
private final String value;
protected InternalPlaceholder(final String placeholder, final String value) {
this.placeholder = placeholder;
this.value = value;
@hamza-cskn
hamza-cskn / Invite.java
Last active June 17, 2022 09:12
Useful invite code that provides players invites others.
package mc.obliviate.test.textapi;
import com.google.common.base.Preconditions;
import mc.obliviate.test.Test;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.UUID;
import java.util.function.Consumer;
@hamza-cskn
hamza-cskn / ChainExecutor.java
Last active December 5, 2022 22:27
Simple Task Chain for Bukkit
import org.bukkit.Bukkit;
import java.util.function.Function;
public class ChainExecutor {
private ChainTask first;
private static Function<ChainTask, Boolean> toBooleanFunction(Runnable runnable) {
return chain -> {
@hamza-cskn
hamza-cskn / TimeFormatUtil.java
Created December 25, 2022 10:27
Formats durations to relative times
public static Duration getRelativeDuration(Date date) {
return Duration.ofMillis(Objects.requireNonNull(date).toInstant().toEpochMilli() - System.currentTimeMillis());
}
public static String formatRelativeDuration(Duration duration, boolean verbose) {
if (duration.isZero()) return "now";
String direction = duration.isNegative() ? "ago" : "later";
duration = duration.abs();
StringBuilder builder = new StringBuilder();
if (!applyTimeFormat(builder, duration.toDaysPart(), "day") || verbose)
@hamza-cskn
hamza-cskn / ChatEntry.java
Created January 22, 2023 10:31
Provides taking text input from players using chat. Extremely lightweight.
public final class ChatEntry implements Listener {
private static final Map<UUID, ChatEntry> entryMap = new HashMap<>();
public Consumer<AsyncPlayerChatEvent> action;
public ChatEntry(UUID uuid) {
entryMap.put(uuid, this);
Bukkit.getPluginManager().registerEvents(this, SeniorRegions.getInstance());
}