f
This commit is contained in:
disclearing 2019-02-11 00:14:38 +00:00
parent d90134702a
commit 96860b575f
554 changed files with 24893 additions and 0 deletions

13
.idea/compiler.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="HCFactions" />
</profile>
</annotationProcessing>
</component>
</project>

4
.idea/encodings.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

14
.idea/misc.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

485
.idea/workspace.xml Normal file
View File

@ -0,0 +1,485 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="31a44cee-19b5-4bdc-a7a1-4b4a65ef0590" name="Default Changelist" comment="" />
<ignored path="$PROJECT_DIR$/target/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/BorderListener.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="15" column="13" selection-start-line="15" selection-start-column="13" selection-end-line="15" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/command/subcommand/ModeCreateCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="14" column="13" selection-start-line="14" selection-start-column="13" selection-end-line="14" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/command/subcommand/ModeDeleteCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="16" column="13" selection-start-line="16" selection-start-column="13" selection-end-line="16" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/command/subcommand/ModeStartCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="23" column="13" selection-start-line="23" selection-start-column="13" selection-end-line="23" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/command/subcommand/ModeStopCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="23" column="13" selection-start-line="23" selection-start-column="13" selection-end-line="23" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/Mode.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="18" column="13" selection-start-line="18" selection-start-column="13" selection-end-line="18" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/command/ModeCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="15" column="13" selection-start-line="15" selection-start-column="13" selection-end-line="15" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/ModeListeners.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="10" column="13" selection-start-line="10" selection-start-column="13" selection-end-line="10" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/ScoreboardListeners.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="22" column="13" selection-start-line="22" selection-start-column="13" selection-end-line="22" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/StrengthListener.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="12" column="13" selection-start-line="12" selection-start-column="13" selection-end-line="12" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="MavenImportPreferences">
<option name="importingSettings">
<MavenImportingSettings>
<option name="importAutomatically" value="true" />
</MavenImportingSettings>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-8" />
<option name="y" value="-8" />
<option name="width" value="1936" />
<option name="height" value="1056" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="HCFactions" type="b2602c69:ProjectViewProjectNode" />
<item name="HCFactions" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="HCFactions" type="b2602c69:ProjectViewProjectNode" />
<item name="HCFactions" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="HCFactions" type="b2602c69:ProjectViewProjectNode" />
<item name="HCFactions" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="HCFactions" type="b2602c69:ProjectViewProjectNode" />
<item name="HCFactions" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="462c0819:PsiDirectoryNode" />
<item name="java" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="HCFactions" type="b2602c69:ProjectViewProjectNode" />
<item name="HCFactions" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="462c0819:PsiDirectoryNode" />
<item name="java" type="462c0819:PsiDirectoryNode" />
<item name="hcfactions" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="HCFactions" type="b2602c69:ProjectViewProjectNode" />
<item name="HCFactions" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="462c0819:PsiDirectoryNode" />
<item name="resources" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1549230107273" />
<property name="settings.editor.selected.configurable" value="reference.settings.project.maven.importing" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="31a44cee-19b5-4bdc-a7a1-4b4a65ef0590" name="Default Changelist" comment="" />
<created>1549229945165</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1549229945165</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<layout>
<window_info id="Image Layers" />
<window_info id="Designer" />
<window_info id="UI Designer" />
<window_info id="Capture Tool" />
<window_info id="Favorites" side_tool="true" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Palette" />
<window_info anchor="right" id="Theme Preview" />
<window_info anchor="right" id="Maven" />
<window_info anchor="right" id="Capture Analysis" />
<window_info anchor="right" id="Palette&#9;" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/pom.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="391">
<caret line="23" column="20" lean-forward="true" selection-start-line="23" selection-start-column="20" selection-end-line="23" selection-end-column="20" />
</state>
</provider>
<provider editor-type-id="MavenHelperPluginDependencyAnalyzer" />
</entry>
<entry file="file://$PROJECT_DIR$/src/main/resources/config.yml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-2720">
<caret line="53" column="17" lean-forward="true" selection-start-line="53" selection-start-column="17" selection-end-line="53" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/FactionsPlugin.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1247">
<caret line="217" column="19" selection-start-line="217" selection-start-column="19" selection-end-line="217" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/chat/FactionsChatFormat.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="14" column="13" selection-start-line="14" selection-start-column="13" selection-end-line="14" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/blockoperation/state/type/BlockOperationBrewingStandState.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="10" column="13" selection-start-line="10" selection-start-column="13" selection-end-line="10" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/blockoperation/state/type/BlockOperationFurnaceState.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="10" column="13" selection-start-line="10" selection-start-column="13" selection-end-line="10" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/blockoperation/state/BlockOperationState.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85">
<caret line="5" column="17" selection-start-line="5" selection-start-column="17" selection-end-line="5" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/blockoperation/BlockOperationModifier.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="20" column="13" selection-start-line="20" selection-start-column="13" selection-end-line="20" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/blockoperation/BlockOperationModifierListeners.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="17" column="13" selection-start-line="17" selection-start-column="13" selection-end-line="17" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/commands/economy/AddBalanceCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="16" column="13" selection-start-line="16" selection-start-column="13" selection-end-line="16" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/commands/economy/PayCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="16" column="13" selection-start-line="16" selection-start-column="13" selection-end-line="16" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/commands/economy/BalanceCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="16" column="13" selection-start-line="16" selection-start-column="13" selection-end-line="16" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/commands/economy/SetBalanceCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-128">
<caret line="16" column="13" selection-start-line="16" selection-start-column="13" selection-end-line="16" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/commands/FocusCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="16" column="13" selection-start-line="16" selection-start-column="13" selection-end-line="16" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/commands/XPShopCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="13" column="13" selection-start-line="13" selection-start-column="13" selection-end-line="13" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/commands/TellLocationCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="18" column="13" selection-start-line="18" selection-start-column="13" selection-end-line="18" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/DurabilityListener.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="12" column="13" selection-start-line="12" selection-start-column="13" selection-end-line="12" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/EnderpearlListener.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="20" column="13" selection-start-line="20" selection-start-column="13" selection-end-line="20" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/GlitchListeners.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="27" column="13" selection-start-line="27" selection-start-column="13" selection-end-line="27" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/KitMapListener.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="39" column="13" selection-start-line="39" selection-start-column="13" selection-end-line="39" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/KitmapSigns.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119">
<caret line="23" column="13" selection-start-line="23" selection-start-column="13" selection-end-line="23" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/ScoreboardListeners.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="22" column="13" selection-start-line="22" selection-start-column="13" selection-end-line="22" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/StrengthListener.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="12" column="13" selection-start-line="12" selection-start-column="13" selection-end-line="12" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/misc/listeners/BorderListener.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="15" column="13" selection-start-line="15" selection-start-column="13" selection-end-line="15" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/command/subcommand/ModeCreateCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="14" column="13" selection-start-line="14" selection-start-column="13" selection-end-line="14" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/command/subcommand/ModeDeleteCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="16" column="13" selection-start-line="16" selection-start-column="13" selection-end-line="16" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/command/subcommand/ModeStartCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="23" column="13" selection-start-line="23" selection-start-column="13" selection-end-line="23" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/command/subcommand/ModeStopCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="23" column="13" selection-start-line="23" selection-start-column="13" selection-end-line="23" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/Mode.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="18" column="13" selection-start-line="18" selection-start-column="13" selection-end-line="18" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/command/ModeCommand.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="15" column="13" selection-start-line="15" selection-start-column="13" selection-end-line="15" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/amberpvp/hcfactions/mode/ModeListeners.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="10" column="13" selection-start-line="10" selection-start-column="13" selection-end-line="10" selection-end-column="13" />
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ScopeChooserConfigurable.UI">
<settings>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>

41
HCFactions (1).iml Normal file
View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="MavenCustomPomFilePath">
<option name="mavenPomFileUrl" value="file://$MODULE_DIR$/dependency-reduced-pom.xml" />
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$/src/main/java">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
</content>
<content url="file://$MODULE_DIR$/src/main/resources">
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
</content>
<content url="file://$MODULE_DIR$/src/test/java">
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="Maven: me.joeleoli.ragespigot:ragespigot:1.8.8-R0.1-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/server (2).jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="Maven: com.amberpvp.basic:Basic:1.0.0-SNAPSHOT" level="project" />
<orderEntry type="module-library">
<library name="Maven: me.joeleoli.nucleus:nucleus:1.0-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/nucleus-1.0-SNAPSHOT (18).jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.14.8" level="project" />
</component>
</module>

59
HCFactions (2).iml Normal file
View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/server (2).jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/nucleus-1.0-SNAPSHOT (18).jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: me.joeleoli.ragespigot:ragespigot:1.8.8-R0.1-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/server (2).jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Maven: com.amberpvp.basic:Basic:1.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3.1" level="project" />
<orderEntry type="module-library">
<library name="Maven: me.joeleoli.nucleus:nucleus:1.0-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/nucleus-1.0-SNAPSHOT (18).jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.14.8" level="project" />
<orderEntry type="library" name="Maven: redis.clients:jedis:2.8.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.4.2" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver:3.8.2" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:bson:3.8.2" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-core:3.8.2" level="project" />
</component>
</module>

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amberpvp.hcfactions</groupId>
<artifactId>HCFactions</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>me.joeleoli.ragespigot</groupId>
<artifactId>ragespigot</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>C:\Users\William\Desktop\AmberPVP Dev Folder\HCFactions/libs/server (2).jar</systemPath>
</dependency>
<dependency>
<groupId>com.amberpvp.basic</groupId>
<artifactId>Basic</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.joeleoli.nucleus</groupId>
<artifactId>nucleus</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>C:\Users\William\Desktop\AmberPVP Dev Folder\HCFactions/libs/nucleus-1.0-SNAPSHOT (18).jar</systemPath>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

BIN
libs/ProtocolLib-3.6.0.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
libs/server (2).jar Normal file

Binary file not shown.

84
pom.xml Normal file
View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amberpvp.hcfactions</groupId>
<artifactId>HCFactions</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>me.joeleoli.ragespigot</groupId>
<artifactId>ragespigot</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/server (2).jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.joeleoli.nucleus</groupId>
<artifactId>nucleus</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/nucleus-1.0-SNAPSHOT (18).jar</systemPath>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.8.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,335 @@
package com.amberpvp.hcfactions;
import com.amberpvp.hcfactions.blockoperation.BlockOperationModifier;
import com.amberpvp.hcfactions.blockoperation.BlockOperationModifierListeners;
import com.amberpvp.hcfactions.chat.FactionsChatFormat;
import com.amberpvp.hcfactions.claimwall.ClaimWallListeners;
import com.amberpvp.hcfactions.combatlogger.CombatLogger;
import com.amberpvp.hcfactions.combatlogger.CombatLoggerListeners;
import com.amberpvp.hcfactions.combatlogger.commands.CombatLoggerCommand;
import com.amberpvp.hcfactions.command.CloneInventoryCommand;
import com.amberpvp.hcfactions.command.GiveInventoryCommand;
import com.amberpvp.hcfactions.command.LastInventoryCommand;
import com.amberpvp.hcfactions.crowbar.CrowbarListeners;
import com.amberpvp.hcfactions.deathlookup.DeathLookupCommand;
import com.amberpvp.hcfactions.deathlookup.DeathLookupListeners;
import com.amberpvp.hcfactions.economysign.EconomySignListeners;
import com.amberpvp.hcfactions.enchantmentlimiter.EnchantmentLimiterListeners;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEventListeners;
import com.amberpvp.hcfactions.event.glowstone.command.GlowstoneForceCommand;
import com.amberpvp.hcfactions.event.glowstone.procedure.GlowstoneCreateProcedureListeners;
import com.amberpvp.hcfactions.event.glowstone.procedure.command.GlowstoneProcedureCommand;
import com.amberpvp.hcfactions.event.glowstone.procedure.command.GlowstoneRemoveCommand;
import com.amberpvp.hcfactions.event.koth.KothEvent;
import com.amberpvp.hcfactions.event.koth.KothEventListeners;
import com.amberpvp.hcfactions.event.koth.command.KothCommand;
import com.amberpvp.hcfactions.event.koth.command.KothScheduleCommand;
import com.amberpvp.hcfactions.event.koth.command.KothStartCommand;
import com.amberpvp.hcfactions.event.koth.command.KothStopCommand;
import com.amberpvp.hcfactions.event.koth.procedure.KothCreateProcedureListeners;
import com.amberpvp.hcfactions.event.koth.procedure.command.KothCreateProcedureCommand;
import com.amberpvp.hcfactions.event.koth.procedure.command.KothRemoveCommand;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.claims.ClaimListeners;
import com.amberpvp.hcfactions.factions.claims.ClaimPillar;
import com.amberpvp.hcfactions.factions.claims.CustomMovementHandler;
import com.amberpvp.hcfactions.factions.commands.*;
import com.amberpvp.hcfactions.factions.commands.admin.*;
import com.amberpvp.hcfactions.factions.commands.leader.FactionDemoteCommand;
import com.amberpvp.hcfactions.factions.commands.leader.FactionDisbandCommand;
import com.amberpvp.hcfactions.factions.commands.leader.FactionLeaderCommand;
import com.amberpvp.hcfactions.factions.commands.leader.FactionPromoteCommand;
import com.amberpvp.hcfactions.factions.commands.officer.*;
import com.amberpvp.hcfactions.factions.commands.system.FactionColorCommand;
import com.amberpvp.hcfactions.factions.commands.system.FactionCreateSystemCommand;
import com.amberpvp.hcfactions.factions.commands.system.FactionToggleDeathbanCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.files.ConfigFile;
import com.amberpvp.hcfactions.itemdye.ItemDye;
import com.amberpvp.hcfactions.itemdye.ItemDyeListeners;
import com.amberpvp.hcfactions.misc.commands.*;
import com.amberpvp.hcfactions.misc.commands.economy.AddBalanceCommand;
import com.amberpvp.hcfactions.misc.commands.economy.BalanceCommand;
import com.amberpvp.hcfactions.misc.commands.economy.PayCommand;
import com.amberpvp.hcfactions.misc.commands.economy.SetBalanceCommand;
import com.amberpvp.hcfactions.misc.listeners.*;
import com.amberpvp.hcfactions.mode.Mode;
import com.amberpvp.hcfactions.mode.ModeListeners;
import com.amberpvp.hcfactions.mode.command.ModeCommand;
import com.amberpvp.hcfactions.potionlimiter.PotionLimiterListeners;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.ProfileAutoSaver;
import com.amberpvp.hcfactions.profile.ProfileListeners;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldownListeners;
import com.amberpvp.hcfactions.profile.fight.command.KillStreakCommand;
import com.amberpvp.hcfactions.profile.kit.ProfileKitActionListeners;
import com.amberpvp.hcfactions.profile.kit.command.ProfileKitCommand;
import com.amberpvp.hcfactions.profile.options.command.ProfileOptionsCommand;
import com.amberpvp.hcfactions.profile.ore.ProfileOreCommand;
import com.amberpvp.hcfactions.profile.protection.ProfileProtection;
import com.amberpvp.hcfactions.profile.protection.command.ProfileProtectionCommand;
import com.amberpvp.hcfactions.statracker.StatTrackerListeners;
import com.amberpvp.hcfactions.subclaim.SubclaimListeners;
import com.amberpvp.hcfactions.util.FactionsBoardAdapter;
import com.amberpvp.hcfactions.util.command.CommandFramework;
import com.amberpvp.hcfactions.util.database.FactionsDatabase;
import com.amberpvp.hcfactions.util.player.PlayerUtility;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import lombok.Getter;
import lombok.Setter;
import me.joeleoli.nucleus.Nucleus;
import me.joeleoli.nucleus.board.BoardManager;
import me.joeleoli.ragespigot.RageSpigot;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
@Getter
public class FactionsPlugin extends JavaPlugin {
@Getter
private static FactionsPlugin instance;
private CommandFramework framework;
private FactionsDatabase factionsDatabase;
private ConfigFile mainConfig, scoreboardConfig, languageConfig, kothScheduleConfig;
@Setter
private boolean loaded;
@Setter
private boolean kitmapMode;
public void onEnable() {
instance = this;
this.mainConfig = new ConfigFile(this, "config");
this.languageConfig = new ConfigFile(this, "lang");
this.scoreboardConfig = new ConfigFile(this, "scoreboard");
this.kothScheduleConfig = new ConfigFile(this, "koth-schedule");
this.factionsDatabase = new FactionsDatabase(this);
this.kitmapMode = this.mainConfig.getBoolean("KITMAP_MODE");
for (Player player : PlayerUtility.getOnlinePlayers()) {
new Profile(player.getUniqueId());
}
for (World world : Bukkit.getWorlds()) {
for (Entity entity : world.getEntities()) {
if (entity.getType() == CombatLogger.ENTITY_TYPE) {
if (entity instanceof LivingEntity) {
if (entity.getCustomName() != null) {
entity.remove();
}
}
}
}
}
this.framework = new CommandFramework(this);
SimpleOfflinePlayer.load(this);
Faction.load();
Mode.load();
KothEvent.load();
GlowstoneEvent.load();
BlockOperationModifier.run();
ProfileProtection.run(this);
registerRecipes();
registerListeners();
registerCommands();
PlayerFaction.runTasks();
this.getServer().getScheduler().runTaskTimerAsynchronously(this, new ProfileAutoSaver(this), 5000L, 5000L);
Nucleus.getInstance().setBoardManager(new BoardManager(this, new FactionsBoardAdapter(this)));
Nucleus.getInstance().setChatFormat(new FactionsChatFormat());
RageSpigot.INSTANCE.addMovementHandler(new CustomMovementHandler());
}
public void onDisable() {
Faction.save();
for (Player player : PlayerUtility.getOnlinePlayers()) {
Profile profile = Profile.getByPlayer(player);
if (profile.getClaimProfile() != null) {
profile.getClaimProfile().removePillars();
}
for (ClaimPillar claimPillar : profile.getMapPillars()) {
claimPillar.remove();
}
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
}
try {
SimpleOfflinePlayer.save(this);
} catch (IOException e) {
e.printStackTrace();
}
for (Profile profile : Profile.getProfiles()) {
profile.save();
}
for (Mode mode : Mode.getModes()) {
mode.save();
}
for (CombatLogger logger : CombatLogger.getLoggers()) {
logger.getEntity().remove();
}
for (Event event : EventManager.getInstance().getEvents()) {
if (event instanceof KothEvent) {
((KothEvent) event).save();
} else if (event instanceof GlowstoneEvent) {
((GlowstoneEvent) event).save();
}
}
factionsDatabase.getClient().close();
}
private void registerRecipes() {
for (Material material : Material.values()) {
if (material.name().contains("CHESTPLATE") || material.name().contains("SWORD") || material.name().contains("LEGGINGS") || material.name().contains("BOOTS") || material.name().contains("HELMET") || material.name().contains("AXE") || material.name().contains("SPADE")) {
for (ItemDye dye : ItemDye.values()) {
Bukkit.addRecipe(ItemDye.getRecipe(material, dye));
}
}
}
Bukkit.addRecipe(new ShapelessRecipe(new ItemStack(Material.EXP_BOTTLE)).addIngredient(1, Material.GLASS_BOTTLE));
}
private void registerCommands() {
new ProfileProtectionCommand();
new ProfileOreCommand();
new CloneInventoryCommand();
new LastInventoryCommand();
new GiveInventoryCommand();
new DeathLookupCommand();
new ProfileKitCommand();
new KillStreakCommand();
new CombatLoggerCommand();
new ModeCommand();
new KothCommand();
new KothScheduleCommand();
new KothCreateProcedureCommand();
new KothRemoveCommand();
new KothStartCommand();
new KothStopCommand();
new GlowstoneProcedureCommand();
new GlowstoneRemoveCommand();
new GlowstoneForceCommand();
new BalanceCommand();
new ReclaimCommand();
new ReclaimRemoveCommand();
new StackCommand();
new CobbleCommand();
new PayCommand();
new SetBalanceCommand();
new AddBalanceCommand();
new HelpCommand();
new SpawnCommand();
new ProfileOptionsCommand();
new MapKitCommand();
new RenameCommand();
new PlayTimeCommand();
new TellLocationCommand();
new FocusCommand();
new SetGKitCommand();
new MedicReviveCommand();
new FactionHelpCommand();
new FactionDisbandCommand();
new FactionCreateCommand();
new FactionDisbandAllCommand();
new FactionInviteCommand();
new FactionJoinCommand();
new FactionRenameCommand();
new FactionPromoteCommand();
new FactionDemoteCommand();
new FactionLeaderCommand();
new FactionUninviteCommand();
new FactionChatCommand();
new FactionSetHomeCommand();
new FactionMessageCommand();
new FactionAnnouncementCommand();
new FactionLeaveCommand();
new FactionShowCommand();
new FactionKickCommand();
new FactionInvitesCommand();
new FactionDepositCommand();
new FactionWithdrawCommand();
new FactionClaimCommand();
new FactionMapCommand();
new FactionUnclaimCommand();
new FactionListCommand();
new FactionHomeCommand();
new FactionStuckCommand();
new FactionCreateSystemCommand();
new FactionToggleDeathbanCommand();
new FactionColorCommand();
new FactionFreezeCommand();
new FactionThawCommand();
new FactionSetDtrCommand();
new FactionAdminCommand();
new FixCommand();
if (this.mainConfig.getBoolean("FACTION_GENERAL.ALLIES.ENABLED")) {
new FactionAllyCommand();
}
if (mainConfig.getBoolean("FACTION_GENERAL.ALLIES.ENABLED")) {
new FactionEnemyCommand();
}
if (kitmapMode) {
new ChestCommand();
}
}
private void registerListeners() {
PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.registerEvents(new ProfileListeners(this), this);
pluginManager.registerEvents(new CrowbarListeners(), this);
pluginManager.registerEvents(new EconomySignListeners(), this);
pluginManager.registerEvents(new StatTrackerListeners(), this);
pluginManager.registerEvents(new ProfileCooldownListeners(), this);
pluginManager.registerEvents(new ProfileKitActionListeners(), this);
pluginManager.registerEvents(new ClaimWallListeners(this), this);
pluginManager.registerEvents(new EnchantmentLimiterListeners(), this);
pluginManager.registerEvents(new PotionLimiterListeners(), this);
pluginManager.registerEvents(new DeathLookupListeners(), this);
pluginManager.registerEvents(new CombatLoggerListeners(this), this);
pluginManager.registerEvents(new BlockOperationModifierListeners(), this);
pluginManager.registerEvents(new KothCreateProcedureListeners(), this);
pluginManager.registerEvents(new GlowstoneCreateProcedureListeners(), this);
pluginManager.registerEvents(new KothEventListeners(), this);
pluginManager.registerEvents(new GlowstoneEventListeners(), this);
pluginManager.registerEvents(new SubclaimListeners(), this);
pluginManager.registerEvents(new ItemDyeListeners(), this);
pluginManager.registerEvents(new GlitchListeners(), this);
pluginManager.registerEvents(new ModeListeners(), this);
pluginManager.registerEvents(new ScoreboardListeners(), this);
pluginManager.registerEvents(new ClaimListeners(), this);
pluginManager.registerEvents(new BorderListener(), this);
pluginManager.registerEvents(new EnderpearlListener(this), this);
pluginManager.registerEvents(new StrengthListener(), this);
pluginManager.registerEvents(new DurabilityListener(), this);
pluginManager.registerEvents(new KitmapSigns(this), this);
}
}

View File

@ -0,0 +1,102 @@
package com.amberpvp.hcfactions.blockoperation;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.blockoperation.state.type.BlockOperationBrewingStandState;
import com.amberpvp.hcfactions.blockoperation.state.type.BlockOperationFurnaceState;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.blockoperation.state.BlockOperationState;
import com.amberpvp.hcfactions.blockoperation.state.type.BlockOperationBrewingStandState;
import com.amberpvp.hcfactions.blockoperation.state.type.BlockOperationFurnaceState;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.block.Block;
import org.bukkit.block.BrewingStand;
import org.bukkit.block.Furnace;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class BlockOperationModifier {
private static FactionsPlugin main = FactionsPlugin.getInstance();
private static Set<BlockOperationModifier> modifiers = new HashSet<>();
@Getter @Setter private final BlockOperationState state;
public BlockOperationModifier(BlockOperationState state) {
this.state = state;
modifiers.add(this);
}
public static BlockOperationModifier getByBlock(Block block) {
for (BlockOperationModifier modifier : modifiers) {
if (modifier.getState() instanceof BlockOperationFurnaceState) {
BlockOperationFurnaceState state = (BlockOperationFurnaceState) modifier.getState();
if (state.getFurnace().getBlock().equals(block)) {
return modifier;
}
} else {
BlockOperationBrewingStandState state = (BlockOperationBrewingStandState) modifier.getState();
if (state.getBrewingStand().getBlock().equals(block)) {
return modifier;
}
}
}
return null;
}
public static Set<BlockOperationModifier> getModifiers() {
return modifiers;
}
public static void run() {
new BukkitRunnable() {
@Override
public void run() {
Iterator<BlockOperationModifier> iterator = modifiers.iterator();
while (iterator.hasNext()) {
BlockOperationModifier modifier = iterator.next();
if (modifier.getState() instanceof BlockOperationFurnaceState) {
BlockOperationFurnaceState state = (BlockOperationFurnaceState) modifier.getState();
Furnace furnace = state.getFurnace();
if (furnace.getInventory().getItem(0) != null) {
if (furnace.getCookTime() > 0 || furnace.getBurnTime() > 0) {
furnace.setCookTime((short) (furnace.getCookTime() + state.getIncrease()));
furnace.setBurnTime((short) (furnace.getBurnTime() + state.getIncrease()));
}
} else {
if (furnace.getInventory().getViewers().isEmpty()) {
iterator.remove();
}
furnace.setCookTime((short) 0);
furnace.setBurnTime((short) 0);
}
continue;
}
if (modifier.getState() instanceof BlockOperationBrewingStandState) {
BlockOperationBrewingStandState state = (BlockOperationBrewingStandState) modifier.getState();
BrewingStand brewingStand = state.getBrewingStand();
if (brewingStand.getInventory().getViewers().isEmpty() && brewingStand.getInventory().getItem(3) == null) {
iterator.remove();
}
if (brewingStand.getBrewingTime() > 1) {
brewingStand.setBrewingTime(Math.max(1, brewingStand.getBrewingTime() - state.getIncrease()));
}
}
}
}
}.runTaskTimerAsynchronously(main, 2L, 2L);
}
}

View File

@ -0,0 +1,48 @@
package com.amberpvp.hcfactions.blockoperation;
import com.amberpvp.hcfactions.blockoperation.state.type.BlockOperationBrewingStandState;
import com.amberpvp.hcfactions.blockoperation.state.type.BlockOperationFurnaceState;
import com.amberpvp.hcfactions.blockoperation.state.type.BlockOperationBrewingStandState;
import com.amberpvp.hcfactions.blockoperation.state.type.BlockOperationFurnaceState;
import org.bukkit.block.Block;
import org.bukkit.block.BrewingStand;
import org.bukkit.block.Furnace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import java.util.Iterator;
public class BlockOperationModifierListeners implements Listener {
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEvent(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block block = event.getClickedBlock();
if (block.getState() instanceof Furnace || block.getState() instanceof BrewingStand) {
BlockOperationModifier modifier = BlockOperationModifier.getByBlock(event.getClickedBlock());
if (modifier == null) {
if (block.getState() instanceof Furnace) {
new BlockOperationModifier(new BlockOperationFurnaceState((Furnace) block.getState()));
} else {
new BlockOperationModifier(new BlockOperationBrewingStandState((BrewingStand) block.getState()));
}
}
}
}
}
@EventHandler
public void onChunkUnloadEvent(ChunkUnloadEvent event) {
Iterator<BlockOperationModifier> iterator = BlockOperationModifier.getModifiers().iterator();
while (iterator.hasNext()) {
BlockOperationModifier modifier = iterator.next();
if (modifier.getState().getLocation().getChunk().equals(event.getChunk())) {
iterator.remove();
}
}
}
}

View File

@ -0,0 +1,12 @@
package com.amberpvp.hcfactions.blockoperation.state;
import org.bukkit.Location;
public interface BlockOperationState {
String getName();
int getIncrease();
Location getLocation();
}

View File

@ -0,0 +1,36 @@
package com.amberpvp.hcfactions.blockoperation.state.type;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.blockoperation.state.BlockOperationState;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.block.BrewingStand;
public class BlockOperationBrewingStandState implements BlockOperationState {
private static FactionsPlugin main = FactionsPlugin.getInstance();
private static final String NAME = "BlockOperationBrewingStandState";
@Getter @Setter private final BrewingStand brewingStand;
public BlockOperationBrewingStandState(BrewingStand brewingStand) {
this.brewingStand = brewingStand;
}
@Override
public Location getLocation() {
return brewingStand.getLocation();
}
@Override
public int getIncrease() {
return main.getMainConfig().getInt("BLOCK_MODIFIER.BREWING_STAND_BREW_INCREASE");
}
@Override
public String getName() {
return NAME;
}
}

View File

@ -0,0 +1,36 @@
package com.amberpvp.hcfactions.blockoperation.state.type;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.blockoperation.state.BlockOperationState;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.block.Furnace;
public class BlockOperationFurnaceState implements BlockOperationState {
private static FactionsPlugin main = FactionsPlugin.getInstance();
private static final String NAME = "BlockOperationFurnaceState";
@Getter @Setter private final Furnace furnace;
public BlockOperationFurnaceState(Furnace furnace) {
this.furnace = furnace;
}
@Override
public Location getLocation() {
return furnace.getLocation();
}
@Override
public int getIncrease() {
return main.getMainConfig().getInt("BLOCK_MODIFIER.FURNACE_COOK_INCREASE");
}
@Override
public String getName() {
return NAME;
}
}

View File

@ -0,0 +1,49 @@
package com.amberpvp.hcfactions.chat;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.ProfileChatType;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.ProfileChatType;
import me.joeleoli.nucleus.chat.ChatFormat;
import me.joeleoli.nucleus.player.PlayerData;
import me.joeleoli.nucleus.util.CC;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class FactionsChatFormat implements ChatFormat {
@Override
public String format(Player sender, Player receiver, String message) {
final PlayerData playerData = PlayerData.getByUuid(sender.getUniqueId());
final Profile profile = Profile.getByUuid(sender.getUniqueId());
final PlayerFaction playerFaction = PlayerFaction.getByPlayer(sender);
ProfileChatType chatType = playerFaction == null ? ProfileChatType.PUBLIC : profile.getChatType();
if (chatType == ProfileChatType.PUBLIC) {
return (playerFaction != null ? CC.GOLD + "[" + CC.YELLOW + (playerFaction == profile.getFaction() ? ChatColor.GREEN + playerFaction.getName(): ChatColor.RED + playerFaction.getName()) + CC.GOLD + "]" : "") + playerData.getActiveRank().getPrefix() + (playerData.getActivePrefix() == null ? "":playerData.getActivePrefix().getPrefix()) + sender.getDisplayName() + CC.GRAY + ": " + CC.WHITE + message;
} else {
if (!sender.getUniqueId().equals(receiver.getUniqueId())) {
if (chatType == ProfileChatType.ALLY) {
final PlayerFaction targetFaction = PlayerFaction.getByPlayer(receiver);
if (targetFaction == null) {
return null;
}
if (!playerFaction.getAllies().contains(targetFaction)) {
return null;
}
} else if (chatType == ProfileChatType.FACTION) {
if (!playerFaction.getMembers().contains(receiver.getUniqueId())) {
return null;
}
}
}
return chatType == ProfileChatType.ALLY ? CC.YELLOW + "(" + CC.BLUE + "Ally" + CC.YELLOW + ") " + sender.getName() + ": " + CC.BLUE + message:CC.YELLOW + "(" + CC.DARK_GREEN + "Faction" + CC.YELLOW + ") " + sender.getName() + ": " + CC.DARK_GREEN + message;
}
}
}

View File

@ -0,0 +1,30 @@
package com.amberpvp.hcfactions.claimwall;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@Accessors(chain = true)
public class ClaimWall {
@Getter private final ClaimWallType type;
@Getter private final Location location;
public ClaimWall(ClaimWallType type, Location location) {
this.type = type;
this.location = location;
}
public ClaimWall show(Player player) {
player.sendBlockChange(location, type.getBlockType(), (byte) type.getBlockData());
return this;
}
public ClaimWall hide(Player player) {
player.sendBlockChange(location, Material.AIR, (byte) 0);
return this;
}
}

View File

@ -0,0 +1,182 @@
package com.amberpvp.hcfactions.claimwall;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.player.PlayerUtility;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldown;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldownType;
import com.amberpvp.hcfactions.util.player.PlayerUtility;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.util.Set;
public class ClaimWallListeners implements Listener {
private FactionsPlugin main;
public ClaimWallListeners(FactionsPlugin main) {
this.main = main;
new BukkitRunnable() {
@Override
public void run() {
for (Player player : PlayerUtility.getOnlinePlayers() ) {
Profile profile = Profile.getByPlayer(player);
for (ClaimWallType type : ClaimWallType.values()) {
if ((profile.getProtection() == null && type == ClaimWallType.PVP_PROTECTION) || (profile.getCooldownByType(ProfileCooldownType.SPAWN_TAG) == null && type == ClaimWallType.SPAWN_TAG)) {
if ( (profile.getProtection() == null) && profile.getCooldownByType(ProfileCooldownType.SPAWN_TAG) == null && !profile.getWalls().isEmpty()) {
int min = player.getLocation().getBlockY() - (type.getRange() / 2);
int max = player.getLocation().getBlockY() + (type.getRange() / 2);
Set<Claim> nearbyClaims = Claim.getNearbyClaimsAt(player.getLocation(),type.getRange() * 2);
if (!(nearbyClaims.isEmpty())) {
for (Claim claim : nearbyClaims) {
if(claim == null) {
continue;
}
if (!(type.isValid(claim))) {
continue;
}
if (claim.getBorder() == null) {
continue;
}
for (Location location : claim.getBorder()) {
for (int i = min - (20); i < max + (20); i++) {
location.setY(i);
if (location.getBlock().isEmpty()) {
if (profile.getWalls().containsKey(location)) {
profile.getWalls().get(location).hide(player);
profile.getWalls().remove(location);
}
}
}
}
}
}
}
continue;
}
int min = player.getLocation().getBlockY() - (type.getRange() / 2);
int max = player.getLocation().getBlockY() + (type.getRange() / 2);
Set<Claim> nearbyClaims = Claim.getNearbyClaimsAt(player.getLocation(),type.getRange() * 2);
if (!(nearbyClaims.isEmpty())) {
for (Claim claim : nearbyClaims) {
if(claim == null) {
continue;
}
if (!(type.isValid(claim))) {
continue;
}
if (claim.getBorder() == null) {
continue;
}
for (Location location : claim.getBorder()) {
for (int i = min - (20); i < max + (20); i++) {
location.setY(i);
if (location.getBlock().isEmpty()) {
if (location.distance(player.getLocation()) <= type.getRange() && !claim.isInside(player.getLocation()) && i < max && i > min) {
if (profile.getProtection() == null && profile.getCooldownByType(ProfileCooldownType.SPAWN_TAG) == null && !profile.getWalls().isEmpty()) {
if (profile.getWalls().containsKey(location)) {
profile.getWalls().get(location).hide(player);
profile.getWalls().remove(location);
}
} else {
profile.getWalls().put(location, new ClaimWall(type, location).show(player));
}
} else {
if (profile.getWalls().containsKey(location)) {
profile.getWalls().get(location).hide(player);
profile.getWalls().remove(location);
}
}
}
}
}
}
} else {
if (!(profile.getWalls().isEmpty())) {
for (Location location : profile.getWalls().keySet()) {
if (profile.getWalls().containsKey(location)) {
profile.getWalls().get(location).hide(player);
}
}
profile.getWalls().clear();
}
}
}
}
}
}.runTaskTimerAsynchronously(main, 2L, 2L);
}
@EventHandler
public void onPlayerTeleportEvent(PlayerTeleportEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.getCooldownByType(ProfileCooldownType.SPAWN_TAG) != null) {
Claim entering = Claim.getProminentClaimAt(event.getTo());
Claim leaving = Claim.getProminentClaimAt(event.getFrom());
if (entering != null && (leaving == null || !leaving.equals(entering))) {
if (ClaimWallType.SPAWN_TAG.isValid(entering)) {
if (event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL) {
player.sendMessage(ProfileCooldownType.SPAWN_TAG.getMessage());
player.sendMessage(main.getLanguageConfig().getString("SPAWN_TAG.PEARL_REFUNDED"));
ProfileCooldown cooldown = profile.getCooldownByType(ProfileCooldownType.ENDER_PEARL);
if (cooldown != null) {
profile.getCooldowns().remove(cooldown);
player.getInventory().addItem(new ItemStack(Material.ENDER_PEARL));
}
}
event.setCancelled(true);
}
}
}
if (profile.getProtection() != null) {
Claim entering = Claim.getProminentClaimAt(event.getTo());
Claim leaving = Claim.getProminentClaimAt(event.getFrom());
if (entering != null && (leaving == null || !leaving.equals(entering))) {
if (ClaimWallType.PVP_PROTECTION.isValid(entering)) {
event.setCancelled(true);
player.sendMessage(main.getLanguageConfig().getString("PVP_PROTECTION.CANT_ENTER").replace("%FACTION%", entering.getFaction().getName()).replace("%TIME%", profile.getProtection().getTimeLeft()));
}
}
}
}
}

