Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4713598
Added ToggleLamp
bigbrainiac10 Apr 11, 2019
8dccbcb
Merge pull request #5 from bigbrainiac10/master
Maxopoly Apr 22, 2019
1ae55c5
Merge branch 'master' of github.com:CivClassic/SimpleAdminHacks
Maxopoly Apr 22, 2019
7977358
Removed debug messages
bigbrainiac10 Apr 22, 2019
067aadc
Merge pull request #6 from bigbrainiac10/master
Maxopoly Apr 22, 2019
5f0d04d
Add new BasicHack and autoloading infrastructure
Maxopoly Aug 20, 2019
ab1e6ad
Partial 1.14 update
Maxopoly Aug 20, 2019
4d52acf
Mostly complete 1.14 update
Maxopoly Aug 20, 2019
a2a8f51
Add all of Humbug
Maxopoly Aug 22, 2019
9cb7b0d
Reverting some null checks, I know this will cause warnings in IDE bu…
ProgrammerDan Sep 4, 2019
118e28f
Adding in dragon controls, might need to separate out a bit, but adds…
ProgrammerDan Sep 10, 2019
3746205
Fix up ArthropodEgg hack
Maxopoly Oct 24, 2019
64cb6b3
Resolve merge conflict
Maxopoly Oct 25, 2019
b6ad1a0
Last fixes to make compile
Maxopoly Oct 25, 2019
7056077
Add api version to plugin.yml
Maxopoly Oct 25, 2019
28beac2
Actually launch hacks
Maxopoly Oct 27, 2019
118d6c7
Actually make everything new work
Maxopoly Oct 27, 2019
a66b625
Fixed issue where onPlayerInteract() would re-enable cancelled event
Apr 12, 2020
e13f45c
Merge pull request #9 from Falvyu/civ14_2
Maxopoly Apr 13, 2020
67e90ac
Cherry pick autorespawn
Protonull Feb 17, 2020
89bfa33
FIx banner hack
Maxopoly Apr 22, 2020
cf3f1be
Begin implementing EventDebugger
Maxopoly Apr 23, 2020
bdc233c
Working eventdebug
Maxopoly Apr 24, 2020
4ef71b7
Prevent cobble mountains and wandering trader
Maxopoly Apr 24, 2020
ea20108
Added configuration option to disable the Bad Omen effect given by
Apr 18, 2020
d2a99e9
Added config option to disable pillager patrols
Apr 18, 2020
c3d6081
Completed status() function with the other GameTuning options
Apr 18, 2020
677d1ce
Added option to disable Phantoms
Apr 25, 2020
6e34681
Fixed GameFeaturesConfig so that phantomSpawning is properly set
Apr 25, 2020
136999e
Implement anti fastbreak
Maxopoly Apr 26, 2020
bbd784c
Advanced anti fast break
Maxopoly Apr 27, 2020
eb7b4bb
Readd Humbugs Pearl TP fixes
Maxopoly Apr 27, 2020
91c384d
Merge pull request #10 from Falvyu/civ14_2
Maxopoly Apr 27, 2020
396dd97
Added Phantom Management
Protonull Apr 29, 2020
5b06e5f
Merge pull request #11 from Protonull/civ14
Maxopoly Apr 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.programmerdan.minecraft.simpleadminhacks;

import java.lang.reflect.Field;
import java.util.logging.Level;

import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;

