mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-25 12:15:14 +01:00
Fix leak, add LeakDetect sub-command
This commit is contained in:
parent
7920a6add1
commit
7affe9f332
@ -24,7 +24,7 @@
|
||||
|
||||
package com.github.creeper123123321.viarift;
|
||||
|
||||
import com.github.creeper123123321.viarift.platform.VRCommandHandler;
|
||||
import com.github.creeper123123321.viarift.commands.VRCommandHandler;
|
||||
import com.github.creeper123123321.viarift.platform.VRInjector;
|
||||
import com.github.creeper123123321.viarift.platform.VRLoader;
|
||||
import com.github.creeper123123321.viarift.platform.VRPlatform;
|
||||
|
@ -22,9 +22,17 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.creeper123123321.viarift.platform;
|
||||
package com.github.creeper123123321.viarift.commands;
|
||||
|
||||
import com.github.creeper123123321.viarift.commands.subs.LeakDetectSubCommand;
|
||||
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
||||
|
||||
public class VRCommandHandler extends ViaCommandHandler {
|
||||
{
|
||||
try {
|
||||
registerSubCommand(new LeakDetectSubCommand());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 creeper123123321 and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.creeper123123321.viarift.commands.subs;
|
||||
|
||||
import io.netty.util.ResourceLeakDetector;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LeakDetectSubCommand extends ViaSubCommand {
|
||||
@Override
|
||||
public String name() {
|
||||
return "leakdetect";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Sets ResourceLeakDetector level";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(ViaCommandSender viaCommandSender, String[] strings) {
|
||||
if (strings.length == 1) {
|
||||
try {
|
||||
ResourceLeakDetector.Level level = ResourceLeakDetector.Level.valueOf(strings[0]);
|
||||
ResourceLeakDetector.setLevel(level);
|
||||
viaCommandSender.sendMessage("Set leak detector level to " + level);
|
||||
} catch (IllegalArgumentException e) {
|
||||
viaCommandSender.sendMessage("Invalid level (" + Arrays.toString(ResourceLeakDetector.Level.values()) +")");
|
||||
}
|
||||
} else {
|
||||
viaCommandSender.sendMessage("Current leak detection level is " + ResourceLeakDetector.getLevel());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -71,7 +71,7 @@ public class VRInHandler extends ByteToMessageDecoder {
|
||||
buf.clear();
|
||||
buf.writeBytes(newPacket);
|
||||
} catch (Exception e) {
|
||||
buf.clear();
|
||||
buf.release();
|
||||
throw e;
|
||||
} finally {
|
||||
newPacket.release();
|
||||
|
@ -88,7 +88,7 @@ public class VROutHandler extends MessageToByteEncoder {
|
||||
pre.writeBytes(newPacket);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
pre.clear();
|
||||
pre.release();
|
||||
throw e;
|
||||
} finally {
|
||||
newPacket.release();
|
||||
|
Loading…
Reference in New Issue
Block a user