View File

@ -0,0 +1,56 @@
package com.amberpvp.hcfactions.claimwall;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import org.bukkit.Material;
public enum ClaimWallType {
PVP_PROTECTION,
SPAWN_TAG;
private static FactionsPlugin main = FactionsPlugin.getInstance();
public Material getBlockType() {
return Material.valueOf(main.getMainConfig().getString("CLAIM_WALL." + name() + ".BLOCK"));
}
public int getBlockData() {
return main.getMainConfig().getInt("CLAIM_WALL." + name() + ".DATA");
}
public int getSize() {
return main.getMainConfig().getInt("CLAIM_WALL." + name() + ".SIZE");
}
public int getRange() {
return main.getMainConfig().getInt("CLAIM_WALL." + name() + ".RANGE");
}
public boolean isValid(Claim claim) {
if (claim == null) {
return true;
}
if (this == ClaimWallType.PVP_PROTECTION && claim.getFaction() instanceof SystemFaction) {
return false;
}
boolean isSystem = claim.getFaction() instanceof SystemFaction;
boolean isDeathban = isSystem && ((SystemFaction) claim.getFaction()).isDeathban();
if (this == ClaimWallType.SPAWN_TAG && !isSystem) {
return false;
}
if (this == ClaimWallType.SPAWN_TAG && isDeathban) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,85 @@
package com.amberpvp.hcfactions.combatlogger;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.profile.deathban.ProfileDeathban;
import com.amberpvp.hcfactions.profile.fight.ProfileFightEffect;
import lombok.Getter;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import java.util.*;
public class CombatLogger {
private static Map<CombatLogger, Long> loggers = new HashMap<>();
private static FactionsPlugin main = FactionsPlugin.getInstance();
public static final EntityType ENTITY_TYPE = EntityType.valueOf(main.getMainConfig().getString("COMBAT_LOGGER.ENTITY_TYPE"));
private static final String ENTITY_CUSTOM_NAME = main.getLanguageConfig().getString("COMBAT_LOGGER.NAME");
@Getter private final LivingEntity entity;
@Getter private final String name;
@Getter private final UUID uuid;
@Getter private final long deathbanDuration;
@Getter private final double hunger;
@Getter private final List<ProfileFightEffect> effects;
@Getter private ItemStack[] contents, armor;
public CombatLogger(Player player) {
this.uuid = player.getUniqueId();
this.name = player.getName();
this.deathbanDuration = ProfileDeathban.getDuration(player);
this.contents = player.getInventory().getContents();
this.armor = player.getInventory().getArmorContents();
this.hunger = player.getFoodLevel();
this.effects = new ArrayList<>();
for (PotionEffect effect : player.getActivePotionEffects()) {
effects.add(new ProfileFightEffect(effect));
}
this.entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), ENTITY_TYPE);
this.entity.setMaxHealth(player.getMaxHealth());
this.entity.setHealth(player.getHealth());
this.entity.setFallDistance(player.getFallDistance());
this.entity.setLastDamageCause(player.getLastDamageCause());
this.entity.setCustomName(ENTITY_CUSTOM_NAME.replace("%PLAYER%", player.getName()));
if (this.entity instanceof Villager) {
Villager villager = (Villager) this.entity;
villager.setProfession(Villager.Profession.FARMER);
villager.setAdult();
}
this.entity.setCustomNameVisible(true);
loggers.put(this, System.currentTimeMillis());
}
public static CombatLogger getByEntity(LivingEntity entity) {
for (CombatLogger logger : loggers.keySet()) {
if (logger.getEntity().getEntityId() == entity.getEntityId()) {
return logger;
}
}
return null;
}
public static CombatLogger getByPlayer(Player player) {
for (CombatLogger logger : loggers.keySet()) {
if (logger.getUuid().equals(player.getUniqueId())) {
return logger;
}
}
return null;
}
public static Set<CombatLogger> getLoggers() {
return loggers.keySet();
}
public static Map<CombatLogger, Long> getLoggersMap() {
return loggers;
}
}

View File

@ -0,0 +1,417 @@
package com.amberpvp.hcfactions.combatlogger;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.mode.Mode;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.ItemNames;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import com.amberpvp.hcfactions.mode.Mode;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldownType;
import com.amberpvp.hcfactions.profile.deathban.ProfileDeathban;
import com.amberpvp.hcfactions.profile.deathmessage.ProfileDeathMessage;
import com.amberpvp.hcfactions.profile.deathmessage.ProfileDeathMessageTemplate;
import com.amberpvp.hcfactions.profile.fight.ProfileFight;
import com.amberpvp.hcfactions.profile.fight.ProfileFightEnvironment;
import com.amberpvp.hcfactions.profile.fight.killer.type.ProfileFightEnvironmentKiller;
import com.amberpvp.hcfactions.profile.fight.killer.type.ProfileFightPlayerKiller;
import com.amberpvp.hcfactions.profile.fight.killstreaks.KillStreakType;
import com.amberpvp.hcfactions.util.ItemNames;
import me.joeleoli.nucleus.util.CC;
import me.joeleoli.nucleus.util.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.event.EventPriority;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.math.BigDecimal;
import java.util.*;
public class CombatLoggerListeners implements Listener {
private FactionsPlugin main;
public CombatLoggerListeners(FactionsPlugin main) {
this.main = main;
new BukkitRunnable() {
@Override
public void run() {
Iterator<Map.Entry<CombatLogger, Long>> iterator = CombatLogger.getLoggersMap().entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<CombatLogger, Long> entry = iterator.next();
CombatLogger logger = entry.getKey();
long time = entry.getValue();
if (System.currentTimeMillis() - time > (main.getMainConfig().getInt("COMBAT_LOGGER.DESPAWN_TIME") * 1000)) {
logger.getEntity().remove();
iterator.remove();
}
}
}
}.runTaskTimerAsynchronously(main, 25 * 20L, 20L);
}
@EventHandler
public void onPlayerQuitEvent(PlayerQuitEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE) {
return;
}
Profile profile = Profile.getByPlayer(player);
if (profile.getProtection() != null) {
return;
}
for (Mode mode : Mode.getModes()) {
if (mode.isActive()) {
return;
}
}
if (profile.isSafeLogout()) {
return;
}
Claim claim = Claim.getProminentClaimAt(player.getLocation());
if (claim == null) {
if (!FactionsPlugin.getInstance().isKitmapMode()) {
new CombatLogger(player);
}
return;
}
Faction faction = claim.getFaction();
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
if (!systemFaction.isDeathban()) {
return;
}
}
if (!FactionsPlugin.getInstance().isKitmapMode()) {
new CombatLogger(player);
}
}
@EventHandler
public void onEntityDamageEventPlayer(EntityDamageEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
Profile profile = Profile.getByPlayer(player);
if (profile.getCooldownByType(ProfileCooldownType.LOGOUT) != null) {
player.sendMessage(main.getLanguageConfig().getString("COMBAT_LOGGER.LOGOUT_CANCELLED"));
profile.getCooldowns().remove(profile.getCooldownByType(ProfileCooldownType.LOGOUT));
profile.setLogoutLocation(null);
}
}
}
@EventHandler
public void onChunkLoadEvent(ChunkLoadEvent event) {
for (Entity entity : event.getChunk().getEntities()) {
if (entity.getType() == CombatLogger.ENTITY_TYPE) {
if (entity instanceof LivingEntity) {
if (entity.getCustomName() != null) {
entity.remove();
}
}
}
}
}
@EventHandler
public void onChunkUnloadEvent(ChunkUnloadEvent event) {
for (Entity entity : event.getChunk().getEntities()) {
if (entity instanceof LivingEntity) {
CombatLogger logger = CombatLogger.getByEntity((LivingEntity) entity);
if (logger != null) {
entity.remove();
CombatLogger.getLoggers().remove(logger);
}
}
}
}
@EventHandler
public void onPlayerJoinEvent(PlayerJoinEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
CombatLogger logger = CombatLogger.getByPlayer(player);
if (logger != null) {
event.getPlayer().teleport(logger.getEntity().getLocation());
logger.getEntity().remove();
CombatLogger.getLoggers().remove(logger);
}
if (profile.isCombatLogged()) {
player.getInventory().clear();
player.getInventory().setArmorContents(null);
player.setExp(0);
player.setHealth(0);
}
}
@EventHandler
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
if (event.getRightClicked() instanceof LivingEntity) {
CombatLogger logger = CombatLogger.getByEntity((LivingEntity) event.getRightClicked());
if (logger != null) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDeathEvent(EntityDeathEvent event) {
LivingEntity entity = event.getEntity();
CombatLogger logger = CombatLogger.getByEntity(entity);
if (logger != null) {
Profile profile = new Profile(logger.getUuid());
for (ItemStack itemStack : logger.getArmor()) {
if (itemStack != null && itemStack.getType() != Material.AIR) {
entity.getWorld().dropItemNaturally(entity.getLocation(), itemStack);
}
}
for (ItemStack itemStack : logger.getContents()) {
if (itemStack != null && itemStack.getType() != Material.AIR) {
entity.getWorld().dropItemNaturally(entity.getLocation(), itemStack);
}
}
profile.getCooldowns().clear();
event.getDrops().clear();
PlayerFaction playerFaction = PlayerFaction.getByPlayerName(logger.getName());
if (playerFaction != null) {
playerFaction.freeze(FactionsPlugin.getInstance().getMainConfig().getInt("FACTION_GENERAL.FREEZE_DURATION"));
playerFaction.setDeathsTillRaidable(playerFaction.getDeathsTillRaidable().subtract(BigDecimal.ONE));
playerFaction.sendMessage(CC.RED + "Member Death: " + entity.getName());
playerFaction.sendMessage(CC.RED + "DTR: " + playerFaction.getDeathsTillRaidable());
}
EntityDamageEvent damageEvent = entity.getLastDamageCause();
entity.getWorld().strikeLightningEffect(entity.getLocation());
if (!main.isKitmapMode()) {
profile.setDeathban(new ProfileDeathban(logger.getDeathbanDuration()));
}
profile.setCombatLogged(true);
if (entity.getKiller() != null) {
ProfileFight fight = new ProfileFight(UUID.randomUUID(), -1, System.currentTimeMillis(), logger.getContents(), logger.getArmor(), logger.getHunger(), logger.getEffects(), new ProfileFightPlayerKiller(entity.getKiller()), entity.getLocation());
profile.getFights().add(fight);
Profile.getByPlayer(entity.getKiller()).getFights().add(fight);
Player killer = entity.getKiller();
entity.getWorld().dropItemNaturally(entity.getLocation(), new ItemBuilder(Material.SKULL_ITEM).durability(3).owner(logger.getName()).build());
Profile killerProfile = Profile.getByPlayer(killer);
killerProfile.setKillStreak((killerProfile.getKillStreak() + 1));
for (KillStreakType killStreakType : KillStreakType.values()) {
if (killerProfile.getKillStreak() == killStreakType.getCount()) {
Bukkit.broadcastMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("KILL_STREAK.MESSAGE").replace("%PLAYER%", killer.getName()).replace("%COUNT%", killerProfile.getKillStreak() + ""));
for (ItemStack item : killStreakType.getItems()) {
killer.getInventory().addItem(item);
}
}
}
String weapon = "their fists";
if (profile.getLastDamager() != null && profile.getLastDamager().getKey() != null && profile.getLastDamager().getKey().equals(killer.getUniqueId())) {
ItemStack item = profile.getLastDamager().getValue();
if (item != null) {
if (item.getItemMeta().hasDisplayName()) {
weapon = item.getItemMeta().getDisplayName();
} else {
weapon = ItemNames.lookup(item);
}
}
} else {
if (killer.getItemInHand() != null && killer.getItemInHand().getType() != Material.AIR) {
if (killer.getItemInHand().getItemMeta().hasDisplayName()) {
weapon = killer.getItemInHand().getItemMeta().getDisplayName();
} else {
weapon = ItemNames.lookup(killer.getItemInHand());
}
}
}
new ProfileDeathMessage(ProfileDeathMessageTemplate.LOGGER, profile, killerProfile, weapon);
new BukkitRunnable() {
@Override
public void run() {
profile.save();
Profile.getProfilesMap().remove(profile.getUuid());
}
}.runTaskAsynchronously(this.main);
return;
}
if (damageEvent == null) {
new ProfileDeathMessage(ProfileDeathMessageTemplate.CUSTOM, profile);
profile.getFights().add(new ProfileFight(UUID.randomUUID(), -1, System.currentTimeMillis(), logger.getContents(), logger.getArmor(), logger.getHunger(), logger.getEffects(), new ProfileFightEnvironmentKiller(ProfileFightEnvironment.CUSTOM), entity.getLocation()));
new BukkitRunnable() {
@Override
public void run() {
profile.save();
Profile.getProfilesMap().remove(profile.getUuid());
}
}.runTaskAsynchronously(this.main);
return;
}
EntityDamageEvent.DamageCause cause = damageEvent.getCause();
if (cause == EntityDamageEvent.DamageCause.PROJECTILE || cause == EntityDamageEvent.DamageCause.ENTITY_ATTACK || cause == EntityDamageEvent.DamageCause.POISON || cause == EntityDamageEvent.DamageCause.MAGIC || cause == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) {
return;
}
try {
profile.getFights().add(new ProfileFight(UUID.randomUUID(), -1, System.currentTimeMillis(), logger.getContents(), logger.getArmor(), logger.getHunger(), logger.getEffects(), new ProfileFightEnvironmentKiller(ProfileFightEnvironment.valueOf(cause.name().toUpperCase())), entity.getLocation()));
} catch (Exception ignored) {
profile.getFights().add(new ProfileFight(UUID.randomUUID(), -1, System.currentTimeMillis(), logger.getContents(), logger.getArmor(), logger.getHunger(), logger.getEffects(), new ProfileFightEnvironmentKiller(ProfileFightEnvironment.CUSTOM), entity.getLocation()));
}
ProfileDeathMessageTemplate template;
try {
template = ProfileDeathMessageTemplate.valueOf(cause.name());
} catch (Exception exception) {
return;
}
new ProfileDeathMessage(template, profile);
profile.save();
Profile.getProfilesMap().remove(profile.getUuid());
}
}
@EventHandler
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof LivingEntity) {
Player damager;
if (event.getDamager() instanceof Player) {
damager = (Player) event.getDamager();
} else if (event.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) event.getDamager();
if (projectile.getShooter() instanceof Player) {
damager = (Player) projectile.getShooter();
} else {
return;
}
} else {
return;
}
CombatLogger logger = CombatLogger.getByEntity((LivingEntity) event.getEntity());
if (logger != null) {
PlayerFaction damagedFaction = PlayerFaction.getByPlayerName(logger.getName());
PlayerFaction damagerFaction = PlayerFaction.getByPlayerName(damager.getName());
if (damagedFaction == null || damagerFaction == null) {
CombatLogger.getLoggersMap().put(logger, System.currentTimeMillis());
return;
}
if (damagedFaction == damagerFaction) {
damager.sendMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("FACTION_OTHER.CANNOT_DAMAGE_FRIENDLY").replace("%PLAYER%", logger.getName()));
event.setCancelled(true);
return;
}
if (damagedFaction.getAllies().contains(damagerFaction) && !FactionsPlugin.getInstance().getMainConfig().getBoolean("ALLIES.DAMAGE_ALLIES")) {
damager.sendMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("FACTION_OTHER.CANNOT_DAMAGE_ALLY").replace("%PLAYER%", logger.getName()));
event.setCancelled(true);
}
}
}
}
@EventHandler
public void onEntityDamageEvent(EntityDamageEvent event) {
if (event.getEntity() instanceof LivingEntity) {
CombatLogger logger = CombatLogger.getByEntity((LivingEntity) event.getEntity());
if (logger != null) {
CombatLogger.getLoggersMap().put(logger, System.currentTimeMillis());
new BukkitRunnable() {
@Override
public void run() {
event.getEntity().setVelocity(new Vector());
}
}.runTaskLaterAsynchronously(main, 1L);
if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
event.setDamage(event.getFinalDamage() * 5);
}
}
}
}
}

View File

@ -0,0 +1,30 @@
package com.amberpvp.hcfactions.combatlogger.commands;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldown;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldownType;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.entity.Player;
public class CombatLoggerCommand extends PluginCommand {
@Command(name = "logout", aliases = "combatlog")
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.getCooldownByType(ProfileCooldownType.LOGOUT) != null) {
player.sendMessage(langFile.getString("COMBAT_LOGGER.LOGOUT_ALREADY"));
return;
}
player.sendMessage(langFile.getString("COMBAT_LOGGER.LOGOUT").replace("%TIME%", main.getMainConfig().getInt("COMBAT_LOGGER.LOGOUT_TIME") + ""));
profile.getCooldowns().add(new ProfileCooldown(ProfileCooldownType.LOGOUT, main.getMainConfig().getInt("COMBAT_LOGGER.LOGOUT_TIME")));
profile.setLogoutLocation(player.getLocation());
}
}

View File

@ -0,0 +1,39 @@
package com.amberpvp.hcfactions.command;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class CloneInventoryCommand extends PluginCommand {
@Command(name = "cloneinventory", aliases = {"cloneinv", "copyinv", "copyinventory", "cpfrom"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
String[] args = command.getArgs();
if (!player.hasPermission("staff.sradmin")) {
player.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
Player toClone;
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "/" + command.getLabel() + " <player>");
return;
} else {
toClone = Bukkit.getPlayer(StringUtils.join(args));
if (toClone == null) {
player.sendMessage(ChatColor.RED + "No player named '" + StringUtils.join(args) + "' found.");
return;
}
}
player.getInventory().setContents(toClone.getInventory().getContents());
player.getInventory().setArmorContents(toClone.getInventory().getArmorContents());
player.sendMessage(ChatColor.RED + "Inventory successfully cloned");
}
}

View File

@ -0,0 +1,39 @@
package com.amberpvp.hcfactions.command;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class GiveInventoryCommand extends PluginCommand {
@Command(name = "giveinv", aliases = {"sendinv", "cpto"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
String[] args = command.getArgs();
if (!player.hasPermission("staff.sradmin")) {
player.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
Player toSend;
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "/" + command.getLabel() + " <player>");
return;
} else {
toSend = Bukkit.getPlayer(StringUtils.join(args));
if (toSend == null) {
player.sendMessage(ChatColor.RED + "No player named '" + StringUtils.join(args) + "' found.");
return;
}
}
toSend.getInventory().setContents(player.getInventory().getContents());
toSend.getInventory().setArmorContents(player.getInventory().getArmorContents());
player.sendMessage(ChatColor.RED + "Inventory successfully sent.");
}
}

View File

@ -0,0 +1,111 @@
package com.amberpvp.hcfactions.command;
import com.mongodb.client.FindIterable;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.fight.ProfileFight;
import com.amberpvp.hcfactions.util.InventorySerialisation;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bson.Document;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.io.IOException;
import java.util.UUID;
import static com.mongodb.client.model.Filters.eq;
import static com.mongodb.client.model.Sorts.descending;
public class LastInventoryCommand extends PluginCommand {
@Command(name = "lastinventory", aliases = {"lastinv", "restoreinv", "restoreinventory"}
)
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
String[] args = command.getArgs();
Profile toRestore;
Player toRestorePlayer = null;
if (!player.hasPermission("staff.mod")) {
player.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "/" + command.getLabel() + " <player>");
return;
} else {
toRestorePlayer = Bukkit.getPlayer(args[0]);
if (toRestorePlayer != null) {
toRestore = Profile.getByPlayer(toRestorePlayer);
} else {
toRestore = Profile.getByName(args[0]);
}
}
if (toRestore == null) {
player.sendMessage(ChatColor.RED + "No player named '" + args[0] + "' found.");
return;
}
UUID uuid = null;
if (args.length > 1) {
try {
uuid = UUID.fromString(args[1]);
} catch (Exception ex) {
player.sendMessage(ChatColor.RED + "Invalid query.");
return;
}
}
ItemStack[] contents = null, armor = null;
if (!toRestore.getFights().isEmpty()) {
for (ProfileFight oneFight : toRestore.getFights()) {
if (oneFight.getKiller() != null && oneFight.getKiller().getName() != null && oneFight.getKiller().getName().equals(toRestore.getName())) continue;
if (uuid != null && !oneFight.getUuid().equals(uuid)) continue;
contents = oneFight.getContents();
armor = oneFight.getArmor();
}
} else {
Document fightDocument;
FindIterable iterable = main.getFactionsDatabase().getFights().find(eq("killed", toRestore.getUuid().toString())).sort(descending("occurred_at"));
if (uuid == null) {
fightDocument = (Document) iterable.first();
} else {
fightDocument = (Document) iterable.filter(eq("uuid", uuid.toString())).first();
}
if (fightDocument == null) {
player.sendMessage(ChatColor.RED + toRestore.getName() + " has no previous inventories to restore. (document)");
return;
}
try {
contents = InventorySerialisation.itemStackArrayFromJson(fightDocument.getString("contents"));
armor = InventorySerialisation.itemStackArrayFromJson(fightDocument.getString("armor"));
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "An error occurred when attempting to grab that inventory.");
return;
}
}
if (contents == null || armor == null) {
player.sendMessage(ChatColor.RED + "An error occurred when attempting to grab that inventory.");
return;
}
if(toRestorePlayer != null && toRestorePlayer.isOnline()) {
toRestorePlayer.getInventory().setContents(contents);
toRestorePlayer.getInventory().setArmorContents(armor);
toRestorePlayer.sendMessage(ChatColor.RED + "Inventory successfully received.");
toRestorePlayer.sendMessage(ChatColor.RED + "Inventory successfully sent.");
}
}
}

View File

@ -0,0 +1,97 @@
package com.amberpvp.hcfactions.crowbar;
import com.amberpvp.hcfactions.FactionsPlugin;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
@Accessors(chain = true)
public class
Crowbar {
private static FactionsPlugin main = FactionsPlugin.getInstance();
private static final Material MATERIAL = Material.getMaterial(main.getMainConfig().getString("CROWBAR.ITEM"));
private static final String NAME = main.getLanguageConfig().getString("CROWBAR.NAME");
private static final List<String> LORE = main.getLanguageConfig().getStringList("CROWBAR.LORE");
@Getter private ItemStack itemStack;
@Getter @Setter private int spawnerUses;
@Getter @Setter private int portalUses;
public Crowbar(ItemStack itemStack) {
this.itemStack = itemStack;
setup();
}
public Crowbar update() {
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName(NAME);
List<String> lore = new ArrayList<>();
for (String sub : LORE) {
lore.add(sub.replace("%SPAWNER_USES%", spawnerUses + "").replace("%PORTAL_USES%", portalUses + ""));
}
meta.setLore(lore);
itemStack.setItemMeta(meta);
return this;
}
private void setup() {
int spawnerIndex = 0;
int portalIndex = 0;
for (int i = 0; i < LORE.size(); i++) {
String sub = LORE.get(i);
if (sub.contains("%SPAWNER_USES%")) {
spawnerIndex = i;
}
if (sub.contains("%PORTAL_USES%")) {
portalIndex = i;
}
}
int spawner;
int portal;
try {spawner = Integer.parseInt(ChatColor.stripColor(itemStack.getItemMeta().getLore().get(spawnerIndex)).replaceAll("[^0-9]", "").replace(" ", ""));} catch (Exception ignored) { ignored.printStackTrace(); spawner = 0; }
try {portal = Integer.parseInt(ChatColor.stripColor(itemStack.getItemMeta().getLore().get(portalIndex)).replaceAll("[^0-9]", "").replace(" ", ""));} catch (Exception ignored) { ignored.printStackTrace(); portal = 0; }
spawnerUses = spawner;
portalUses = portal;
}
public static Crowbar getNewCrowbar() {
ItemStack toReturn = new ItemStack(MATERIAL);
ItemMeta meta = toReturn.getItemMeta();
meta.setDisplayName(NAME);
List<String> lore = new ArrayList<>();
for (String sub : LORE) {
lore.add(sub.replace("%SPAWNER_USES%", 1 + "").replace("%PORTAL_USES%", 8 + ""));
}
meta.setLore(lore);
toReturn.setItemMeta(meta);
return new Crowbar(toReturn);
}
public static Crowbar getByItemStack(ItemStack itemStack) {
return itemStack.getType() == MATERIAL && NAME.equals(itemStack.getItemMeta().getDisplayName()) && itemStack.getItemMeta().hasLore() && itemStack.getItemMeta().getLore().size() == LORE.size() ? new Crowbar(itemStack) : null;
}
}

View File

@ -0,0 +1,112 @@
package com.amberpvp.hcfactions.crowbar;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import com.amberpvp.hcfactions.profile.Profile;
import me.joeleoli.nucleus.util.ItemBuilder;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public class CrowbarListeners implements Listener {
private static FactionsPlugin main = FactionsPlugin.getInstance();
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEvent(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getItem() != null) {
Player player = event.getPlayer();
Block block = event.getClickedBlock();
Crowbar crowbar = Crowbar.getByItemStack(event.getItem());
if (crowbar == null) {
return;
}
event.setCancelled(true);
if (block.getType() == Material.ENDER_PORTAL_FRAME || block.getType() == Material.MOB_SPAWNER) {
boolean spawner = block.getType() == Material.MOB_SPAWNER;
if (spawner && crowbar.getSpawnerUses() <= 0) {
player.sendMessage(main.getLanguageConfig().getString("CROWBAR.NO_SPAWNER_USES"));
return;
}
if (!spawner && crowbar.getPortalUses() <= 0) {
player.sendMessage(main.getLanguageConfig().getString("CROWBAR.NO_PORTAL_USES"));
return;
}
Profile profile = Profile.getByPlayer(player);
PlayerFaction playerFaction = profile.getFaction();
Location location = block.getLocation();
Claim claim = Claim.getProminentClaimAt(location);
if (claim != null && !profile.isInAdminMode()) {
Faction faction = claim.getFaction();
if (faction != null && (playerFaction == null || !faction.equals(playerFaction))) {
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
player.sendMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("FACTION_CLAIM.CANNOT_BUILD_SYSTEM").replace("%COLOR%", systemFaction.getColor() + "").replace("%FACTION%", systemFaction.getName()));
return;
}
else {
if (faction instanceof PlayerFaction && playerFaction != null && playerFaction.getAllies().contains(faction)) {
player.sendMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("FACTION_CLAIM.CANNOT_BUILD_ALLY").replace("%FACTION%", faction.getName()));
return;
}
else {
player.sendMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("FACTION_CLAIM.CANNOT_BUILD_ENEMY").replace("%FACTION%", faction.getName()));
return;
}
}
}
}
ItemStack toDrop;
if (spawner) {
crowbar.setSpawnerUses(crowbar.getSpawnerUses() - 1).update();
CreatureSpawner creatureSpawner = (CreatureSpawner) block.getState();
toDrop = new ItemBuilder(Material.MOB_SPAWNER).name(ChatColor.GREEN + creatureSpawner.getCreatureTypeName() + " Spawner").build();
} else {
crowbar.setPortalUses(crowbar.getPortalUses() - 1).update();
toDrop = new ItemStack(block.getType());
}
block.getWorld().dropItemNaturally(block.getLocation(), toDrop);
block.setType(Material.AIR);
player.updateInventory();
}
}
}
@EventHandler(ignoreCancelled = true)
public void onBlockPlaceEvent(BlockPlaceEvent event) {
ItemStack itemStack = event.getItemInHand();
if (itemStack.getType() == Material.MOB_SPAWNER) {
if (itemStack.getItemMeta().hasDisplayName()) {
String name = itemStack.getItemMeta().getDisplayName();
if (name.startsWith(ChatColor.GREEN.toString())) {
((CreatureSpawner)event.getBlock().getState()).setCreatureTypeByName(ChatColor.stripColor(name.replace(" Spawner", "")));
}
}
}
}
}

View File

