mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-09-30 16:17:31 +02:00
c5f0550953
* don't enforce async calls for thread-safe listeners (closes #1551) * cleanups, remove structure compiling * improve cloning a bit * fix small issue in no-op structure modifier * remove last usages of FieldUtils * improve and fix equality check in container test
58 lines
1.5 KiB
Java
58 lines
1.5 KiB
Java
/**
|
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. Copyright (C) 2015 dmulloy2
|
|
* <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 2 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, write to the Free
|
|
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
package com.comphenix.protocol.utility;
|
|
|
|
import java.io.Closeable;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @author dmulloy2
|
|
*/
|
|
|
|
// TODO Switch to AutoCloseable w/ Java 7
|
|
@Deprecated
|
|
public class Closer implements AutoCloseable {
|
|
private final List<Closeable> list;
|
|
|
|
private Closer() {
|
|
this.list = new ArrayList<>();
|
|
}
|
|
|
|
public static Closer create() {
|
|
return new Closer();
|
|
}
|
|
|
|
public static void closeQuietly(Closeable close) {
|
|
try {
|
|
close.close();
|
|
} catch (Throwable ex) {
|
|
}
|
|
}
|
|
|
|
public <C extends Closeable> C register(C close) {
|
|
list.add(close);
|
|
return close;
|
|
}
|
|
|
|
@Override
|
|
public void close() {
|
|
for (Closeable close : list) {
|
|
closeQuietly(close);
|
|
}
|
|
}
|
|
|
|
}
|