VulnerabilityPatcher/src/main/java/me/cooljwb/vulnerabilitypatcher/patches/Follow_Range.java
2019-01-20 01:33:46 +01:00

54 lines
1.9 KiB
Java

package me.cooljwb.vulnerabilitypatcher.patches;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
/*
* Copyright 2019 CoolJWB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author CoolJWB
*/
public class Follow_Range extends Patches implements Listener {
private Logger log = Logger.getLogger("Minecraft");
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntitySpawnEvent(EntitySpawnEvent event) {
if (event.getEntity() != null && event.getEntity() instanceof LivingEntity) {
LivingEntity entity = (LivingEntity) event.getEntity();
if (entity.getAttribute(Attribute.GENERIC_FOLLOW_RANGE) != null) {
double followrange = entity.getAttribute(Attribute.GENERIC_FOLLOW_RANGE).getBaseValue();
if (followrange >= 128)
entity.getAttribute(Attribute.GENERIC_FOLLOW_RANGE).setBaseValue(entity.getAttribute(Attribute.GENERIC_FOLLOW_RANGE).getDefaultValue());
}
}
if(devmode)
log.log(Level.INFO, String.format("[%s] Event: %s", pluginName, ReflectionToStringBuilder.toString(event)));
}
}