@ -0,0 +1,286 @@
package com.amberpvp.hcfactions.deathlookup;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.InventorySerialisation;
import com.amberpvp.hcfactions.util.LocationSerialization;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.fight.ProfileFight;
import com.amberpvp.hcfactions.profile.fight.ProfileFightEffect;
import com.amberpvp.hcfactions.profile.fight.ProfileFightEnvironment;
import com.amberpvp.hcfactions.profile.fight.killer.ProfileFightKiller;
import com.amberpvp.hcfactions.profile.fight.killer.type.ProfileFightEnvironmentKiller;
import com.amberpvp.hcfactions.profile.fight.killer.type.ProfileFightPlayerKiller;
import com.amberpvp.hcfactions.util.InventorySerialisation;
import com.amberpvp.hcfactions.util.LocationSerialization;
import me.joeleoli.nucleus.util.ItemBuilder;
import me.joeleoli.nucleus.util.NumberUtil;
import org.apache.commons.lang.WordUtils;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mongodb.client.MongoCursor;
import lombok.Getter;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.bson.Document;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.mongodb.client.model.Filters.eq;
import static com.mongodb.client.model.Sorts.descending;
/*
This is in beta, not going to be making it configurable for quite some time.
*/
public class
DeathLookup {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
private static final int PAGE_SIZE = 9;
private static final String INVENTORY_TITLE = ChatColor.RED + "Deaths - %PAGE%/%TOTAL%";
private static FactionsPlugin main = FactionsPlugin.getInstance();
@Getter private final Profile profile;
@Getter private final DeathLookupData data;
public DeathLookup(Profile profile) {
this.profile = profile;
this.data = new DeathLookupData();
}
public Inventory getDeathInventory(int page) {
int total = (int) Math.ceil(getDeathsCount() / 9.0);
if (total == 0) {
total = 1;
}
Inventory toReturn = Bukkit.createInventory(null, 18, INVENTORY_TITLE.replace("%PLAYER%", profile.getName()).replace("%PAGE%", page + "").replace("%TOTAL%", total + ""));
toReturn.setItem(0, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Previous Page").build());
toReturn.setItem(8, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Next Page").build());
toReturn.setItem(4, new ItemBuilder(Material.PAPER).name(ChatColor.RED + "Page " + page + "/" + total).lore(Arrays.asList(ChatColor.YELLOW + "Player: " + ChatColor.RED + profile.getName())).build());
int count = 0;
for (ProfileFight death : getDeaths(page)) {
ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM).name(ChatColor.YELLOW + DATE_FORMAT.format(new Date(death.getOccurredAt())));
List<String> lore = new ArrayList<>();
lore.addAll(Arrays.asList(
"&7&m------------------------------",
"&eKilled by: &c" + (death.getKiller().getName() == null ? "Environment (" + WordUtils.capitalize(((ProfileFightEnvironmentKiller) death.getKiller()).getType().name().toLowerCase()) + ")" : death.getKiller().getName())
));
if (!(death.getEffects().isEmpty())) {
lore.add("&7&m------------------------------");
lore.add("&cEffects:");
for (ProfileFightEffect effect : death.getEffects()) {
String name = WordUtils.capitalize(effect.getType().getName().replace("_", " ").toLowerCase());
lore.add(" &e" + name + " " + NumberUtil.toRomanNumeral(effect.getLevel()) + "&c for &e" + DurationFormatUtils.formatDuration(effect.getDuration(), "mm:ss") + "m");
}
}
lore.add("&7&m------------------------------");
builder.lore(lore);
toReturn.setItem(PAGE_SIZE + count, builder.build());
count++;
}
return toReturn;
}
public int getTotalPages() {
int total = (int) Math.ceil(getDeathsCount() / 9.0);
if (total == 0) {
total = 1;
}
return total;
}
public long getDeathsCount() {
return main.getFactionsDatabase().getFights().count(eq("killed", profile.getUuid().toString())) + profile.getFights().size();
}
public List<ProfileFight> getDeaths(int page) {
List<ProfileFight> toReturn = new ArrayList<>();
int toLimit = 0;
for (ProfileFight fight : profile.getFights()) {
if (fight.getKiller() instanceof ProfileFightPlayerKiller && ((ProfileFightPlayerKiller) fight.getKiller()).getUuid().equals(profile.getUuid())) {
continue;
}
toReturn.add(fight);
toLimit++;
}
MongoCursor cursor = main.getFactionsDatabase().getFights().find(eq("killed", profile.getUuid().toString())).skip((page - 1) * PAGE_SIZE).limit(PAGE_SIZE - toLimit).sort(descending("occurred_at")).iterator();
while (cursor.hasNext()) {
Document document = (Document) cursor.next();
List<ProfileFightEffect> effects = new ArrayList<>();
for (JsonElement effectElement : (JsonArray) new JsonParser().parse(document.getString("effects"))) {
JsonObject effectObject = (JsonObject) effectElement;
effects.add(new ProfileFightEffect(new PotionEffect(PotionEffectType.getByName(effectObject.get("type").getAsString()), effectObject.get("duration").getAsInt() / 1000 * 20, effectObject.get("level").getAsInt() - 1)));
}
try {
Document killerDocument = (Document) document.get("killer");
ProfileFightKiller killer;
if (killerDocument.get("type").equals("PLAYER")) {
List<ProfileFightEffect> killerEffects = new ArrayList<>();
for (JsonElement effectElement : (JsonArray) new JsonParser().parse(killerDocument.getString("effects"))) {
JsonObject effectObject = (JsonObject) effectElement;
killerEffects.add(new ProfileFightEffect(new PotionEffect(PotionEffectType.getByName(effectObject.get("type").getAsString()), effectObject.get("duration").getAsInt() / 1000 * 20, effectObject.get("level").getAsInt() - 1)));
}
killer = new ProfileFightPlayerKiller(killerDocument.getString("name"), UUID.fromString(killerDocument.getString("uuid")), killerDocument.getInteger("ping"), InventorySerialisation.itemStackArrayFromJson(killerDocument.getString("contents")), InventorySerialisation.itemStackArrayFromJson(killerDocument.getString("armor")), killerDocument.getDouble("health"), killerDocument.getDouble("hunger"), killerEffects);
} else if (killerDocument.get("type").equals("MOB")){
killer = new ProfileFightKiller(EntityType.valueOf(killerDocument.getString("mob_type")), killerDocument.getString("name"));
} else {
killer = new ProfileFightEnvironmentKiller(ProfileFightEnvironment.valueOf(killerDocument.getString("type")));
}
toReturn.add(new ProfileFight(UUID.fromString(document.getString("uuid")), document.getInteger("ping"), document.getLong("occurred_at"), InventorySerialisation.itemStackArrayFromJson(document.getString("contents")), InventorySerialisation.itemStackArrayFromJson(document.getString("armor")), document.getDouble("hunger"), effects, killer, LocationSerialization.deserializeLocation(document.getString("location"))));
} catch (IOException e) {
e.printStackTrace();
}
}
return toReturn;
}
public Inventory getFightItemInventory(ProfileFight fight) {
int deathNumber = (int) (getDeathsCount() - (((getData().getPage() - 1) * 9) + getData().getIndex()));
Inventory toReturn = Bukkit.createInventory(null, 9 * 6, ChatColor.RED + "Inventory #" + deathNumber);
toReturn.setItem(0, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Return").build());
toReturn.setItem(8, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Return").build());
toReturn.setItem(4, new ItemBuilder(Material.PAPER).name(ChatColor.RED + "Inventory Contents").lore(Arrays.asList(ChatColor.YELLOW + "Player: " + ChatColor.RED + profile.getName())).build());
List<ItemStack> contents = new ArrayList<>(Arrays.asList(fight.getContents()));
List<ItemStack> armor = new ArrayList<>(Arrays.asList(fight.getArmor()));
for (int i = 0; i < contents.size(); i++) {
if (i <= 8) {
ItemStack item = contents.get(i);
if (item != null) {
toReturn.setItem(i + 9, item);
}
}
}
for (int i = 0; i < contents.size(); i++) {
if (i > 8) {
ItemStack item = contents.get(i);
if (item != null) {
int position = i;
if (position <= 17) {
position += 27;
} else if (position > 17 && position < 27) {
position += 9;
} else if (position >= 27) {
position -= 18;
}
while (toReturn.getItem(position) != null) {
position++;
if (position == toReturn.getSize()) break;
}
if (position != toReturn.getSize()) {
toReturn.setItem(position, item);
}
}
}
}
for (int i = 0; i < 2; i++) {
toReturn.setItem(49 + i, new ItemBuilder(Material.STAINED_GLASS_PANE).durability(14).name(" ").build());
}
for (int i = 0; i < armor.size(); i++) {
ItemStack item = armor.get(i);
System.out.println(item);
if (item != null && item.getType() != Material.AIR) {
toReturn.setItem(45 + i, item);
} else {
toReturn.setItem(45 + i, new ItemBuilder(Material.STAINED_GLASS_PANE).durability(14).name(" ").build());
}
}
List<String> lore = new ArrayList<>();
if (!fight.getEffects().isEmpty()) {
lore.add("&7&m------------------------------");
for (ProfileFightEffect effect : fight.getEffects()) {
String name = WordUtils.capitalize(effect.getType().getName().replace("_", " ").toLowerCase());
lore.add("&e" + name + " " + NumberUtil.toRomanNumeral(effect.getLevel()) + "&c for &e" + DurationFormatUtils.formatDuration(effect.getDuration(), "mm:ss") + "m");
}
lore.add("&7&m------------------------------");
}
ItemStack effects = new ItemBuilder(Material.POTION).name(ChatColor.RED + (fight.getEffects().isEmpty() ? "No Potion Effects" : fight.getEffects().size() + " Effect" + (fight.getEffects().size() == 1 ? "" : "s"))).lore(lore).build();
toReturn.setItem(51, new ItemBuilder(Material.CHEST).name(ChatColor.RED + "Copy Inventory").build());
toReturn.setItem(52, new ItemBuilder(Material.PUMPKIN_PIE).name(ChatColor.RED + "Food Level of " + ((int)fight.getHunger() / 2)).build());
toReturn.setItem(53, effects);
return toReturn;
}
public Inventory getFightInventory(ProfileFight fight) {
int deathNumber = (int) (getDeathsCount() - (((getData().getPage() - 1) * 9) + getData().getIndex()));
Inventory toReturn = Bukkit.createInventory(null, 18, ChatColor.RED + "Death #" + deathNumber);
toReturn.setItem(0, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Previous Death").build());
toReturn.setItem(8, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Next Death").build());
toReturn.setItem(4, new ItemBuilder(Material.PAPER).name(ChatColor.RED + "Death Information").lore(Arrays.asList(ChatColor.YELLOW + "Player: " + ChatColor.RED + profile.getName())).build());
ItemStack inventoryContents = new ItemBuilder(Material.CHEST).name(ChatColor.RED + "Inventory Contents").lore(Arrays.asList(
"&7&m------------------------------",
(fight.getInventorySize() == 0 ? "&e" + profile.getName() + "&c had an empty inventory" : "&e" + profile.getName() + "&c had " + fight.getInventorySize() + " items"),
(fight.hasArmor() ? "&e" + profile.getName() + "&c was wearing armor" : "&e" + profile.getName() + "&c was not wearing armor"),
"&7&m------------------------------",
"&eClick to view expanded details",
"&7&m------------------------------"
)).build();
ItemStack deathLocation = new ItemBuilder(Material.EMPTY_MAP).name(ChatColor.RED + "Death Location").lore(Arrays.asList(
"&7&m------------------------------",
"&eWorld: &c" + WordUtils.capitalize(fight.getLocation().getWorld().getName().replace("_", " ").toLowerCase()),
"&eCoordinates: &cX: " + fight.getLocation().getBlockX() + ", Y: " + fight.getLocation().getBlockY() + ", Z: " + fight.getLocation().getBlockZ(),
"&7&m------------------------------",
"&eClick to teleport to death location",
"&7&m------------------------------"
)).build();
if (profile.getDeathban() != null) {
toReturn.setItem(10, inventoryContents);
toReturn.setItem(13, deathLocation);
toReturn.setItem(16, new ItemBuilder(Material.SKULL_ITEM).durability(2).name(ChatColor.RED + "Revive " + profile.getName()).build());
} else {
toReturn.setItem(11, inventoryContents);
toReturn.setItem(15, deathLocation);
}
return toReturn;
}
}

View File

@ -0,0 +1,53 @@
package com.amberpvp.hcfactions.deathlookup;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
/*
This is in beta, not going to be making it configurable for quite some time.
*/
public class DeathLookupCommand extends PluginCommand {
@Command(name = "deathlookup", aliases = {"lookupdeath", "dl"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
Profile profile = Profile.getByPlayer(player);
String[] args = command.getArgs();
if (!player.hasPermission("staff.trialmod")) {
player.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /" + command.getLabel() + " <target>");
return;
}
Profile toLookupProfile;
Player toLookup = Bukkit.getPlayer(StringUtils.join(args));
if (toLookup != null) {
toLookupProfile = Profile.getByPlayer(toLookup);
} else {
toLookupProfile = Profile.getByName(StringUtils.join(args));
}
if (toLookupProfile == null) {
player.sendMessage(ChatColor.RED + "No player with name '" + StringUtils.join(args) + "' found.");
return;
}
profile.setDeathLookup(new DeathLookup(toLookupProfile));
player.openInventory(profile.getDeathLookup().getDeathInventory(1));
}
}

View File

@ -0,0 +1,13 @@
package com.amberpvp.hcfactions.deathlookup;
import com.amberpvp.hcfactions.profile.fight.ProfileFight;
import lombok.Getter;
import lombok.Setter;
public class DeathLookupData {
@Getter @Setter private ProfileFight fight;
@Getter @Setter private int page;
@Getter @Setter private int index;
}

View File

@ -0,0 +1,177 @@
package com.amberpvp.hcfactions.deathlookup;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.fight.ProfileFight;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import java.text.SimpleDateFormat;
public class DeathLookupListeners implements Listener {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
@EventHandler
public void onInventoryClickEvent(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
Profile profile = Profile.getByPlayer(player);
ItemStack itemStack = event.getCurrentItem();
if (itemStack != null && itemStack.getType() != Material.AIR) {
String title = event.getInventory().getTitle();
String displayName = itemStack.getItemMeta().getDisplayName();
DeathLookup lookup = profile.getDeathLookup();
if (((title.contains("Deaths") || title.contains("Death #") || title.contains("Inventory #")) && player.hasPermission("staff.mod") && lookup != null)) {
event.setCancelled(true);
if (displayName == null) {
return;
}
int page = 0;
int total = 0;
if (title.contains("Deaths")) {
page = Integer.parseInt(title.substring(title.lastIndexOf("/") - 1, title.lastIndexOf("/")));
total = Integer.parseInt(title.substring(title.lastIndexOf("/") + 1, title.lastIndexOf("/") + 2));
}
if (displayName.contains("Next Page")) {
if (page + 1 > total) {
player.sendMessage(ChatColor.RED + "There are no more pages.");
return;
}
player.openInventory(lookup.getDeathInventory(page + 1));
return;
}
if (displayName.contains("Previous Page")) {
if (page == 1) {
player.sendMessage(ChatColor.RED + "You're on the first page.");
return;
}
player.openInventory(lookup.getDeathInventory(page - 1));
return;
}
if (displayName.contains("Previous Death")) {
ProfileFight fight = lookup.getData().getFight();
if (fight != null) {
if (lookup.getData().getIndex() == 0 && lookup.getData().getPage() == 1) {
player.sendMessage(ChatColor.RED + "You're viewing the latest death.");
return;
}
ProfileFight previousFight;
int previousPage;
int previousIndex;
if (lookup.getData().getIndex() == 0) {
previousFight = lookup.getDeaths(lookup.getData().getPage() - 1).get(8);
previousPage = lookup.getData().getPage() - 1;
previousIndex = 8;
} else {
previousFight = lookup.getDeaths(lookup.getData().getPage()).get(lookup.getData().getIndex() - 1);
previousPage = lookup.getData().getPage();
previousIndex = lookup.getData().getIndex() - 1;
}
lookup.getData().setFight(previousFight);
lookup.getData().setPage(previousPage);
lookup.getData().setIndex(previousIndex);
player.openInventory(lookup.getFightInventory(previousFight));
}
return;
}
if (displayName.contains("Next Death")) {
ProfileFight fight = lookup.getData().getFight();
if (fight != null) {
if (lookup.getData().getIndex() == (lookup.getDeaths(lookup.getTotalPages()).size() - 1) && lookup.getData().getPage() == lookup.getTotalPages()) {
player.sendMessage(ChatColor.RED + "You're viewing the last death.");
return;
}
ProfileFight nextFight;
int nextPage;
int nextIndex;
if (lookup.getData().getIndex() == 8) {
nextFight = lookup.getDeaths(lookup.getData().getPage() + 1).get(0);
nextPage = lookup.getData().getPage() + 1;
nextIndex = 0;
} else {
nextFight = lookup.getDeaths(lookup.getData().getPage()).get(lookup.getData().getIndex() + 1);
nextPage = lookup.getData().getPage();
nextIndex = lookup.getData().getIndex() + 1;
}
lookup.getData().setFight(nextFight);
lookup.getData().setPage(nextPage);
lookup.getData().setIndex(nextIndex);
player.openInventory(lookup.getFightInventory(nextFight));
}
return;
}
if (displayName.contains("Death Location")) {
player.teleport(lookup.getData().getFight().getLocation());
return;
}
if (displayName.contains("Inventory Contents")) {
ProfileFight fight = lookup.getData().getFight();
if (fight != null) {
player.openInventory(lookup.getFightItemInventory(fight));
}
}
if (displayName.contains("Return")) {
ProfileFight fight = lookup.getData().getFight();
if (fight != null) {
player.openInventory(lookup.getFightInventory(fight));
}
}
if (displayName.contains("Copy Inventory")) {
ProfileFight fight = lookup.getData().getFight();
if (fight != null) {
Bukkit.dispatchCommand(player, "lastinv " + lookup.getProfile().getName() + " " + fight.getUuid());
player.closeInventory();
}
}
if (displayName.contains("Revive")) {
ProfileFight fight = lookup.getData().getFight();
if (fight != null) {
Bukkit.dispatchCommand(player, "pvp revive " + lookup.getProfile().getName());
player.closeInventory();
}
}
if (itemStack.getType() == Material.SKULL_ITEM && itemStack.getDurability() == 0) {
ProfileFight fight = lookup.getDeaths(page).get(event.getRawSlot() - 9);
lookup.getData().setFight(fight);
lookup.getData().setPage(page);
lookup.getData().setIndex(event.getRawSlot() - 9);
player.openInventory(lookup.getFightInventory(fight));
}
}
}
}
}

View File

@ -0,0 +1,112 @@
package com.amberpvp.hcfactions.economysign;
import com.amberpvp.hcfactions.crowbar.Crowbar;
import com.amberpvp.hcfactions.crowbar.Crowbar;
import lombok.Getter;
import me.joeleoli.nucleus.util.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.inventory.ItemStack;
public class EconomySign {
@Getter private final Sign sign;
@Getter private final EconomySignType type;
@Getter private final ItemStack itemStack;
@Getter private final int amount;
@Getter private final int price;
public EconomySign(Sign sign, EconomySignType type, ItemStack itemStack, int amount, int price) {
this.sign = sign;
this.type = type;
this.itemStack = itemStack;
this.amount = amount;
this.price = price;
}
public static EconomySign getByBlock(Block block) {
BlockState state = block.getState();
if (state instanceof Sign) {
Sign sign = (Sign) state;
String[] lines = sign.getLines();
EconomySignType type = null;
for (EconomySignType possibleType : EconomySignType.values()) {
if (possibleType.getSignText().get(0).equals(lines[0])) {
type = possibleType;
}
}
if (type == null) {
return null;
}
String materialName = lines[1];
ItemStack itemStack;
if (materialName.equalsIgnoreCase("Crowbar")) {
itemStack = Crowbar.getNewCrowbar().getItemStack();
} else if (materialName.equalsIgnoreCase("Portal Frame")) {
itemStack = new ItemStack(Material.ENDER_PORTAL_FRAME);
} else if (materialName.equalsIgnoreCase("Cow Egg")) {
itemStack = new ItemBuilder(Material.MONSTER_EGG).durability(92).build();
} else if (materialName.equalsIgnoreCase("Nether Wart")) {
itemStack = new ItemStack(Material.NETHER_STALK);
} else if (materialName.equalsIgnoreCase("Fresh Potato")) {
itemStack = new ItemStack(Material.POTATO_ITEM);
} else if (materialName.equalsIgnoreCase("Fresh Carrot")) {
itemStack = new ItemStack(Material.CARROT_ITEM);
} else if (materialName.equalsIgnoreCase("Dye")) {
itemStack = new ItemStack(Material.INK_SACK);
} else if (materialName.equalsIgnoreCase("Fermented Eye")) {
itemStack = new ItemStack(Material.FERMENTED_SPIDER_EYE);
} else if (materialName.equalsIgnoreCase("Gun Powder")) {
itemStack = new ItemStack(Material.SULPHUR);
} else if (materialName.equalsIgnoreCase("OakWood")) {
itemStack = new ItemStack(Material.LOG);
} else if (materialName.equalsIgnoreCase("Diamond Block")) {
itemStack = new ItemStack(Material.DIAMOND_BLOCK);
} else if (materialName.equalsIgnoreCase("Gold Block")) {
itemStack = new ItemStack(Material.GOLD_BLOCK);
} else if (materialName.equalsIgnoreCase("Iron Block")) {
itemStack = new ItemStack(Material.IRON_BLOCK);
} else if (materialName.equalsIgnoreCase("Redstone Block")) {
itemStack = new ItemStack(Material.REDSTONE_BLOCK);
} else if (materialName.equalsIgnoreCase("Coal Block")) {
itemStack = new ItemStack(Material.COAL_BLOCK);
} else if (materialName.equalsIgnoreCase("Lapis Block")) {
itemStack = new ItemStack(Material.LAPIS_BLOCK);
} else if (materialName.equalsIgnoreCase("Emerald Block")) {
itemStack = new ItemStack(Material.EMERALD_BLOCK);
} else {
try {
itemStack = new ItemStack(Material.valueOf(materialName.replace(" ", "_").toUpperCase()));
} catch (Exception ex) {
return null;
}
}
int amount;
try {
amount = Integer.parseInt(lines[2].replaceAll("[^0-9]", ""));
} catch (Exception ex) {
return null;
}
int price;
try {
price = Integer.parseInt(lines[3].replaceAll("[^0-9]", ""));
} catch (Exception ex) {
return null;
}
return new EconomySign(sign, type, itemStack, amount, price);
}
return null;
}
}

View File

@ -0,0 +1,171 @@
package com.amberpvp.hcfactions.economysign;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.ItemNames;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.ItemNames;
import me.joeleoli.nucleus.util.ItemBuilder;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
public class EconomySignListeners implements Listener {
private static FactionsPlugin main = FactionsPlugin.getInstance();
@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block block = event.getClickedBlock();
EconomySign sign = EconomySign.getByBlock(block);
if (sign != null) {
event.setCancelled(true);
new BukkitRunnable() {
@Override
public void run() {
if (player.getWorld().equals(block.getWorld()) && player.getLocation().distance(block.getLocation()) < 30) {
player.sendSignChange(block.getLocation(), new String[]{sign.getSign().getLine(0), sign.getSign().getLine(1), sign.getSign().getLine(2), sign.getSign().getLine(3)});
}
}
}.runTaskLater(main, 30);
if (sign.getType() == EconomySignType.BUY) {
if (player.getInventory().firstEmpty() == -1) {
player.sendMessage(main.getLanguageConfig().getString("ECONOMY.SIGN.ERROR.INVENTORY_FULL"));
player.sendSignChange(block.getLocation(), new String[]{main.getLanguageConfig().getString("ECONOMY.SIGN.INVENTORY_FULL"), sign.getSign().getLine(1), sign.getSign().getLine(2), sign.getSign().getLine(3)});
return;
}
if (Profile.getByPlayer(player).getBalance() < sign.getPrice()) {
player.sendMessage(main.getLanguageConfig().getString("ECONOMY.SIGN.ERROR.NOT_ENOUGH_MONEY"));
player.sendSignChange(block.getLocation(), new String[]{main.getLanguageConfig().getString("ECONOMY.SIGN.CANNOT_AFFORD"), sign.getSign().getLine(1), sign.getSign().getLine(2), sign.getSign().getLine(3)});
return;
}
Profile.getByPlayer(player).setBalance((Profile.getByPlayer(player).getBalance() - sign.getPrice()));
player.getInventory().addItem(new ItemBuilder(sign.getItemStack()).amount(sign.getAmount()).build());
player.sendSignChange(block.getLocation(), new String[]{main.getLanguageConfig().getString("ECONOMY.SIGN.BOUGHT_TEXT"), sign.getSign().getLine(1), sign.getSign().getLine(2), sign.getSign().getLine(3)});
player.updateInventory();
return;
}
if (sign.getType() == EconomySignType.SELL) {
if (!(player.getInventory().contains(sign.getItemStack().getType()))) {
player.sendMessage(main.getLanguageConfig().getString("ECONOMY.SIGN.ERROR.NOT_ENOUGH"));
player.sendSignChange(block.getLocation(), new String[]{main.getLanguageConfig().getString("ECONOMY.SIGN.NOT_ENOUGH_TOP"), sign.getSign().getLine(1), main.getLanguageConfig().getString("ECONOMY.SIGN.NOT_ENOUGH_BOTTOM"), ""});
return;
}
double pricePerItem = (((double)sign.getPrice()) / ((double)sign.getAmount()));
int toSell = 0;
for (ItemStack itemStack : player.getInventory().getContents()) {
if (itemStack == null) continue;
if (toSell >= sign.getAmount()) break;
if (toSell + itemStack.getAmount() >= sign.getAmount()) { toSell = sign.getAmount(); break; }
toSell += itemStack.getAmount();
}
player.sendSignChange(block.getLocation(), new String[]{main.getLanguageConfig().getString("ECONOMY.SIGN.SOLD"), sign.getSign().getLine(1), sign.getSign().getLine(2), sign.getSign().getLine(3)});
player.getInventory().removeItem(new ItemBuilder(sign.getItemStack()).amount(toSell).build());
Profile.getByPlayer(player).setBalance((Profile.getByPlayer(player).getBalance() + (int) Math.floor(pricePerItem * toSell)));
player.updateInventory();
}
}
}
}
@EventHandler
public void onSignChangeEvent(SignChangeEvent event) {
Player player = event.getPlayer();
if (player.hasPermission("shopsign.create")) {
String[] lines = event.getLines();
String typeLine = lines[0];
EconomySignType type;
if (typeLine.equalsIgnoreCase("[Buy]")) {
type = EconomySignType.BUY;
} else if (typeLine.equalsIgnoreCase("[Sell]")) {
type = EconomySignType.SELL;
} else {
return;
}
String itemStackName;
try {
if (lines[1].equalsIgnoreCase("crowbar")) {
itemStackName = "Crowbar";
} else if (lines[1].equalsIgnoreCase("portal frame")) {
itemStackName = "Portal Frame";
} else if (lines[1].equalsIgnoreCase("cow egg")) {
itemStackName = "Cow Egg";
} else if (lines[1].equalsIgnoreCase("fresh potato")) {
itemStackName = "Fresh Potato";
} else if (lines[1].equalsIgnoreCase("fresh carrot")) {
itemStackName = "Fresh Carrot";
} else if (lines[1].equalsIgnoreCase("dye")) {
itemStackName = "Dye";
} else {
itemStackName = ItemNames.lookup(new ItemStack(Material.valueOf(lines[1].replace(" ", "_").toUpperCase())));
}
} catch (Exception ex) {
player.sendMessage(ChatColor.RED + "Invalid material.");
return;
}
int amount;
try {
amount = Integer.parseInt(lines[2].replaceAll("[^0-9]", ""));
} catch (Exception ex) {
player.sendMessage(ChatColor.RED + "Invalid quantity.");
return;
}
if (amount <= 0) {
player.sendMessage(ChatColor.RED + "Amount must be greater than 0.");
return;
}
int price;
try {
price = Integer.parseInt(lines[3].replaceAll("[^0-9]", ""));
} catch (Exception ex) {
player.sendMessage(ChatColor.RED + "Invalid price.");
return;
}
if (price <= 0) {
player.sendMessage(ChatColor.RED + "Price must be greater than $0.");
return;
}
int pos = 0;
for (String line : main.getLanguageConfig().getStringList("ECONOMY.SIGN." + type.name() + "_TEXT")) {
event.setLine(pos, line.replace("%ITEM%", itemStackName).replace("%AMOUNT%", amount + "").replace("%PRICE%", price + ""));
pos++;
}
}
}
}

View File

@ -0,0 +1,18 @@
package com.amberpvp.hcfactions.economysign;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.FactionsPlugin;
import java.util.List;
public enum EconomySignType {
BUY,
SELL;
private static FactionsPlugin main = FactionsPlugin.getInstance();
public List<String> getSignText() {
return main.getLanguageConfig().getStringList("ECONOMY.SIGN." + name() + "_TEXT");
}
}

View File

@ -0,0 +1,24 @@
package com.amberpvp.hcfactions.enchantmentlimiter;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.FactionsPlugin;
import org.bukkit.enchantments.Enchantment;
public class EnchantmentLimiter {
private static final EnchantmentLimiter instance = new EnchantmentLimiter();
private static FactionsPlugin main = FactionsPlugin.getInstance();
public int getEnchantmentLimit(Enchantment enchantment) {
if (main.getMainConfig().getConfiguration().contains("ENCHANTMENT_LIMITER." + enchantment.getName())) {
return main.getMainConfig().getInt("ENCHANTMENT_LIMITER." + enchantment.getName());
}
return enchantment.getMaxLevel();
}
public static EnchantmentLimiter getInstance() {
return instance;
}
}

View File

@ -0,0 +1,96 @@
package com.amberpvp.hcfactions.enchantmentlimiter;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
public class EnchantmentLimiterListeners implements Listener {
@EventHandler
public void onEnchantItemtEvent(EnchantItemEvent event) {
for (Enchantment enchantment : new HashSet<>(event.getEnchantsToAdd().keySet())) {
int limit = EnchantmentLimiter.getInstance().getEnchantmentLimit(enchantment);
int level = event.getEnchantsToAdd().get(enchantment);
if (level > limit) {
if (limit == 0) {
event.getEnchantsToAdd().remove(enchantment);
} else {
event.getEnchantsToAdd().remove(enchantment);
event.getEnchantsToAdd().put(enchantment, limit);
}
}
}
}
@EventHandler(ignoreCancelled = true)
public void onInventoryClickEvent(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
Inventory inventory = event.getInventory();
if (inventory.getType() == InventoryType.ANVIL && event.getRawSlot() == 2) {
ItemStack result = inventory.getItem(2);
if (result != null) {
event.setCancelled(true);
for (Enchantment enchantment : new HashSet<>(result.getEnchantments().keySet())) {
int limit = EnchantmentLimiter.getInstance().getEnchantmentLimit(enchantment);
int level = result.getEnchantmentLevel(enchantment);
if (level > limit) {
if (limit == 0) {
result.removeEnchantment(enchantment);
} else {
result.removeEnchantment(enchantment);
result.addEnchantment(enchantment, limit);
}
player.updateInventory();
}
}
inventory.setItem(0, new ItemStack(Material.AIR));
inventory.setItem(1, new ItemStack(Material.AIR));
inventory.setItem(2, new ItemStack(Material.AIR));
if (event.getClick().name().contains("SHIFT")) {
player.getInventory().addItem(result);
} else {
event.setCursor(result);
}
}
}
}
@EventHandler
public void onEntityDeathEvent(EntityDeathEvent event) {
LivingEntity entity = event.getEntity();
Player player = entity.getKiller();
if (player != null) {
ItemStack itemStack = player.getItemInHand();
if (itemStack != null && itemStack.getType() != Material.AIR && itemStack.getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS) > 0) {
int level = (itemStack.getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS) + 1) * 2;
event.setDroppedExp(event.getDroppedExp() * level);
}
}
}
}

View File

@ -0,0 +1,11 @@
package com.amberpvp.hcfactions.event;
import java.util.List;
public interface Event {
String getName();
List<String> getScoreboardText();
boolean isActive();
}

View File

@ -0,0 +1,54 @@
package com.amberpvp.hcfactions.event;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.event.schedule.ScheduleHandler;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.event.schedule.ScheduleHandler;
import org.bukkit.Location;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
public class EventManager {
private static EventManager instance = new EventManager(FactionsPlugin.getInstance());
@Getter private final FactionsPlugin main;
@Getter private final List<Event> events;
public EventManager(FactionsPlugin main) {
this.main = main;
this.events = new ArrayList<>();
ScheduleHandler.setSchedules(this, this.main.getKothScheduleConfig());
new EventTimer(this.main);
}
public Event getByName(String name) {
for (Event event : events) {
if (event.getName().equalsIgnoreCase(name)) {
return event;
}
}
return null;
}
public GlowstoneEvent getGlowstoneEvent(Location location) {
for(Event event : this.events) {
if(event != null && event instanceof GlowstoneEvent) {
GlowstoneEvent glowstoneEvent = (GlowstoneEvent) event;
if(glowstoneEvent.getCuboid() != null && glowstoneEvent.getCuboid().contains(location)) {
return glowstoneEvent;
}
}
}
return null;
}
public static EventManager getInstance() {
return instance;
}
}

View File

@ -0,0 +1,51 @@
package com.amberpvp.hcfactions.event;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.event.schedule.ScheduleHandler;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.event.schedule.ScheduleHandler;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashMap;
public class EventTimer extends BukkitRunnable {
private FactionsPlugin plugin;
private HashMap<String, Long> glowstoneMountain;
public EventTimer(FactionsPlugin plugin) {
this.plugin = plugin;
this.glowstoneMountain = new HashMap<>();
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, this, 20L, 20L);
}
@Override
public void run() {
ScheduleHandler.runSchedule();
this.checkGlowstoneMountain();
}
private void checkGlowstoneMountain() {
if (!this.glowstoneMountain.containsKey("glowstone")) {
this.glowstoneMountain.put("glowstone", System.currentTimeMillis());
}
if (elapsed(this.glowstoneMountain.get("glowstone"), this.plugin.getMainConfig().getInt("GLOWSTONE.RESET_TIME"))) {
this.glowstoneMountain.put("glowstone", System.currentTimeMillis());
for(Event event : EventManager.getInstance().getEvents()) {
if(event != null && event instanceof GlowstoneEvent) {
((GlowstoneEvent) event).start();
}
}
}
}
private boolean elapsed(long from, long required) {
return System.currentTimeMillis() - from > required;
}
}

View File

@ -0,0 +1,58 @@
package com.amberpvp.hcfactions.event;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class EventZone {
@Getter @Setter private final Location firstLocation, secondLocation;
@Getter @Setter private final Location minPos, maxPos;
@Getter @Setter private int height;
public EventZone(Location firstLocation, Location secondLocation) {
this.firstLocation = firstLocation;
this.secondLocation = secondLocation;
this.minPos = this.getMinimum(this.firstLocation, this.secondLocation);
this.maxPos = this.getMaximum(this.firstLocation, this.secondLocation);
}
private Location getMinimum(Location loc1, Location loc2) {
return new Location(loc1.getWorld(), (loc1.getX() < loc2.getX()) ? loc1.getX() : loc2.getX(), (loc1.getY() < loc2.getY()) ? loc1.getY() : loc2.getY(), (loc1.getZ() < loc2.getZ()) ? loc1.getZ() : loc2.getZ());
}
private Location getMaximum(Location loc1, Location loc2) {
return new Location(loc1.getWorld(), (loc1.getX() > loc2.getX()) ? loc1.getX() : loc2.getX(), (loc1.getY() > loc2.getY()) ? loc1.getY() + height : loc2.getY() + height, (loc1.getZ() > loc2.getZ()) ? loc1.getZ() : loc2.getZ());
}
private boolean isInAABB(Location pos, Location pos2, Location pos3) {
Location min = getMinimum(pos2, pos3);
Location max = getMaximum(pos2, pos3);
if (min.getBlockX() <= pos.getBlockX() && max.getBlockX() >= pos.getBlockX() && min.getBlockY() <= pos.getBlockY() && max.getBlockY() >= pos.getBlockY() && min.getBlockZ() <= pos.getBlockZ() && max.getBlockZ() >= pos.getBlockZ()) {
return true;
}
return false;
}
public boolean isInside(Player player) {
if (player.getWorld() == this.firstLocation.getWorld()) {
Location loc = player.getLocation();
if (isInAABB(loc, minPos, maxPos)) {
return true;
}
}
return false;
}
public Location getCenter() {
int x = (maxPos.getBlockX() + minPos.getBlockX()) / 2;
int y = (maxPos.getBlockY() + minPos.getBlockY()) / 2;
int z = (maxPos.getBlockZ() + minPos.getBlockZ()) / 2;
return new Location(minPos.getWorld(), x, y, z);
}
}

View File

@ -0,0 +1,111 @@
package com.amberpvp.hcfactions.event.glowstone;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.UpdateOptions;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.utils.Cuboid;
import com.amberpvp.hcfactions.util.LocationSerialization;
import lombok.Getter;
import lombok.Setter;
import org.bson.Document;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static com.mongodb.client.model.Filters.eq;
public class GlowstoneEvent implements Event {
private static FactionsPlugin main = FactionsPlugin.getInstance();
private static EventManager manager = EventManager.getInstance();
@Getter private final UUID uuid;
@Getter private final String name;
@Getter private final Cuboid cuboid;
@Getter @Setter private boolean active;
public GlowstoneEvent(UUID uuid, String name, Cuboid cuboid) {
this.uuid = uuid;
this.name = name;
this.cuboid = cuboid;
this.active = false;
manager.getEvents().add(this);
}
public GlowstoneEvent(String name, Cuboid cuboid) {
this(UUID.randomUUID(), name, cuboid);
}
public void start() {
if(cuboid == null) return;
for (Block block : cuboid){
block.setType(Material.GLOWSTONE);
}
Bukkit.broadcastMessage(main.getLanguageConfig().getString("GLOWSTONE.START").replace("%GLOWSTONE%", name));
}
@Override
public List<String> getScoreboardText() {
return new ArrayList<>();
}
@Override
public boolean isActive() {
return active;
}
public void remove() {
main.getFactionsDatabase().getGlowstone().deleteOne(eq("uuid", this.uuid.toString()));
manager.getEvents().remove(this);
}
public static void load() {
MongoCollection collection = main.getFactionsDatabase().getGlowstone();
MongoCursor cursor = collection.find().iterator();
while (cursor.hasNext()) {
Document document = (Document) cursor.next();
UUID uuid = UUID.fromString(document.getString("uuid"));
String name = document.getString("name");
JsonArray zoneArray = new JsonParser().parse(document.getString("zone")).getAsJsonArray();
Location firstLocation = LocationSerialization.deserializeLocation(zoneArray.get(0).getAsString());
Location secondLocation = LocationSerialization.deserializeLocation(zoneArray.get(1).getAsString());
Cuboid zone = new Cuboid(firstLocation, secondLocation);
new GlowstoneEvent(uuid, name, zone);
}
}
public void save() {
MongoCollection collection = main.getFactionsDatabase().getGlowstone();
Document document = new Document();
document.put("uuid", uuid.toString());
document.put("name", name);
JsonArray zoneArray = new JsonArray();
zoneArray.add(new JsonPrimitive(LocationSerialization.serializeLocation(cuboid.getLocationOne())));
zoneArray.add(new JsonPrimitive(LocationSerialization.serializeLocation(cuboid.getLocationTwo())));
document.put("zone", zoneArray.toString());
collection.replaceOne(eq("uuid", uuid.toString()), document, new UpdateOptions().upsert(true));
}
}

View File

@ -0,0 +1,67 @@
package com.amberpvp.hcfactions.event.glowstone;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.event.EventManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
public class GlowstoneEventListeners implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreakEvent(BlockBreakEvent event) {
GlowstoneEvent glowstoneEvent = EventManager.getInstance().getGlowstoneEvent(event.getBlock().getLocation());
if (glowstoneEvent != null) {
int there =0;
int gone = 0;
for(Block block : glowstoneEvent.getCuboid()){
if(block.getType().equals(Material.GLOWSTONE)){
there++;
}else{
gone++;
}
}
if(event.getBlock().getType().equals(Material.GLOWSTONE)){
there--;
gone++;
}
if(there == gone){
Bukkit.broadcastMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("GLOWSTONE.PERCENTAGE_MINED").replace("%GLOWSTONE%", glowstoneEvent.getName()).replace("%PERCENTAGE%", "50%"));
}
if(gone > there) {
int total = there + gone;
int fifty = total / 2;
int twenty = fifty / 2;
if (there == twenty && gone == (fifty+twenty)) {
Bukkit.broadcastMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("GLOWSTONE.PERCENTAGE_MINED").replace("%GLOWSTONE%", glowstoneEvent.getName()).replace("%PERCENTAGE%", "25%"));
}
}
if(there > gone) {
int total = there + gone;
int fifty = total / 2;
int twenty = fifty / 2;
if (gone == twenty && there == (fifty + twenty)) {
Bukkit.broadcastMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("GLOWSTONE.PERCENTAGE_MINED").replace("%GLOWSTONE%", glowstoneEvent.getName()).replace("%PERCENTAGE%", "75%"));
}
}
if(there == 0 && event.getBlock().getType() == Material.GLOWSTONE){
Bukkit.broadcastMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("GLOWSTONE.FULLY_MINED").replace("%GLOWSTONE%", glowstoneEvent.getName()));
}
}
}
}

View File

@ -0,0 +1,42 @@
package com.amberpvp.hcfactions.event.glowstone.command;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender;
public class GlowstoneForceCommand extends PluginCommand {
@Command(name = "glowstone.force")
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
String[] args = command.getArgs();
if (!sender.hasPermission("staff.sradmin")) {
sender.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/glowstone force <zone>");
return;
}
Event event = EventManager.getInstance().getByName(args[0]);
if (event == null || (!(event instanceof GlowstoneEvent))) {
sender.sendMessage(ChatColor.RED + "Please specify a valid Glowstone Mountain.");
return;
}
GlowstoneEvent glowstoneEvent = (GlowstoneEvent) event;
glowstoneEvent.start();
}
}

View File

@ -0,0 +1,53 @@
package com.amberpvp.hcfactions.event.glowstone.procedure;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.joeleoli.nucleus.util.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
@Accessors(chain = true, fluent = true)
public class GlowstoneCreateProcedure {
@Getter @Setter private GlowstoneCreateProcedureStage stage;
@Getter @Setter private String name;
@Getter @Setter private Location locationOne, locationTwo;
@Getter @Setter private int clicks;
@Getter @Setter private int height;
public static ItemStack getWand() {
return new ItemBuilder(Material.DIAMOND_HOE).name(ChatColor.GREEN + "Glowstone Zone Selection").lore(Arrays.asList(
"&aLeft click the ground&7 to set the &afirst&7 point.",
"&aRight click the ground&7 to set the &asecond&7 point.",
"&aSneak and left click the air&7 to confirm zone once both points set.",
"&aRight click the air twice&7 to clear your selection."
)).build();
}
public static Inventory getConfirmationInventory(GlowstoneCreateProcedure procedure) {
Inventory toReturn = Bukkit.createInventory(null, 18, ChatColor.RED + "Confirm Glowstone?");
toReturn.setItem(0, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Cancel").build());
toReturn.setItem(8, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Cancel").build());
toReturn.setItem(4, new ItemBuilder(Material.PAPER).name(ChatColor.RED + "Procedure Information").lore(Arrays.asList(
ChatColor.YELLOW + "Name: " + ChatColor.RED + procedure.name(),
ChatColor.YELLOW + "Corner 1: &cWorld: " + procedure.locationOne.getWorld().getName().replace("_", " ") + ", &cX: " + procedure.locationOne.getBlockX() + ", Y: " + procedure.locationOne.getBlockY() + ", Z: " + procedure.locationOne.getBlockZ(),
ChatColor.YELLOW + "Corner 2: &cWorld: " + procedure.locationTwo.getWorld().getName().replace("_", " ") + ", &cX: " + procedure.locationTwo.getBlockX() + ", Y: " + procedure.locationTwo.getBlockY() + ", Z: " + procedure.locationTwo.getBlockZ()
)).build());
for (int i = 0; i < 9; i++) {
toReturn.setItem(9 + i, new ItemBuilder(Material.WOOL).durability(5).name(ChatColor.GREEN + "" + ChatColor.BOLD + "Confirm Glowstone Mountain").build());
}
return toReturn;
}
}

View File

@ -0,0 +1,231 @@
package com.amberpvp.hcfactions.event.glowstone.procedure;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.event.utils.Cuboid;
import com.amberpvp.hcfactions.profile.Profile;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
public class GlowstoneCreateProcedureListeners implements Listener {
@EventHandler
public void onInventoryClickEvent(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
Profile profile = Profile.getByPlayer(player);
GlowstoneCreateProcedure procedure = profile.getGlowstoneCreateProcedure();
if (procedure != null) {
if (procedure.stage() == GlowstoneCreateProcedureStage.CONFIRMATION && event.getInventory().getTitle().contains("Confirm Glowstone?")) {
event.setCancelled(true);
ItemStack itemStack = event.getCurrentItem();
if (itemStack != null && itemStack.getType() != Material.AIR) {
String displayName = itemStack.getItemMeta().getDisplayName();
if (displayName != null) {
if (displayName.contains("Cancel")) {
profile.setGlowstoneCreateProcedure(null);
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "Glowstone Mountain create procedure cancelled.");
player.sendMessage(" ");
player.getInventory().removeItem(GlowstoneCreateProcedure.getWand());
player.closeInventory();
return;
}
if (displayName.contains("Confirm")) {
profile.setGlowstoneCreateProcedure(null);
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "Glowstone Mountain successfully created.");
player.sendMessage(" ");
player.getInventory().removeItem(GlowstoneCreateProcedure.getWand());
player.closeInventory();
Cuboid zone = new Cuboid(procedure.locationOne(), procedure.locationTwo());
new GlowstoneEvent(procedure.name(), zone);
}
}
}
}
}
}
@EventHandler
public void onInventoryCloseEvent(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
Profile profile = Profile.getByPlayer(player);
GlowstoneCreateProcedure procedure = profile.getGlowstoneCreateProcedure();
if (procedure != null) {
if (procedure.stage() == GlowstoneCreateProcedureStage.CONFIRMATION && event.getInventory().getTitle().contains("Confirm Glowstone?")) {
new BukkitRunnable() {
@Override
public void run() {
player.openInventory(GlowstoneCreateProcedure.getConfirmationInventory(procedure));
}
}.runTaskLaterAsynchronously(FactionsPlugin.getInstance(), 2L);
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
GlowstoneCreateProcedure procedure = profile.getGlowstoneCreateProcedure();
if (procedure != null) {
event.setCancelled(true);
if (event.getMessage().equalsIgnoreCase("cancel")) {
profile.setGlowstoneCreateProcedure(null);
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "Glowstone Mountain create procedure cancelled.");
player.sendMessage(" ");
player.getInventory().removeItem(GlowstoneCreateProcedure.getWand());
return;
}
if (procedure.stage() == GlowstoneCreateProcedureStage.NAME_SELECTION) {
String name = event.getMessage().replace(" ", "");
if (EventManager.getInstance().getByName(name) != null) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "An event with that name already exists.");
player.sendMessage(" ");
return;
}
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "Glowstone Mountain name set to '" + procedure.name(name).name() + "'.");
player.sendMessage(ChatColor.YELLOW + "You have received the zone wand.");
player.sendMessage(" ");
player.getInventory().removeItem(GlowstoneCreateProcedure.getWand());
player.getInventory().addItem(GlowstoneCreateProcedure.getWand());
procedure.stage(GlowstoneCreateProcedureStage.ZONE_SELECTION);
}
}
}
@EventHandler
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
GlowstoneCreateProcedure procedure = profile.getGlowstoneCreateProcedure();
if (event.getItemDrop().getItemStack().isSimilar(GlowstoneCreateProcedure.getWand())) {
event.getItemDrop().remove();
if (procedure != null) {
profile.setGlowstoneCreateProcedure(null);
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "Glowstone Mountain create procedure cancelled.");
player.sendMessage(" ");
player.getInventory().removeItem(GlowstoneCreateProcedure.getWand());
}
}
}
@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
GlowstoneCreateProcedure procedure = profile.getGlowstoneCreateProcedure();
Action action = event.getAction();
if (procedure == null && event.getItem() != null && event.getItem().isSimilar(GlowstoneCreateProcedure.getWand())) {
player.getInventory().removeItem(event.getItem());
return;
}
if (procedure != null && event.getItem() != null && event.getItem().isSimilar(GlowstoneCreateProcedure.getWand())) {
event.setCancelled(true);
if (procedure.stage() == GlowstoneCreateProcedureStage.ZONE_SELECTION) {
if (action == Action.LEFT_CLICK_BLOCK) {
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "First position set.");
player.sendMessage(" ");
procedure.locationOne(event.getClickedBlock().getLocation());
return;
}
if (action == Action.RIGHT_CLICK_BLOCK) {
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "Second position set.");
player.sendMessage(" ");
procedure.locationTwo(event.getClickedBlock().getLocation());
return;
}
if (action == Action.RIGHT_CLICK_AIR) {
int clicks = procedure.clicks();
if (procedure.locationOne() == null && procedure.locationTwo() == null) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "Glowstone Mountain locations not defined.");
player.sendMessage(" ");
}
if (clicks == 0) {
procedure.clicks(1);
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "Click again to reset Glowstone Mountain locations.");
player.sendMessage(" ");
return;
}
procedure.clicks(0);
procedure.locationOne(null);
procedure.locationTwo(null);
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "Glowstone Mountain zone locations have been reset.");
player.sendMessage(" ");
return;
}
if (action == Action.LEFT_CLICK_AIR && player.isSneaking()) {
if (procedure.locationOne() == null && procedure.locationTwo() == null) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "Glowstone Mountain locations not defined.");
player.sendMessage(" ");
return;
}
player.getInventory().removeItem(GlowstoneCreateProcedure.getWand());
player.openInventory(GlowstoneCreateProcedure.getConfirmationInventory(procedure));
procedure.stage(GlowstoneCreateProcedureStage.CONFIRMATION);
}
}
}
}
}