/**
* Utility automating a lot of the boiler plate required by SimpleHack and thus allowing easier creation
* of small hacks
*
*/
public abstract class BasicHack extends SimpleHack<BasicHackConfig> implements Listener {

public BasicHack(SimpleAdminHacks plugin, BasicHackConfig config) {
super(plugin, config);
}

@Override
public void registerListeners() {
SimpleAdminHacks.instance().registerListener(this);
}

@Override
public void registerCommands() {
//override in subclass if needed
}

@Override
public void dataBootstrap() {
//override in subclass if needed
}

@Override
public void unregisterListeners() {
HandlerList.unregisterAll(this);

}

@Override
public void unregisterCommands() {
//override in subclass if needed
}

@Override
public void dataCleanup() {
//override in subclass if needed

}

@Override
public String status() {
StringBuilder genStatus = new StringBuilder();
genStatus.append(this.getClass().getSimpleName());
genStatus.append(" is ");
if (config == null || !config.isEnabled()) {
genStatus.append("disabled");
return genStatus.toString();
}
genStatus.append("enabled\n");
for(Field field : this.getClass().getDeclaredFields()) {
genStatus.append(field.getName());
genStatus.append(" = ");
field.setAccessible(true);
try {
genStatus.append(field.get(this));
} catch (IllegalArgumentException | IllegalAccessException e) {
plugin().log(Level.WARNING, "Failed to read field", e);
}
genStatus.append('\n');
}
return genStatus.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.programmerdan.minecraft.simpleadminhacks;

import org.bukkit.configuration.ConfigurationSection;

public class BasicHackConfig extends SimpleHackConfig {

public BasicHackConfig(SimpleAdminHacks plugin, ConfigurationSection base) {
super(plugin, base);
}

@Override
protected void wireup(ConfigurationSection config) {
//not needed
}

public static BasicHackConfig generate(SimpleAdminHacks plugin, ConfigurationSection config) {
return new BasicHackConfig(plugin, config);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private boolean showHacks(CommandSender sender) {

sb.append(ChatColor.WHITE).append("List of hacks:\n");

for (SimpleHack<?> hack : plugin.getHacks()) {
for (SimpleHack<?> hack : plugin.getHackManager().getHacks()) {
sb.append(" ")
.append(ChatColor.AQUA).append(hack.getName())
.append(ChatColor.WHITE).append(": ");
Expand All @@ -87,7 +87,7 @@ private boolean showHacks(CommandSender sender) {
* Internal utility to get a hack from name.
*/
private SimpleHack<?> findHack(String hackName) {
for (SimpleHack<?> candidate : plugin.getHacks()) {
for (SimpleHack<?> candidate : plugin.getHackManager().getHacks()) {
if (candidate.getName().equals(hackName)) {
return candidate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package com.programmerdan.minecraft.simpleadminhacks;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;

import org.bukkit.configuration.ConfigurationSection;

import com.google.common.reflect.ClassPath;
import com.programmerdan.minecraft.simpleadminhacks.autoload.AutoLoad;

public class HackManager {

private SimpleAdminHacks plugin;
private List<SimpleHack<?>> hacks;

public HackManager(SimpleAdminHacks plugin) {
this.plugin = plugin;
this.hacks = new LinkedList<>();
}

public void reloadHacks() {
// Now load all the Hacks and register.
ConfigurationSection hackConfigs = plugin.getConfig().getConfigurationSection("hacks");
try {
ClassPath getSamplersPath = ClassPath.from(plugin.exposeClassLoader());

for (ClassPath.ClassInfo clsInfo : getSamplersPath
.getTopLevelClassesRecursive("com.programmerdan.minecraft.simpleadminhacks.hacks")) {
try {
Class<?> clazz = clsInfo.load();
if (clazz != null && SimpleHack.class.isAssignableFrom(clazz)) {
plugin.log(Level.INFO,
"Found a hack class {0}, attempting to find a generating method and constructor",
clazz.getName());
ConfigurationSection hackConfig = hackConfigs.getConfigurationSection(clazz.getSimpleName());
SimpleHackConfig hackingConfig = null;
if (hackConfig != null) {
try {
Method genBasic = clazz.getMethod("generate", SimpleAdminHacks.class,
ConfigurationSection.class);
hackingConfig = (SimpleHackConfig) genBasic.invoke(null, this, hackConfig);
} catch (IllegalAccessException failure) {
plugin.log(Level.WARNING,
"Creating configuration for hack {0} failed, illegal access failure",
clazz.getName());
} catch (IllegalArgumentException failure) {
plugin.log(Level.WARNING,
"Creating configuration for hack {0} failed, illegal argument failure",
clazz.getName());
} catch (InvocationTargetException failure) {
plugin.log(Level.WARNING,
"Creating configuration for hack {0} failed, invocation target failure",
clazz.getName());
}
} else {
plugin.log(Level.INFO, "Hack for {0} found but no configuration, skipping.",
clazz.getSimpleName());
}

if (hackingConfig != null) {
plugin.log(Level.INFO, "Configuration for Hack {0} found, instance: {1}",
clazz.getSimpleName(), hackingConfig.toString());
SimpleHack<?> hack = null;
try {
Constructor<?> constructBasic = clazz.getConstructor(SimpleAdminHacks.class,
hackingConfig.getClass());
hack = (SimpleHack<?>) constructBasic.newInstance(this, hackingConfig);
plugin.log(Level.INFO, "Created a new Hack of type {0}", clazz.getSimpleName());
} catch (InvalidConfigException ice) {
plugin.log(Level.WARNING, "Failed to activate {0} hack, configuration failed",
clazz.getSimpleName());
} catch (Exception e) {
plugin.log(Level.WARNING, "Failed to activate {0} hack, configuration failed: {1}",
clazz.getSimpleName(), e.getMessage());
}

if (hack == null) {
plugin.log(Level.WARNING, "Failed to create a Hack of type {0}", clazz.getSimpleName());
} else {
register(hack);
plugin.log(Level.INFO, "Registered a new hack: {0}", clazz.getSimpleName());
}
} else {
plugin.log(Level.INFO, "Configuration generation for Hack {0} failed, skipping.",
clazz.getSimpleName());
}
}
} catch (NoClassDefFoundError e) {
plugin.log(Level.INFO, "Unable to load discovered class {0} due to dependency failure",
clsInfo.getName());
} catch (Exception e) {
plugin.log(Level.WARNING, "Failed to complete hack discovery {0}", clsInfo.getName());
}
}
} catch (Exception e) {
plugin.log(Level.WARNING, "Failed to complete hack registration");
}
// Warning if no hacks.
if (hacks.isEmpty()) {
plugin.log(Level.WARNING, "No hacks enabled.");
return;
}
// Boot up the hacks.
List<SimpleHack<?>> iterList = new ArrayList<>(hacks);
for (SimpleHack<?> hack : iterList) {
try {
populateParameter(hack);
hack.enable();
} catch (NoClassDefFoundError err) {
plugin.log(Level.WARNING, "Unable to activate hack {0}, missing dependency: {1}", hack.getName(),
err.getMessage());
unregister(hack);
} catch (Exception e) {
plugin.log(Level.WARNING, "Unable to activate hack {0}, unrecognized error: {1}", hack.getName(),
e.getMessage());
plugin.log(Level.WARNING, "Full stack trace: ", e);
unregister(hack);
}
}
}

public void disableAllHacks() {
for (SimpleHack<?> hack : hacks) {
try {
hack.disable();
} catch (NoClassDefFoundError err) {
plugin.log(Level.WARNING, "Unable to cleanly disable hack {0}, missing dependency: {1}", hack.getName(),
err.getMessage());
} catch (Exception e) {
plugin.log(Level.WARNING, "Unable to cleanly disable hack {0}, unrecognized error: {1}", hack.getName(),
e.getMessage());
plugin.log(Level.WARNING, "Full stack trace: ", e);
}
}
hacks.clear();
}

private void populateParameter(SimpleHack<? extends SimpleHackConfig> hack) {
Class<?> hackClass = hack.getClass();
ConfigurationSection config = hack.config().getBase();
for (Field field : hackClass.getDeclaredFields()) {
AutoLoad autoLoad = field.getAnnotation(AutoLoad.class);
if (autoLoad == null) {
continue;
}
String identifier;
if (autoLoad.id().equals("")) {
identifier = field.getName();
} else {
identifier = autoLoad.id();
}
Object value;
try {
value = config.getObject(identifier, field.getClass(), null);
} catch (Exception e) {
throw new IllegalArgumentException("Hack " + hackClass.getSimpleName() + " failed to read parameter "
+ identifier, e);
}
field.setAccessible(true);
try {
field.set(hack, value);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new IllegalStateException(field.getClass().getSimpleName() + " in " + hackClass.getSimpleName()
+ " could not be set " + e.toString());
}
plugin.log(Level.INFO, "Loaded '{0}' = '{1}'", identifier, value);
}
}

/**
* Registers a new SimpleHack.
*/
void register(SimpleHack<?> hack) {
hacks.add(hack);
}

/**
* Unregisters an existing SimpleHack.
*/
void unregister(SimpleHack<?> hack) {
hacks.remove(hack);
}

/**
* Returns a wrapped version of hacks preventing external removal but allowing
* interaction with the hacks.
*/
public List<SimpleHack<? extends SimpleHackConfig>> getHacks() {
return Collections.unmodifiableList(hacks);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class InvalidConfigException extends RuntimeException {

private static final long serialVersionUID = 7614429135140646756L;

public InvalidConfigException(String message) {
super(message);
}
Expand Down
Loading