Compare commits

...

9 Commits

Author SHA1 Message Date
BradB e77739f297
Merge 0e5d5f5cd8 into e1255edb32 2024-04-07 20:47:41 +02:00
Dan Mulloy e1255edb32
Fix build 2024-04-07 11:18:58 -05:00
Dan Mulloy 6f057b361b
Bump version to 5.2.0 for release 2024-04-07 10:04:32 -05:00
BradBot_1 0e5d5f5cd8 Rollback Spliterator implemenation in favor of api 2023-08-05 16:06:05 -05:00
BradBot_1 18c87ee2b7 Allow access 2 internal structure via intermediate 2023-08-05 16:06:05 -05:00
BradBot_1 9f4ede696a Custom Spliterator for Structure Modifier 2023-08-05 16:06:05 -05:00
BradBot_1 f768ea025f Throw NSE Exception over null 2023-08-05 16:06:05 -05:00
BradBot_1 13545ab5db Add StructureModifierIntermediate for r/w access 2023-08-05 16:06:05 -05:00
BradBot_1 71c39a25b9 Make StructureModifier Iterable 2023-08-05 16:06:05 -05:00
5 changed files with 154 additions and 2 deletions

View File

@ -5,7 +5,7 @@ plugins {
}
group = 'com.comphenix.protocol'
version = '5.2.0-SNAPSHOT'
version = '5.2.0'
description = 'Provides access to the Minecraft protocol'
def isSnapshot = version.endsWith('-SNAPSHOT')

View File

@ -145,6 +145,16 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
return lastSeen;
}
@Override
public Location getRespawnLocation() {
return null;
}
@Override
public Location getLocation() {
return null;
}
// TODO do we need to implement this?
public void incrementStatistic(Statistic statistic) throws IllegalArgumentException {

View File

@ -26,6 +26,8 @@ import com.comphenix.protocol.utility.MinecraftReflection;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import java.lang.Iterable;
import java.util.Iterator;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.lang.reflect.Field;
@ -40,8 +42,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Provides list-oriented access to the fields of a Minecraft packet.
@ -51,7 +56,7 @@ import java.util.stream.Collectors;
* @param <T> Type of the fields to retrieve.
* @author Kristian
*/
public class StructureModifier<T> {
public class StructureModifier<T> implements Iterable<StructureModifierIntermediate<T>> {
// Instance generator we will use
private static final DefaultInstances DEFAULT_GENERATOR = getDefaultGenerator();
@ -665,4 +670,20 @@ public class StructureModifier<T> {
public String toString() {
return "StructureModifier[fieldType=" + this.fieldType + ", data=" + this.accessors + "]";
}
/**
* {@inheritDoc}
*/
@Override
public Iterator<StructureModifierIntermediate<T>> iterator() {
return new StructureModifierIterator<T>(this);
}
/**
* {@inheritDoc}
*/
@Override
public Spliterator<StructureModifierIntermediate<T>> spliterator() {
return Spliterators.spliterator(this.iterator(), this.size(), Spliterator.DISTINCT | Spliterator.NONNULL | Spliterator.ORDERED | Spliterator.SIZED);
}
}

View File

@ -0,0 +1,64 @@
/*
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland
*
* 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 2 of
* the License, or (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
package com.comphenix.protocol.reflect;
/**
* Created by {@link StructureModifierIterator} iterator access to a {@link StructureModifier}
*
* @param <T> Type of the fields in the {@link StructureModifier}
* @author BradBot_1
*/
public class StructureModifierIntermediate<T> {
protected final StructureModifier<T> structure;
protected final int index;
/**
* @param structure - {@link StructureModifier} to operate on.
* @param index - index to access.
*
* @apiNote Must be public, else extending it would not work properly.
*/
public StructureModifierIntermediate(final StructureModifier<T> structure, final int index) {
this.structure = structure;
this.index = index;
}
/**
* @return Object at index.
*/
public T get() {
return this.structure.read(this.index);
}
/**
* Overwrites the existing value at the index in the structure.
*
* @param toWrite - Object to overwrite the existing one.
*/
public void set(final T toWrite) {
this.structure.write(index, toWrite);
}
/**
* @return The internal structure modifier
*/
public StructureModifier<T> getInternalStructureModifier() {
return this.structure;
}
}

View File

@ -0,0 +1,57 @@
/*
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland
*
* 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 2 of
* the License, or (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
package com.comphenix.protocol.reflect;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* Provides iterator access to a {@link StructureModifier}
*
* @param <T> Type of the fields in the {@link StructureModifier}
* @author BradBot_1
*/
class StructureModifierIterator<T> implements Iterator<StructureModifierIntermediate<T>> {
private final StructureModifier<T> structure;
private int index = 0;
/**
* @param structure - {@link StructureModifier} to operate on.
*/
StructureModifierIterator(final StructureModifier<T> structure) {
this.structure = structure;
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasNext() {
return this.index < this.structure.size();
}
/**
* {@inheritDoc}
*/
@Override
public StructureModifierIntermediate<T> next() {
if (!this.hasNext()) throw new NoSuchElementException();
return new StructureModifierIntermediate<T>(this.structure, this.index++);
}
}