View File

@ -0,0 +1,7 @@
package com.amberpvp.hcfactions.event.glowstone.procedure;
public enum GlowstoneCreateProcedureStage {
NAME_SELECTION,
ZONE_SELECTION,
CONFIRMATION
}

View File

@ -0,0 +1,59 @@
package com.amberpvp.hcfactions.event.glowstone.procedure.command;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.glowstone.procedure.GlowstoneCreateProcedure;
import com.amberpvp.hcfactions.event.glowstone.procedure.GlowstoneCreateProcedureStage;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Player;
public class GlowstoneProcedureCommand extends PluginCommand {
@Command(name = "glowstone.create", aliases = {"glowstone.new", "createglowstone", "newglowstone"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
Profile profile = Profile.getByPlayer(player);
String[] args = command.getArgs();
if (!player.hasPermission("staff.sradmin")) {
player.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (profile.getGlowstoneCreateProcedure() != null) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "You're already in the process of creating a Glowstone Mountain.");
player.sendMessage(ChatColor.RED + "Type 'cancel' in chat to stop the procedure.");
player.sendMessage(" ");
return;
}
if (args.length == 0) {
profile.setGlowstoneCreateProcedure(new GlowstoneCreateProcedure().stage(GlowstoneCreateProcedureStage.NAME_SELECTION));
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "Please type a name for this Glowstone Mountain in chat.");
player.sendMessage(" ");
} else {
if (EventManager.getInstance().getByName(StringUtils.join(args)) != null) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "An event with that name already exists.");
player.sendMessage(" ");
return;
}
profile.setGlowstoneCreateProcedure(new GlowstoneCreateProcedure().stage(GlowstoneCreateProcedureStage.ZONE_SELECTION).name(StringUtils.join(args)));
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "You have received the zone wand.");
player.sendMessage(" ");
player.getInventory().removeItem(GlowstoneCreateProcedure.getWand());
player.getInventory().addItem(GlowstoneCreateProcedure.getWand());
}
}
}

View File

@ -0,0 +1,46 @@
package com.amberpvp.hcfactions.event.glowstone.procedure.command;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.glowstone.GlowstoneEvent;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender;
public class GlowstoneRemoveCommand extends PluginCommand {
@Command(name = "glowstone.remove", aliases = {"glowstone.delete", "glowstoneremove", "removeglowstone"})
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
if (!sender.hasPermission("staff.sradmin")) {
sender.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
String[] args = command.getArgs();
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/glowstone remove <zone>");
return;
}
Event event = EventManager.getInstance().getByName(args[0]);
if (event == null || (!(event instanceof GlowstoneEvent))) {
sender.sendMessage(ChatColor.RED + "Please specify a valid Glowstone Mountain.");
return;
}
GlowstoneEvent glowstoneEvent = (GlowstoneEvent) event;
sender.sendMessage(ChatColor.YELLOW + "(" + glowstoneEvent.getName() + ") Glowstone Mountain has been removed.");
glowstoneEvent.remove();
}
}

View File

@ -0,0 +1,198 @@
package com.amberpvp.hcfactions.event.koth;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.UpdateOptions;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.EventZone;
import com.amberpvp.hcfactions.util.DateUtil;
import com.amberpvp.hcfactions.util.LocationSerialization;
import lombok.Getter;
import lombok.Setter;
import org.bson.Document;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static com.mongodb.client.model.Filters.eq;
public class KothEvent implements Event {
private static final DecimalFormat SECONDS_FORMATTER = new DecimalFormat("#0.0");
private static FactionsPlugin main = FactionsPlugin.getInstance();
private static EventManager manager = EventManager.getInstance();
@Getter private final UUID uuid;
@Getter private final String name;
@Getter private final int height;
@Getter private final EventZone zone;
@Getter @Setter private long time;
@Getter @Setter private long capTime;
@Getter @Setter private long grace;
@Getter @Setter private boolean active;
@Getter @Setter private Player cappingPlayer;
public KothEvent(UUID uuid, String name, int height, EventZone zone) {
this.uuid = uuid;
this.name = name;
this.zone = zone;
this.height = height;
manager.getEvents().add(this);
}
public KothEvent(String name, int height, EventZone zone) {
this(UUID.randomUUID(), name, height, zone);
}
public void start(long capTime) {
this.capTime = capTime;
this.active = true;
Bukkit.broadcastMessage(main.getLanguageConfig().getString("KOTH.START").replace("%KOTH%", name).replace("%TIME%", getTimeLeft()) + ChatColor.GRAY + " (" + (FactionsPlugin.getInstance().isKitmapMode() ? getKitMapKothLocation(this) : getKothLocation(this)) + ")");
}
public void stop(boolean force) {
if (force || cappingPlayer == null) {
Bukkit.broadcastMessage(main.getLanguageConfig().getString("KOTH.STOP").replace("%KOTH%", name).replace("%TIME%", getTimeLeft()));
} else {
Bukkit.broadcastMessage(main.getLanguageConfig().getString("KOTH.STOP_WINNER").replace("%KOTH%", name).replace("%TIME%", getTimeLeft()).replace("%PLAYER%", cappingPlayer.getName()));
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "crate givekey " + cappingPlayer.getName() + " Koth 5");
}
this.active = false;
this.capTime = 0;
this.time = 0;
this.cappingPlayer = null;
}
public boolean isGrace() {
return time + grace > System.currentTimeMillis();
}
public boolean isFinished() {
return active && time + capTime - (System.currentTimeMillis() + 1000) <= 0 && cappingPlayer != null;
}
public void setCappingPlayer(Player player) {
if (player == null) {
Bukkit.broadcastMessage(main.getLanguageConfig().getString("KOTH.KNOCKED").replace("%KOTH%", name).replace("%TIME%", getTimeLeft()).replace("%PLAYER%", cappingPlayer.getName()));
grace = 5000;
time = System.currentTimeMillis();
} else {
Bukkit.broadcastMessage(main.getLanguageConfig().getString("KOTH.CONTESTED").replace("%KOTH%", name).replace("%TIME%", getTimeLeft()).replace("%PLAYER%", player.getName()));
}
this.cappingPlayer = player;
this.time = System.currentTimeMillis();
}
public long getDecisecondsLeft() {
if (cappingPlayer == null) {
return capTime / 100;
} else {
return (time + capTime - System.currentTimeMillis()) / 100;
}
}
public String getTimeLeft() {
long millis = 0;
if(cappingPlayer == null) {
millis = capTime;
} else {
millis = time + capTime - System.currentTimeMillis();
}
if (millis >= 3600000) {
return DateUtil.formatTime(millis);
} else if (millis >= 60000) {
return DateUtil.formatTime(millis);
} else {
return SECONDS_FORMATTER.format(((millis) / 1000.0f)) + "s";
}
}
@Override
public List<String> getScoreboardText() {
List<String> toReturn = new ArrayList<>();
for (String line : main.getScoreboardConfig().getStringList("PLACE_HOLDER.KOTH")) {
line = line.replace("%KOTH%", name);
line = line.replace("%TIME%", getTimeLeft());
toReturn.add(line);
}
return toReturn;
}
@Override
public boolean isActive() {
return active;
}
public void remove() {
main.getFactionsDatabase().getKoths().deleteOne(eq("uuid", this.uuid.toString()));
manager.getEvents().remove(this);
}
public static void load() {
MongoCollection collection = main.getFactionsDatabase().getKoths();
MongoCursor cursor = collection.find().iterator();
while (cursor.hasNext()) {
Document document = (Document) cursor.next();
UUID uuid = UUID.fromString(document.getString("uuid"));
String name = document.getString("name");
int height = document.getInteger("height");
JsonArray zoneArray = new JsonParser().parse(document.getString("zone")).getAsJsonArray();
Location firstLocation = LocationSerialization.deserializeLocation(zoneArray.get(0).getAsString());
Location secondLocation = LocationSerialization.deserializeLocation(zoneArray.get(1).getAsString());
EventZone zone = new EventZone(firstLocation, secondLocation); zone.setHeight(height);
new KothEvent(uuid, name, height, zone);
}
}
public void save() {
MongoCollection collection = main.getFactionsDatabase().getKoths();
Document document = new Document();
document.put("uuid", uuid.toString());
document.put("name", name);
document.put("height", height);
JsonArray zoneArray = new JsonArray();
zoneArray.add(new JsonPrimitive(LocationSerialization.serializeLocation(zone.getFirstLocation())));
zoneArray.add(new JsonPrimitive(LocationSerialization.serializeLocation(zone.getSecondLocation())));
document.put("zone", zoneArray.toString());
collection.replaceOne(eq("uuid", uuid.toString()), document, new UpdateOptions().upsert(true));
}
private String getKothLocation(KothEvent event) {
return (event.getZone().getCenter().getX() < 0 ? "-500" : "500") + ", " + event.getZone().getCenter().getBlockY() + ", " + (event.getZone().getCenter().getZ() < 0 ? "-500" : "500");
}
private String getKitMapKothLocation(KothEvent event) {
return (event.getZone().getCenter().getX() < 0 ? "150" : "150") + ", " + event.getZone().getCenter().getBlockY() + ", " + (event.getZone().getCenter().getZ() < 0 ? "-250" : "250");
}
}

View File

@ -0,0 +1,69 @@
package com.amberpvp.hcfactions.event.koth;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.player.PlayerUtility;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitRunnable;
public class KothEventListeners implements Listener {
public KothEventListeners() {
new BukkitRunnable() {
@Override
public void run() {
for (Event possibleEvent : EventManager.getInstance().getEvents()) {
if (possibleEvent instanceof KothEvent && possibleEvent.isActive()) {
KothEvent koth = (KothEvent) possibleEvent;
if (koth.isFinished()) {
koth.stop(false);
continue;
}
if (koth.getCappingPlayer() != null) {
Player player = koth.getCappingPlayer();
if (player.isDead() || !player.isValid() || !player.isOnline() || !koth.getZone().isInside(player)) {
koth.setCappingPlayer(null);
} else {
if (koth.getDecisecondsLeft() % 600 == 0 && koth.getDecisecondsLeft() != koth.getCapTime() / 100 && koth.getDecisecondsLeft() != 0) {
Bukkit.broadcastMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("KOTH.CONTESTED").replace("%KOTH%", koth.getName()).replace("%TIME%", koth.getTimeLeft()).replace("%PLAYER%", player.getName()));
//Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "crate givekey " + player.getName() + " Koth 5");
}
}
} else {
if (!(koth.isGrace())) {
for (Player player : PlayerUtility.getOnlinePlayers() ) {
Profile profile = Profile.getByPlayer(player);
if (player.isDead()) {
continue;
}
if (profile.getProtection() != null) {
continue;
}
if (koth.getZone().isInside(player)) {
koth.setCappingPlayer(player);
break;
}
}
}
}
}
}
}
}.runTaskTimerAsynchronously(FactionsPlugin.getInstance(), 2L, 2L);
}
}

View File

@ -0,0 +1,44 @@
package com.amberpvp.hcfactions.event.koth.command;
import com.amberpvp.hcfactions.event.schedule.Schedule;
import com.amberpvp.hcfactions.event.schedule.ScheduleHandler;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.koth.KothEvent;
import com.amberpvp.hcfactions.event.schedule.Schedule;
import com.amberpvp.hcfactions.event.schedule.ScheduleHandler;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.Locale;
import java.util.TimeZone;
public class KothCommand extends PluginCommand {
@Command(name = "koth", inGameOnly = true)
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
for (Event possibleEvent : EventManager.getInstance().getEvents()) {
if (possibleEvent instanceof KothEvent && possibleEvent.isActive()) {
player.sendMessage(ChatColor.GOLD + "[KOTH] " + ChatColor.YELLOW.toString() + ChatColor.UNDERLINE + possibleEvent.getName() + ChatColor.GOLD + " can be contested now.");
return;
}
}
Schedule kothEvent = ScheduleHandler.getNextEvent();
FastDateFormat formatter = FastDateFormat.getInstance("EEEE, hh:mma", TimeZone.getDefault(), Locale.ENGLISH);
player.sendMessage(ChatColor.GOLD + "[KOTH] " + ChatColor.YELLOW + kothEvent.getName() + ChatColor.GOLD + " can be captured at " + ChatColor.BLUE + kothEvent.getFormatDay() + ChatColor.GOLD + ".");
player.sendMessage(ChatColor.GOLD + "[KOTH] " + ChatColor.YELLOW + "It is currently " + ChatColor.BLUE + formatter.format(System.currentTimeMillis()) + ChatColor.GOLD + ".");
player.sendMessage(ChatColor.YELLOW + "Type '/koth schedule' to see more upcoming KOTHs.");
}
}

View File

@ -0,0 +1,32 @@
package com.amberpvp.hcfactions.event.koth.command;
import com.amberpvp.hcfactions.event.schedule.Schedule;
import com.amberpvp.hcfactions.event.schedule.ScheduleHandler;
import com.amberpvp.hcfactions.event.schedule.Schedule;
import com.amberpvp.hcfactions.event.schedule.ScheduleHandler;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.apache.commons.lang.time.FastDateFormat;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.Locale;
import java.util.TimeZone;
public class KothScheduleCommand extends PluginCommand {
@Command(name = "koth.schedule", inGameOnly = true)
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
FastDateFormat formatter = FastDateFormat.getInstance("EEEE, hh:mma", TimeZone.getDefault(), Locale.ENGLISH);
for(Schedule schedule : ScheduleHandler.schedules) {
player.sendMessage(ChatColor.GOLD + "[KOTH] " + ChatColor.YELLOW + schedule.getName() + ChatColor.GOLD + " can be captured at " + ChatColor.BLUE + schedule.getFormatDay() + ChatColor.GOLD + ".");
}
player.sendMessage(ChatColor.GOLD + "[KOTH] " + ChatColor.YELLOW + "It is currently " + ChatColor.BLUE + formatter.format(System.currentTimeMillis()) + ChatColor.GOLD + ".");
}
}

View File

@ -0,0 +1,60 @@
package com.amberpvp.hcfactions.event.koth.command;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.koth.KothEvent;
import com.amberpvp.hcfactions.util.DateUtil;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender;
public class KothStartCommand extends PluginCommand {
private static final long DEFAULT_DURATION = 900000;
@Command(name = "koth.start")
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
String[] args = command.getArgs();
if (!sender.hasPermission("staff.sradmin")) {
sender.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/koth start <koth> [<duration>]");
return;
}
Event event = EventManager.getInstance().getByName(args[0]);
if (event == null || (!(event instanceof KothEvent))) {
sender.sendMessage(ChatColor.RED + "Please specify a valid KoTH.");
return;
}
long capTime = DEFAULT_DURATION;
if (args.length > 1) {
try {
capTime = System.currentTimeMillis() - DateUtil.parseDateDiff(args[1], false);
} catch (Exception e) {
e.printStackTrace();
}
}
KothEvent koth = (KothEvent) event;
if (koth.isActive()) {
sender.sendMessage(ChatColor.RED + "KoTH " + koth.getName() + " is already active!");
return;
}
koth.start(capTime);
}
}

View File

@ -0,0 +1,47 @@
package com.amberpvp.hcfactions.event.koth.command;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.koth.KothEvent;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender;
public class KothStopCommand extends PluginCommand {
private static final long DEFAULT_DURATION = 900000;
@Command(name = "koth.stop")
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
String[] args = command.getArgs();
if (!sender.hasPermission("staff.sradmin")) {
sender.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/koth stop <koth>");
return;
}
Event event = EventManager.getInstance().getByName(args[0]);
if (event == null || (!(event instanceof KothEvent))) {
sender.sendMessage(ChatColor.RED + "Please specify a valid KoTH.");
return;
}
KothEvent koth = (KothEvent) event;
if (!(koth.isActive())) {
sender.sendMessage(ChatColor.RED + "KoTH " + koth.getName() + " isn't active!");
return;
}
koth.stop(true);
}
}

View File

@ -0,0 +1,58 @@
package com.amberpvp.hcfactions.event.koth.procedure;
import com.amberpvp.hcfactions.factions.claims.ClaimPillar;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.joeleoli.nucleus.util.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
@Accessors(chain = true, fluent = true)
public class KothCreateProcedure {
@Getter @Setter private KothCreateProcedureStage stage;
@Getter @Setter private String name;
@Getter @Setter private ClaimPillar[] pillars;
@Getter @Setter private int clicks;
@Getter @Setter private int height;
public KothCreateProcedure() {
pillars = new ClaimPillar[2];
}
public static ItemStack getWand() {
return new ItemBuilder(Material.DIAMOND_HOE).name(ChatColor.GREEN + "KoTH Zone Selection").lore(Arrays.asList(
"&aLeft click the ground&7 to set the &afirst&7 point.",
"&aRight click the ground&7 to set the &asecond&7 point.",
"&aSneak and left click the air&7 to confirm zone once both points set.",
"&aRight click the air twice&7 to clear your selection."
)).build();
}
public static Inventory getConfirmationInventory(KothCreateProcedure procedure) {
Inventory toReturn = Bukkit.createInventory(null, 18, ChatColor.RED + "Confirm KoTH?");
toReturn.setItem(0, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Cancel").build());
toReturn.setItem(8, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Cancel").build());
toReturn.setItem(4, new ItemBuilder(Material.PAPER).name(ChatColor.RED + "Procedure Information").lore(Arrays.asList(
ChatColor.YELLOW + "Name: " + ChatColor.RED + procedure.name(),
ChatColor.YELLOW + "Height: " + ChatColor.RED + procedure.height(),
ChatColor.YELLOW + "Corner 1: &cWorld: " + procedure.pillars[0].getOriginalLocation().getWorld().getName().replace("_", " ") + ", &cX: " + procedure.pillars[0].getOriginalLocation().getBlockX() + ", Y: " + procedure.pillars[0].getOriginalLocation().getBlockY() + ", Z: " + procedure.pillars[0].getOriginalLocation().getBlockZ(),
ChatColor.YELLOW + "Corner 2: &cWorld: " + procedure.pillars[1].getOriginalLocation().getWorld().getName().replace("_", " ") + ", &cX: " + procedure.pillars[1].getOriginalLocation().getBlockX() + ", Y: " + procedure.pillars[1].getOriginalLocation().getBlockY() + ", Z: " + procedure.pillars[1].getOriginalLocation().getBlockZ()
)).build());
for (int i = 0; i < 9; i++) {
toReturn.setItem(9 + i, new ItemBuilder(Material.WOOL).durability(5).name(ChatColor.GREEN + "" + ChatColor.BOLD + "Confirm KoTH").build());
}
return toReturn;
}
}

View File

@ -0,0 +1,272 @@
package com.amberpvp.hcfactions.event.koth.procedure;
import com.amberpvp.hcfactions.event.koth.KothEvent;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.EventZone;
import com.amberpvp.hcfactions.event.koth.KothEvent;
import com.amberpvp.hcfactions.factions.claims.ClaimPillar;
import com.amberpvp.hcfactions.profile.Profile;
import org.apache.commons.lang.StringUtils;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
public class KothCreateProcedureListeners implements Listener {
@EventHandler
public void onInventoryClickEvent(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
Profile profile = Profile.getByPlayer(player);
KothCreateProcedure procedure = profile.getKothCreateProcedure();
if (procedure != null) {
if (procedure.stage() == KothCreateProcedureStage.CONFIRMATION && event.getInventory().getTitle().contains("Confirm KoTH?")) {
event.setCancelled(true);
ItemStack itemStack = event.getCurrentItem();
if (itemStack != null && itemStack.getType() != Material.AIR) {
String displayName = itemStack.getItemMeta().getDisplayName();
if (displayName != null) {
if (displayName.contains("Cancel")) {
profile.setKothCreateProcedure(null);
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "KoTH create procedure cancelled.");
player.sendMessage(" ");
player.getInventory().removeItem(KothCreateProcedure.getWand());
player.closeInventory();
return;
}
if (displayName.contains("Confirm")) {
profile.setKothCreateProcedure(null);
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "KoTH successfully created.");
player.sendMessage(" ");
player.getInventory().removeItem(KothCreateProcedure.getWand());
player.closeInventory();
EventZone zone = new EventZone(procedure.pillars()[0].getOriginalLocation(), procedure.pillars()[1].getOriginalLocation()); zone.setHeight(procedure.height());
new KothEvent(procedure.name(), procedure.height(), zone);
}
}
}
}
}
}
@EventHandler
public void onInventoryCloseEvent(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
Profile profile = Profile.getByPlayer(player);
KothCreateProcedure procedure = profile.getKothCreateProcedure();
if (procedure != null) {
if (procedure.stage() == KothCreateProcedureStage.CONFIRMATION && event.getInventory().getTitle().contains("Confirm KoTH?")) {
new BukkitRunnable() {
@Override
public void run() {
player.openInventory(KothCreateProcedure.getConfirmationInventory(procedure));
}
}.runTaskLaterAsynchronously(FactionsPlugin.getInstance(), 2L);
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
KothCreateProcedure procedure = profile.getKothCreateProcedure();
if (procedure != null) {
event.setCancelled(true);
if (event.getMessage().equalsIgnoreCase("cancel")) {
profile.setKothCreateProcedure(null);
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "KoTH create procedure cancelled.");
player.sendMessage(" ");
player.getInventory().removeItem(KothCreateProcedure.getWand());
return;
}
if (procedure.stage() == KothCreateProcedureStage.NAME_SELECTION) {
String name = event.getMessage().replace(" ", "");
if (EventManager.getInstance().getByName(name) != null) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "An event with that name already exists.");
player.sendMessage(" ");
return;
}
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "KoTH name set to '" + procedure.name(name).name() + "'.");
player.sendMessage(ChatColor.YELLOW + "Please type the height of the KoTH.");
player.sendMessage(" ");
procedure.stage(KothCreateProcedureStage.HEIGHT_SELECTION);
}
else if (procedure.stage() == KothCreateProcedureStage.HEIGHT_SELECTION) {
String name = event.getMessage().replace(" ", "");
if (!StringUtils.isNumeric(name)) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "That's an incorrect height number");
player.sendMessage(" ");
return;
}
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "KoTH height set to '" + procedure.height(Integer.parseInt(name)).height() + "'.");
player.sendMessage(ChatColor.YELLOW + "You have received the zone wand.");
player.sendMessage(" ");
player.getInventory().removeItem(KothCreateProcedure.getWand());
player.getInventory().addItem(KothCreateProcedure.getWand());
procedure.stage(KothCreateProcedureStage.ZONE_SELECTION);
}
}
}
@EventHandler
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
KothCreateProcedure procedure = profile.getKothCreateProcedure();
if (event.getItemDrop().getItemStack().isSimilar(KothCreateProcedure.getWand())) {
event.getItemDrop().remove();
if (procedure != null) {
profile.setKothCreateProcedure(null);
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "KoTH create procedure cancelled.");
player.sendMessage(" ");
player.getInventory().removeItem(KothCreateProcedure.getWand());
}
}
}
@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
KothCreateProcedure procedure = profile.getKothCreateProcedure();
Action action = event.getAction();
if (procedure == null && event.getItem() != null && event.getItem().isSimilar(KothCreateProcedure.getWand())) {
player.getInventory().removeItem(event.getItem());
return;
}
if (procedure != null && event.getItem() != null && event.getItem().isSimilar(KothCreateProcedure.getWand())) {
event.setCancelled(true);
if (procedure.stage() == KothCreateProcedureStage.ZONE_SELECTION) {
if (action == Action.LEFT_CLICK_BLOCK) {
ClaimPillar claimPillar = procedure.pillars()[0];
if (claimPillar != null) {
claimPillar.remove();
}
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "First position set.");
player.sendMessage(" ");
procedure.pillars()[0] = new ClaimPillar(player, event.getClickedBlock().getLocation()).show(Material.LAPIS_BLOCK, 0);
return;
}
if (action == Action.RIGHT_CLICK_BLOCK) {
ClaimPillar claimPillar = procedure.pillars()[1];
if (claimPillar != null) {
claimPillar.remove();
}
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "Second position set.");
player.sendMessage(" ");
new BukkitRunnable() {
@Override
public void run() {
procedure.pillars()[1] = new ClaimPillar(player, event.getClickedBlock().getLocation()).show(Material.LAPIS_BLOCK, 0);
}
}.runTaskLaterAsynchronously(FactionsPlugin.getInstance(), 2L);
return;
}
if (action == Action.RIGHT_CLICK_AIR) {
int clicks = procedure.clicks();
if (procedure.pillars()[0] == null && procedure.pillars()[1] == null) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "KoTH pillars not defined.");
player.sendMessage(" ");
}
if (clicks == 0) {
procedure.clicks(1);
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "Click again to reset KoTH pillars.");
player.sendMessage(" ");
return;
}
for (ClaimPillar claimPillar : procedure.pillars()) {
if (claimPillar != null) {
claimPillar.remove();
}
}
procedure.clicks(0);
procedure.pillars()[0] = null;
procedure.pillars()[1] = null;
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "KoTH zone pillars have been reset.");
player.sendMessage(" ");
return;
}
if (action == Action.LEFT_CLICK_AIR && player.isSneaking()) {
for (ClaimPillar claimPillar : procedure.pillars()) {
if (claimPillar == null) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "KoTH zone not defined.");
player.sendMessage(" ");
return;
}
}
for (ClaimPillar claimPillar : procedure.pillars()) {
claimPillar.remove();
}
player.getInventory().removeItem(KothCreateProcedure.getWand());
player.openInventory(KothCreateProcedure.getConfirmationInventory(procedure));
procedure.stage(KothCreateProcedureStage.CONFIRMATION);
}
}
}
}
}

View File

@ -0,0 +1,8 @@
package com.amberpvp.hcfactions.event.koth.procedure;
public enum KothCreateProcedureStage {
NAME_SELECTION,
HEIGHT_SELECTION,
ZONE_SELECTION,
CONFIRMATION
}

View File

@ -0,0 +1,59 @@
package com.amberpvp.hcfactions.event.koth.procedure.command;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.koth.procedure.KothCreateProcedure;
import com.amberpvp.hcfactions.event.koth.procedure.KothCreateProcedureStage;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Player;
public class KothCreateProcedureCommand extends PluginCommand {
@Command(name = "koth.create", aliases = {"koth.new", "createkoth", "newkoth"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
Profile profile = Profile.getByPlayer(player);
String[] args = command.getArgs();
if (!player.hasPermission("staff.sradmin")) {
player.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (profile.getKothCreateProcedure() != null) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "You're already in the process of creating a KoTH.");
player.sendMessage(ChatColor.RED + "Type 'cancel' in chat to stop the procedure.");
player.sendMessage(" ");
return;
}
if (args.length == 0) {
profile.setKothCreateProcedure(new KothCreateProcedure().stage(KothCreateProcedureStage.NAME_SELECTION));
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "Please type a name for this KoTH in chat.");
player.sendMessage(" ");
} else {
if (EventManager.getInstance().getByName(StringUtils.join(args)) != null) {
player.sendMessage(" ");
player.sendMessage(ChatColor.RED + "An event with that name already exists.");
player.sendMessage(" ");
return;
}
profile.setKothCreateProcedure(new KothCreateProcedure().stage(KothCreateProcedureStage.ZONE_SELECTION).name(StringUtils.join(args)));
player.sendMessage(" ");
player.sendMessage(ChatColor.YELLOW + "You have received the zone wand.");
player.sendMessage(" ");
player.getInventory().removeItem(KothCreateProcedure.getWand());
player.getInventory().addItem(KothCreateProcedure.getWand());
}
}
}

View File

@ -0,0 +1,44 @@
package com.amberpvp.hcfactions.event.koth.procedure.command;
import com.amberpvp.hcfactions.event.koth.KothEvent;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.koth.KothEvent;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender;
public class KothRemoveCommand extends PluginCommand {
@Command(name = "koth.remove", aliases = {"koth.delete", "removekoth", "kothremove"})
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
String[] args = command.getArgs();
if (!sender.hasPermission("staff.sradmin")) {
sender.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/koth remove <koth>");
return;
}
Event event = EventManager.getInstance().getByName(args[0]);
if (event == null || (!(event instanceof KothEvent))) {
sender.sendMessage(ChatColor.RED + "Please specify a valid KoTH.");
return;
}
KothEvent koth = (KothEvent) event;
sender.sendMessage(ChatColor.YELLOW + "(" + koth.getName() + ") KoTH has been removed.");
koth.remove();
}
}

View File

@ -0,0 +1,73 @@
package com.amberpvp.hcfactions.event.schedule;
import com.amberpvp.hcfactions.event.Event;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.event.koth.KothEvent;
import com.amberpvp.hcfactions.util.DateUtil;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
public class Schedule {
private String name;
private String formatDay;
private long eventTime;
private long announceTime;
private String runTime;
public Schedule(long eventTime, String runTime, String name, String formatDay) {
this.name = name;
this.eventTime = eventTime;
this.announceTime = this.eventTime - 30 * 60 * 1000L;
this.runTime = runTime;
this.formatDay = formatDay;
}
public void runEvent() {
if(System.currentTimeMillis() > this.eventTime) {
Event event = EventManager.getInstance().getByName(name);
if(event != null && event instanceof KothEvent && !event.isActive()) {
KothEvent koth = (KothEvent) event;
try {
long capTime = System.currentTimeMillis() - DateUtil.parseDateDiff(this.runTime, false);
koth.start(capTime);
setNextEventTime();
} catch (Exception e) {
e.printStackTrace();
}
}
}
if(System.currentTimeMillis() > this.announceTime) {
Event event = EventManager.getInstance().getByName(name);
if(event != null && event instanceof KothEvent && !event.isActive()) {
Bukkit.broadcastMessage(ChatColor.YELLOW + "Scheduled KoTH Event " + ChatColor.GRAY + "(" + name + ") " + ChatColor.YELLOW + "will start in 30 minutes.");
setNextAnnounceTime();
}
}
}
public String getFormatDay() {
return formatDay;
}
public long getEventTime() {
return this.eventTime;
}
public String getName() {
return name;
}
private void setNextEventTime(){
this.eventTime += 1000 * 60 * 60 * 24 * 7;
}
private void setNextAnnounceTime() {
this.announceTime += 1000 * 60 * 60 * 24 * 7;
}
}

View File

@ -0,0 +1,151 @@
package com.amberpvp.hcfactions.event.schedule;
import com.amberpvp.hcfactions.files.ConfigFile;
import com.amberpvp.hcfactions.event.EventManager;
import com.amberpvp.hcfactions.files.ConfigFile;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;
public class ScheduleHandler {
public static List<Schedule> schedules = new ArrayList<Schedule>();
public static void setSchedules(EventManager manager, ConfigFile config) {
schedules.clear();
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone(config.getString("schedule-timezone")));
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.clear(Calendar.MINUTE);
calendar.clear(Calendar.SECOND);
calendar.clear(Calendar.MILLISECOND);
calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
long calendarMillis = calendar.getTimeInMillis();
if(config.getConfiguration().contains("schedule-monday")) {
readSchedule(manager, config, "monday", 0, calendarMillis);
Bukkit.getLogger().info("[HCF] (KOTH): Loaded schedule for monday.");
}
if(config.getConfiguration().contains("schedule-tuesday")) {
readSchedule(manager, config, "tuesday", 1, calendarMillis);
Bukkit.getLogger().info("[HCF] (KOTH): Loaded schedule for tuesday.");
}
if(config.getConfiguration().contains("schedule-wednesday")) {
readSchedule(manager, config, "wednesday", 2, calendarMillis);
Bukkit.getLogger().info("[HCF] (KOTH): Loaded schedule for wednesday.");
}
if(config.getConfiguration().contains("schedule-thursday")) {
readSchedule(manager, config, "thursday", 3, calendarMillis);
Bukkit.getLogger().info("[HCF] (KOTH): Loaded schedule for thursday.");
}
if(config.getConfiguration().contains("schedule-friday")) {
readSchedule(manager, config, "friday", 4, calendarMillis);
Bukkit.getLogger().info("[HCF] (KOTH): Loaded schedule for friday.");
}
if(config.getConfiguration().contains("schedule-saturday")) {
readSchedule(manager, config, "saturday", 5, calendarMillis);
Bukkit.getLogger().info("[HCF] (KOTH): Loaded schedule for saturday.");
}
if(config.getConfiguration().contains("schedule-sunday")) {
readSchedule(manager, config, "sunday", 6, calendarMillis);
Bukkit.getLogger().info("[HCF] (KOTH): Loaded schedule for sunday.");
}
}
public static void readSchedule(EventManager manager, ConfigFile config, String day, int dayInId, long calendarMillis) {
try {
String[] events = config.getString("schedule-" + day).split("#");
for(int i = 0; i < events.length; i++) {
String[] event = events[i].split("/");
String time = event[0];
String area = event[1];
String runTime = event[2];
int hours = 0, minute = 0;
if (time.contains(":")) {
String[] build = time.split(":");
hours = Integer.parseInt(build[0]);
minute = Integer.parseInt(build[1].replaceAll("[a-zA-Z]", ""));
} else {
hours = Integer.parseInt(time.replaceAll("[a-zA-Z]", ""));
}
if (time.endsWith("PM")) {
hours += 12;
}
long eventTime = calendarMillis + (dayInId * 24 * 60 * 60 * 1000) + (hours * 60 * 60 * 1000) + (minute * 60 * 1000);
if (eventTime < System.currentTimeMillis()) {
eventTime += 7 * 24 * 60 * 60 * 1000;
}
schedules.add(new Schedule(eventTime, runTime, area, StringUtils.capitalize(day) + " " + time));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Schedule getNextEvent() {
Schedule ret = null;
for(Schedule sched : schedules) {
if(ret == null) {
ret = sched;
} else if(sched.getEventTime() < ret.getEventTime()) {
ret = sched;
}
}
return ret;
}
public static Schedule getNextEvent(String arenaName) {
Schedule schedule = null;
for(Schedule sched : schedules) {
if(schedule == null) {
schedule = sched;
}
else if(sched.getEventTime() < schedule.getEventTime()) {
schedule = sched;
}
}
return schedule;
}
public static void runSchedule(){
for(Schedule schedule : schedules){
schedule.runEvent();
}
}
}

View File

@ -0,0 +1,528 @@
package com.amberpvp.hcfactions.event.utils;
import com.google.common.base.Preconditions;
import com.amberpvp.hcfactions.util.player.PlayerUtility;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializable {
private static final int CHUNK_SIZE = 16;
protected final String worldName;
protected final Location locationOne;
protected final Location locationTwo;
protected int x1;
protected int y1;
protected int z1;
protected int x2;
protected int y2;
protected int z2;
public Cuboid(final Map<String, Object> map) {
this.worldName = (String) map.get("worldName");
this.locationOne = null;
this.locationTwo = null;
this.x1 = (Integer) map.get("x1");
this.y1 = (Integer) map.get("y1");
this.z1 = (Integer) map.get("z1");
this.x2 = (Integer) map.get("x2");
this.y2 = (Integer) map.get("y2");
this.z2 = (Integer) map.get("z2");
}
public Cuboid(final World world, final int x1, final int y1, final int z1, final int x2, final int y2, final int z2) {
this(((World) Preconditions.checkNotNull((Object) world)).getName(), x1, y1, z1, x2, y2, z2);
}
private Cuboid(final String worldName, final int x1, final int y1, final int z1, final int x2, final int y2, final int z2) {
Preconditions.checkNotNull((Object) worldName, "World name cannot be null");
this.worldName = worldName;
this.locationOne = null;
this.locationTwo = null;
this.x1 = Math.min(x1, x2);
this.y1 = Math.min(y1, y2);
this.z1 = Math.min(z1, z2);
this.x2 = Math.max(x1, x2);
this.y2 = Math.max(y1, y2);
this.z2 = Math.max(z1, z2);
}
public Cuboid(final Location first, final Location second) {
Preconditions.checkNotNull((Object) first, "Location 1 cannot be null");
Preconditions.checkNotNull((Object) second, "Location 2 cannot be null");
Preconditions.checkArgument(first.getWorld().equals(second.getWorld()), "Locations must be on the same world");
this.worldName = first.getWorld().getName();
this.locationOne = first;
this.locationTwo = second;
this.x1 = Math.min(first.getBlockX(), second.getBlockX());
this.y1 = Math.min(first.getBlockY(), second.getBlockY());
this.z1 = Math.min(first.getBlockZ(), second.getBlockZ());
this.x2 = Math.max(first.getBlockX(), second.getBlockX());
this.y2 = Math.max(first.getBlockY(), second.getBlockY());
this.z2 = Math.max(first.getBlockZ(), second.getBlockZ());
}
public Cuboid(final Location location) {
this(location, location);
}
public Cuboid(final Cuboid other) {
this(other.getWorld().getName(), other.x1, other.y1, other.z1, other.x2, other.y2, other.z2);
}
public Map<String, Object> serialize() {
final Map<String, Object> map = new LinkedHashMap<>();
map.put("worldName", this.worldName);
map.put("x1", this.x1);
map.put("y1", this.y1);
map.put("z1", this.z1);
map.put("x2", this.x2);
map.put("y2", this.y2);
map.put("z2", this.z2);
return map;
}
public boolean hasBothPositionsSet() {
return this.getMinimumPoint() != null && this.getMaximumPoint() != null;
}
public int getMinimumX() {
return Math.min(this.x1, this.x2);
}
public int getMinimumZ() {
return Math.min(this.z1, this.z2);
}
public int getMaximumX() {
return Math.max(this.x1, this.x2);
}
public int getMaximumZ() {
return Math.max(this.z1, this.z2);
}
public List<Vector> edges() {
final Location v1 = this.getMinimumPoint();
final Location v2 = this.getMaximumPoint();
final int minX = v1.getBlockX();
final int maxX = v2.getBlockX();
final int minZ = v1.getBlockZ();
final int startX = minZ + 1;
final int maxZ = v2.getBlockZ();
int capacity = (maxX - minX) * 4 + (maxZ - minZ) * 4;
capacity += 4;
final List<Vector> result = new ArrayList<>(capacity);
if(capacity <= 0) {
return result;
}
final int minY = v1.getBlockY();
final int maxY = v1.getBlockY();
for(int x = minX; x <= maxX; ++x) {
result.add(new Vector(x, minY, minZ));
result.add(new Vector(x, minY, maxZ));
result.add(new Vector(x, maxY, minZ));
result.add(new Vector(x, maxY, maxZ));
}
for(int z = startX; z < maxZ; ++z) {
result.add(new Vector(minX, minY, z));
result.add(new Vector(minX, maxY, z));
result.add(new Vector(maxX, minY, z));
result.add(new Vector(maxX, maxY, z));
}
return result;
}
public Set<Player> getPlayers() {
final Set<Player> players = new HashSet<>();
for(final Player player : PlayerUtility.getOnlinePlayers() ) {
if(this.contains(player)) {
players.add(player);
}
}
return players;
}
public Location getLowerNE() {
return new Location(this.getWorld(), (double) this.x1, (double) this.y1, (double) this.z1);
}
public Location getUpperSW() {
return new Location(this.getWorld(), (double) this.x2, (double) this.y2, (double) this.z2);
}
public Location getCenter() {
final int x1 = this.x2 + 1;
final int y1 = this.y2 + 1;
final int z1 = this.z2 + 1;
return new Location(this.getWorld(), this.x1 + (x1 - this.x1) / 2.0, this.y1 + (y1 - this.y1) / 2.0, this.z1 + (z1 - this.z1) / 2.0);
}
public String getWorldName() {
return this.worldName;
}
public World getWorld() {
return Bukkit.getWorld(this.worldName);
}
public int getSizeX() {
return this.x2 - this.x1 + 1;
}
public int getSizeY() {
return this.y2 - this.y1 + 1;
}
public int getSizeZ() {
return this.z2 - this.z1 + 1;
}
public int getX1() {
return this.x1;
}
public void setX1(final int x1) {
this.x1 = x1;
}
public int getY1() {
return this.y1;
}
public void setY1(final int y1) {
this.y1 = y1;
}
public int getZ1() {
return this.z1;
}
public void setZ1(final int z1) {
this.z1 = z1;
}
public int getX2() {
return this.x2;
}
public int getY2() {
return this.y2;
}
public void setY2(final int y2) {
this.y2 = y2;
}
public int getZ2() {
return this.z2;
}
public Location[] getCornerLocations() {
final Location[] result = new Location[8];
final Block[] cornerBlocks = this.getCornerBlocks();
for(int i = 0; i < cornerBlocks.length; ++i) {
result[i] = cornerBlocks[i].getLocation();
}
return result;
}
public Block[] getCornerBlocks() {
final Block[] result = new Block[8];
final World world = this.getWorld();
result[0] = world.getBlockAt(this.x1, this.y1, this.z1);
result[1] = world.getBlockAt(this.x1, this.y1, this.z2);
result[2] = world.getBlockAt(this.x1, this.y2, this.z1);
result[3] = world.getBlockAt(this.x1, this.y2, this.z2);
result[4] = world.getBlockAt(this.x2, this.y1, this.z1);
result[5] = world.getBlockAt(this.x2, this.y1, this.z2);
result[6] = world.getBlockAt(this.x2, this.y2, this.z1);
result[7] = world.getBlockAt(this.x2, this.y2, this.z2);
return result;
}
public Cuboid expand(final CuboidDirection dir, final int amount) {
switch(dir) {
case NORTH: {
return new Cuboid(this.worldName, this.x1 - amount, this.y1, this.z1, this.x2, this.y2, this.z2);
}
case SOUTH: {
return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2 + amount, this.y2, this.z2);
}
case EAST: {
return new Cuboid(this.worldName, this.x1, this.y1, this.z1 - amount, this.x2, this.y2, this.z2);
}
case WEST: {
return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, this.z2 + amount);
}
case DOWN: {
return new Cuboid(this.worldName, this.x1, this.y1 - amount, this.z1, this.x2, this.y2, this.z2);
}
case UP: {
return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2 + amount, this.z2);
}
default: {
throw new IllegalArgumentException("invalid direction " + dir);
}
}
}
public Cuboid shift(final CuboidDirection dir, final int amount) {
return this.expand(dir, amount).expand(dir.opposite(), -amount);
}
public Cuboid outset(final CuboidDirection dir, final int amount) {
switch(dir) {
case HORIZONTAL: {
return this.expand(CuboidDirection.NORTH, amount).expand(CuboidDirection.SOUTH, amount).expand(CuboidDirection.EAST, amount).expand(CuboidDirection.WEST, amount);
}
case VERTICAL: {
return this.expand(CuboidDirection.DOWN, amount).expand(CuboidDirection.UP, amount);
}
case BOTH: {
return this.outset(CuboidDirection.HORIZONTAL, amount).outset(CuboidDirection.VERTICAL, amount);
}
default: {
throw new IllegalArgumentException("invalid direction " + dir);
}
}
}
public Cuboid inset(final CuboidDirection direction, final int amount) {
return this.outset(direction, -amount);
}
public boolean contains(final Cuboid cuboid) {
return this.contains(cuboid.getMinimumPoint()) || this.contains(cuboid.getMaximumPoint());
}
public boolean contains(final Player player) {
return this.contains(player.getLocation());
}
public boolean contains(final World world, final int x, final int z) {
return (world == null || this.getWorld().equals(world)) && x >= this.x1 && x <= this.x2 && z >= this.z1 && z <= this.z2;
}
public boolean contains(final int x, final int y, final int z) {
return x >= this.x1 && x <= this.x2 && y >= this.y1 && y <= this.y2 && z >= this.z1 && z <= this.z2;
}
public boolean contains(final Block block) {
return this.contains(block.getLocation());
}
public boolean contains(final Location location) {
if(location == null || this.worldName == null) {
return false;
}
final World world = location.getWorld();
return world != null && this.worldName.equals(location.getWorld().getName()) && this.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
public int getVolume() {
return this.getSizeX() * this.getSizeY() * this.getSizeZ();
}
public int getArea() {
final Location min = this.getMinimumPoint();
final Location max = this.getMaximumPoint();
return (max.getBlockX() - min.getBlockX() + 1) * (max.getBlockZ() - min.getBlockZ() + 1);
}
public byte getAverageLightLevel() {
long total = 0L;
int count = 0;
for(final Block block : this) {
if(block.isEmpty()) {
total += block.getLightLevel();
++count;
}
}
return (count > 0) ? ((byte) (total / count)) : 0;
}
public Location getMinimumPoint() {
return new Location(this.getWorld(), (double) Math.min(this.x1, this.x2), (double) Math.min(this.y1, this.y2), (double) Math.min(this.z1, this.z2));
}
public Location getMaximumPoint() {
return new Location(this.getWorld(), (double) Math.max(this.x1, this.x2), (double) Math.max(this.y1, this.y2), (double) Math.max(this.z1, this.z2));
}
public Location getLocationOne() {
return locationOne;
}
public Location getLocationTwo() {
return locationTwo;
}
public int getWidth() {
return this.getMaximumPoint().getBlockX() - this.getMinimumPoint().getBlockX();
}
public int getHeight() {
return this.getMaximumPoint().getBlockY() - this.getMinimumPoint().getBlockY();
}
public int getLength() {
return this.getMaximumPoint().getBlockZ() - this.getMinimumPoint().getBlockZ();
}
public Cuboid contract() {
return this.contract(CuboidDirection.DOWN).contract(CuboidDirection.SOUTH).contract(CuboidDirection.EAST).contract(CuboidDirection.UP).contract(CuboidDirection.NORTH).contract(CuboidDirection.WEST);
}
public Cuboid contract(final CuboidDirection direction) {
Cuboid face = this.getFace(direction.opposite());
switch(direction) {
case DOWN: {
while(face.containsOnly(Material.AIR) && face.y1 > this.y1) {
face = face.shift(CuboidDirection.DOWN, 1);
}
return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, face.y2, this.z2);
}
case UP: {
while(face.containsOnly(Material.AIR) && face.y2 < this.y2) {
face = face.shift(CuboidDirection.UP, 1);
}
return new Cuboid(this.worldName, this.x1, face.y1, this.z1, this.x2, this.y2, this.z2);
}
case NORTH: {
while(face.containsOnly(Material.AIR) && face.x1 > this.x1) {
face = face.shift(CuboidDirection.NORTH, 1);
}
return new Cuboid(this.worldName, this.x1, this.y1, this.z1, face.x2, this.y2, this.z2);
}
case SOUTH: {
while(face.containsOnly(Material.AIR) && face.x2 < this.x2) {
face = face.shift(CuboidDirection.SOUTH, 1);
}
return new Cuboid(this.worldName, face.x1, this.y1, this.z1, this.x2, this.y2, this.z2);
}
case EAST: {
while(face.containsOnly(Material.AIR) && face.z1 > this.z1) {
face = face.shift(CuboidDirection.EAST, 1);
}
return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, face.z2);
}
case WEST: {
while(face.containsOnly(Material.AIR) && face.z2 < this.z2) {
face = face.shift(CuboidDirection.WEST, 1);
}
return new Cuboid(this.worldName, this.x1, this.y1, face.z1, this.x2, this.y2, this.z2);
}
default: {
throw new IllegalArgumentException("Invalid direction " + direction);
}
}
}
public Cuboid getFace(final CuboidDirection direction) {
switch(direction) {
case DOWN: {
return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y1, this.z2);
}
case UP: {
return new Cuboid(this.worldName, this.x1, this.y2, this.z1, this.x2, this.y2, this.z2);
}
case NORTH: {
return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x1, this.y2, this.z2);
}
case SOUTH: {
return new Cuboid(this.worldName, this.x2, this.y1, this.z1, this.x2, this.y2, this.z2);
}
case EAST: {
return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, this.z1);
}
case WEST: {
return new Cuboid(this.worldName, this.x1, this.y1, this.z2, this.x2, this.y2, this.z2);
}
default: {
throw new IllegalArgumentException("Invalid direction " + direction);
}
}
}
public boolean containsOnly(final Material material) {
for(final Block block : this) {
if(block.getType() != material) {
return false;
}
}
return true;
}
public Cuboid getBoundingCuboid(final Cuboid other) {
if(other == null) {
return this;
}
final int xMin = Math.min(this.x1, other.x1);
final int yMin = Math.min(this.y1, other.y1);
final int zMin = Math.min(this.z1, other.z1);
final int xMax = Math.max(this.x2, other.x2);
final int yMax = Math.max(this.y2, other.y2);
final int zMax = Math.max(this.z2, other.z2);
return new Cuboid(this.worldName, xMin, yMin, zMin, xMax, yMax, zMax);
}
public Block getRelativeBlock(final int x, final int y, final int z) {
return this.getWorld().getBlockAt(this.x1 + x, this.y1 + y, this.z1 + z);
}
public Block getRelativeBlock(final World world, final int x, final int y, final int z) {
return world.getBlockAt(this.x1 + x, this.y1 + y, this.z1 + z);
}
public List<Chunk> getChunks() {
final World world = this.getWorld();
final int x1 = this.x1 & 0xFFFFFFF0;
final int x2 = this.x2 & 0xFFFFFFF0;
final int z1 = this.z1 & 0xFFFFFFF0;
final int z2 = this.z2 & 0xFFFFFFF0;
final List<Chunk> result = new ArrayList<>(x2 - x1 + 16 + (z2 - z1) * 16);
for(int x3 = x1; x3 <= x2; x3 += 16) {
for(int z3 = z1; z3 <= z2; z3 += 16) {
result.add(world.getChunkAt(x3 >> 4, z3 >> 4));
}
}
return result;
}
@Override
public Iterator<Block> iterator() {
return new CuboidBlockIterator(this.getWorld(), this.x1, this.y1, this.z1, this.x2, this.y2, this.z2);
}
public Iterator<Location> locationIterator() {
return new CuboidLocationIterator(this.getWorld(), this.x1, this.y1, this.z1, this.x2, this.y2, this.z2);
}
public Cuboid clone() {
try {
return (Cuboid) super.clone();
} catch(CloneNotSupportedException e) {
throw new RuntimeException("this could never happen", e);
}
}
@Override
public String toString() {
return "Cuboid: " + this.worldName + ',' + this.x1 + ',' + this.y1 + ',' + this.z1 + "=>" + this.x2 + ',' + this.y2 + ',' + this.z2;
}
}

View File

@ -0,0 +1,55 @@
package com.amberpvp.hcfactions.event.utils;
import java.util.*;
import org.bukkit.block.*;
import org.bukkit.*;
public class CuboidBlockIterator implements Iterator<Block>
{
private final World world;
private final int baseX;
private final int baseY;
private final int baseZ;
private final int sizeX;
private final int sizeY;
private final int sizeZ;
private int x;
private int y;
private int z;
public CuboidBlockIterator(final World world, final int x1, final int y1, final int z1, final int x2, final int y2, final int z2) {
this.world = world;
this.baseX = x1;
this.baseY = y1;
this.baseZ = z1;
this.sizeX = Math.abs(x2 - x1) + 1;
this.sizeY = Math.abs(y2 - y1) + 1;
this.sizeZ = Math.abs(z2 - z1) + 1;
final boolean x3 = false;
this.z = 0;
this.y = 0;
this.x = 0;
}
@Override
public boolean hasNext() {
return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ;
}
@Override
public Block next() {
final Block block = this.world.getBlockAt(this.baseX + this.x, this.baseY + this.y, this.baseZ + this.z);
if (++this.x >= this.sizeX) {
this.x = 0;
if (++this.y >= this.sizeY) {
this.y = 0;
++this.z;
}
}
return block;
}
@Override
public void remove() {
}
}

View File

@ -0,0 +1,87 @@
package com.amberpvp.hcfactions.event.utils;
import org.bukkit.block.*;
public enum CuboidDirection
{
NORTH,
EAST,
SOUTH,
WEST,
UP,
DOWN,
HORIZONTAL,
VERTICAL,
BOTH,
UNKNOWN;
public CuboidDirection opposite() {
switch (this) {
case NORTH: {
return CuboidDirection.SOUTH;
}
case EAST: {
return CuboidDirection.WEST;
}
case SOUTH: {
return CuboidDirection.NORTH;
}
case WEST: {
return CuboidDirection.EAST;
}
case HORIZONTAL: {
return CuboidDirection.VERTICAL;
}
case VERTICAL: {
return CuboidDirection.HORIZONTAL;
}
case UP: {
return CuboidDirection.DOWN;
}
case DOWN: {
return CuboidDirection.UP;
}
case BOTH: {
return CuboidDirection.BOTH;
}
default: {
return CuboidDirection.UNKNOWN;
}
}
}
public BlockFace toBukkitDirection() {
switch (this) {
case NORTH: {
return BlockFace.NORTH;
}
case EAST: {
return BlockFace.EAST;
}
case SOUTH: {
return BlockFace.SOUTH;
}
case WEST: {
return BlockFace.WEST;
}
case HORIZONTAL: {
return null;
}
case VERTICAL: {
return null;
}
case UP: {
return BlockFace.UP;
}
case DOWN: {
return BlockFace.DOWN;
}
case BOTH: {
return null;
}
default: {
return null;
}
}
}
}

View File

@ -0,0 +1,54 @@
package com.amberpvp.hcfactions.event.utils;
import java.util.*;
import org.bukkit.*;
public class CuboidLocationIterator implements Iterator<Location>
{
private final World world;
private final int baseX;
private final int baseY;
private final int baseZ;
private final int sizeX;
private final int sizeY;
private final int sizeZ;
private int x;
private int y;
private int z;
public CuboidLocationIterator(final World world, final int x1, final int y1, final int z1, final int x2, final int y2, final int z2) {
this.world = world;
this.baseX = x1;
this.baseY = y1;
this.baseZ = z1;
this.sizeX = Math.abs(x2 - x1) + 1;
this.sizeY = Math.abs(y2 - y1) + 1;
this.sizeZ = Math.abs(z2 - z1) + 1;
final boolean x3 = false;
this.z = 0;
this.y = 0;
this.x = 0;
}
@Override
public boolean hasNext() {
return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ;
}
@Override
public Location next() {
final Location location = new Location(this.world, (double)(this.baseX + this.x), (double)(this.baseY + this.y), (double)(this.baseZ + this.z));
if (++this.x >= this.sizeX) {
this.x = 0;
if (++this.y >= this.sizeY) {
this.y = 0;
++this.z;
}
}
return location;
}
@Override
public void remove() {
}
}

View File

@ -0,0 +1,443 @@
package com.amberpvp.hcfactions.factions;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import com.amberpvp.hcfactions.files.ConfigFile;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.player.PlayerUtility;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import com.mongodb.*;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.UpdateOptions;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import com.amberpvp.hcfactions.files.ConfigFile;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.player.PlayerUtility;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import lombok.Getter;
import lombok.Setter;
import me.joeleoli.nucleus.util.ItemBuilder;
import org.bson.Document;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.math.BigDecimal;
import java.util.*;
import static com.mongodb.client.model.Filters.eq;
@Getter
public class Faction {
private static Set<Faction> factions = new HashSet<>();
private static FactionsPlugin main = FactionsPlugin.getInstance();
private static ConfigFile mainConfig = main.getMainConfig();
@Setter private String name, home, announcement;
private UUID uuid;
private Set<Claim> claims;
public Faction(String name, UUID uuid) {
this.name = name;
this.uuid = uuid;
claims = new HashSet<>();
if (uuid == null) {
this.uuid = UUID.randomUUID();
}
factions.add(this);
}
public static Faction getByName(String name) {
for (Faction faction : getFactions()) {
if (faction.getName().replace(" ", "").equalsIgnoreCase(name.replace(" ", ""))) {
return faction;
}
}
return null;
}
public static Faction getByUuid(UUID uuid) {
for (Faction faction : getFactions()) {
if (faction.getUuid().equals(uuid)) {
return faction;
}
}
return null;
}
public static Set<Faction> getAllByString(String string) {
Set<Faction> toReturn = new HashSet<>();
for (Faction faction : factions) {
if (!(toReturn.contains(faction))) {
if (faction.getName().replace(" ", "").equalsIgnoreCase(string)) {
toReturn.add(faction);
}
if (faction instanceof PlayerFaction) {
PlayerFaction playerFaction = (PlayerFaction) faction;
for (UUID uuid : playerFaction.getAllPlayerUuids()) {
SimpleOfflinePlayer offlinePlayer = SimpleOfflinePlayer.getByUuid(uuid);
if (offlinePlayer != null && offlinePlayer.getName().equalsIgnoreCase(string)) {
toReturn.add(faction);
}
}
}
}
}
return toReturn;
}
public boolean isNearBorder(Location l) {
for (Claim claim : getClaims()) {
if (claim.getWorldName().equals(l.getWorld().getName())) {
if (claim.isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(0, 0, 1))) {
return true;
}
if (claim.isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(1, 0, 0))) {
return true;
}
if (claim.isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(0, 0, -1))) {
return true;
}
if (claim.isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(-1, 0, 0))) {
return true;
}
if (claim.isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(-1, 0, 1))) {
return true;
}
if (claim.isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(-1, 0, -1))) {
return true;
}
if (claim.isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(1, 0, 1))) {
return true;
}
if (claim.isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(1, 0, -1))) {
return true;
}
}
}
return false;
}
public static ItemStack getWand() {
return new ItemBuilder(Material.valueOf(main.getMainConfig().getString("FACTION_CLAIMING.WAND.TYPE")))
.lore(main.getMainConfig().getStringList("FACTION_CLAIMING.WAND.LORE"))
.name(main.getMainConfig().getString("FACTION_CLAIMING.WAND.NAME"))
.data(main.getMainConfig().getInt("FACTION_CLAIMING.WAND.DATA")).build();
}
public static void load() {
MongoCollection sCollection = main.getFactionsDatabase().getDatabase().getCollection("systemFactions");
MongoCollection pCollection = main.getFactionsDatabase().getDatabase().getCollection("playerFactions");
sCollection.find().forEach(new Block() {
@Override
public void apply(Object obj) {
Document dbo = (Document) obj;
UUID uuid = UUID.fromString(dbo.getString("uuid"));
String name = dbo.getString("name");
final SystemFaction systemFaction = new SystemFaction(name, uuid);
boolean deathban = dbo.getBoolean("deathban");
ChatColor color = ChatColor.valueOf(dbo.getString("color"));
if (dbo.containsKey("home")) {
systemFaction.setHome(dbo.getString("home"));
}
if (dbo.containsKey("announcement")) {
systemFaction.setAnnouncement(dbo.getString("announcement"));
}
systemFaction.setDeathban(deathban);
systemFaction.setColor(color);
List<String> claims = (List<String>) dbo.get("claims");
for (String claim : claims) {
if (claim.length() >= 5) {
String[] claimParts = (claim).split(";");
final String worldName = claimParts[0];
final int x1 = Integer.parseInt(claimParts[1]);
final int z1 = Integer.parseInt(claimParts[2]);
final int x2 = Integer.parseInt(claimParts[3]);
final int z2 = Integer.parseInt(claimParts[4]);
new Claim(systemFaction, new int[]{x1, x2, z1, z2}, worldName);
}
}
}
});
final Map<PlayerFaction, Set<UUID>> allyCache = new HashMap<>();
pCollection.find().forEach(new Block() {
@Override
public void apply(Object obj) {
Document dbo = (Document) obj;
UUID uuid = UUID.fromString(dbo.getString("uuid"));
UUID leader = UUID.fromString(dbo.getString("leader"));
String name = dbo.getString("name");
double dtr = dbo.getDouble("dtr");
int balance = dbo.getInteger("balance");
int[] freezeInformation = null;
String home = null;
String announcement = null;
UUID focusPlayer = null;
Set<UUID> officers = new HashSet<>();
Set<UUID> members = new HashSet<>();
Map<UUID, UUID> invitedPlayers = new HashMap<>();
if (dbo.containsKey("freezeLength") && dbo.containsKey("freezeInit")) {
freezeInformation = new int[]{dbo.getInteger("freezeLength"), dbo.getInteger("freezeInit")};
}
if (dbo.containsKey("home")) {
home = dbo.getString("home");
}
if(dbo.containsKey("focusPlayer")) {
focusPlayer = UUID.fromString(dbo.getString("focusPlayer"));
}
if (dbo.containsKey("announcement")) {
announcement = dbo.getString("announcement");
}
Document invitedPlayerMap = (Document) dbo.get("invitedPlayers");
for (String key : invitedPlayerMap.keySet()) {
UUID invitedPlayer = UUID.fromString(key);
UUID invitedBy = (UUID) invitedPlayerMap.get(key);
invitedPlayers.put(invitedPlayer, invitedBy);
}
List<String> membersList = (List<String>) dbo.get("members");
for (String member : membersList) {
if (member.length() == uuid.toString().length()) {
members.add(UUID.fromString(member));
}
}
List<String> officerList = (List<String>) dbo.get("officers");
for (String officer : officerList) {
if (officer.length() == uuid.toString().length()) {
officers.add(UUID.fromString(officer));
}
}
final PlayerFaction playerFaction = new PlayerFaction(name, leader, uuid);
playerFaction.setOfficers(officers);
playerFaction.setMembers(members);
playerFaction.setBalance(balance);
playerFaction.setDeathsTillRaidable(BigDecimal.valueOf(dtr));
playerFaction.setFreezeInformation(freezeInformation);
playerFaction.setHome(home);
playerFaction.setInvitedPlayers(invitedPlayers);
playerFaction.setAnnouncement(announcement);
playerFaction.setFocusPlayer(focusPlayer);
List<String> claims = (List<String>) dbo.get("claims");
for (String claim : claims) {
if (claim.length() >= 5) {
String[] claimParts = (claim).split(";");
final String worldName = claimParts[0];
final int x1 = Integer.parseInt(claimParts[1]);
final int z1 = Integer.parseInt(claimParts[2]);
final int x2 = Integer.parseInt(claimParts[3]);
final int z2 = Integer.parseInt(claimParts[4]);
new Claim(playerFaction, new int[]{x1, x2, z1, z2}, worldName);
}
}
List<String> allies = (List<String>) dbo.get("allies");
for (String ally : allies) {
if (ally.length() == uuid.toString().length()) {
if (allyCache.containsKey(playerFaction)) {
allyCache.get(playerFaction).add(UUID.fromString(ally));
} else {
allyCache.put(playerFaction, new HashSet<>(Arrays.asList(UUID.fromString(ally))));
}
}
}
}
});
for (PlayerFaction key : allyCache.keySet()) {
for (UUID allyUuid : allyCache.get(key)) {
Faction allyFaction = Faction.getByUuid(allyUuid);
if (allyFaction instanceof PlayerFaction) {
key.getAllies().add((PlayerFaction) allyFaction);
}
}
}
for (Player player : PlayerUtility.getOnlinePlayers() ) {
Profile profile = Profile.getByPlayer(player);
Claim claim = Claim.getProminentClaimAt(player.getLocation());
if (claim != null) {
profile.setLastInside(claim);
}
PlayerFaction playerFaction = PlayerFaction.getByPlayerName(player.getName());
if (profile.getFaction() == null && playerFaction != null) {
profile.setFaction(playerFaction);
}
}
Profile.sendGlobalTabUpdate();
main.setLoaded(true);
}
public static void save() {
if (!(getFactions().isEmpty())) {
System.out.println("Preparing to save " + getFactions().size() + " factions.");
MongoCollection sCollection = main.getFactionsDatabase().getDatabase().getCollection("systemFactions");
MongoCollection pCollection = main.getFactionsDatabase().getDatabase().getCollection("playerFactions");
for (Faction faction : getFactions()) {
if (faction instanceof PlayerFaction) {
PlayerFaction playerFaction = (PlayerFaction) faction;
Document dbo = new Document();
dbo.put("uuid", playerFaction.getUuid().toString());
dbo.put("leader", playerFaction.getLeader().toString());
dbo.put("name", playerFaction.getName());
dbo.put("name_lower", playerFaction.getName().toLowerCase());
dbo.put("dtr", playerFaction.getDeathsTillRaidable().doubleValue());
dbo.put("balance", playerFaction.getBalance());
if(playerFaction.getFocusPlayer() != null) {
dbo.put("focusPlayer", playerFaction.getFocusPlayer().toString());
}
if (playerFaction.isFrozen()) {
dbo.put("freezeLength", playerFaction.getFreezeInformation()[0]);
dbo.put("freezeInit", playerFaction.getFreezeInformation()[1]);
}
if (playerFaction.getHome() != null) {
dbo.put("home", playerFaction.getHome());
}
if (playerFaction.getAnnouncement() != null) {
dbo.put("announcement", playerFaction.getAnnouncement());
}
List<String> officers = new ArrayList<>();
List<String> members = new ArrayList<>();
List<String> allies = new ArrayList<>();
List<String> requestedAllies = new ArrayList<>();
Document invitedPlayers = new Document();
List<String> claims = new ArrayList<>();
officers.addAll(PlayerUtility.getConvertedUuidSet(playerFaction.getOfficers()));
members.addAll(PlayerUtility.getConvertedUuidSet(playerFaction.getMembers()));
allies.addAll(PlayerUtility.getConvertedUuidSet(playerFaction.getAllyUuids()));
requestedAllies.addAll(PlayerUtility.getConvertedUuidSet(playerFaction.getRequestedAllies()));
for (UUID invitedPlayer : playerFaction.getInvitedPlayers().keySet()) {
invitedPlayers.put(invitedPlayer.toString(), playerFaction.getInvitedPlayers().get(invitedPlayer));
}
for (Claim claim : playerFaction.getClaims()) {
claims.add(claim.getWorldName() + ";" + claim.getFirstX() + ";" + claim.getFirstZ() + ";" + claim.getSecondX() + ";" + claim.getSecondZ());
}
dbo.put("officers", officers);
dbo.put("members", members);
dbo.put("allies", allies);
dbo.put("requestedAllies", requestedAllies);
dbo.put("invitedPlayers", invitedPlayers);
dbo.put("claims", claims);
pCollection.replaceOne(eq("uuid", playerFaction.getUuid().toString()), dbo, new UpdateOptions().upsert(true));
} else {
SystemFaction systemFaction = (SystemFaction) faction;
Document dbo = new Document();
dbo.put("uuid", systemFaction.getUuid().toString());
dbo.put("deathban", systemFaction.isDeathban());
dbo.put("color", systemFaction.getColor().name());
dbo.put("name", systemFaction.getName());
dbo.put("name_lower", systemFaction.getName().toLowerCase());
if (systemFaction.getAnnouncement() != null) {
dbo.put("announcement", systemFaction.getAnnouncement());
}
if (systemFaction.getHome() != null) {
dbo.put("home", systemFaction.getHome());
}
BasicDBList claims = new BasicDBList();
for (Claim claim : systemFaction.getClaims()) {
claims.add(claim.getWorldName() + ";" + claim.getFirstX() + ";" + claim.getFirstZ() + ";" + claim.getSecondX() + ";" + claim.getSecondZ());
}
dbo.put("claims", claims);
sCollection.replaceOne(eq("uuid", systemFaction.getUuid().toString()), dbo, new UpdateOptions().upsert(true));
}
}
}
}
public static Set<Faction> getFactions() {
return factions;
}
public String getDisplayName(Player player) {
if (this == null) {
return ChatColor.RED + this.getName();
}
if (this instanceof PlayerFaction) {
PlayerFaction playerFaction = (PlayerFaction)this;
if (playerFaction.equals(this)) {
return ChatColor.GREEN + this.getName();
}
if (playerFaction.getAllies().contains(this)) {
return ChatColor.BLUE + this.getName();
}
}
return ChatColor.RED + this.getName();
}
}

View File

@ -0,0 +1,285 @@
package com.amberpvp.hcfactions.factions.claims;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import lombok.Getter;
import org.bukkit.*;
import java.util.*;
@Getter
public class Claim {
private static Set<Claim> claims = new HashSet<>();
private static Map<String, HashSet<Claim>> chunkClaimMap = new HashMap<>();
private Faction faction;
private String worldName;
private int[] coordinates;
private Location[] corners;
private ArrayList<Location> border;
public Claim(Faction faction, int[] coordinates, String worldName) {
this.faction = faction;
this.coordinates = new int[]{Math.min(coordinates[0], coordinates[1]), Math.min(coordinates[2], coordinates[3]), Math.max(coordinates[0], coordinates[1]), Math.max(coordinates[2], coordinates[3])};
this.worldName = worldName;
Location firstCorner = new Location(Bukkit.getWorld(worldName), getFirstX(), 0, getFirstZ());
Location secondCorner = new Location(Bukkit.getWorld(worldName), getFirstX(), 0, getSecondZ());
Location thirdCorner = new Location(Bukkit.getWorld(worldName), getSecondX(), 0, getFirstZ());
Location fourthCorner = new Location(Bukkit.getWorld(worldName), getSecondX(), 0, getSecondZ());
corners = new Location[]{firstCorner, secondCorner, thirdCorner, fourthCorner};
index();
setupBorder();
faction.getClaims().add(this);
claims.add(this);
}
private void index() {
for (int x = getFirstX(); x < getSecondX() + 1; x++) {
for (int z = getFirstZ(); z < getSecondZ() + 1; z++) {
int toSetX = x >> 4;
int toSetZ = z >> 4;
if (!(chunkClaimMap.containsKey(toSetX + ":" + toSetZ))) {
chunkClaimMap.put(toSetX + ":" + toSetZ, new HashSet<Claim>());
}
chunkClaimMap.get(toSetX + ":" + toSetZ).add(Claim.this);
}
}
}
public boolean isGreaterThan(Claim claim) {
if (FactionsPlugin.getInstance().getMainConfig().getStringList("FACTION_GENERAL.BYPASS_INSIDE_CHECK").contains(faction.getName())) {
return false;
}
if (FactionsPlugin.getInstance().getMainConfig().getStringList("FACTION_GENERAL.BYPASS_INSIDE_CHECK").contains(claim.getFaction().getName())) {
return true;
}
int distance1 = (int) claim.getCorners()[0].distance(claim.getCorners()[3]);
int distance2 = (int) getCorners()[0].distance(getCorners()[3]);
return distance2 > distance1;
}
public int getWidth() {
return (int) corners[2].distance(corners[0]) + 1;
}
public int getLength() {
return (int) corners[2].distance(corners[1]) + 1;
}
public static ArrayList<Material> getMapBlocks() {
ArrayList<Material> toReturn = new ArrayList<>();
for (Material material : Material.values()) {
if (material.isBlock() && material.isOccluding() && material.isSolid() && !material.name().contains("STAIRS") && !material.name().contains("SLAB") && !material.name().contains("MUSHROOM")) {
toReturn.add(material);
}
}
return toReturn;
}
public boolean overlaps(double x1, double z1, double x2, double z2) {
double[] dim = new double[2];
dim[0] = x1;
dim[1] = x2;
Arrays.sort(dim);
if (getFirstX() > dim[1] || getSecondX() < dim[0]) {
return false;
}
dim[0] = z1;
dim[1] = z2;
Arrays.sort(dim);
if (getFirstZ() > dim[1] || getSecondZ() < dim[0]) {
return false;
}
return true;
}
public boolean isNearby(Location l, int buffer) {
if (Bukkit.getWorld(worldName) == new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).getWorld()) {
if (isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(0, 0, buffer))) {
return true;
}
if (isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(buffer, 0, 0))) {
return true;
}
if (isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(0, 0, -buffer))) {
return true;
}
if (isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(-buffer, 0, 0))) {
return true;
}
if (isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(-buffer, 0, buffer))) {
return true;
}
if (isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(buffer, 0, -buffer))) {
return true;
}
if (isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(-buffer, 0, -buffer))) {
return true;
}
if (isInside(new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()).add(buffer, 0, buffer))) {
return true;
}
}
return false;
}
private void setupBorder() {
ArrayList<Location> toReturn = new ArrayList<>();
World world = Bukkit.getWorld(worldName);
for (int i = Math.min(corners[0].getBlockZ(), corners[1].getBlockZ()); i < Math.max(corners[0].getBlockZ(), corners[1].getBlockZ()); i++) {
toReturn.add(new Location(world, corners[0].getBlockX(), 0, i));
}
for (int i = Math.min(corners[2].getBlockZ(), corners[3].getBlockZ()); i < Math.max(corners[2].getBlockZ(), corners[3].getBlockZ()); i++) {
toReturn.add(new Location(world, corners[3].getBlockX(), 0, i));
}
for (int i = Math.min(corners[1].getBlockX(), corners[3].getBlockX()); i < Math.max(corners[1].getBlockX(), corners[3].getBlockX()) + 1; i++) {
toReturn.add(new Location(world, i, 0, corners[1].getBlockZ()));
}
for (int i = Math.min(corners[0].getBlockX(), corners[2].getBlockX()); i < Math.max(corners[0].getBlockX(), corners[2].getBlockX()); i++) {
toReturn.add(new Location(world, i, 0, corners[0].getBlockZ()));
}
border = toReturn;
}
public void remove() {
claims.remove(this);
for (String key : Claim.getChunkClaimMap().keySet()) {
HashSet<Claim> keySet = chunkClaimMap.get(key);
if (keySet.contains(this)) {
keySet.remove(this);
}
}
for (String key : new ArrayList<>(Claim.getChunkClaimMap().keySet())) {
if (Claim.getChunkClaimMap().get(key).isEmpty()) {
chunkClaimMap.remove(key);
}
}
for (Profile profile : Profile.getProfiles()) {
if (!(profile.getMapPillars().isEmpty())) {
for (ClaimPillar claimPillar : new HashSet<>(profile.getMapPillars())) {
if (isInside(claimPillar.getLocation())) {
claimPillar.remove();
profile.getMapPillars().remove(claimPillar);
}
}
if (profile.getMapPillars().isEmpty()) {
profile.setViewingMap(false);
}
}
}
if (faction instanceof PlayerFaction) {
PlayerFaction playerFaction = (PlayerFaction) faction;
Location cornerThree = new Location(Bukkit.getWorld(worldName), getFirstX(), 0, getSecondZ());
int width = (int) cornerThree.distance(corners[0]) + 1;
int length = (int) cornerThree.distance(corners[3]) + 1;
int value = (int) (width * length * FactionsPlugin.getInstance().getMainConfig().getDouble("FACTION_CLAIMING.PRICE_MULTIPLIER"));
playerFaction.setBalance(playerFaction.getBalance() + value);
}
faction.getClaims().remove(this);
}
public int getFirstX() {
return coordinates[0];
}
public int getSecondX() {
return coordinates[2];
}
public int getFirstZ() {
return coordinates[1];
}
public int getSecondZ() {
return coordinates[3];
}
public boolean isInside(Location location) {
return (location.getWorld().getName().equalsIgnoreCase(worldName) && (location.getBlockX() >= getFirstX() && location.getBlockX() <= getSecondX()) && (location.getBlockZ() >= getFirstZ() && location.getBlockZ() <= getSecondZ()));
}
public static Claim getProminentClaimAt(Location location) {
List<Claim> possibleClaims = getClaimsAt(location);
if (possibleClaims != null) {
Claim currentClaim = null;
for (Claim claim : possibleClaims) {
if (claim.isInside(location)) {
if (currentClaim != null) {
if (currentClaim.isGreaterThan(claim)) {
currentClaim = claim;
}
}
else {
currentClaim = claim;
}
}
}
return currentClaim;
}
return null;
}
public static ArrayList<Claim> getClaimsAt(Location location) {
if (chunkClaimMap.containsKey((location.getBlockX() >> 4) + ":" + (location.getBlockZ() >> 4))) {
return new ArrayList<>(chunkClaimMap.get((location.getBlockX() >> 4) + ":" + (location.getBlockZ() >> 4)));
}
return null;
}
public static Set<Claim> getNearbyClaimsAt(Location location, int radius) {
Set<Claim> toReturn = new HashSet<>();
int[] pos = new int[]{location.getBlockX(), location.getBlockZ()};
Location currentLocation = new Location(location.getWorld(), pos[0], 0, pos[1]);
for (int x = pos[0] - radius; x < pos[0] + radius; x++) {
for (int z = pos[1] - radius; z < pos[1] + radius; z++) {
currentLocation.setX(x);
currentLocation.setZ(z);
Claim claim = getProminentClaimAt(currentLocation);
if (claim != null && !toReturn.contains(claim)) {
toReturn.add(claim);
}
}
}
return toReturn;
}
private static Map<String, HashSet<Claim>> getChunkClaimMap() {
return chunkClaimMap;
}
public static Set<Claim> getClaims() {
return claims;
}
}

View File

@ -0,0 +1,880 @@
package com.amberpvp.hcfactions.factions.claims;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.files.ConfigFile;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.LocationSerialization;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import com.amberpvp.hcfactions.files.ConfigFile;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldownType;
import com.amberpvp.hcfactions.util.LocationSerialization;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.ContainerBlock;
import org.bukkit.block.Sign;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.*;
import org.bukkit.material.Openable;
import org.bukkit.material.Redstone;
import org.bukkit.scheduler.BukkitRunnable;
public class ClaimListeners implements Listener {
private FactionsPlugin main = FactionsPlugin.getInstance();
private ConfigFile mainConfig = main.getMainConfig();
private ConfigFile langConfig = main.getLanguageConfig();
@EventHandler
public void onPlayerInteractClaim(final PlayerInteractEvent event) {
final Player player = event.getPlayer();
if (event.getItem() != null && event.getItem().equals(Faction.getWand())) {
event.setCancelled(true);
Profile profile = Profile.getByPlayer(player);
ClaimProfile claimProfile = profile.getClaimProfile();
if (claimProfile == null) {
if (profile.getFaction() != null) {
claimProfile = new ClaimProfile(player, profile.getFaction());
}
else {
return;
}
}
final Faction faction = claimProfile.getFaction();
if (faction instanceof PlayerFaction) {
PlayerFaction playerFaction = (PlayerFaction) faction;
if (playerFaction.getLeader() != player.getUniqueId() && !playerFaction.getOfficers().contains(player.getUniqueId())) {
player.getInventory().removeItem(Faction.getWand());
claimProfile.removePillars();
return;
}
}
if (event.getAction().name().contains("BLOCK")) {
claimProfile.setResetClicked(false);
final Material material = Material.valueOf(mainConfig.getString("FACTION_CLAIMING.CLAIM_PILLAR.TYPE"));
final int data = mainConfig.getInt("FACTION_CLAIMING.CLAIM_PILLAR.DATA");
final Location location = event.getClickedBlock().getLocation();
int toDisplay = 0;
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
toDisplay = 1;
}
else {
if (!faction.getClaims().isEmpty() && faction instanceof PlayerFaction && !faction.isNearBorder(location)) {
player.sendMessage(langConfig.getString("ERROR.MUST_CLAIM_CLOSER"));
return;
}
}
final ClaimPillar pillar = claimProfile.getPillars()[toDisplay];
final String message = (langConfig.getString("FACTION_CLAIM.SET_POSITION_" + (toDisplay + 1)).replace("%X_POS%", location.getBlockX() + "").replace("%Z_POS%", location.getBlockZ() + ""));
for (Claim claim : Claim.getClaims()) {
if (claim.isInside(location) && (!(faction instanceof SystemFaction))) {
player.sendMessage(langConfig.getString("ERROR.CANNOT_CLAIM_HERE"));
return;
}
if (claim.isNearby(location, mainConfig.getInt("FACTION_CLAIMING.BUFFER")) && claim.getFaction() != faction && (!(faction instanceof SystemFaction))) {
player.sendMessage(langConfig.getString("ERROR.CANNOT_CLAIM_BUFFER"));
return;
}
}
if (toDisplay == 1) {
final ClaimProfile finalClaimProfile = claimProfile;
new BukkitRunnable() {
@Override
public void run() {
ClaimPillar secondPillar = finalClaimProfile.getPillars()[0];
ClaimPillar firstPillar = new ClaimPillar(player, location);
if (secondPillar != null) {
Location cornerOne = firstPillar.getLocation();
Location cornerTwo = secondPillar.getLocation();
Location cornerThree = new Location(cornerOne.getWorld(), cornerOne.getBlockX(), 0, cornerTwo.getBlockZ());
int width = (int) cornerThree.distance(cornerOne) + 1;
int length = (int) cornerThree.distance(cornerTwo) + 1;
if (width < mainConfig.getInt("FACTION_CLAIMING.MIN_SIZE") || length < mainConfig.getInt("FACTION_CLAIMING.MIN_SIZE")) {
player.sendMessage(langConfig.getString("ERROR.CLAIM_TOO_SMALL"));
return;
}
player.sendMessage(message);
player.sendMessage(langConfig.getString("FACTION_CLAIM.BOTH_POSITIONS_SET").replace("%COST%", calculateCosts(firstPillar, secondPillar) + "").replace("%LENGTH%", length + "").replace("%WIDTH%", width + "").replace("%TOTAL_BLOCKS%", length * width + ""));
}
else {
player.sendMessage(message);
}
if (pillar != null) {
if (pillar.getLocation().equals(location)) {
return;
}
else {
pillar.remove();
}
}
finalClaimProfile.getPillars()[1] = firstPillar.show(material, data);
}
}.runTaskLaterAsynchronously(main, 1L);
}
else {
ClaimPillar secondPillar = claimProfile.getPillars()[1];
ClaimPillar firstPillar = new ClaimPillar(player, location);
if (secondPillar != null) {
Location cornerOne = firstPillar.getLocation();
Location cornerTwo = secondPillar.getLocation();
Location cornerThree = new Location(cornerOne.getWorld(), cornerOne.getBlockX(), 0, cornerTwo.getBlockZ());
int width = (int) cornerThree.distance(cornerOne) + 1;
int length = (int) cornerThree.distance(cornerTwo) + 1;
if (width < mainConfig.getInt("FACTION_CLAIMING.MIN_SIZE") || length < mainConfig.getInt("FACTION_CLAIMING.MIN_SIZE")) {
player.sendMessage(langConfig.getString("ERROR.CLAIM_TOO_SMALL"));
return;
}
player.sendMessage(message);
player.sendMessage(langConfig.getString("FACTION_CLAIM.BOTH_POSITIONS_SET").replace("%COST%", calculateCosts(firstPillar, secondPillar) + "").replace("%LENGTH%", length + "").replace("%WIDTH%", width + "").replace("%TOTAL_BLOCKS%", length * width + ""));
}
else {
player.sendMessage(message);
}
if (pillar != null) {
if (pillar.getLocation().equals(location)) {
return;
}
else {
pillar.remove();
}
}
claimProfile.getPillars()[0] = firstPillar.show(material, data);
}
return;
}
if (event.getAction() == Action.LEFT_CLICK_AIR && player.isSneaking()) {
if (claimProfile.getPillars()[0] == null || claimProfile.getPillars()[1] == null) {
player.sendMessage(langConfig.getString("ERROR.INVALID_SELECTION"));
return;
}
ClaimPillar firstPillar = claimProfile.getPillars()[0];
ClaimPillar secondPillar = claimProfile.getPillars()[1];
Location cornerOne = firstPillar.getLocation();
Location cornerTwo = secondPillar.getLocation();
Location cornerThree = new Location(cornerOne.getWorld(), cornerOne.getBlockX(), 0, cornerTwo.getBlockZ());
Location cornerFour = new Location(cornerOne.getWorld(), cornerTwo.getBlockX(), 0, cornerOne.getBlockZ());
if (faction instanceof PlayerFaction) {
for (Claim claim : Claim.getClaims()) {
if (claim.overlaps(firstPillar.getLocation().getBlockX(), firstPillar.getLocation().getBlockZ(), secondPillar.getLocation().getBlockX(), secondPillar.getLocation().getBlockZ())) {
player.sendMessage(langConfig.getString("ERROR.CANNOT_OVERCLAIM"));
return;
}
if (claim.isNearby(cornerOne, mainConfig.getInt("FACTION_CLAIMING.BUFFER")) && claim.getFaction() != faction) {
player.sendMessage(langConfig.getString("ERROR.CANNOT_CLAIM_BUFFER"));
return;
}
if (claim.isNearby(cornerTwo, mainConfig.getInt("FACTION_CLAIMING.BUFFER")) && claim.getFaction() != faction) {
player.sendMessage(langConfig.getString("ERROR.CANNOT_CLAIM_BUFFER"));
return;
}
if (claim.isNearby(cornerThree, mainConfig.getInt("FACTION_CLAIMING.BUFFER")) && claim.getFaction() != faction) {
player.sendMessage(langConfig.getString("ERROR.CANNOT_CLAIM_BUFFER"));
return;
}
if (claim.isNearby(cornerFour, mainConfig.getInt("FACTION_CLAIMING.BUFFER")) && claim.getFaction() != faction) {
player.sendMessage(langConfig.getString("ERROR.CANNOT_CLAIM_BUFFER"));
return;
}
}
}
int price = calculateCosts(firstPillar, secondPillar);
if (faction instanceof PlayerFaction) {
PlayerFaction playerFaction = (PlayerFaction) faction;
if (playerFaction.getBalance() < price) {
player.sendMessage(langConfig.getString("ERROR.FACTION_NOT_ENOUGH_MONEY"));
return;
}
playerFaction.setBalance(playerFaction.getBalance() - price);
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_CLAIM_LAND").replace("%PLAYER%", player.getName()));
}
new Claim(faction, new int[]{firstPillar.getLocation().getBlockX(), secondPillar.getLocation().getBlockX(), firstPillar.getLocation().getBlockZ(), secondPillar.getLocation().getBlockZ()}, firstPillar.getLocation().getWorld().getName());
claimProfile.removePillars();
player.getInventory().remove(Faction.getWand());
}
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
if (claimProfile.getPillars()[0] == null && claimProfile.getPillars()[1] == null) {
player.sendMessage(langConfig.getString("ERROR.INVALID_SELECTION"));
return;
}
if (claimProfile.isResetClicked()) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.SELECTION_RESET"));
claimProfile.setResetClicked(false);
claimProfile.removePillars();
}
else {
claimProfile.setResetClicked(true);
player.sendMessage(langConfig.getString("FACTION_CLAIM.CLICK_TO_RESET_SELECTION"));
}
}
}
}
private int calculateCosts(ClaimPillar firstPillar, ClaimPillar secondPillar) {
Location cornerOne = firstPillar.getLocation();
Location cornerTwo = secondPillar.getLocation();
Location cornerThree = new Location(cornerOne.getWorld(), cornerOne.getBlockX(), 0, cornerTwo.getBlockZ());
int width = (int) cornerThree.distance(cornerOne) + 1;
int length = (int) cornerThree.distance(cornerTwo) + 1;
return (int) (width * length * mainConfig.getDouble("FACTION_CLAIMING.PRICE_MULTIPLIER"));
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
event.getPlayer().getInventory().removeItem(Faction.getWand());
}
@EventHandler
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player && event.getEntity().getType() == EntityType.ITEM_FRAME) {
Player player = (Player) event.getDamager();
Profile profile = Profile.getByPlayer(player);
if (profile.isInAdminMode()) {
return;
}
Claim claim = Claim.getProminentClaimAt(event.getEntity().getLocation());
if (claim != null) {
Faction faction = claim.getFaction();
if (faction instanceof PlayerFaction && ((PlayerFaction) faction).isRaidable()) {
return;
}
if(faction instanceof SystemFaction && faction.getName().equalsIgnoreCase("Warzone")) {
if(this.getSpawnLocation() != null && this.getSpawnLocation().distance(event.getEntity().getLocation()) >= 302) {
return;
}
}
if (profile.getFaction() == null || !faction.equals(profile.getFaction())) {
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_SYSTEM").replace("%COLOR%", systemFaction.getColor() + "").replace("%FACTION%", systemFaction.getName()));
}
else {
if (faction instanceof PlayerFaction && profile.getFaction() != null && profile.getFaction().getAllies().contains(faction)) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ALLY").replace("%FACTION%", faction.getName()));
}
else {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ENEMY").replace("%FACTION%", faction.getName()));
}
}
event.setCancelled(true);
}
}
}
}
@EventHandler
public void onHangingPlaceEvent(HangingPlaceEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.isInAdminMode()) {
return;
}
Claim claim = Claim.getProminentClaimAt(event.getEntity().getLocation());
if (claim != null) {
Faction faction = claim.getFaction();
if (faction instanceof PlayerFaction && ((PlayerFaction) faction).isRaidable()) {
return;
}
if(faction instanceof SystemFaction && faction.getName().equalsIgnoreCase("Warzone")) {
if(this.getSpawnLocation() != null && this.getSpawnLocation().distance(event.getEntity().getLocation()) >= 302) {
return;
}
}
if (profile.getFaction() == null || !faction.equals(profile.getFaction())) {
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_SYSTEM").replace("%COLOR%", systemFaction.getColor() + "").replace("%FACTION%", systemFaction.getName()));
}
else {
if (faction instanceof PlayerFaction && profile.getFaction() != null && profile.getFaction().getAllies().contains(faction)) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ALLY").replace("%FACTION%", faction.getName()));
}
else {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ENEMY").replace("%FACTION%", faction.getName()));
}
}
event.setCancelled(true);
}
}
}
@EventHandler
public void onBlockPistonExtendEvent(BlockPistonExtendEvent event) {
Block block = event.getBlock();
if (Claim.getProminentClaimAt(block.getLocation()) == null) {
for (Block other : event.getBlocks()) {
if (Claim.getProminentClaimAt(other.getLocation()) != null) {
event.setCancelled(true);
}
}
}
}
@EventHandler
public void onBlockPistonRetractEvent(BlockPistonRetractEvent event) {
Block block = event.getBlock();
if (Claim.getProminentClaimAt(block.getLocation()) == null) {
if (Claim.getProminentClaimAt(event.getRetractLocation()) != null) {
event.setCancelled(true);
}
}
}
@EventHandler
public void onHangingBreakByEntityEvent(HangingBreakByEntityEvent event) {
if (event.getRemover() instanceof Player) {
Player player = (Player) event.getRemover();
Profile profile = Profile.getByPlayer(player);
if (profile.isInAdminMode()) {
return;
}
Claim claim = Claim.getProminentClaimAt(event.getEntity().getLocation());
if (claim != null) {
Faction faction = claim.getFaction();
if (faction instanceof PlayerFaction && ((PlayerFaction) faction).isRaidable()) {
return;
}
if(faction instanceof SystemFaction && faction.getName().equalsIgnoreCase("Warzone")) {
if(this.getSpawnLocation() != null && this.getSpawnLocation().distance(event.getEntity().getLocation()) >= 302) {
return;
}
}
if (profile.getFaction() == null || !faction.equals(profile.getFaction())) {
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_SYSTEM").replace("%COLOR%", systemFaction.getColor() + "").replace("%FACTION%", systemFaction.getName()));
}
else {
if (faction instanceof PlayerFaction && profile.getFaction() != null && profile.getFaction().getAllies().contains(faction)) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ALLY").replace("%FACTION%", faction.getName()));
}
else {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ENEMY").replace("%FACTION%", faction.getName()));
}
}
event.setCancelled(true);
}
}
}
}
@EventHandler
public void onDropItem(PlayerDropItemEvent event) {
if (event.getItemDrop().getItemStack().getItemMeta().hasDisplayName()) {
if (event.getItemDrop().getItemStack().getItemMeta().getDisplayName().equals(Faction.getWand().getItemMeta().getDisplayName())) {
event.getItemDrop().remove();
ClaimProfile profile = Profile.getByPlayer(event.getPlayer()).getClaimProfile();
if (profile != null) {
for (ClaimPillar pillar : profile.getPillars()) {
if (pillar != null) {
pillar.remove();
}
}
}
}
}
}
@EventHandler
public void onExplodeEvent(EntityExplodeEvent event) {
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onDamageInSafezone(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player) {
Player damager;
if (event.getDamager() instanceof Player) {
damager = (Player) event.getDamager();
}
else if (event.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) event.getDamager();
if (projectile.getShooter() instanceof Player) {
damager = (Player) projectile.getShooter();
}
else {
return;
}
}
else {
return;
}
Player damaged = (Player) event.getEntity();
Profile damagerProfile = Profile.getByPlayer(damager);
Claim damagerClaim = Claim.getProminentClaimAt(damager.getLocation());
if (!damagerProfile.isInAdminMode() && damagerClaim != null && damagerClaim.isInside(damager.getLocation()) && damagerClaim.getFaction() instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) damagerClaim.getFaction();
if (!(systemFaction.isDeathban())) {
damager.sendMessage(langConfig.getString("FACTION_CLAIM.DAMAGER_IN_SAFEZONE").replace("%FACTION%", systemFaction.getName()).replace("%COLOR%", systemFaction.getColor() + ""));
event.setCancelled(true);
return;
}
}
Claim damagedClaim = Claim.getProminentClaimAt(damaged.getLocation());
if (!damagerProfile.isInAdminMode() && damagedClaim != null && damagedClaim.getFaction() instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) damagedClaim.getFaction();
if (!(systemFaction.isDeathban())) {
damager.sendMessage(langConfig.getString("FACTION_CLAIM.DAMAGED_IN_SAFEZONE").replace("%FACTION%", systemFaction.getName()).replace("%COLOR%", systemFaction.getColor() + ""));
event.setCancelled(true);
}
}
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.isInAdminMode()) {
return;
}
Claim claim = Claim.getProminentClaimAt(event.getBlock().getLocation());
if (claim != null) {
Faction faction = claim.getFaction();
if (faction instanceof PlayerFaction && ((PlayerFaction) faction).isRaidable()) {
return;
}
if(faction instanceof SystemFaction && faction.getName().equalsIgnoreCase("Warzone")) {
if(this.getSpawnLocation() != null && this.getSpawnLocation().distance(event.getBlock().getLocation()) >= 302) {
return;
}
}
if (!faction.equals(profile.getFaction())) {
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_SYSTEM").replace("%COLOR%", systemFaction.getColor() + "").replace("%FACTION%", systemFaction.getName()));
}
else {
if (faction instanceof PlayerFaction && profile.getFaction() != null && profile.getFaction().getAllies().contains(faction)) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ALLY").replace("%FACTION%", faction.getName()));
}
else {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ENEMY").replace("%FACTION%", faction.getName()));
}
}
event.setCancelled(true);
}
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.isInAdminMode()) {
return;
}
Claim claim = Claim.getProminentClaimAt(event.getBlock().getLocation());
if (claim != null) {
Faction faction = claim.getFaction();
if (faction instanceof PlayerFaction && ((PlayerFaction) faction).isRaidable()) {
return;
}
if(faction instanceof SystemFaction && faction.getName().equalsIgnoreCase("Warzone")) {
if(this.getSpawnLocation() != null && this.getSpawnLocation().distance(event.getBlock().getLocation()) >= 302) {
return;
}
}
if (!faction.equals(profile.getFaction())) {
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_SYSTEM").replace("%COLOR%", systemFaction.getColor() + "").replace("%FACTION%", systemFaction.getName()));
}
else {
if (faction instanceof PlayerFaction && profile.getFaction() != null && profile.getFaction().getAllies().contains(faction)) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ALLY").replace("%FACTION%", faction.getName()));
}
else {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ENEMY").replace("%FACTION%", faction.getName()));
}
}
event.setCancelled(true);
}
}
}
@EventHandler
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.isInAdminMode()) {
return;
}
Claim claim = Claim.getProminentClaimAt(event.getBlockClicked().getLocation());
if (claim != null) {
Faction faction = claim.getFaction();
if (faction instanceof PlayerFaction && ((PlayerFaction) faction).isRaidable()) {
return;
}
if(faction instanceof SystemFaction && faction.getName().equalsIgnoreCase("Warzone")) {
if(this.getSpawnLocation() != null && this.getSpawnLocation().distance(event.getBlockClicked().getLocation()) >= 302) {
return;
}
}
if (!faction.equals(profile.getFaction())) {
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_SYSTEM").replace("%COLOR%", systemFaction.getColor() + "").replace("%FACTION%", systemFaction.getName()));
}
else {
if (faction instanceof PlayerFaction && profile.getFaction() != null && profile.getFaction().getAllies().contains(faction)) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ALLY").replace("%FACTION%", faction.getName()));
}
else {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ENEMY").replace("%FACTION%", faction.getName()));
}
}
event.setCancelled(true);
}
}
}
@EventHandler
public void onBucketFill(PlayerBucketFillEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.isInAdminMode()) {
return;
}
Claim claim = Claim.getProminentClaimAt(event.getBlockClicked().getLocation());
if (claim != null) {
Faction faction = claim.getFaction();
if (faction instanceof PlayerFaction && ((PlayerFaction) faction).isRaidable()) {
return;
}
if(faction instanceof SystemFaction && faction.getName().equalsIgnoreCase("Warzone")) {
if(this.getSpawnLocation() != null && this.getSpawnLocation().distance(event.getBlockClicked().getLocation()) >= 302) {
return;
}
}
if (!faction.equals(profile.getFaction())) {
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_SYSTEM").replace("%COLOR%", systemFaction.getColor() + "").replace("%FACTION%", systemFaction.getName()));
}
else {
if (faction instanceof PlayerFaction && profile.getFaction() != null && profile.getFaction().getAllies().contains(faction)) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ALLY").replace("%FACTION%", faction.getName()));
}
else {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ENEMY").replace("%FACTION%", faction.getName()));
}
}
event.setCancelled(true);
}
}
}
@EventHandler
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (event.getRightClicked() instanceof Hanging) {
Entity entity = event.getRightClicked();
Claim claim = Claim.getProminentClaimAt(entity.getLocation());
if (claim != null) {
Faction faction = claim.getFaction();
if (profile.isInAdminMode()) {
return;
}
if(entity instanceof Sign) {
return;
}
if (faction instanceof PlayerFaction && ((PlayerFaction) faction).isRaidable()) {
return;
}
if(faction instanceof SystemFaction && faction.getName().equalsIgnoreCase("Warzone")) {
if(this.getSpawnLocation() != null && this.getSpawnLocation().distance(entity.getLocation()) >= 302) {
return;
}
}
if (profile.getFaction() == null || !faction.equals(profile.getFaction())) {
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_SYSTEM").replace("%COLOR%", systemFaction.getColor() + "").replace("%FACTION%", systemFaction.getName()));
}
else {
if (faction instanceof PlayerFaction && profile.getFaction() != null && profile.getFaction().getAllies().contains(faction)) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ALLY").replace("%FACTION%", faction.getName()));
}
else {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_BUILD_ENEMY").replace("%FACTION%", faction.getName()));
}
}
event.setCancelled(true);
}
}
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.isInAdminMode()) {
return;
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block block = event.getClickedBlock();
if (block.getState() instanceof ContainerBlock || block.getState().getData() instanceof Redstone || block.getState().getData() instanceof Openable) {
Claim claim = Claim.getProminentClaimAt(block.getLocation());
if (claim != null) {
Faction faction = claim.getFaction();
if (faction instanceof PlayerFaction && ((PlayerFaction) faction).isRaidable()) {
return;
}
if(faction instanceof SystemFaction && faction.getName().equalsIgnoreCase("Warzone")) {
if(this.getSpawnLocation() != null && this.getSpawnLocation().distance(block.getLocation()) >= 302) {
return;
}
}
if (!faction.equals(profile.getFaction())) {
if (faction instanceof SystemFaction) {
SystemFaction systemFaction = (SystemFaction) faction;
if(block.getType() != Material.TRAPPED_CHEST || block.getType() == Material.ENDER_CHEST) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_INTERACT_SYSTEM").replace("%COLOR%", systemFaction.getColor() + "").replace("%FACTION%", systemFaction.getName()));
}
}
else {
if (faction instanceof PlayerFaction && profile.getFaction() != null && profile.getFaction().getAllies().contains(faction)) {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_INTERACT_ALLY").replace("%FACTION%", faction.getName()));
}
else {
player.sendMessage(langConfig.getString("FACTION_CLAIM.CANNOT_INTERACT_ENEMY").replace("%FACTION%", faction.getName()));
}
}
event.setCancelled(true);
}
}
}
}
}
@EventHandler
public void onPhsycialInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.isInAdminMode()) {
return;
}
if (event.getAction() == Action.PHYSICAL) {
Block block = event.getClickedBlock();
Claim claim = Claim.getProminentClaimAt(block.getLocation());
if (claim != null) {
Faction faction = claim.getFaction();
if (faction instanceof PlayerFaction && ((PlayerFaction) faction).isRaidable()) {
return;
}
if(faction instanceof SystemFaction && faction.getName().equalsIgnoreCase("Warzone")) {
if(this.getSpawnLocation() != null && this.getSpawnLocation().distance(block.getLocation()) >= 302) {
return;
}
}
if (!faction.equals(profile.getFaction())) {
if (!(faction instanceof SystemFaction)) {
event.setCancelled(true);
}
else {
if (block.getType() == Material.SOIL) {
event.setCancelled(true);
}
}
}
}
}
}
@EventHandler
public void onInventoryInreact(InventoryMoveItemEvent event) {
if (event.getItem() == Faction.getWand()) {
event.setCancelled(true);
}
}
// @EventHandler
// public void onInventoryInreact(InventoryClickEvent event) {
// if (event.getInventory().contains(Faction.getWand())) {
// event.getInventory().remove(Faction.getWand());
// Player player = (Player) event.getWhoClicked();
// ClaimProfile profile = Profile.getByPlayer(player).getClaimProfile();
// if (profile != null) {
// for (ClaimPillar pillar : profile.getPillars()) {
// if (pillar != null) {
// pillar.remove();
// }
// }
// }
// }
// }
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL && event.getEntity() instanceof Monster) {
Claim claim = Claim.getProminentClaimAt(event.getLocation());
if (claim != null) {
if (claim.getFaction() instanceof SystemFaction) {
event.setCancelled(true);
}
}
}
}
private Location getSpawnLocation() {
SystemFaction faction = SystemFaction.getByName("Spawn");
if (faction != null && faction.getHome() != null) {
return LocationSerialization.deserializeLocation(faction.getHome());
}
return null;
}
}

View File

@ -0,0 +1,65 @@
package com.amberpvp.hcfactions.factions.claims;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.FactionsPlugin;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@Getter
public class ClaimPillar {
private static FactionsPlugin main = FactionsPlugin.getInstance();
private Player player;
private final Location originalLocation;
private Location location;
public ClaimPillar(Player player, Location location) {
this.location = location;
this.originalLocation = location.clone();
this.location.setY(0);
this.player = player;
}
public ClaimPillar show(Material material, int data) {
Location loc = new Location(originalLocation.getWorld(), originalLocation.getX(), 0, originalLocation.getZ());
int pos = 0;
for (int i = 0; i < loc.getWorld().getMaxHeight(); i++) {
if (pos == 5) {
if (loc.getBlock().isEmpty()) {
player.sendBlockChange(loc, material, (byte) data);
}
pos = 0;
}
else {
if (loc.getBlock().isEmpty()) {
player.sendBlockChange(loc, Material.GLASS, (byte) 0);
}
}
pos += 1;
loc.add(0, 1, 0);
}
return this;
}
public ClaimPillar remove() {
Location loc = new Location(originalLocation.getWorld(), originalLocation.getX(), 0, originalLocation.getZ());
for (int i = 0; i < loc.getWorld().getMaxHeight(); i++) {
if (loc.getBlock().isEmpty()) {
player.sendBlockChange(loc, Material.AIR, (byte) 0);
}
loc.add(0, 1, 0);
}
return this;
}
}

View File

@ -0,0 +1,38 @@
package com.amberpvp.hcfactions.factions.claims;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.profile.Profile;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.entity.Player;
@Getter
@Setter
public class ClaimProfile {
private Player player;
private Profile profile;
private Faction faction;
private boolean resetClicked;
private ClaimPillar[] pillars;
public ClaimProfile(Player player, Faction faction) {
this.player = player;
this.faction = faction;
this.pillars = new ClaimPillar[2];
this.profile = Profile.getByPlayer(player);
this.profile.setClaimProfile(this);
}
public void removePillars() {
for (ClaimPillar claimPillar : pillars) {
if (claimPillar != null) {
claimPillar.remove();
}
}
this.pillars = new ClaimPillar[2];
}
}

View File

@ -0,0 +1,251 @@
package com.amberpvp.hcfactions.factions.claims;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.claimwall.ClaimWallType;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import com.amberpvp.hcfactions.files.ConfigFile;
import com.amberpvp.hcfactions.misc.listeners.BorderListener;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.LocationSerialization;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.claimwall.ClaimWallType;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.events.player.PlayerCancelFactionTeleportEvent;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import com.amberpvp.hcfactions.files.ConfigFile;
import com.amberpvp.hcfactions.misc.listeners.BorderListener;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldownType;
import com.amberpvp.hcfactions.profile.teleport.ProfileTeleportType;
import com.amberpvp.hcfactions.util.LocationSerialization;
import me.joeleoli.ragespigot.handler.MovementHandler;
import net.minecraft.server.v1_8_R3.PacketPlayInFlying;
import org.bukkit.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
public class CustomMovementHandler implements MovementHandler {
private final FactionsPlugin plugin = FactionsPlugin.getInstance();
private ConfigFile mainConfig = plugin.getMainConfig();
private ConfigFile langConfig = plugin.getLanguageConfig();
@Override
public void handleUpdateLocation(Player p, Location to, Location from, PacketPlayInFlying packetPlayInFlying) {
Profile profile = Profile.getByPlayer(p);
if (from.getBlockX() != to.getBlockX() || from.getBlockY() != to.getBlockY() || from.getBlockZ() != to.getBlockZ()) {
if (profile.getTeleportWarmup() != null) {
if (profile.getTeleportWarmup().getEvent().getTeleportType() == ProfileTeleportType.HOME_TELEPORT) {
profile.getTeleportWarmup().getEvent().setCancelled(true);
Bukkit.getPluginManager().callEvent(new PlayerCancelFactionTeleportEvent(p, null, ProfileTeleportType.HOME_TELEPORT));
profile.setTeleportWarmup(null);
p.sendMessage(langConfig.getString("ERROR.TELEPORT_CANCELLED"));
} else {
if (p.getLocation().distance(profile.getTeleportWarmup().getEvent().getInitialLocation()) >= mainConfig.getInt("TELEPORT_COUNTDOWN.STUCK.DISTANCE")) {
profile.getTeleportWarmup().getEvent().setCancelled(true);
Bukkit.getPluginManager().callEvent(new PlayerCancelFactionTeleportEvent(p, profile.getTeleportWarmup().getEvent().getFaction(), ProfileTeleportType.STUCK_TELEPORT));
profile.setTeleportWarmup(null);
p.sendMessage(langConfig.getString("ERROR.TELEPORT_CANCELLED"));
}
}
}
}
if (profile.getCooldownByType(ProfileCooldownType.LOGOUT) != null && profile.getLogoutLocation() != null) {
if (from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ() || from.getBlockY() != to.getBlockY()) {
if (to.distance(profile.getLogoutLocation()) > mainConfig.getInt("COMBAT_LOGGER.LOGOUT_CANCEL_RANGE")) {
p.sendMessage(langConfig.getString("COMBAT_LOGGER.LOGOUT_CANCELLED"));
profile.getCooldowns().remove(profile.getCooldownByType(ProfileCooldownType.LOGOUT));
profile.setLogoutLocation(null);
}
}
}
if (profile.getCooldownByType(ProfileCooldownType.SPAWN_TAG) != null) {
Claim entering = Claim.getProminentClaimAt(to);
Claim leaving = Claim.getProminentClaimAt(from);
if (entering != null && (leaving == null || !leaving.equals(entering))) {
if (ClaimWallType.SPAWN_TAG.isValid(entering)) {
p.teleport(from);
p.setSprinting(false);
if (p.getVehicle() != null) {
p.getVehicle().eject();
}
p.setVelocity(new Vector());
}
}
}
if (profile.getProtection() != null) {
Claim entering = Claim.getProminentClaimAt(to);
Claim leaving = Claim.getProminentClaimAt(from);
if (entering != null && (leaving == null || !leaving.equals(entering))) {
if (ClaimWallType.PVP_PROTECTION.isValid(entering)) {
p.teleport(from);
if (p.getVehicle() != null) {
p.getVehicle().eject();
}
p.setSprinting(false);
p.setVelocity(new Vector());
}
}
}
if (!BorderListener.isWithinBorder(to) && BorderListener.isWithinBorder(from)) {
if (from.getBlockX() == to.getBlockX() && from.getBlockZ() == to.getBlockZ()) {
return;
}
p.sendMessage(ChatColor.RED + "You can't go past the border.");
p.teleport(from);
final Entity vehicle = p.getVehicle();
if (vehicle != null) {
vehicle.eject();
vehicle.teleport(from);
vehicle.setPassenger(p);
}
}
if (p.getWorld().getEnvironment() == World.Environment.THE_END) {
if ((from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ() || from.getBlockY() != to.getBlockY()) && to.getBlock() != null && from.getWorld().getEnvironment() == World.Environment.THE_END) {
final Material type = p.getWorld().getBlockAt(p.getLocation()).getType();
if (type == Material.STATIONARY_WATER || type == Material.WATER) {
Faction faction = Faction.getByName("South Road");
if (faction != null && faction instanceof SystemFaction) {
if (faction.getHome() == null) {
p.sendMessage(FactionsPlugin.getInstance().getLanguageConfig().getString("ERROR.HOME_NOT_SET"));
return;
}
Location location = LocationSerialization.deserializeLocation(faction.getHome());
if (location != null) {
p.teleport(location);
}
}
}
}
}
if (to.getX() != from.getX() || to.getZ() != from.getZ()) {
final Claim claim = Claim.getProminentClaimAt(to);
if (claim != null) {
if (claim.isInside(to)) {
if (profile.getLastInside() == null) {
profile.setLastInside(claim);
p.sendMessage(langConfig.getString("FACTION_CLAIM.LEAVE.WILDERNESS"));
p.sendMessage(getEnteringMessage(profile, claim));
return;
}
if (profile.getLastInside().getFaction() != claim.getFaction()) {
if (profile.getLastInside().isInside(to) && !profile.getLastInside().isGreaterThan(claim)) {
return;
}
p.sendMessage(getLeavingMessage(profile, profile.getLastInside()));
p.sendMessage(getEnteringMessage(profile, claim));
}
profile.setLastInside(claim);
} else {
if (profile.getLastInside() != null && profile.getLastInside() == claim) {
new BukkitRunnable() {
@Override
public void run() {
if (profile.getLastInside() != null && profile.getLastInside() == claim) {
p.sendMessage(getLeavingMessage(profile, claim));
p.sendMessage(langConfig.getString("FACTION_CLAIM.ENTER.WILDERNESS"));
profile.setLastInside(null);
}
}
}.runTaskLater(plugin, 1L);
}
}
} else {
if (profile.getLastInside() != null) {
p.sendMessage(getLeavingMessage(profile, profile.getLastInside()));
p.sendMessage(langConfig.getString("FACTION_CLAIM.ENTER.WILDERNESS"));
profile.setLastInside(profile.getLastInside());
profile.setLastInside(null);
}
}
}
}
@Override
public void handleUpdateRotation(Player player, Location location, Location location1, PacketPlayInFlying packetPlayInFlying) {
}
private String getLeavingMessage(Profile profile, Claim inside) {
if (profile.getFaction() != null && profile.getFaction() == inside.getFaction()) {
return langConfig.getString("FACTION_CLAIM.LEAVE.FRIENDLY").replace("%FACTION%", inside.getFaction().getName());
} else if (profile.getFaction() != null && inside.getFaction() instanceof PlayerFaction && profile.getFaction().getAllies().contains(inside.getFaction())) {
return langConfig.getString("FACTION_CLAIM.LEAVE.ALLY").replace("%FACTION%", inside.getFaction().getName());
} else if (!(inside.getFaction() instanceof PlayerFaction)) {
SystemFaction systemFaction = (SystemFaction) inside.getFaction();
if (systemFaction.isDeathban()) {
return langConfig.getString("FACTION_CLAIM.LEAVE.SYSTEM_FACTION_DEATHBAN").replace("%FACTION%", systemFaction.getName()).replace("%COLOR%", systemFaction.getColor() + "");
} else {
return langConfig.getString("FACTION_CLAIM.LEAVE.SYSTEM_FACTION_NON-DEATHBAN").replace("%FACTION%", systemFaction.getName()).replace("%COLOR%", systemFaction.getColor() + "");
}
} else {
return langConfig.getString("FACTION_CLAIM.LEAVE.ENEMY").replace("%FACTION%", inside.getFaction().getName());
}
}
private String getEnteringMessage(Profile profile, Claim inside) {
if (profile.getFaction() != null && profile.getFaction() == inside.getFaction()) {
return langConfig.getString("FACTION_CLAIM.ENTER.FRIENDLY").replace("%FACTION%", inside.getFaction().getName());
} else if (profile.getFaction() != null && inside.getFaction() instanceof PlayerFaction && profile.getFaction().getAllies().contains(inside.getFaction())) {
return langConfig.getString("FACTION_CLAIM.ENTER.ALLY").replace("%FACTION%", inside.getFaction().getName());
} else if (!(inside.getFaction() instanceof PlayerFaction)) {
SystemFaction systemFaction = (SystemFaction) inside.getFaction();
if (systemFaction.isDeathban()) {
return langConfig.getString("FACTION_CLAIM.ENTER.SYSTEM_FACTION_DEATHBAN").replace("%FACTION%", systemFaction.getName()).replace("%COLOR%", systemFaction.getColor() + "");
} else {
Player player = Bukkit.getPlayer(profile.getUuid());
if (player != null) {
player.setHealth(player.getMaxHealth());
player.setFoodLevel(20);
player.setFireTicks(0);
player.setSaturation(4.0F);
}
return langConfig.getString("FACTION_CLAIM.ENTER.SYSTEM_FACTION_NON-DEATHBAN").replace("%FACTION%", systemFaction.getName()).replace("%COLOR%", systemFaction.getColor() + "");
}
} else {
return langConfig.getString("FACTION_CLAIM.ENTER.ENEMY").replace("%FACTION%", inside.getFaction().getName());
}
}
}

View File

@ -0,0 +1,178 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.ProfileChatType;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.ProfileChatType;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionChatCommand extends FactionCommand implements Listener {
public FactionChatCommand() {
Bukkit.getPluginManager().registerEvents(this, main);
}
@Command(name = "f.c", aliases = {"faction.c", "factions.c", "factions.chat", "f.chat", "faction.chat"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
String[] args = command.getArgs();
List<String> chatTypes = new ArrayList<>(Arrays.asList(
"a", "ally", "f", "faction", "p", "public"
));
Profile profile = Profile.getByPlayer(player);
if (args.length == 0 || (!chatTypes.contains(args[0]))) {
ProfileChatType toToggle = getToToggle(profile);
if (toToggle != ProfileChatType.PUBLIC && profile.getFaction() == null) {
player.sendMessage(langConfig.getString("ERROR.MUST_BE_IN_FACTION_FOR_CHAT_TYPE"));
return;
}
setChatType(player, toToggle);
return;
}
String arg = args[0];
if (arg.equalsIgnoreCase("public") || arg.equalsIgnoreCase("p")) {
setChatType(player, ProfileChatType.PUBLIC);
return;
}
if (profile.getFaction() == null) {
player.sendMessage(langConfig.getString("ERROR.MUST_BE_IN_FACTION_FOR_CHAT_TYPE"));
return;
}
if (arg.equalsIgnoreCase("a") || arg.equalsIgnoreCase("ally") || arg.equalsIgnoreCase("alliance")) {
setChatType(player, ProfileChatType.ALLY);
return;
}
if (arg.equalsIgnoreCase("f") || arg.equalsIgnoreCase("faction")) {
setChatType(player, ProfileChatType.FACTION);
}
}
private ProfileChatType getToToggle(Profile profile) {
if (profile.getFaction() == null && profile.getChatType() != ProfileChatType.PUBLIC) {
return ProfileChatType.PUBLIC;
}
switch (profile.getChatType()) {
case FACTION:
return ProfileChatType.ALLY;
case ALLY:
return ProfileChatType.PUBLIC;
case PUBLIC:
return ProfileChatType.FACTION;
}
return null;
}
private void setChatType(Player player, ProfileChatType type) {
final String ROOT = "FACTION_OTHER.CHAT_CHANGED.";
Profile profile = Profile.getByPlayer(player);
profile.setChatType(type);
switch (type) {
case PUBLIC: {
player.sendMessage(langConfig.getString(ROOT + "PUBLIC"));
break;
}
case FACTION: {
player.sendMessage(langConfig.getString(ROOT + "FACTION"));
break;
}
case ALLY: {
player.sendMessage(langConfig.getString(ROOT + "ALLY"));
break;
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getByPlayer(player);
PlayerFaction playerFaction = profile.getFaction();
if (event.getMessage().startsWith("!") && event.getMessage().length() > 1) {
event.setMessage(event.getMessage().substring(1, event.getMessage().length()));
return;
}
if (event.getMessage().startsWith("@") && event.getMessage().length() > 1) {
event.setCancelled(true);
if (playerFaction == null) {
player.sendMessage(langConfig.getString("ERROR.MUST_BE_IN_FACTION_FOR_CHAT_TYPE"));
return;
}
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_FACTION_CHAT").replace("%PLAYER%", player.getName()).replace("%MESSAGE%", event.getMessage().substring(1, event.getMessage().length())).replace("%FACTION%", playerFaction.getName()));
return;
}
if (event.getMessage().startsWith("#") && event.getMessage().length() > 1) {
event.setCancelled(true);
if (playerFaction == null) {
player.sendMessage(langConfig.getString("ERROR.MUST_BE_IN_FACTION_FOR_CHAT_TYPE"));
return;
}
String message = langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_ALLY_CHAT").replace("%PLAYER%", player.getName()).replace("%MESSAGE%", event.getMessage().substring(1, event.getMessage().length())).replace("%FACTION%", playerFaction.getName());
playerFaction.sendMessage(message);
for (PlayerFaction allyFaction : playerFaction.getAllies()) {
allyFaction.sendMessage(message);
}
}
boolean inFactionChat = profile.getChatType() == ProfileChatType.FACTION;
if (inFactionChat || profile.getChatType() == ProfileChatType.ALLY) {
event.setCancelled(true);
if (playerFaction == null) {
player.sendMessage(langConfig.getString("ERROR.MUST_BE_IN_FACTION_FOR_CHAT_TYPE"));
return;
}
if (inFactionChat) {
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_FACTION_CHAT").replace("%PLAYER%", player.getName()).replace("%MESSAGE%", event.getMessage()).replace("%FACTION%", playerFaction.getName()));
} else {
String message = langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_ALLY_CHAT").replace("%PLAYER%", player.getName()).replace("%MESSAGE%", event.getMessage()).replace("%FACTION%", playerFaction.getName());
playerFaction.sendMessage(message);
for (PlayerFaction allyFaction : playerFaction.getAllies()) {
allyFaction.sendMessage(message);
}
}
}
}
}

View File

@ -0,0 +1,18 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.files.ConfigFile;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.files.ConfigFile;
public class FactionCommand {
public FactionsPlugin main = FactionsPlugin.getInstance();
public ConfigFile langConfig = main.getLanguageConfig();
public ConfigFile mainConfig = main.getMainConfig();
public FactionCommand() {
main.getFramework().registerCommands(this);
}
}

View File

@ -0,0 +1,93 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.factions.events.player.PlayerCreateFactionEvent;
import com.amberpvp.hcfactions.mode.Mode;
import com.amberpvp.hcfactions.mode.ModeType;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.events.player.PlayerCreateFactionEvent;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.mode.Mode;
import com.amberpvp.hcfactions.mode.ModeType;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionCreateCommand extends FactionCommand {
@Command(name = "f.create", aliases = {"faction.create", "factions.create"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
String[] args = command.getArgs();
for(Mode mode : Mode.getModes()) {
if(mode.getModeType() == ModeType.EOTW && mode.isActive()) {
player.sendMessage(langConfig.getString("ERROR.EOTW_FACTION_CREATE"));
return;
}
}
if (args.length == 0) {
player.sendMessage(langConfig.getString("TOO_FEW_ARGS.CREATE"));
return;
}
Profile profile = Profile.getByPlayer(player);
if (profile.getFaction() != null) {
player.sendMessage(langConfig.getString("ERROR.ALREADY_IN_FACTION"));
return;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < args.length; i++) {
sb.append(command.getArgs()[i]).append(" ");
}
String name = sb.toString().trim().replace(" ", "");
if (name.length() < mainConfig.getInt("FACTION_NAME.MIN_CHARACTERS")) {
player.sendMessage(langConfig.getString("ERROR.TAG_TOO_SHORT"));
return;
}
if (name.length() > mainConfig.getInt("FACTION_NAME.MAX_CHARACTERS")) {
player.sendMessage(langConfig.getString("ERROR.TAG_TOO_LONG"));
return;
}
if (!(StringUtils.isAlphanumeric(name))) {
player.sendMessage(langConfig.getString("ERROR.NOT_ALPHANUMERIC"));
return;
}
for (String string : mainConfig.getStringList("FACTION_NAME.BLOCKED_NAMES")) {
if (name.contains(string)) {
player.sendMessage(langConfig.getString("ERROR.BLOCKED_NAME"));
return;
}
}
if (Faction.getByName(name) != null) {
player.sendMessage(langConfig.getString("ERROR.NAME_TAKEN"));
return;
}
PlayerFaction playerFaction = new PlayerFaction(name, player.getUniqueId(), null);
profile.setFaction(playerFaction);
Bukkit.broadcastMessage(langConfig.getString("ANNOUNCEMENTS.FACTION_CREATED").replace("%PLAYER%", player.getDisplayName()).replace("%NAME%", name));
Bukkit.getPluginManager().callEvent(new PlayerCreateFactionEvent(player, playerFaction));
}
}

View File

@ -0,0 +1,61 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.entity.Player;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionDepositCommand extends FactionCommand {
@Command(name = "f.deposit", aliases = {"faction.deposit", "factions.deposit", "f.d", "faction.d", "factions.d"}, inFactionOnly = true)
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
String[] args = command.getArgs();
if (args.length == 0) {
player.sendMessage(langConfig.getString("TOO_FEW_ARGS.DEPOSIT"));
return;
}
Profile profile = Profile.getByPlayer(player);
int amount;
if (args[0].equalsIgnoreCase("all") || args[0].equalsIgnoreCase("a")) {
amount = (int) Math.floor(profile.getBalance());
} else {
if (!(NumberUtils.isNumber(args[0]))) {
player.sendMessage(langConfig.getString("ERROR.INVALID_NUMBER").replace("%STRING%", args[0]));
return;
}
amount = (int) Math.floor(Double.valueOf(args[0]));
if (amount > profile.getBalance()) {
player.sendMessage(langConfig.getString("ERROR.NOT_ENOUGH_MONEY"));
return;
}
}
if (amount <= 0) {
player.sendMessage(langConfig.getString("ERROR.INVALID_DEPOSIT_AMOUNT"));
return;
}
profile.setBalance(profile.getBalance() - amount);
PlayerFaction playerFaction = profile.getFaction();
playerFaction.setBalance(playerFaction.getBalance() + amount);
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_DEPOSIT_MONEY").replace("%PLAYER%", player.getName()).replace("%AMOUNT%", amount + ""));
}
}

View File

@ -0,0 +1,45 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.apache.commons.lang.math.NumberUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionHelpCommand extends FactionCommand {
@Command(name = "f", aliases = {"faction", "factions"}, inGameOnly = false, description = "Base command for all faction-related functions.")
public void onCommand(CommandArgs command) {
String[] args = command.getArgs();
List<List<String>> help = new ArrayList<>();
for (String key : langConfig.getConfiguration().getConfigurationSection("FACTION_HELP").getKeys(false)) {
help.add(langConfig.getStringList("FACTION_HELP." + key));
}
if (args.length == 2) {
if (args[0].equalsIgnoreCase("help")) {
if (NumberUtils.isNumber(args[1])) {
int page = (int) Double.parseDouble(args[1]);
if (page > 0 && page <= help.size()) {
for (String msg : help.get(page - 1)) {
command.getSender().sendMessage(msg);
}
return;
}
}
}
}
for (String msg : help.get(0)) {
command.getSender().sendMessage(msg);
}
}
}

View File

@ -0,0 +1,152 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.factions.events.player.PlayerInitiateFactionTeleportEvent;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.LocationSerialization;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.events.player.PlayerInitiateFactionTeleportEvent;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldown;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldownListeners;
import com.amberpvp.hcfactions.profile.cooldown.ProfileCooldownType;
import com.amberpvp.hcfactions.profile.teleport.ProfileTeleportTask;
import com.amberpvp.hcfactions.profile.teleport.ProfileTeleportType;
import com.amberpvp.hcfactions.util.LocationSerialization;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.concurrent.TimeUnit;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionHomeCommand extends FactionCommand {
@Command(name = "f.home", aliases = {"faction.home", "factions.home", "f.hq", "faction.hq", "factions.hq"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.getTeleportWarmup() != null) {
return;
}
Faction faction;
if (command.getArgs().length >= 1) {
String name = command.getArgs(0);
Faction faction1 = PlayerFaction.getAnyByString(name);
if (faction1 != null) {
faction = faction1;
} else {
player.sendMessage(langConfig.getString("ERROR.NO_FACTIONS_FOUND").replace("%NAME%", name));
return;
}
} else {
faction = profile.getFaction();
if (faction == null) {
player.sendMessage(langConfig.getString("ERROR.NOT_IN_FACTION"));
return;
}
}
if (faction.getHome() == null) {
player.sendMessage(langConfig.getString("ERROR.HOME_NOT_SET"));
return;
}
Location location = LocationSerialization.deserializeLocation(faction.getHome());
Claim claim = Claim.getProminentClaimAt(player.getLocation());
if (claim != null && claim.getFaction() instanceof SystemFaction && !((SystemFaction) claim.getFaction()).isDeathban()) {
player.teleport(LocationSerialization.deserializeLocation(faction.getHome()));
return;
}
if (command.getArgs().length >= 1) {
player.teleport(LocationSerialization.deserializeLocation(faction.getHome()));
} else {
if(claim != null && (claim.getFaction() instanceof PlayerFaction && (claim.getFaction() != faction) && mainConfig.getBoolean("FACTION_GENERAL.FACTION_HOME_IN_ENEMY_TERRITORY"))) {
player.sendMessage(langConfig.getString("ERROR.NO_HOME_ENEMY"));
return;
}
if (profile.getProtection() != null) {
player.sendMessage(langConfig.getString("ERROR.NO_HOME_PVP_PROTECTION"));
return;
}
if (profile.getCooldownByType(ProfileCooldownType.SPAWN_TAG) != null) {
player.sendMessage(ChatColor.RED + "You can't do this whist in combat!");
return;
}
int time = 0;
String worldName = player.getLocation().getWorld().getName();
String root = "TELEPORT_COUNTDOWN.HOME";
for (String world : new String[]{"OVERWORLD", "NETHER", "END"}) {
if (worldName.equalsIgnoreCase(mainConfig.getString(world))) {
if (!mainConfig.getBoolean(root + "." + world + ".ENABLED")) {
player.sendMessage(langConfig.getString("ERROR.NO_HOME_TELEPORT_IN_WORLD"));
return;
} else {
time = mainConfig.getInt(root + "." + world + ".TIME");
}
}
}
long hours = TimeUnit.SECONDS.toHours(time);
long minutes = TimeUnit.SECONDS.toMinutes(time) - (hours * 60);
long seconds = TimeUnit.SECONDS.toSeconds(time) - ((hours * 60 * 60) + (minutes * 60));
String formatted;
if (hours == 0 && minutes > 0 && seconds > 0) {
formatted = minutes + " minutes and " + seconds + " seconds";
} else if (hours == 0 && minutes > 0 && seconds == 0) {
formatted = minutes + " minutes";
} else if (hours == 0 && minutes == 0 && seconds > 0) {
formatted = seconds + " seconds";
} else if (hours > 0 && minutes > 0 && seconds == 0) {
formatted = hours + " hours and " + minutes + " minutes";
} else if (hours > 0 && minutes == 0 && seconds > 0) {
formatted = hours + " hours and " + seconds + " seconds";
} else {
formatted = hours + "hours, " + minutes + " minutes and " + seconds + " seconds";
}
if (hours == 1) {
formatted = formatted.replace("hours", "hour");
}
if (minutes == 1) {
formatted = formatted.replace("minutes", "minute");
}
if (seconds == 1) {
formatted = formatted.replace("seconds", "second");
}
player.sendMessage(langConfig.getString("FACTION_OTHER.TELEPORTING_TO_HOME").replace("%TIME%", formatted + ""));
profile.setTeleportWarmup(new ProfileTeleportTask(new PlayerInitiateFactionTeleportEvent(player, profile.getFaction(), ProfileTeleportType.HOME_TELEPORT, time, location, player.getLocation())));
profile.getTeleportWarmup().runTaskLaterAsynchronously(main, (long) (time * 20));
}
}
}

View File

@ -0,0 +1,67 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.UUID;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionInvitesCommand extends FactionCommand {
@Command(name = "f.invites", aliases = {"faction.invites", "factions.invites"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
String invites = "";
HashSet<PlayerFaction> factionsInvitedTo = new HashSet<>();
Profile profile = Profile.getByPlayer(player);
for (PlayerFaction playerFaction : PlayerFaction.getPlayerFactions()) {
if (playerFaction.getInvitedPlayers().containsKey(player.getUniqueId())) {
factionsInvitedTo.add(playerFaction);
}
}
String splitter = langConfig.getString("FACTION_OTHER.INVITES.SPLITTER");
if (factionsInvitedTo.isEmpty()) {
invites = langConfig.getString("FACTION_OTHER.INVITES.PLAYER_INVITES_PLACEHOLDER");
} else {
for (PlayerFaction playerFaction : factionsInvitedTo) {
invites = playerFaction.getName() + splitter;
}
invites = invites.substring(0, invites.lastIndexOf(splitter));
}
player.sendMessage(langConfig.getString("FACTION_OTHER.INVITES.PLAYER_INVITES").replace("%INVITES%", invites));
if (profile.getFaction() != null) {
PlayerFaction playerFaction = profile.getFaction();
if (!playerFaction.getInvitedPlayers().isEmpty()) {
String invitedPlayers = "";
for (UUID invitedPlayer : playerFaction.getInvitedPlayers().keySet()) {
SimpleOfflinePlayer offlinePlayer = SimpleOfflinePlayer.getByUuid(invitedPlayer);
if (offlinePlayer != null) {
invitedPlayers = invitedPlayers + offlinePlayer.getName() + splitter;
}
}
invitedPlayers = invitedPlayers.substring(0, invitedPlayers.lastIndexOf(splitter));
player.sendMessage(langConfig.getString("FACTION_OTHER.INVITES.FACTION_INVITES").replace("%INVITES%", invitedPlayers)); //TODO ADD /F WHO
}
}
}
}

View File

@ -0,0 +1,68 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.events.player.PlayerJoinFactionEvent;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionJoinCommand extends FactionCommand {
@Command(name = "f.join", aliases = {"faction.join", "factions.join", "f.accept", "factions.accept", "faction.accept"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
if (command.getArgs().length == 0) {
player.sendMessage(langConfig.getString("TOO_FEW_ARGS.JOIN"));
return;
}
Profile profile = Profile.getByPlayer(player);
if (profile.getFaction() != null) {
player.sendMessage(langConfig.getString("ERROR.ALREADY_IN_FACTION"));
return;
}
String factionName = command.getArgs(0);
Faction faction = Faction.getByName(factionName);
PlayerFaction playerFaction = null;
if (faction instanceof PlayerFaction) {
playerFaction = (PlayerFaction) faction;
}
if (faction == null || (!(faction instanceof PlayerFaction) || (!(playerFaction.getInvitedPlayers().containsKey(player.getUniqueId()))))) {
playerFaction = PlayerFaction.getByPlayerName(factionName);
if (playerFaction == null || !(playerFaction.getInvitedPlayers().containsKey(player.getUniqueId()))) {
player.sendMessage(langConfig.getString("ERROR.NOT_INVITED"));
return;
}
}
if (playerFaction.getAllPlayerUuids().size() >= mainConfig.getInt("FACTION_GENERAL.MAX_PLAYERS")) {
player.sendMessage(langConfig.getString("ERROR.MAX_PLAYERS").replace("%FACTION%", playerFaction.getName()));
return;
}
player.sendMessage(langConfig.getString("FACTION_OTHER.JOINED").replace("%FACTION%", playerFaction.getName()));
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_JOINED").replace("%PLAYER%", player.getName()));
playerFaction.getInvitedPlayers().remove(player.getUniqueId());
playerFaction.getMembers().add(player.getUniqueId());
profile.setFaction(playerFaction);
Bukkit.getPluginManager().callEvent(new PlayerJoinFactionEvent(player, playerFaction));
}
}

View File

@ -0,0 +1,43 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.events.player.PlayerLeaveFactionEvent;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionLeaveCommand extends FactionCommand {
@Command(name = "f.leave", aliases = {"faction.leave", "factions.leave", "f.quit", "factions.quit", "faction.quit"}, inFactionOnly = true)
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
Profile profile = Profile.getByPlayer(player);
PlayerFaction playerFaction = profile.getFaction();
if (playerFaction.getLeader().equals(player.getUniqueId())) {
player.sendMessage(langConfig.getString("ERROR.CANT_LEAVE_WHEN_LEADER"));
return;
}
player.sendMessage(langConfig.getString("FACTION_OTHER.LEFT").replace("%FACTION%", playerFaction.getName()));
playerFaction.getMembers().remove(player.getUniqueId());
playerFaction.getOfficers().remove(player.getUniqueId());
profile.setFaction(null);
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_LEFT").replace("%PLAYER%", player.getName()));
Bukkit.getPluginManager().callEvent(new PlayerLeaveFactionEvent(player, playerFaction));
}
}

View File

@ -0,0 +1,88 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.util.Clickable;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.util.Clickable;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.command.CommandSender;
import java.util.*;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionListCommand extends FactionCommand {
@Command(name = "f.list", aliases = {"faction.list", "factions.list"}, inGameOnly = false)
public void onCommand(CommandArgs command) {
String[] args = command.getArgs();
CommandSender sender = command.getSender();
final HashMap<PlayerFaction, Integer> factions = new HashMap<>();
int page = 1;
for (PlayerFaction playerFaction : PlayerFaction.getPlayerFactions()) {
if (playerFaction.getOnlinePlayers().size() > 0) {
factions.put(playerFaction, playerFaction.getOnlinePlayers().size());
}
}
List<PlayerFaction> sortedList = new ArrayList<>(factions.keySet());
Collections.sort(sortedList, new Comparator<PlayerFaction>() {
@Override
public int compare(PlayerFaction firstFaction, PlayerFaction secondFaction) {
return factions.get(secondFaction).compareTo(factions.get(firstFaction));
}
});
if (args.length == 2) {
if (args[0].equalsIgnoreCase("list")) {
if (NumberUtils.isNumber(args[1])) {
page = (int) Double.parseDouble(args[1]);
}
}
}
if (sortedList.isEmpty()) {
sender.sendMessage(langConfig.getString("ERROR.NO_FACTIONS_TO_LIST"));
return;
}
int listSize = Math.round(sortedList.size() / 10);
if (listSize == 0) {
listSize = 1;
}
if (page > listSize) {
page = listSize;
}
for (String msg : langConfig.getStringList("FACTION_LIST")) {
if (msg.contains("%FACTION%")) {
for (int i = page * 10 - 10; i < page * 10; i++) {
if (sortedList.size() > i) {
PlayerFaction playerFaction = sortedList.get(i);
Clickable clickable = new Clickable(msg.replace("%FACTION%", playerFaction.getName()).replace("%DTR%", playerFaction.getDeathsTillRaidable() + "").replace("%MAX_DTR%", playerFaction.getMaxDeathsTillRaidable() + "").replace("%BALANCE%", playerFaction.getBalance() + "").replace("%ONLINE_COUNT%", playerFaction.getOnlinePlayers().size() + "").replace("%MAX_COUNT%", playerFaction.getAllPlayerUuids().size() + "").replace("%POSITION%", (i + 1) + ""),
ChatColor.GRAY + "Click to view faction information",
"/f show " + playerFaction.getName());
if(sender instanceof Player) {
clickable.sendToPlayer((Player) sender);
}
}
}
} else {
sender.sendMessage(msg.replace("%PAGE%", page + "").replace("%TOTAL_PAGES%", listSize + ""));
}
}
}
}

View File

@ -0,0 +1,141 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.claims.ClaimPillar;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.*;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionMapCommand extends FactionCommand {
@Command(name = "f.map", aliases = {"faction.map", "factions.map"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.isViewingMap()) {
for (ClaimPillar claimPillar : profile.getMapPillars()) {
claimPillar.remove();
}
profile.getMapPillars().clear();
player.sendMessage(langConfig.getString("FACTION_MAP.MAP_REMOVED"));
profile.setViewingMap(false);
return;
}
Set<Claim> toDisplay = new HashSet<>();
int[] pos = new int[]{player.getLocation().getBlockX(), player.getLocation().getBlockZ()};
for (int x = pos[0] - 64; x < pos[0] + 64; x++) {
for (int z = pos[1] - 64; z < pos[1] + 64; z++) {
Location location = new Location(player.getWorld(), x, 0, z);
ArrayList<Claim> claims = Claim.getClaimsAt(location);
if (claims != null) {
for (Claim claim : claims) {
if (claim.getWorldName().equalsIgnoreCase(location.getWorld().getName())) {
toDisplay.add(claim);
}
}
}
}
}
if (toDisplay.isEmpty()) {
player.sendMessage(langConfig.getString("ERROR.NO_CLAIMS_NEARBY"));
return;
}
Map<Faction, Material> shown = new HashMap<>();
for (Claim claim : toDisplay) {
Faction faction = claim.getFaction();
Material material;
if (faction == profile.getFaction()) {
if (mainConfig.getString("FACTION_MAP.PILLAR.FRIENDLY").equalsIgnoreCase("RANDOM")) {
material = Claim.getMapBlocks().get(new Random().nextInt(Claim.getMapBlocks().size()));
} else {
material = Material.valueOf(mainConfig.getString("FACTION_MAP.PILLAR.FRIENDLY"));
}
} else if (profile.getFaction() != null && faction instanceof PlayerFaction && profile.getFaction().getAllies().contains(faction)) {
if (mainConfig.getString("FACTION_MAP.PILLAR.ALLY").equalsIgnoreCase("RANDOM")) {
material = Claim.getMapBlocks().get(new Random().nextInt(Claim.getMapBlocks().size()));
} else {
material = Material.valueOf(mainConfig.getString("FACTION_MAP.PILLAR.ALLY"));
}
} else if (!(faction instanceof PlayerFaction)) {
SystemFaction systemFaction = (SystemFaction) faction;
if (systemFaction.isDeathban()) {
if (mainConfig.getString("FACTION_MAP.PILLAR.SYSTEM_FACTION.DEATHBAN").equalsIgnoreCase("RANDOM")) {
material = Claim.getMapBlocks().get(new Random().nextInt(Claim.getMapBlocks().size()));
} else {
material = Material.valueOf(mainConfig.getString("FACTION_MAP.PILLAR.SYSTEM_FACTION.DEATHBAN"));
}
} else {
if (mainConfig.getString("FACTION_MAP.PILLAR.SYSTEM_FACTION.NON-DEATHBAN").equalsIgnoreCase("RANDOM")) {
material = Claim.getMapBlocks().get(new Random().nextInt(Claim.getMapBlocks().size()));
} else {
material = Material.valueOf(mainConfig.getString("FACTION_MAP.PILLAR.SYSTEM_FACTION.NON-DEATHBAN"));
}
}
} else {
if (mainConfig.getString("FACTION_MAP.PILLAR.ENEMY").equalsIgnoreCase("RANDOM")) {
material = Claim.getMapBlocks().get(new Random().nextInt(Claim.getMapBlocks().size()));
} else {
material = Material.valueOf(mainConfig.getString("FACTION_MAP.PILLAR.ENEMY"));
}
}
if (!(shown.containsKey(faction))) {
shown.put(claim.getFaction(), material);
for (Location corner : claim.getCorners()) {
profile.getMapPillars().add(new ClaimPillar(player, corner).show(material, 0));
}
String name = material.name().toLowerCase();
name = name.replace("_", " ");
String[] segments = name.split(" ");
name = "";
for (String segment : segments) {
segment = segment.substring(0, 1).toUpperCase() + segment.substring(1, segment.length());
if (name.equals("")) {
name = segment;
} else {
name = name + " " + segment;
}
}
if (faction instanceof PlayerFaction) {
if (profile.getFaction() == faction) {
player.sendMessage(langConfig.getString("FACTION_MAP.DISPLAY.FRIENDLY").replace("%BLOCK%", name).replace("%FACTION%", faction.getName()));
} else if (profile.getFaction() != null && profile.getFaction().getAllies().contains(faction)) {
player.sendMessage(langConfig.getString("FACTION_MAP.DISPLAY.ALLY").replace("%BLOCK%", name).replace("%FACTION%", faction.getName()));
} else {
player.sendMessage(langConfig.getString("FACTION_MAP.DISPLAY.ENEMY").replace("%BLOCK%", name).replace("%FACTION%", faction.getName()));
}
} else {
player.sendMessage(langConfig.getString("FACTION_MAP.DISPLAY.SYSTEM_FACTION").replace("%BLOCK%", name).replace("%FACTION%", faction.getName()).replace("%COLOR%", ((SystemFaction)faction).getColor() + ""));
}
} else {
for (Location corner : claim.getCorners()) {
profile.getMapPillars().add(new ClaimPillar(player, corner).show(shown.get(claim.getFaction()), 0));
}
}
}
profile.setViewingMap(true);
}
}

View File

@ -0,0 +1,45 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.entity.Player;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionMessageCommand extends FactionCommand {
@Command(name = "f.msg", aliases = {"faction.msg", "factions.msg", "f.message", "faction.message", "factions.message"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
String[] args = command.getArgs();
if (args.length == 0) {
player.sendMessage(langConfig.getString("TOO_FEW_ARGS.MESSAGE"));
return;
}
Profile profile = Profile.getByPlayer(player);
PlayerFaction playerFaction = profile.getFaction();
if (playerFaction == null) {
player.sendMessage(langConfig.getString("ERROR.MUST_BE_IN_FACTION_FOR_CHAT_TYPE"));
return;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < command.getArgs().length; i++) {
sb.append(command.getArgs()[i]).append(" ");
}
String message = sb.toString().trim();
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_FACTION_CHAT").replace("%PLAYER%", player.getName()).replace("%MESSAGE%", message).replace("%FACTION%", playerFaction.getName()));
}
}

View File

@ -0,0 +1,280 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.LocationSerialization;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.factions.type.SystemFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.LocationSerialization;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionShowCommand extends FactionCommand {
@Command(name = "f.show", aliases = {"faction.show", "factions.show", "f.i", "faction.i", "factions.i", "f.info", "faction.info", "factions.info", "f.who", "faction.who", "factions.who"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (command.getArgs().length == 0) {
PlayerFaction playerFaction = profile.getFaction();
if (playerFaction == null) {
player.sendMessage(langConfig.getString("ERROR.NOT_IN_FACTION"));
return;
}
sendFactionInformation(player, playerFaction);
return;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < command.getArgs().length; i++) {
sb.append(command.getArgs()[i]).append(" ");
}
String name = sb.toString().trim().replace(" ", "");
Set<Faction> matchedFactions = Faction.getAllByString(name);
if (matchedFactions.isEmpty()) {
player.sendMessage(langConfig.getString("ERROR.NO_FACTIONS_FOUND").replace("%NAME%", name));
return;
}
for (Faction faction : matchedFactions) {
sendFactionInformation(player, faction);
}
}
private void sendFactionInformation(Player player, Faction faction) { //This method is legit aids, need to fix this when I have time...
List<String> toSend = new ArrayList<>();
if (faction instanceof PlayerFaction) {
PlayerFaction playerFaction = (PlayerFaction) faction;
final String ROOT = "FACTION_SHOW.PLAYER_FACTION.";
final String ROOT_SETTINGS = ROOT + "SETTINGS.";
ChatColor offlineColor = ChatColor.valueOf(langConfig.getString(ROOT_SETTINGS + "OFFLINE_COLOR").toUpperCase());
ChatColor onlineColor = ChatColor.valueOf(langConfig.getString(ROOT_SETTINGS + "ONLINE_COLOR").toUpperCase());
ChatColor raidableColor = ChatColor.valueOf(langConfig.getString(ROOT_SETTINGS + "DTR_COLOR.RAIDABLE").toUpperCase());
ChatColor notRaidableColor = ChatColor.valueOf(langConfig.getString(ROOT_SETTINGS + "DTR_COLOR.NOT_RAIDABLE").toUpperCase());
String killFormat = langConfig.getString(ROOT_SETTINGS + "SHOW_KILLS.FORMAT");
String splitNamesFormat = langConfig.getString(ROOT_SETTINGS + "SPLIT_NAMES.FORMAT");
boolean splitNamesEnabled = langConfig.getBoolean(ROOT_SETTINGS + "SPLIT_NAMES.ENABLED");
boolean killFormatEnabled = langConfig.getBoolean(ROOT_SETTINGS + "SHOW_KILLS.ENABLED");
for (String string : langConfig.getStringList(ROOT + "MESSAGE")) {
string = string.replace("%FACTION%", faction.getName());
string = string.replace("%ONLINE_COUNT%", playerFaction.getOnlinePlayers().size() + "");
string = string.replace("%MAX_COUNT%", playerFaction.getAllPlayerUuids().size() + "");
if (player.hasPermission("command.mod")) {
string = string.replace("%MANAGE%", "[Manage]");
} else {
string = string.replace("%MANAGE%", "");
}
if (string.contains("%HOME%")) {
if (playerFaction.getHome() == null) {
string = string.replace("%HOME%", langConfig.getString(ROOT_SETTINGS + "HOME_PLACEHOLDER"));
} else {
Location homeLocation = LocationSerialization.deserializeLocation(playerFaction.getHome());
string = string.replace("%HOME%", homeLocation.getBlockX() + ", " + homeLocation.getBlockZ());
}
}
if (string.contains("%LEADER%")) {
String leaderString;
UUID leader = playerFaction.getLeader();
SimpleOfflinePlayer leaderPlayer = SimpleOfflinePlayer.getByUuid(leader);
if (leaderPlayer == null) {
continue;
}
if (Bukkit.getPlayer(leader) == null) {
leaderString = offlineColor + leaderPlayer.getName();
} else {
leaderString = onlineColor + leaderPlayer.getName();
}
if (killFormatEnabled) {
leaderString = leaderString + killFormat.replace("%KILLS%", leaderPlayer.getKills() + "");
}
string = string.replace("%LEADER%", leaderString);
}
if (string.contains("%OFFICERS%")) {
String officerString = "";
if (playerFaction.getOfficers().isEmpty()) {
continue;
}
for (UUID uuid : playerFaction.getOfficers()) {
SimpleOfflinePlayer officer = SimpleOfflinePlayer.getByUuid(uuid);
if (officer == null) {
continue;
}
if (Bukkit.getPlayer(uuid) == null) {
officerString = officerString + offlineColor + officer.getName();
} else {
officerString = officerString + onlineColor + officer.getName();
}
if (killFormatEnabled) {
officerString = officerString + killFormat.replace("%KILLS%", officer.getKills() + "");
}
if (splitNamesEnabled) {
officerString = officerString + splitNamesFormat;
}
}
string = string.replace("%OFFICERS%", officerString);
}
if (string.contains("%MEMBERS%")) {
String memberString = "";
if (playerFaction.getMembers().isEmpty()) {
continue;
}
for (UUID uuid : playerFaction.getMembers()) {
SimpleOfflinePlayer member = SimpleOfflinePlayer.getByUuid(uuid);
if (member == null) {
continue;
}
if (Bukkit.getPlayer(uuid) == null) {
memberString = memberString + offlineColor + member.getName();
} else {
memberString = memberString + onlineColor + member.getName();
}
if (killFormatEnabled) {
memberString = memberString + killFormat.replace("%KILLS%", member.getKills() + "");
}
if (splitNamesEnabled) {
memberString = memberString + splitNamesFormat;
}
}
string = string.replace("%MEMBERS%", memberString);
}
if (string.contains("%ALLIES%")) {
if (playerFaction.getAllies().isEmpty()) {
continue;
}
ChatColor allyColor = ChatColor.valueOf(mainConfig.getString("TAB_LIST.ALLY_COLOR"));
String allies = "";
for (PlayerFaction ally : playerFaction.getAllies()) {
allies = allies + allyColor + ally.getName();
if (splitNamesEnabled) {
allies = allies + splitNamesFormat;
}
}
string = string.replace("%ALLIES%", allies);
}
if (string.contains("%DTR%")) {
if (playerFaction.isRaidable()) {
string = string.replace("%DTR%", raidableColor + "" + playerFaction.getDeathsTillRaidable());
} else {
string = string.replace("%DTR%", notRaidableColor + "" + playerFaction.getDeathsTillRaidable());
}
}
if (string.contains("%DTR_SYMBOL%")) {
if (playerFaction.getDeathsTillRaidable().equals(playerFaction.getMaxDeathsTillRaidable())) {
string = string.replace("%DTR_SYMBOL%", langConfig.getString(ROOT_SETTINGS + "DTR_SYMBOL.FULL"));
} else {
if (playerFaction.isFrozen()) {
string = string.replace("%DTR_SYMBOL%", langConfig.getString(ROOT_SETTINGS + "DTR_SYMBOL.FROZEN"));
} else {
string = string.replace("%DTR_SYMBOL%", langConfig.getString(ROOT_SETTINGS + "DTR_SYMBOL.REGENERATING"));
}
}
}
string = string.replace("%BALANCE%", playerFaction.getBalance() + "");
string = string.replace("%MAX_DTR%", playerFaction.getMaxDeathsTillRaidable() + "");
if (string.contains("%ANNOUNCEMENT%")) {
if (playerFaction.getAnnouncement() == null || !playerFaction.getOnlinePlayers().contains(player)) {
continue;
}
string = string.replace("%ANNOUNCEMENT%", playerFaction.getAnnouncement());
}
if (string.contains("%REGEN_TIME%")) {
if (!(playerFaction.isFrozen())) {
continue;
}
string = string.replace("%REGEN_TIME%", playerFaction.getFormattedFreezeDuration());
}
if (splitNamesEnabled && string.contains(splitNamesFormat)) {
string = string.substring(0, string.lastIndexOf(splitNamesFormat));
}
toSend.add(string);
}
} else {
SystemFaction systemFaction = (SystemFaction) faction;
final String ROOT = "FACTION_SHOW.SYSTEM_FACTION.";
final String ROOT_SETTINGS = ROOT + "SETTINGS.";
for (String string : langConfig.getStringList(ROOT + "MESSAGE")) {
string = string.replace("%FACTION%", faction.getName());
string = string.replace("%COLOR%", systemFaction.getColor() + "");
if (string.contains("%HOME%")) {
if (faction.getHome() == null) {
string = string.replace("%HOME%", langConfig.getString(ROOT_SETTINGS + "HOME_PLACEHOLDER"));
} else {
Location homeLocation = LocationSerialization.deserializeLocation(faction.getHome());
string = string.replace("%HOME%", homeLocation.getBlockX() + ", " + homeLocation.getBlockZ());
}
}
toSend.add(string);
}
}
for (String message : toSend) {
player.sendMessage(message);
}
}
}

View File

@ -0,0 +1,114 @@
package com.amberpvp.hcfactions.factions.commands;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.events.player.PlayerInitiateFactionTeleportEvent;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.profile.teleport.ProfileTeleportTask;
import com.amberpvp.hcfactions.profile.teleport.ProfileTeleportType;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionStuckCommand extends FactionCommand {
@Command(name = "f.stuck", aliases = {"faction.stuck", "factions.stuck"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
Profile profile = Profile.getByPlayer(player);
if (profile.getTeleportWarmup() != null) {
return;
}
int time = 0;
String worldName = player.getLocation().getWorld().getName();
String root = "TELEPORT_COUNTDOWN.STUCK";
for (String world : new String[]{"OVERWORLD", "NETHER", "END"}) {
if (worldName.equalsIgnoreCase(mainConfig.getString(world))) {
if (!mainConfig.getBoolean(root + "." + world + ".ENABLED")) {
player.sendMessage(langConfig.getString("ERROR.NO_STUCK_TELEPORT_IN_WORLD"));
return;
} else {
time = mainConfig.getInt(root + "." + world + ".TIME");
}
}
}
long hours = TimeUnit.SECONDS.toHours(time);
long minutes = TimeUnit.SECONDS.toMinutes(time) - (hours * 60);
long seconds = TimeUnit.SECONDS.toSeconds(time) - ((hours * 60 * 60) + (minutes * 60));
String formatted;
if (hours == 0 && minutes > 0 && seconds > 0) {
formatted = minutes + " minutes and " + seconds + " seconds";
} else if (hours == 0 && minutes > 0 && seconds == 0) {
formatted = minutes + " minutes";
} else if (hours == 0 && minutes == 0 && seconds > 0) {
formatted = seconds + " seconds";
} else if (hours > 0 && minutes > 0 && seconds == 0) {
formatted = hours + " hours and " + minutes + " minutes";
} else if (hours > 0 && minutes == 0 && seconds > 0) {
formatted = hours + " hours and " + seconds + " seconds";
} else {
formatted = hours + "hours, " + minutes + " minutes and " + seconds + " seconds";
}
if (hours == 1) {
formatted = formatted.replace("hours", "hour");
}
if (minutes == 1) {
formatted = formatted.replace("minutes", "minute");
}
if (seconds == 1) {
formatted = formatted.replace("seconds", "second");
}
Location location = null;
int current = 5;
while (location == null) {
for (int x = player.getLocation().getBlockX() - current; x < player.getLocation().getBlockX() + current; x++) {
for (int z = player.getLocation().getBlockZ() - current; z < player.getLocation().getBlockZ() + current; z++) {
Location newLocation = new Location(player.getLocation().getWorld(), x, 0, z);
List<Claim> claims = Claim.getClaimsAt(newLocation);
if (claims == null) {
location = newLocation;
} else {
for (Claim claim : claims) {
if (claim.getFaction() instanceof PlayerFaction) {
break;
}
}
location = newLocation;
break;
}
}
}
current +=5;
}
location.setDirection(player.getLocation().getDirection());
player.sendMessage(langConfig.getString("FACTION_OTHER.TELEPORTING_TO_STUCK").replace("%TIME%", formatted));
profile.setTeleportWarmup(new ProfileTeleportTask(new PlayerInitiateFactionTeleportEvent(player, null, ProfileTeleportType.STUCK_TELEPORT, time, location.getWorld().getHighestBlockAt(location).getLocation(), player.getLocation())));
profile.getTeleportWarmup().runTaskLaterAsynchronously(main, (long) (time * 20));
}
}

View File

@ -0,0 +1,60 @@
package com.amberpvp.hcfactions.factions.commands.admin;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class FactionAdminCommand extends FactionCommand {
@Command(name = "f.admin", aliases = {"faction.admin", "factions.admin", "f.bypass", "faction.bypass", "factions.bypass"}, inGameOnly = false)
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
String[] args = command.getArgs();
Player player;
if (!sender.hasPermission("staff.admin")) {
sender.sendMessage(ChatColor.RED + "No permission.");
return;
}
if (args.length >= 1) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < command.getArgs().length; i++) {
sb.append(command.getArgs()[i]).append(" ");
}
String name = sb.toString().trim().replace(" ", "");
player = Bukkit.getPlayer(name);
if (player == null) {
sender.sendMessage(langConfig.getString("ERROR.PLAYER_NOT_FOUND").replace("%PLAYER%", name));
return;
}
} else {
if (sender instanceof Player) {
player = (Player) sender;
} else {
sender.sendMessage(langConfig.getString("TOO_FEW_ARGS.ADMIN"));
return;
}
}
Profile profile = Profile.getByPlayer(player);
profile.setInAdminMode(!profile.isInAdminMode());
if (player == sender) {
player.sendMessage(langConfig.getString("ADMIN.ADMIN_MODE").replace("%BOOLEAN%", profile.isInAdminMode() + "").replace("%PLAYER%", player.getName()));
} else {
sender.sendMessage(langConfig.getString("ADMIN.ADMIN_MODE").replace("%BOOLEAN%", profile.isInAdminMode() + "").replace("%PLAYER%", player.getName()));
player.sendMessage(langConfig.getString("ADMIN.ADMIN_MODE").replace("%BOOLEAN%", profile.isInAdminMode() + "").replace("%PLAYER%", player.getName()));
}
}
}

View File

@ -0,0 +1,58 @@
package com.amberpvp.hcfactions.factions.commands.admin;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import java.util.HashSet;
import java.util.Set;
import static com.mongodb.client.model.Filters.eq;
public class FactionDisbandAllCommand extends FactionCommand {
@Command(name = "f.disbandall", inGameOnly = false)
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
if (!sender.hasPermission("staff.owner")) {
sender.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (command.getArgs().length == 0 && sender instanceof ConsoleCommandSender) {
for (Faction faction : Faction.getFactions()) {
if (faction instanceof PlayerFaction) {
Set<Claim> claims = new HashSet<>(faction.getClaims());
for (Claim claim : claims) {
claim.remove();
}
Bukkit.getScheduler().runTaskAsynchronously(FactionsPlugin.getInstance(), new Runnable() {
@Override
public void run() {
main.getFactionsDatabase().getDatabase().getCollection("playerFactions").deleteOne(eq("uuid", faction.getUuid().toString()));
}
});
Faction.getFactions().remove(faction);
}
}
sender.sendMessage(langConfig.getString("ADMIN.DISBAND_ALL"));
}
}
}

View File

@ -0,0 +1,98 @@
package com.amberpvp.hcfactions.factions.commands.admin;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.command.CommandSender;
public class FactionFreezeCommand extends FactionCommand {
@Command(name = "faction.freeze", aliases = {"f.freeze", "factions.freeze", "f.setdtrregen","faction.setdtrregen","factions.setdtrregen"}, inGameOnly = false)
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
if (!sender.hasPermission("staff.triamod")) {
sender.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (command.getArgs().length == 2) {
String name = command.getArgs(0);
Faction faction = Faction.getByName(name);
PlayerFaction playerFaction = null;
if (faction instanceof PlayerFaction) {
playerFaction = (PlayerFaction) faction;
}
if (faction == null || (!(faction instanceof PlayerFaction))) {
playerFaction = PlayerFaction.getByPlayerName(name);
if (playerFaction == null) {
sender.sendMessage(langConfig.getString("ERROR.NO_FACTIONS_FOUND").replace("%NAME%", name));
return;
}
}
try {
playerFaction.freeze(getTime(command.getArgs(1)));
sender.sendMessage(langConfig.getString("ADMIN.FROZEN").replace("%FACTION%", playerFaction.getName()).replace("%TIME%", playerFaction.getFormattedFreezeDuration()));
} catch (Exception e) {
sender.sendMessage(langConfig.getString("ERROR.INVALID_TIME"));
}
} else {
sender.sendMessage(langConfig.getString("TOO_FEW_ARGS.FREEZE"));
}
}
private int getTime(String string) {
int time = 0;
if (string.contains("m")) {
String timeStr = strip(string);
if (NumberUtils.isNumber(timeStr)) {
time = NumberUtils.toInt(timeStr) * 60;
}
} else if (string.contains("h")) {
String timeStr = strip(string);
if (NumberUtils.isNumber(timeStr)) {
time = NumberUtils.toInt(timeStr) * 3600;
}
} else if (string.contains("d")) {
String timeStr = strip(string);
if (NumberUtils.isNumber(timeStr)) {
time = NumberUtils.toInt(timeStr) * 86400;
}
} else if (string.contains("y")) {
String timeStr = strip(string);
if (NumberUtils.isNumber(timeStr)) {
time = NumberUtils.toInt(timeStr) * 31536000;
}
} else {
String timeStr = strip(string);
if (NumberUtils.isNumber(timeStr)) {
time = NumberUtils.toInt(timeStr);
} else {
throw new NumberFormatException("Invalid number");
}
}
return time;
}
private String strip(String src) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < src.length(); i++) {
char c = src.charAt(i);
if (Character.isDigit(c)) {
builder.append(c);
}
}
return builder.toString();
}
}

View File

@ -0,0 +1,54 @@
package com.amberpvp.hcfactions.factions.commands.admin;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class FactionManageCommand extends FactionCommand {
@Command(name = "f.manage", aliases = {"faction.manage", "factions.manage"}, inGameOnly = false)
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
if (!sender.hasPermission("staff.trialmod")) {
sender.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (command.getArgs().length >= 1) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < command.getArgs().length; i++) {
sb.append(command.getArgs()[i]).append(" ");
}
String name = sb.toString().trim().replace(" ", "");
Faction faction = Faction.getByName(name);
PlayerFaction playerFaction = null;
if (faction instanceof PlayerFaction) {
playerFaction = (PlayerFaction) faction;
}
if (faction == null || (!(faction instanceof PlayerFaction))) {
playerFaction = PlayerFaction.getByPlayerName(name);
if (playerFaction == null) {
sender.sendMessage(langConfig.getString("ERROR.NO_FACTIONS_FOUND").replace("%NAME%", name));
return;
}
}
playerFaction.setFreezeInformation(null);
} else {
sender.sendMessage(langConfig.getString("TOO_FEW_ARGS.MANAGE"));
}
}
}

View File

@ -0,0 +1,66 @@
package com.amberpvp.hcfactions.factions.commands.admin;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.CommandSender;
import java.math.BigDecimal;
public class FactionSetDtrCommand extends FactionCommand {
@Command(name = "f.setdtr", aliases = {"faction.setdtr", "factions.setdtr"}, inGameOnly = false)
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
if (!sender.hasPermission("staff.trialmod")) {
sender.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (command.getArgs().length == 2) {
String name = command.getArgs()[0];
if(name.equalsIgnoreCase("*") && sender instanceof ConsoleCommandSender) {
for(Faction faction : Faction.getFactions()) {
if(faction instanceof PlayerFaction) {
((PlayerFaction) faction).setDeathsTillRaidable(BigDecimal.valueOf(Double.valueOf(command.getArgs()[1])));
}
}
sender.sendMessage(langConfig.getString("ADMIN.SET_DTR_ALL").replaceAll("%DTR%", command.getArgs()[1] + ""));
return;
}
Faction faction = Faction.getByName(name);
PlayerFaction playerFaction = null;
if (faction instanceof PlayerFaction) {
playerFaction = (PlayerFaction) faction;
}
if (faction == null || (!(faction instanceof PlayerFaction))) {
playerFaction = PlayerFaction.getByPlayerName(name);
if (playerFaction == null) {
sender.sendMessage(langConfig.getString("ERROR.NO_FACTIONS_FOUND").replace("%NAME%", name));
return;
}
}
playerFaction.setDeathsTillRaidable(BigDecimal.valueOf(Double.valueOf(command.getArgs()[1])));
sender.sendMessage(langConfig.getString("ADMIN.SET_DTR").replaceAll("%FACTION%", playerFaction.getName()).replaceAll("%DTR%", playerFaction.getDeathsTillRaidable().doubleValue() + ""));
} else {
sender.sendMessage(langConfig.getString("TOO_FEW_ARGS.SET_DTR"));
}
}
}

View File

@ -0,0 +1,54 @@
package com.amberpvp.hcfactions.factions.commands.admin;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.util.PluginCommand;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.command.CommandSender;
public class FactionThawCommand extends FactionCommand {
@Command(name = "f.thaw", aliases = {"faction.thaw", "factions.thaw"}, inGameOnly = false)
public void onCommand(CommandArgs command) {
CommandSender sender = command.getSender();
if (!sender.hasPermission("staff.mod")) {
sender.sendMessage(PluginCommand.NO_PERMISSION);
return;
}
if (command.getArgs().length >= 1) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < command.getArgs().length; i++) {
sb.append(command.getArgs()[i]).append(" ");
}
String name = sb.toString().trim().replace(" ", "");
Faction faction = Faction.getByName(name);
PlayerFaction playerFaction = null;
if (faction instanceof PlayerFaction) {
playerFaction = (PlayerFaction) faction;
}
if (faction == null || (!(faction instanceof PlayerFaction))) {
playerFaction = PlayerFaction.getByPlayerName(name);
if (playerFaction == null) {
sender.sendMessage(langConfig.getString("ERROR.NO_FACTIONS_FOUND").replace("%NAME%", name));
return;
}
}
playerFaction.setFreezeInformation(null);
sender.sendMessage(langConfig.getString("ADMIN.THAWED").replaceAll("%FACTION%", playerFaction.getName()));
} else {
sender.sendMessage(langConfig.getString("TOO_FEW_ARGS.THAW"));
}
}
}

View File

@ -0,0 +1,75 @@
package com.amberpvp.hcfactions.factions.commands.leader;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionDemoteCommand extends FactionCommand {
@Command(name = "f.demote", aliases = {"faction.demote", "factions.demote", "f.unmod", "factions.unmod", "faction.unmod", "f.unofficer", "factions.unofficer", "faction.unofficer", "faction.uncaptain", "f.uncaptain", "faction.uncaptain"}, inFactionOnly = true, isLeaderOnly = true
)
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
if (command.getArgs().length == 0) {
player.sendMessage(langConfig.getString("TOO_FEW_ARGS.DEMOTE"));
return;
}
Profile profile = Profile.getByPlayer(player);
PlayerFaction playerFaction = profile.getFaction();
UUID uuid;
String name;
Player toDemote = Bukkit.getPlayer(command.getArgs(0));
if (toDemote == null) {
SimpleOfflinePlayer offlinePlayer = SimpleOfflinePlayer.getByName(command.getArgs(0));
if (offlinePlayer != null) {
uuid = offlinePlayer.getUuid();
name = offlinePlayer.getName();
} else {
player.sendMessage(langConfig.getString("ERROR.NOT_ONLINE").replace("%PLAYER%", command.getArgs(0)));
return;
}
} else {
uuid = toDemote.getUniqueId();
name = toDemote.getName();
}
if (name.equalsIgnoreCase(player.getName()) && player.getUniqueId().equals(playerFaction.getLeader())) {
player.sendMessage(langConfig.getString("ERROR.DEMOTE_YOURSELF"));
return;
}
if (!playerFaction.getAllPlayerUuids().contains(uuid)) {
player.sendMessage(langConfig.getString("ERROR.NOT_IN_YOUR_FACTION").replace("%PLAYER%", name));
return;
}
if (!playerFaction.getOfficers().contains(uuid)) {
player.sendMessage(langConfig.getString("ERROR.NOT_OFFICER").replace("%PLAYER%", name));
return;
}
playerFaction.getOfficers().remove(uuid);
playerFaction.getMembers().add(uuid);
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_DEMOTED").replace("%PLAYER%", name).replace("%LEADER%", player.getName()));
}
}

View File

@ -0,0 +1,158 @@
package com.amberpvp.hcfactions.factions.commands.leader;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.claimwall.ClaimWallType;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.PlayerUtility;
import com.amberpvp.hcfactions.FactionsPlugin;
import com.amberpvp.hcfactions.claimwall.ClaimWallType;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.events.player.PlayerDisbandFactionEvent;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.PlayerUtility;
import org.bukkit.Location;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import static com.mongodb.client.model.Filters.eq;
public class FactionDisbandCommand extends FactionCommand {
@Command(name = "f.disband", aliases = {"faction.disband", "factions.disband"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
Profile profile = Profile.getByPlayer(player);
PlayerFaction playerFaction;
if (command.getArgs().length >= 1) {
String name = command.getArgs(0);
Faction faction = PlayerFaction.getAnyByString(name);
if (faction != null) {
if (faction instanceof PlayerFaction) {
playerFaction = (PlayerFaction) faction;
} else {
player.sendMessage(langConfig.getString("SYSTEM_FACTION.DELETED").replace("%NAME%", faction.getName()));
Faction.getFactions().remove(faction);
Set<Claim> claims = new HashSet<>(faction.getClaims());
for (Claim claim : claims) {
claim.remove();
}
main.getFactionsDatabase().getDatabase().getCollection("systemFactions").deleteOne(eq("uuid", faction.getUuid().toString()));
return;
}
} else {
player.sendMessage(langConfig.getString("ERROR.NO_FACTIONS_FOUND").replace("%NAME%", name));
return;
}
} else {
playerFaction = profile.getFaction();
if (playerFaction == null) {
player.sendMessage(langConfig.getString("ERROR.NOT_IN_FACTION"));
return;
}
if (!playerFaction.getLeader().equals(player.getUniqueId())) {
player.sendMessage(langConfig.getString("ERROR.NOT_LEADER"));
return;
}
}
for (UUID member : playerFaction.getAllPlayerUuids()) {
Profile memberProfile = Profile.getByUuid(member);
if (memberProfile != null && memberProfile.getFaction().equals(playerFaction)) {
memberProfile.setFaction(null);
}
}
profile.setBalance(profile.getBalance() + playerFaction.getBalance());
Bukkit.getPluginManager().callEvent(new PlayerDisbandFactionEvent(player, playerFaction));
Bukkit.broadcastMessage(langConfig.getString("ANNOUNCEMENTS.FACTION_DISBANDED").replace("%PLAYER%", player.getDisplayName()).replace("%NAME%", playerFaction.getName()));
Bukkit.getScheduler().runTaskAsynchronously(FactionsPlugin.getInstance(), new Runnable() {
@Override
public void run() {
main.getFactionsDatabase().getDatabase().getCollection("playerFactions").deleteOne(eq("uuid", playerFaction.getUuid().toString()));
}
});
for (PlayerFaction ally : playerFaction.getAllies()) {
ally.getAllies().remove(playerFaction);
}
Set<Claim> claims = new HashSet<>(playerFaction.getClaims());
this.removeWalls(claims);
for (Claim claim : claims) {
claim.remove();
}
Faction.getFactions().remove(playerFaction);
}
private void removeWalls(Set<Claim> claims) {
new BukkitRunnable() {
@Override
public void run() {
for (Player player : PlayerUtility.getOnlinePlayers() ) {
Profile profile = Profile.getByPlayer(player);
for(Claim claim : claims) {
for (ClaimWallType type : ClaimWallType.values()) {
if (claim == null) {
continue;
}
if (!(type.isValid(claim))) {
continue;
}
if (claim.getBorder() == null) {
continue;
}
int min = player.getLocation().getBlockY() - (type.getRange() / 2);
int max = player.getLocation().getBlockY() + (type.getRange() / 2);
for (Location location : claim.getBorder()) {
for (int i = min - (20); i < max + (20); i++) {
location.setY(i);
if (location.getBlock().isEmpty()) {
if (profile.getWalls().containsKey(location)) {
profile.getWalls().get(location).hide(player);
profile.getWalls().remove(location);
}
}
}
}
}
}
}
}
}.runTaskAsynchronously(this.main);
}
}

View File

@ -0,0 +1,77 @@
package com.amberpvp.hcfactions.factions.commands.leader;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionLeaderCommand extends FactionCommand {
@Command(name = "f.leader", aliases = {"faction.leader", "factions.leader", "f.owner", "factions.owner", "faction.owner", "f.ownership", "factions.ownership", "faction.ownership"}, inFactionOnly = true, isLeaderOnly = true)
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
if (command.getArgs().length == 0) {
player.sendMessage(langConfig.getString("TOO_FEW_ARGS.LEADER"));
return;
}
Profile profile = Profile.getByPlayer(player);
PlayerFaction playerFaction = profile.getFaction();
UUID uuid;
String name;
Player toLeader = Bukkit.getPlayer(command.getArgs(0));
if (toLeader == null) {
SimpleOfflinePlayer offlinePlayer = SimpleOfflinePlayer.getByName(command.getArgs(0));
if (offlinePlayer != null) {
uuid = offlinePlayer.getUuid();
name = offlinePlayer.getName();
} else {
player.sendMessage(langConfig.getString("ERROR.NOT_ONLINE").replace("%PLAYER%", command.getArgs(0)));
return;
}
} else {
uuid = toLeader.getUniqueId();
name = toLeader.getName();
}
if (!playerFaction.getAllPlayerUuids().contains(uuid)) {
player.sendMessage(langConfig.getString("ERROR.NOT_IN_YOUR_FACTION"));
return;
}
if (player.getUniqueId().equals(playerFaction.getLeader()) && uuid.equals(playerFaction.getLeader())) {
player.sendMessage(langConfig.getString("ERROR.ALREADY_LEADER"));
return;
}
if (uuid.equals(playerFaction.getLeader()) && !uuid.equals(player.getUniqueId())) {
player.sendMessage(langConfig.getString("ERROR.PLAYER_ALREADY_LEADER").replace("%PLAYER%", name));
return;
}
playerFaction.getMembers().remove(uuid);
playerFaction.getOfficers().remove(uuid);
playerFaction.getOfficers().add(playerFaction.getLeader());
playerFaction.setLeader(uuid);
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_TRANSFER_LEADERSHIP").replace("%PLAYER%", name).replace("%LEADER%", player.getName()));
}
}

View File

@ -0,0 +1,75 @@
package com.amberpvp.hcfactions.factions.commands.leader;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.util.player.SimpleOfflinePlayer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionPromoteCommand extends FactionCommand {
@Command(name = "f.promote", aliases = {"faction.promote", "factions.promote", "f.mod", "factions.mod", "faction.mod", "f.officer", "factions.officer", "faction.officer", "faction.captain", "f.captain", "faction.captain"}, inFactionOnly = true, isLeaderOnly = true)
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
if (command.getArgs().length == 0) {
player.sendMessage(langConfig.getString("TOO_FEW_ARGS.PROMOTE"));
return;
}
Profile profile = Profile.getByPlayer(player);
PlayerFaction playerFaction = profile.getFaction();
UUID uuid;
String name;
Player toPromote = Bukkit.getPlayer(command.getArgs(0));
if (toPromote == null) {
SimpleOfflinePlayer offlinePlayer = SimpleOfflinePlayer.getByName(command.getArgs(0));
if (offlinePlayer != null) {
uuid = offlinePlayer.getUuid();
name = offlinePlayer.getName();
} else {
player.sendMessage(langConfig.getString("ERROR.NOT_ONLINE").replace("%PLAYER%", command.getArgs(0)));
return;
}
} else {
uuid = toPromote.getUniqueId();
name = toPromote.getName();
}
if (name.equalsIgnoreCase(player.getName()) && player.getUniqueId().equals(playerFaction.getLeader())) {
player.sendMessage(langConfig.getString("ERROR.PROMOTE_YOURSELF"));
return;
}
if (!playerFaction.getAllPlayerUuids().contains(uuid)) {
player.sendMessage(langConfig.getString("ERROR.NOT_IN_YOUR_FACTION").replace("%PLAYER%", name));
return;
}
if (playerFaction.getOfficers().contains(uuid)) {
player.sendMessage(langConfig.getString("ERROR.ALREADY_OFFICER").replace("%PLAYER%", name));
return;
}
playerFaction.getMembers().remove(uuid);
playerFaction.getOfficers().add(uuid);
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_PROMOTED").replace("%PLAYER%", name).replace("%LEADER%", player.getName()));
}
}

View File

@ -0,0 +1,102 @@
package com.amberpvp.hcfactions.factions.commands.officer;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.Clickable;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.events.FactionAllyFactionEvent;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.Clickable;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionAllyCommand extends FactionCommand {
@Command(name = "f.ally", aliases = {"faction.ally", "factions.ally", "f.alliance", "factions.alliance", "faction.alliance"}, inFactionOnly = true, isOfficerOnly = true)
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
if (command.getArgs().length == 0) {
player.sendMessage(langConfig.getString("TOO_FEW_ARGS.ALLY"));
return;
}
Profile profile = Profile.getByPlayer(player);
PlayerFaction playerFaction = profile.getFaction();
String factionName = command.getArgs(0);
Faction faction = Faction.getByName(factionName);
PlayerFaction allyFaction = null;
if (faction instanceof PlayerFaction) {
allyFaction = (PlayerFaction) faction;
}
if (faction == null || (!(faction instanceof PlayerFaction))) {
allyFaction = PlayerFaction.getByPlayerName(factionName);
if (allyFaction == null) {
player.sendMessage(langConfig.getString("ERROR.NO_FACTIONS_FOUND").replace("%NAME%", factionName));
return;
}
}
if (playerFaction.getName().equals(allyFaction.getName())) {
player.sendMessage(langConfig.getString("ERROR.CANT_ALLY_YOURSELF"));
return;
}
if (allyFaction.getAllies().contains(playerFaction)) {
player.sendMessage(langConfig.getString("ERROR.ALREADY_HAVE_RELATION").replace("%FACTION%", allyFaction.getName()));
return;
}
if (playerFaction.getRequestedAllies().contains(allyFaction.getUuid())) {
player.sendMessage(langConfig.getString("ERROR.ALREADY_REQUESTED").replace("%FACTION%", allyFaction.getName()));
return;
}
if (allyFaction.getAllies().size() >= mainConfig.getInt("FACTION_GENERAL.ALLIES.MAX_ALLIES")) {
player.sendMessage(langConfig.getString("ERROR.MAX_ALLIES").replace("%FACTION%", allyFaction.getName()));
return;
}
if (allyFaction.getRequestedAllies().contains(playerFaction.getUuid())) {
allyFaction.getRequestedAllies().remove(playerFaction.getUuid());
allyFaction.getAllies().add(playerFaction);
playerFaction.getAllies().add(allyFaction);
allyFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION_ALLIED").replace("%FACTION%", playerFaction.getName()));
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION_ALLIED").replace("%FACTION%", allyFaction.getName()));
Bukkit.getPluginManager().callEvent(new FactionAllyFactionEvent(new PlayerFaction[]{playerFaction, allyFaction}));
} else {
playerFaction.getRequestedAllies().add(allyFaction.getUuid());
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_SEND_ALLY_REQUEST").replace("%PLAYER%", player.getName()).replace("%FACTION%", allyFaction.getName()));
for (Player allyPlayer : allyFaction.getOnlinePlayers()) {
if (allyPlayer.getUniqueId().equals(allyFaction.getLeader())) {
Clickable clickable = new Clickable(langConfig.getString("ANNOUNCEMENTS.FACTION_RECEIVE_ALLY_REQUEST").replace("%FACTION%", playerFaction.getName()),
ChatColor.GRAY + "Click to accept ally",
"/f ally " + playerFaction.getName());
clickable.sendToPlayer(allyPlayer);
} else {
allyPlayer.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION_RECEIVE_ALLY_REQUEST").replace("%FACTION%", playerFaction.getName()));
}
}
}
}
}

View File

@ -0,0 +1,41 @@
package com.amberpvp.hcfactions.factions.commands.officer;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.entity.Player;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionAnnouncementCommand extends FactionCommand {
@Command(name = "f.announcement", aliases = {"faction.announcement", "factions.announcement", "f.anouncement", "faction.anouncement", "factions.anouncement", "f.announce", "faction.announce", "factions.announce", "f.description", "faction.description", "factions.description"}, inFactionOnly = true, isOfficerOnly = true)
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
String[] args = command.getArgs();
if (args.length == 0) {
player.sendMessage(langConfig.getString("TOO_FEW_ARGS.ANNOUNCEMENT"));
return;
}
Profile profile = Profile.getByPlayer(player);
PlayerFaction playerFaction = profile.getFaction();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < command.getArgs().length; i++) {
sb.append(command.getArgs()[i]).append(" ");
}
String message = sb.toString().trim();
playerFaction.setAnnouncement(message);
playerFaction.sendMessage(langConfig.getString("ANNOUNCEMENTS.FACTION.PLAYER_SET_ANNOUNCEMENT").replace("%PLAYER%", player.getName()).replace("%MESSAGE%", message).replace("%FACTION%", playerFaction.getName()));
}
}

View File

@ -0,0 +1,79 @@
package com.amberpvp.hcfactions.factions.commands.officer;
import com.amberpvp.hcfactions.mode.Mode;
import com.amberpvp.hcfactions.mode.ModeType;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import com.amberpvp.hcfactions.factions.Faction;
import com.amberpvp.hcfactions.factions.claims.Claim;
import com.amberpvp.hcfactions.factions.claims.ClaimProfile;
import com.amberpvp.hcfactions.factions.commands.FactionCommand;
import com.amberpvp.hcfactions.factions.type.PlayerFaction;
import com.amberpvp.hcfactions.mode.Mode;
import com.amberpvp.hcfactions.mode.ModeType;
import com.amberpvp.hcfactions.profile.Profile;
import com.amberpvp.hcfactions.util.command.Command;
import com.amberpvp.hcfactions.util.command.CommandArgs;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
* Copyright 2016 Alexander Maxwell
* Use and or redistribution of compiled JAR file and or source code is permitted only if given
* explicit permission from original author: Alexander Maxwell
*/
public class FactionClaimCommand extends FactionCommand {
@Command(name = "f.claim", aliases = {"faction.claim", "factions.claim", "factions.claimland", "f.claimland", "faction.claimland"})
public void onCommand(CommandArgs command) {
Player player = command.getPlayer();
for(Mode mode : Mode.getModes()) {
if(mode.getModeType() == ModeType.EOTW && mode.isActive()) {
player.sendMessage(langConfig.getString("ERROR.EOTW_CLAIM"));
return;
}
}
Profile profile = Profile.getByPlayer(player);
player.getInventory().remove(Faction.getWand());
Faction faction;
if (command.getArgs().length >= 1) {
String name = command.getArgs(0);
Faction faction1 = PlayerFaction.getAnyByString(name);
if (faction1 != null) {
faction = faction1;
player.sendMessage(langConfig.getString("FACTION_OTHER.CLAIMING_FOR_OTHER").replace("%FACTION%", faction.getName()));
} else {
player.sendMessage(langConfig.getString("ERROR.NO_FACTIONS_FOUND").replace("%NAME%", name));
return;
}
} else {
faction = Profile.getByPlayer(player).getFaction();
if (faction == null) {
player.sendMessage(langConfig.getString("ERROR.NOT_IN_FACTION"));
return;
}
PlayerFaction playerFaction = (PlayerFaction) faction;
if (!playerFaction.getLeader().equals(player.getUniqueId()) && !playerFaction.getOfficers().contains(player.getUniqueId())) {
player.sendMessage(langConfig.getString("ERROR.NOT_OFFICER_OR_LEADER"));
return;
}
}
if (!(profile.isViewingMap())) {
if (!Claim.getNearbyClaimsAt(player.getLocation(), 64).isEmpty()) {
Bukkit.dispatchCommand(player, "f map");
}
}
player.getInventory().addItem(Faction.getWand());
player.sendMessage(langConfig.getString("FACTION_CLAIM.RECEIVED_WAND"));
new ClaimProfile(player, faction);
}
}

Some files were not shown because too many files have changed in this diff Show More